I'm using srmklive/laravel-paypal
package for my laravel
shopping cart. I want to add shipping cost to the sub total.But when I try to execute paypal setExpressCheckout
with checkout data, I got paypal api
error called "The totals of the cart item amounts do not match order amounts".
Here is my PaypalController
public function getExpressCheckout($id,$data,$total){
$orderData = json_decode($data,true);
$checkoutData = [
'items' => $orderData,
'return_url' => route('paypal.success', $id),
'cancel_url' => route('paypal.cancel'),
'invoice_id' => uniqid(),
'invoice_description' => " Order Description ",
];
$sub_total = 0;
foreach ($orderData as $item) {
$sub_total += $item['price'] * $item['qty'];
}
$checkoutData['shipping'] = 5; //example
$checkoutData['sub_total'] = $sub_total;
$checkoutData['total'] = $sub_total+ $checkoutData['shipping'];
//$checkoutData['shipping_discount'] = round((10 / 100) * $sub_total, 2);
$provider = new ExpressCheckout();
$response = $provider->setExpressCheckout($checkoutData);
dd($response, $orderData);
// return redirect($response['paypal_link']);
return response()->json(['message' => 'PayPal Link', 'link' => $response['paypal_link']], 200);
}
OrderItems array
array:3 [
0 => array:3 [
"name" => "sssss"
"price" => 1250
"qty" => "1"
]
1 => array:3 [
"name" => "Upuli Bhagyadf cgfd d"
"price" => 1062.5
"qty" => "1"
]
2 => array:3 [
"name" => "sssss dfd"
"price" => 1100
"qty" => "1"
]
]
I got below error
array:10 [
"TIMESTAMP" => "2020-10-05T09:30:49Z"
"CORRELATIONID" => "1c41cbb7e7447"
"ACK" => "Failure"
"VERSION" => "123"
"BUILD" => "54950761"
"L_ERRORCODE0" => "10413"
"L_SHORTMESSAGE0" => "Transaction refused because of an invalid argument. See additional error messages for details."
"L_LONGMESSAGE0" => "The totals of the cart item amounts do not match order amounts."
"L_SEVERITYCODE0" => "Error"
"paypal_link" => null
]
$checkoutData['shipping'] = 0;
or not exist
There is no error, Its working fine. So How I can add addional shipping cost to sub_total