【问题标题】:Laravel 6 PayPal GateWay subTotal,shipping ,tax not working properlyLaravel 6 PayPal Gateway subTotal,运费,税金无法正常工作
【发布时间】:2020-03-15 19:30:36
【问题描述】:

我正在使用 Laravel 6。我正在尝试将 PayPal 支付网关集成到我的项目中。 我正在关注 PayPal PHP Sdk 的示例源代码。
我有沙盒个人和买家帐户。
从 PayPal PHP Payment Example 复制代码时,支付和交易工作正常。 但是每当我尝试添加多个项目和 subTotal 时,它都会生成错误。


下面的代码: 来自 PayPal Sdk 示例的静态数据。

$item1 = new Item();
    $item1->setName('Ground Coffee 40 oz')
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setSku("22222") // Similar to `item_number` in Classic API
        ->setPrice(7.5);
    $item2 = new Item();
    $item2->setName('Granola bars')
        ->setCurrency('USD')
        ->setQuantity(5)
        ->setSku("852520") // Similar to `item_number` in Classic API
        ->setPrice(2);
    $iteamArr = [$item1,$item2];

    $itemList = new ItemList();
    $itemList->setItems($iteamArr);


默认示例付款详情如下:

以及试图使动态.
代码如下:

    $details = new Details();
    $details->setShipping(7.5)
        ->setTax(5.0)
        ->setSubtotal(17.50);


    $amount = new Amount();
    $amount->setCurrency("USD")
        ->setTotal(30)
        ->setDetails($details);

我的动态过程是:

    for($loop=1;$loop<3;$loop++){

        $item = new Item();
        $itemInfo[]=$item->setName('Dynamic Name '.$loop)
            ->setCurrency('USD')
            ->setQuantity(1)
            ->setSku(rand(1111,9999).$loop) // Similar to `item_number` in Classic API
            ->setPrice(2);

    }

根据我的动态代码,付款详情如下:

$details = new Details();
    $details->setShipping(7.5)
        ->setTax(5.0)
        ->setSubtotal(4);


    $amount = new Amount();
    $amount->setCurrency("USD")
        ->setTotal(16.5)
        ->setDetails($details);

在此之后我收到了来自 PayPal 的回复

Got Http response code 400 when accessing 
https://api.sandbox.paypal.com/v1/payments/payment.

注意:当我从那里的文档中克隆 PayPal 项目信息时,它会成功运行。

【问题讨论】:

    标签: paypal paypal-sandbox laravel-6.2


    【解决方案1】:

    我觉得问题应该是-&gt;setTotal(16.5)

    这条线也应该是动态的,因为总价在结帐车的基础上是动态的

    我将以我的 paypal PaymentController 中的部分代码为例:

    $totalPayment = ($request->get('actual_participants') * $trip->price);        
    
            $payer = new Payer();
            $payer->setPaymentMethod('paypal');
    
            $item = new Item();
    
            $item->setName($trip->title) /** item name **/
                ->setCurrency($trip->currency->currency_type)
                ->setQuantity('1')
                ->setPrice($totalPayment); /** unit price **/
    
            $itemList = new ItemList();
            $itemList->setItems(array($item));
    
            $amount = new Amount();
            $amount->setCurrency($trip->currency->currency_type)
                ->setTotal($totalPayment);
    

    11 个月后,我认为您已经解决了问题,但我祝其他开发人员好运,因为我了解 paypal 集成的困难 :)

    【讨论】:

    • 是的。它解决了。顺便说一句,非常感谢您的贡献。
    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 2013-02-11
    • 2011-07-15
    • 2013-10-19
    • 1970-01-01
    • 2013-11-14
    相关资源
    最近更新 更多