2checkout总是返回哈希不匹配

时间:2015-11-18 11:41:02

标签: php hash 2checkout

我正在使用2co沙箱来测试这样的销售情况。

<form method="post" action="https://sandbox.2checkout.com/checkout/purchase">
    <input type="hidden" value="myAccountNumber" name="sid">
    <input type="hidden" value="2CO" name="mode">
    <input type="hidden" value="product" name="li_0_type">
    <input type="hidden" value="Subscription" name="li_0_name">
    <input type="hidden" value="50.00" name="li_0_price">
    <input type="hidden" value="N" name="li_0_tangible">
    <input type="hidden" value="USD" name="currency_code">
    <input type="submit" value="Checkout" name="submit">
</form>

我有这个代码来处理retun代码

$hashSecretWord = 'testsecretword';  //copied from sandbox account
$hashSid = 'myAccountNumber'; 
$hashTotal = '50.00'; 
$hashOrder = $_REQUEST['order_number'];
echo $_REQUEST['key']."<br>";
echo $StringToHash = strtoupper(md5($hashSecretWord . $hashSid . $hashOrder . $hashTotal));

网址

http://www.domain.com/ipn.php?middle_initial=&li_0_name=Subscription&sid=mySameAccountNumber
&key=CBB0C2CA27FDAC5E3316161D829BAF66&state=test&email=test@test.com&li_0_type=product
&order_number=9093725652885&currency_code=USD&lang=en&invoice_id=9093725652894&li_0_price=50.00
&total=50.00&credit_card_processed=Y&zip=0000&li_0_quantity=1&cart_weight=0&fixed=Y
&submit=Checkout //then other buyer information

但它们完全不同,我得到哈希不匹配错误

2 个答案:

答案 0 :(得分:4)

在沙箱中你应该使用&#39; 1&#39;而不是像这样的$ hashOrder:

$StringToHash = strtoupper(md5($hashSecretWord . $hashSid . 1 . $hashTotal));

答案 1 :(得分:0)

我将TwocheckoutReturn.php类更改为与sendbox相关的@TooCool答案。

替换:

$hashOrder = $params['order_number'];

使用:

$hashOrder = self::$sandbox ? '1' : $params['order_number'];

编辑完课程后,您无需随时手动更改参数,只需在初始化过程中将沙箱设置为true,它就会自动生效。

Twocheckout::sandbox(true);