3

I'm using 2co sandbox to test sale like this.

<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>

And I have this code to process the retun code

$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));

the url

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

But they are totally different and I get hash mismatch error

AnkiiG
  • 3,468
  • 1
  • 17
  • 28
PHP User
  • 2,350
  • 6
  • 46
  • 87

2 Answers2

4

in sandbox you should use '1' instead of $hashOrder like this:

$StringToHash = strtoupper(md5($hashSecretWord . $hashSid . 1 . $hashTotal));
TooCooL
  • 20,356
  • 6
  • 30
  • 49
0

I change the TwocheckoutReturn.php class to work also on sendbox relativ to @TooCool answer.

Replace:

$hashOrder = $params['order_number'];

With:

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

After editing the class you will not need to change manually the parameter any time, just set the sandbox to true in the initializing process and it will automatically work.

Twocheckout::sandbox(true);
Roy Shoa
  • 3,117
  • 1
  • 37
  • 41