问题描述
我在srmklive/laravel-paypal
购物车中使用laravel
包装。我想将运输成本添加到小计中。但是,当我尝试使用结帐数据执行贝宝setExpressCheckout
时,出现了paypal api
错误,称为”。“购物车项目总额不匹配订单金额” 。
这是我的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: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"
]
]
我遇到了错误
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;
或not exist
没有错误,工作正常。因此,我如何将额外的运输费用添加到sub_total
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)