1
votes

I'm having troubles with the PayPal callback feature, i can't for the life of me get it to work at all. I have double checked the callback URL path, it's correct. When the user logs into paypal, it always just returns the default shipping rate. I'm just really not sure what i am missing here, if anyone can help out. Also, i have the callback timeout set to 6, though it seems it only takes about 3 - 4 seconds for it to fail and return the default shipping rate.

I've followed the documentation here https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECInstantUpdateAPI/ and applied it to my website. I've also made sure i am logged into sandbox too.

SetExpressCheckout params:

// SetExpressCheckout
$params = array (
    'METHOD' => 'SetExpressCheckout',
    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
    'VERSION' => $version,                // 124.0
    'USER' => $paypal_user,
    'PWD' => $paypal_password,
    'SIGNATURE' => $signature,
    'L_SHIPPINGOPTIONNAME0' => 'Flat',
    'L_SHIPPINGOPTIONLABEL0' => 'N/A',
    'L_SHIPPINGOPTIONAMOUNT0' => '6.99',
    'L_SHIPPINGOPTIONISDEFAULT0' => 'true',
    'PAYMENTREQUEST_0_INSURANCEOPTIONSOFFERED' => 'false',
    'PAYMENTREQUEST_0_SHIPPINGAMT' => $shipping_default,    // 6.99
    'PAYMENTREQUEST_0_ITEMAMT' => $cart_total,
    'PAYMENTREQUEST_0_AMT' => $cart_total + $shipping_default,
    'MAXAMT' => $cart_total + 30, // 30 is the total possible shipping amount
    'PAYMENTREQUEST_0_CURRENCYCODE' => $paypal_currency,  // AUD
    'RETURNURL' => $paypal_return,
    'CANCELURL' => $paypal_cancel,
    'CALLBACK' => 'HTTP://localhost/moes/php/paypal_callback_php.php',
    'CALLBACKTIMEOUT' => 6,
    'CALLBACKVERSION' => '61.0',
    'ALLOWNOTE' => 1,
    'PAYMENTREQUEST_0_INVNUM' => '123' /*$invoice_number*/,
    'PAYMENTREQUEST_0_TAXAMT' => $tax,    // 0.00
);

// List each product and add to exress check-out array
foreach ($paypal_products as $k => $product){
    $params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name'];
    $params["L_PAYMENTREQUEST_0_AMT$k"] = number_format($product['price'],2);
    $params["L_PAYMENTREQUEST_0_QTY$k"] = $product['qty'];
    $params["L_PAYMENTREQUEST_0_NUMBER$k"] = $product['code'];
    $params["L_PAYMENTREQUEST_0_DESC$k"] = '1';
    /* Optional shipping options to calculate shipping costs on callback
    Option weight (L_PAYMENTREQUEST_n_ITEMWEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMWEITHTUNITm)
    Option height (L_PAYMENTREQUEST_n_ITEMHEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMHEIGHTUNITm)
    Option length (L_PAYMENTREQUEST_n_ITEMLENGTHVALUEm, L_PAYMENTREQUEST_n_ITEMLENGTHUNITm)
    Option width (L_PAYMENTREQUEST_n_ITEMWIDTHVALUEm, L_PAYMENTREQUEST_n_ITEMWIDTHUNITm)*/
}

Callback script:

<?php

// Populate variables into local variables
$method = $_POST['METHOD'];
$version = $_POST['CALLBACKVERSION'];
$token = $_POST['TOKEN'];
$currencycode = $_POST['CURRENCYCODE'];
$localecode = $_POST['LOCALECODE'];
$street = $_POST['SHIPTOSTREET'];
$street2 = $_POST['SHIPTOSTREET2'];
$city = $_POST['SHIPTOCITY'];
$state = $_POST['SHIPTOSTATE'];
$country = $_POST['SHIPTOCOUNTRY'];
$zip = $_POST['SHIPTOZIP'];

// Setting shipping rate based on country [Test only]
if ($country == "US"){
    echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=10.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
} else {
    echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=30.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
}

?>

I'm guessing i missing something fundamental here, or i'm going about it completely the wrong way.

1
Any luck with callbacks?Buri
No, still can't work out the problem. I found this ccaples.com/index.php/misc/ipn-and-databases/… and followed everything there, still can't get it to work with their own sandbox account and script.Bezzzo
I found out this one and it helped me to get it working: stackoverflow.com/questions/24224725/…Buri
I finally figured my problem. I have posted an answer, though quite embarrassing.Bezzzo

1 Answers

0
votes

The solution to my problem was :

localhost/moes/php/paypal_callback_php.php

Obviously PayPal can't send a HTTP request to 'localhost'. My WAMP server is not configured to be accessible over the internet.