Update:
Grr… I found the issue. Seems like PAYMENTREQUEST_0_ITEMAMT must be incremented by the amount being added.
This isn’t part of the gift certificate hook so I’ve no idea why the GC hook doesn’t have to make this adjustment.
If I modified my code below to add:
if( !empty($order_data[‘PAYMENTREQUEST_0_ITEMAMT’]) )Then it seems to go to paypal without error…
$order_data[‘PAYMENTREQUEST_0_ITEMAMT’] += $order_data[‘L_PAYMENTREQUEST_0_AMT’ . $product_index];
/Update
I’m using this hook to add an additional fee in cs-cart V4.2.1.
The resulting order_data at the end of the hook is:
order_data:ArrayI am using exactly the same code to generate the NAME1, NUMBER1, etc. as is used by the gift_certificate addon.
(
[L_PAYMENTREQUEST_0_NAME0] => Blessed - Floral Design V-Neck
[L_PAYMENTREQUEST_0_NUMBER0] => SG497
[L_PAYMENTREQUEST_0_DESC0] => Size: Small
[L_PAYMENTREQUEST_0_QTY0] => 1
[L_PAYMENTREQUEST_0_AMT0] => 21.00
[PAYMENTREQUEST_0_ITEMAMT] => 21
[PAYMENTREQUEST_0_TAXAMT] => 0
[PAYMENTREQUEST_0_SHIPPINGAMT] => 5.00
[PAYMENTREQUEST_0_AMT] => 36.00
[L_PAYMENTREQUEST_0_NAME1] => Charity donation
[L_PAYMENTREQUEST_0_NUMBER1] => Charity
[L_PAYMENTREQUEST_0_DESC1] => Charity donation, Test Charity
[L_PAYMENTREQUEST_0_QTY1] => 1
[L_PAYMENTREQUEST_0_AMT1] => 10.00
)
However I still get an error back from paypal stating:
Error 10413 Transaction refused because of an invalid argument. See additional error messages for details.: The totals of the cart item amounts do not match order amounts.It all sure looks correct to me. Can anyone see what might be wrong?
The GC hook code is:
function fn_gift_certificates_paypal_express_get_order_data(&$data, &$order_data, &$product_index)And mine is:
{
if (!empty($data[‘gift_certificates’])) {
foreach ($data[‘gift_certificates’] as $cart_id => $gift_certificate) {
$order_data[‘L_PAYMENTREQUEST_0_NAME’ . $product_index] = __(‘gift_certificate’);
$order_data[‘L_PAYMENTREQUEST_0_NUMBER’ . $product_index] = $cart_id;
$order_data[‘L_PAYMENTREQUEST_0_DESC’ . $product_index] = fn_paypal_express_get_certificate_data($gift_certificate);
$order_data[‘L_PAYMENTREQUEST_0_QTY’ . $product_index] = 1;
$order_data[‘L_PAYMENTREQUEST_0_AMT’ . $product_index] = $gift_certificate[‘amount’];$product_index++; } }
}
function fn_coch_paypal_express_get_order_data(&$data, &$order_data, &$product_index) {
if( !isset($data[‘coch_amount’]) ) {
// Do this the long way just to be sure
$coch_amount = coch_get_order_data($data[‘order_id’]);
if( $coch_amount )
$data[‘coch_amount’] = $coch_amount;
}
if( !empty($data[‘coch_amount’])) {
// Build the paypal express item for charity amount.
$coch_config = coch_config();
$order_data[‘L_PAYMENTREQUEST_0_NAME’ . $product_index] = __(“coch_charity_donation”);
$order_data[‘L_PAYMENTREQUEST_0_NUMBER’ . $product_index] = “Charity”;
// Note: fn_paypal_substr() not used in 4.2.1
$order_data[‘L_PAYMENTREQUEST_0_DESC’ . $product_index] = (“coch_charity_donation”) . ", ". $coch_config[‘name’]; //fn_paypal_substr((“coch_charity_donation”) . ", ". $coch_config[‘name’]);
$order_data[‘L_PAYMENTREQUEST_0_QTY’ . $product_index] = 1;
$order_data[‘L_PAYMENTREQUEST_0_AMT’ . $product_index] = fn_format_price($data[‘coch_amount’]);$product_index++; }
}