dquoj04882 2015-04-30 17:16
浏览 36

PayPal说Total不匹配,但确实如此?

So, the response I'm getting back from PayPal is that my totals don't match. But if you look at the json response, they do...

    {
"intent": "sale",
"payer": {
    "payment_method": "paypal"
},
"redirect_urls": {
    "return_url": "edited_out",
    "cancel_url": "edited_out"
},
"transactions": [
    {
        "amount": {
            "currency": "USD",
            "total": "18.28"
        },
        "item_list": {
            "items": [
                {
                    "quantity": 2,
                    "name": "This item is a test for shipping calculation",
                    "price": "18.28",
                    "currency": "USD"
                }
            ]
        },
        "description": "Payment description",
        "invoice_number": "554261363c260"
    }
]}{"name":"VALIDATION_ERROR","details":[{"field":"transactions","issue":"Item amount must add up to specified amount subtotal (or total if amount details not specified)"}]

My Code:

        $payer = new Payer();
    $payer->setPaymentMethod("paypal");

    // ### Itemized information
    // (Optional) Lets you specify item wise
    // information
    $total_shipping=0; 
    foreach(Cart::content() as $row)
    {
        foreach(Inventory::where('id', '=', $row->id)->get() as $product)
        {       

            foreach(Inventory::where( 'id', '=', $row->id)->get() as $product) 
            { 
                $total_shipping += $product->shipping; 
                //echo $total_shipping; } echo $total_shipping;
            }
        }
    }

    $i = 0;
    $myshipping = 0;
    foreach(Cart::content() as $row)
    {
        foreach(Inventory::where('id', '=', $row->id)->get() as $product)
        {   
            $myshipping += $product->shipping;

            $items[$i] = new Item();
            $items[$i]->setQuantity($row->qty)
                ->setName($row->name)
                ->setPrice(($row->price * $row->qty) + (($row->price * $row->qty) * 0.07) + $product->shipping)
                ->setCurrency('USD'); 

            $i++;
        }
    }

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

    $amount = new Amount();
    $amount->setCurrency("USD")
        ->setTotal(Cart::total() + (Cart::total() * 0.07) + $total_shipping);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setItemList($itemList)
        ->setDescription("Payment description")
        ->setInvoiceNumber(uniqid());

    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl("edited_out")
        ->setCancelUrl("edited_out");

    $payment = new Payment();
    $payment->setIntent("sale")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));

    $request = clone $payment;

    try {
        $payment->create($apiContext);
    } catch (Exception $ex) {
        //ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
        //var_dump($items);
        echo "<pre>" . $payment;
        echo $ex->getData();
        exit(1);
    }

    $approvalUrl = $payment->getApprovalLink();
    return Redirect::to($approvalUrl);

Any ideas on how I can fix this so my payment is created? If it helps, the miscalculation doesn't happen when the quantity of an item is 1. Or when their are multiple DIFFERENT items. The error only occurs when the quantity is greater than 1.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度