我设置了一个简单的PHP表单,使用表单集成将事务发送到sagepay,密码设置如下:
$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给我一个错误如下,这是没有意义的,因为货币字段绝对是通过的。
此交易尝试失败。我们无法将您重定向回您购买的网上商店。失败的细节如下。
状态:MALFORMED
状态明细:3045:缺少货币字段。
非常感谢任何帮助!
瑞克
答案 0 :(得分: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>
看到更全面的解释