1

我正在设置一个简单的 PHP 表单以使用表单集成将交易发送到 sagepay,cryptkey 设置如下:

$PAYMENT_CRYPT = 
"VendorTxCode=website
&Amount=$total
&Currency=GBP
&Description=Ticket
&SuccessURL=EDITED-OUT/registered-thanks
&FailureURL=EDITED-OUT/registered-fail
&BillingSurname=$surname
&BillingFirstnames=$firstname
&BillingAddress1=$address1
&BillingCity=$city
&BillingPostCode=$postcode
&BillingCountry=UK
&DeliverySurname=$surname
&DeliveryFirstnames=$firstname
&DeliverAddress1=$address1
&DeliveryCity=$city
&DeliveryPostCode=$postcode
&DeliveryCountry=UK
&AllowGiftAid=1"

形式:

<form action="https://live.sagepay.com/gateway/service/vspform-register.vsp" method="POST" id="SagePayForm" name="SagePayForm">
    <input type="hidden" name="VPSProtocol" value="2.23" />
    <input type="hidden" name="TxType" value="PAYMENT" />
    <input type="hidden" name="Vendor" value="MYVENDORID" />
    <input type="hidden" name="Crypt" value="<?= $PAYMENT_CRYPT ?>">    
    <input type="image" src="images/buynow-sagepay.png" />
</form>

Sage 给我一个错误如下,这是没有意义的,因为货币字段肯定是被传递的。

此事务尝试失败。我们无法将您重定向回您购买的网上商店。下面给出了失败的详细信息。

状态:畸形

状态详细信息:3045:缺少货币字段。

任何帮助将非常感激!

瑞克

4

1 回答 1

2

您似乎根本没有加密您的数据。以下内容将帮助您检查并在代码中包含相关功能。

<?php
function pkcs5_pad($text, $blocksize)
{
    $pad = $blocksize - (strlen($text) % $blocksize);
    return $text . str_repeat(chr($pad), $pad);
}

function encryptFieldData($input)
{
    $key = "use your SagePAY encryption key here";
    $iv = $key;

    $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, "");
    if (mcrypt_generic_init($cipher, $key, $iv) != -1)
    {
        $cipherText = mcrypt_generic($cipher,$input );
        mcrypt_generic_deinit($cipher);

        $enc = bin2hex($cipherText);
    }
    return $enc;
}
$str = "Currency=GBP";
$datapadded = pkcs5_pad($str,16);
$cryptpadded = "@" . encryptFieldData($datapadded);
?>
<html>
    <form name="pp_form" action="SagePay test url" method="post">
    <input name="VPSProtocol" type="hidden" value=3.00 />
    <input name="TxType" type="hidden" value=PAYMENT />
    <input name="Vendor" type="hidden" value="YOUR SAGEPAY ACCOUNT NAME HERE"     />
    <input name="Crypt" type="hidden" value=<?php echo $cryptpadded;?> />
    <p>Click here to submit 
        <input type="submit" value="here">
    </p>
    </form>
</html>

你可以在这里看到更完整的解释SagePay form integration with PHP

于 2013-12-28T10:04:59.997 回答