Laravel PayPal错误:购物车商品总金额与订单金额不符

时间:2020-10-05 09:44:07

标签: php laravel paypal paypal-sandbox

我在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

0 个答案:

没有答案