将sagepay 2.23与php集成

时间:2014-02-08 02:36:09

标签: forms sagepay

我正在尝试使用2.23和表单方法将sagepay与phprunner集成。加密由于某种原因不起作用 - 任何人都可以提供帮助,因为我现在已经拔掉了我的每一根头发:(

我正在使用以下代码

include("includes.php");

    if ($values["Payment_Method"]=="Credit Card" || $values["Payment_Method"]=="Debit Card" AND    $values["total_outstanding"]>="5"){
$strCustomerEMail      = $_SESSION["cust_email"];
$strBillingFirstnames  = $values["First_Name"];
$strBillingSurname     = $values["Last_Name"];
$strBillingAddress1    = $values["Address"];
$strBillingAddress2    = $values["Address2"];
$strBillingCity        = $values["Address3"];
$strBillingPostCode    = $values["Postcode"];
$strBillingCountry     = "GB";
   "&SurchargeXML=".$charges;
//$strBillingState       = $values["strBillingState"];
$strBillingPhone       = $values["Telephone"];
$bIsDeliverySame       = true;
$strDeliveryFirstnames = $values["First_Name"];
$strDeliverySurname    = $values["Last_Name"];
$strDeliveryAddress1   = $values["Address"];
$strDeliveryAddress2   = $values["Address2"];
$strDeliveryCity       = $values["Address3"];
$strDeliveryPostCode   = $values["Postcode"];
$strDeliveryCountry    = "GB";
//$strDeliveryState      = $values["strDeliveryState"];
    $strTimeStamp = date("ymdHis", time());
$intRandNum = rand(0,32000)*rand(0,32000);
  $strCode = "FPP-105-"; 
$strVendorTxCode= $strCode . "-" . $strTimeStamp . "-" . $intRandNum;

/** Now to calculate the transaction total based on basket contents. **/
$strBasket="";
$iBasketItems=0;
$sngTotal=0;
if ($values['Cost1']){
$iBasketItems++;
$sngTotal+=$values['Cost1'];
}
else
$values['Cost1'] = 0;

if ($values['Cost2']){
$iBasketItems++;
$sngTotal+=$values['Cost2'];
}
else
$values['Cost2'] = 0;

if ($values['Cost3']){
$iBasketItems++;
$sngTotal+=$values['Cost3'];
}
else
$values['Cost3'] = 0;

if ($values['Cost4']){
$iBasketItems++;
$sngTotal+=$values['Cost4'];
}
else
$values['Cost4'] = 0;

    if ($values['card_charge']){
$iBasketItems++;
$sngTotal+=$values['card_charge'];
}
else
$values['card_charge'] = 0;

$strBasket.=$iBasketItems ;
if ($values['Cost1'])
$strBasket.= ":First Permit                 Charge:1:".$values['Cost1'].":0:".$values['Cost1'].":".$values['Cost1']."";
if ($values['Cost2'])
$strBasket.= ":Second Permit Charge:1:".$values['Cost2'].":0:".$values['Cost2'].":".$values['Cost2']."";
if ($values['Cost3'])
$strBasket.= ":Visitors permit Charge :1:".$values['Cost3'].":0:".$values['Cost3'].":".$values['Cost3']."";
if ($values['Cost4'])
$strBasket.= ":Scratch Cards Charge:1:".$values['Cost4'].":0:".$values['Cost4'].":".$values['Cost4']."";
if ($values['card_charge'])
$strBasket.= ":Cards Charge:1:".$values['card_charge'].":0:".$values['card_charge'].":".$values['card_charge']."";

// Now to build the Form crypt field.  For more details see the Form Protocol 2.23 
$strPost="VendorTxCode=" . $strVendorTxCode; /** As generated above **/

// Optional: If you are a Sage Pay Partner and wish to flag the transactions with your unique partner id, it should be passed here
if (strlen($strPartnerID) > 0)
     $strPost=$strPost . "&ReferrerID=" . $strPartnerID;

$strPost=$strPost . "&Amount=" . number_format($sngTotal,2); // Formatted to 2 decimal places with leading digit
$strPost=$strPost . "&Currency=" . $strCurrency;
// Up to 100 chars of free format description
$strPost=$strPost . "&Description=Permits from " . $strVendorName;

/* The SuccessURL is the page to which Form returns the customer if the transaction is successful 
** You can change this for each transaction, perhaps passing a session ID or state flag if you wish */
$strPost=$strPost . "&SuccessURL=" . $strYourSiteFQDN . $strVirtualDir . "/orderSuccessful.php";

/* The FailureURL is the page to which Form returns the customer if the transaction is unsuccessful
** You can change this for each transaction, perhaps passing a session ID or state flag if you wish */
$strPost=$strPost . "&FailureURL=" . $strYourSiteFQDN . $strVirtualDir . "/orderFailed.php";

// This is an Optional setting. Here we are just using the Billing names given.
$strPost=$strPost . "&CustomerName=" . $strBillingFirstnames . " " . $strBillingSurname;

/* Email settings:
** Flag 'SendEMail' is an Optional setting. 
** 0 = Do not send either customer or vendor e-mails, 
** 1 = Send customer and vendor e-mails if address(es) are provided(DEFAULT). 
** 2 = Send Vendor Email but not Customer Email. If you do not supply this field, 1 is assumed and e-mails are sent if addresses are provided. **/
if ($bSendEMail == 0)
     $strPost=$strPost . "&SendEMail=0";
else {

     if ($bSendEMail == 1) {
        $strPost=$strPost . "&SendEMail=1";
     } else {
        $strPost=$strPost . "&SendEMail=2";
     }

// Billing Details:
$strPost=$strPost . "&BillingFirstnames=" . $strBillingFirstnames;
$strPost=$strPost . "&BillingSurname=" . $strBillingSurname;
$strPost=$strPost . "&BillingAddress1=" . $strBillingAddress1;
if (strlen($strBillingAddress2) > 0) $strPost=$strPost . "&BillingAddress2=" .    $strBillingAddress2;
$strPost=$strPost . "&BillingCity=" . $strBillingCity;
$strPost=$strPost . "&BillingPostCode=" . $strBillingPostCode;
$strPost=$strPost . "&BillingCountry=" . $strBillingCountry;
if (strlen($strBillingState) > 0) $strPost=$strPost . "&BillingState=" . $strBillingState;
if (strlen($strBillingPhone) > 0) $strPost=$strPost . "&BillingPhone=" . $strBillingPhone;

// Delivery Details:
$strPost=$strPost . "&DeliveryFirstnames=" . $strDeliveryFirstnames;
$strPost=$strPost . "&DeliverySurname=" . $strDeliverySurname;
$strPost=$strPost . "&DeliveryAddress1=" . $strDeliveryAddress1;
if (strlen($strDeliveryAddress2) > 0) $strPost=$strPost . "&DeliveryAddress2=" . $strDeliveryAddress2;
$strPost=$strPost . "&DeliveryCity=" . $strDeliveryCity;
$strPost=$strPost . "&DeliveryPostCode=" . $strDeliveryPostCode;
$strPost=$strPost . "&DeliveryCountry=" . $strDeliveryCountry;
if (strlen($strDeliveryState) > 0) $strPost=$strPost . "&DeliveryState=" . $strDeliveryState;
if (strlen($strDeliveryPhone) > 0) $strPost=$strPost . "&DeliveryPhone=" . $strDeliveryPhone;

$strPost=$strPost . "&Basket=" . $strBasket; // As created above 

// For charities registered for Gift Aid, set to 1 to display the Gift Aid check box on the payment pages
$strPost=$strPost . "&AllowGiftAid=0";

/* Allow fine control over AVS/CV2 checks and rules by changing this value. 0 is Default 
** It can be changed dynamically, per transaction, if you wish.  See the Server Protocol document */
if ($strTransactionType!=="AUTHENTICATE")
    $strPost=$strPost . "&ApplyAVSCV2=0";

/* Allow fine control over 3D-Secure checks and rules by changing this value. 0 is Default 
** It can be changed dynamically, per transaction, if you wish.  See the Form Protocol document */
$strPost=$strPost . "&Apply3DSecure=0";

//surcharges
$charges = "<surcharges>";
$charges.="<surcharge><paymentType>VISA</paymentType><fixed>3.00</fixed></surcharge>";
$charges.="<surcharge><paymentType>MAESTRO</paymentType><fixed>1.00</fixed></surcharge>";
$charges.="<surcharge><paymentType>MC</paymentType><fixed>3.00</fixed></surcharge>";
$charges.= "</surcharges>";

$strPost=$strPost . "&SurchargeXML=".$charges;

// Encrypt the plaintext string for inclusion in the hidden field
$strCrypt = encryptAndEncode($strPost);
//save $strVendorTxCode in the database
CustomQuery("update data set strVendorTxCode='".$strVendorTxCode."' where ID=".$keys["ID"]);

$_SESSION["strCrypt"] = $strCrypt;
header("Location: Application_view.php?editid1=".$keys["ID"]."&process=1");
$pageObject->setProxyValue("strCrypt", $strCrypt);
exit();
/*
$form = '<script>document.forms.SagePayForm.Crypt.value="'.$strCrypt.'";
document.forms.SagePayForm.submit();';

'
                    <form action="'.$strPurchaseURL.'" method="POST"    id="SagePayForm" name="SagePayForm"> 
                    <input type="hidden" name="navigate" value="" />
                    <input type="hidden" name="VPSProtocol" value="'.$strProtocol.'">
                    <input type="hidden" name="TxType" value="'.$strTransactionType.'">
                    <input type="hidden" name="Vendor" value="'. $strVendorName.'">
                    <input type="hidden" name="Crypt" value="'.$strCrypt.'">
                    <a href="javascript:SagePayForm.submit();" title="Proceed to Form registration">
<img src="images/proceed.gif" alt="Proceed to Form registration" border="0"></a>
                    </form>';
*/
      }
     if ($values["Payment_Method"]=="Cheque" ){

$email=$_SESSION["cust_email"];
$from="admin@test.com";
$msg="";
$subject="Payment by cheque";

/** Now to calculate the transaction total based on basket contents. **/
$strBasket="";
$iBasketItems=0;
$sngTotal=0;
if ($values['Cost1']){
$iBasketItems++;
$sngTotal+=$values['Cost1'];
}
else
$values['Cost1'] = 0;

if ($values['Cost2']){
$iBasketItems++;
$sngTotal+=$values['Cost2'];
}
else
$values['Cost2'] = 0;

if ($values['Cost3']){
$iBasketItems++;
$sngTotal+=$values['Cost3'];
}
else
$values['Cost3'] = 0;

if ($values['Cost4']){
$iBasketItems++;
$sngTotal+=$values['Cost4'];
}
else
$values['Cost4'] = 0;

$msg.= "Name: ".$values["First_Name"]." ".$values["Last_Name"]."\r\n";
$msg.= "You've selected ".$iBasketItems ." items: "."\r\n";
$msg.= "Total to pay: ".    $sngTotal."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

header("Location: Application_view.php?editid1=".$keys["ID"]."");
exit();

}

2 个答案:

答案 0 :(得分:0)

只是一些简单的问题......

  • 你在使用XOR吗? 2.23协议支持XOR
  • 检查货币。您使用的是与Sage Pay相关联的正确货币吗? 帐户?根据我们的协议文档
  • 确保您使用的是正确的外壳
  • 您使用的是正确的加密密钥吗? Test and Live有不同的加密密码
  • 你得到的错误是什么?

答案 1 :(得分:0)

我认为你需要查看新的webservices sage,我不确定这些是否只是SDO的一个补充https://sdata.sage.com/