I am trying to work with the PayPal NVP API for In-Context Express Checkout. I need to use Instant Update feedback, because delivery is calculated by geographic region, and the PayPal Express Checkout button is used as a quick check before we receive any information about the client.
The problem is that it doesn't seem to work or call the callback url, which is never the case. To start payment, I use the following:
$currencyCode = $this->currency_model->code();
$cost = $this->basket_model->get_cart_total(false, true, false, false);
$shippingCost = number_format($this->basket_model->cart_calc_delivery(), 2);
$finalCost = number_format(((float) $cost) + ((float) $shippingCost), 2);
$transaction = [
'USER' => $username,
'PWD' => $password,
'SIGNATURE' => $signature,
'VERSION' => '124.0',
'METHOD' => 'SetExpressCheckout',
'RETURNURL' => 'https://'.$siteUrl.'/checkout/pp/process/',
'CANCELURL' => 'https://'.$siteUrl.'/basket/',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_ITEMAMT' => $cost,
'MAXAMT' => number_format(((float) $finalCost) + 5, 2),
'PAYMENTREQUEST_0_SHIPPINGAMT' => $shippingCost,
'PAYMENTREQUEST_0_AMT' => $finalCost,
'PAYMENTREQUEST_0_CURRENCYCODE' => $currencyCode,
'CALLBACK' => 'https://'.$siteUrl.'/checkout/pp/options/',
'CALLBACKTIMEOUT' => '3',
'L_SHIPPINGOPTIONISDEFAULT0' => 'true',
'L_SHIPPINGOPTIONNAME0' => 'Shipping1',
'L_SHIPPINGOPTIONAMOUNT0' => $shippingCost,
'L_SHIPPINGOPTIONISDEFAULT1' => 'false',
'L_SHIPPINGOPTIONNAME1' => 'Shipping2',
'L_SHIPPINGOPTIONAMOUNT1' => number_format(((float) $shippingCost) + 5, 2),
];
$itemIndex = 0;
foreach ($_SESSION['basket'] as $key => $item) {
$transaction['L_PAYMENTREQUEST_0_NAME'.$itemIndex] = $item->name;
$transaction['L_PAYMENTREQUEST_0_AMT'.$itemIndex] = number_format($item->unit_price, 2);
$transaction['L_PAYMENTREQUEST_0_QTY'.$itemIndex] = $item->quantity;
$transaction['L_PAYMENTREQUEST_0_TAXAMT'.$itemIndex] = '0.00';
$transaction['L_PAYMENTREQUEST_0_NUMBER'.$itemIndex] = $item->sku;
$itemIndex++;
}
And the answer in the callback is this:
echo 'METHOD=CallbackResponse'.
'&OFFERINSURANCEOPTION=false'.
'&L_SHIPPINGOPTIONNAME0=Shipping'.
'&L_SHIPPINGOPTIONAMOUNT0=20.00'.
'&L_TAXAMT0=0'.
'&L_SHIPPINGOPTIONISDEFAULT0=true';
Just check if it works. Despite the fact that I offer two methods of initial delivery, the selector does not allow the client to choose a delivery method. And the callback url is never called, and the delivery is never updated.