2014-02-08 7 views
0

Я пытаюсь интегрировать sagepay с phprunner, используя 2.23 и метод формы. Шифрование не работает по какой-то причине - может кто-нибудь помочь, как я уже вытащил каждую прядь волос у меня было :(Интеграция sagepay 2.23 с php

Я uising следующий код

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="[email protected]"; 
$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(); 

}

+0

Что значит «не работает» означает? Что не работает? Есть ли сообщение об ошибке? Что происходит, что вам не нравится? Пользователи здесь не собираются проходить через гору кода, чтобы понять, что вы имеете в виду. –

ответ

0

Просто несколько простых вопросов ...

  • вы используете XOR? 2,23 протокол поддерживает XOR
  • Проверьте валюту. вы используете правильный валюта, связанная с учетной записью Sage Pay ? Убедитесь, что вы используете правильный корпус согласно нашей документации протокола.
  • Вы используете правильный ключ шифрования? Тест и Live имеют разные пароли шифрования
  • Какая ошибка вы получаете?
0

Я думаю, вы должны смотреть на новых веб-сервисов шалфей обеспечивают Я не уверен, если это замена только дополнение к SDO https://sdata.sage.com/

Смежные вопросы