【问题标题】:PayPal PHP API quatity >1PayPal PHP API 数量 >1
【发布时间】:2018-07-28 19:54:50
【问题描述】:

我在使用 PayPal PHP API 时遇到了一个恼人的错误。

如果我对每个 Item 对象使用 Quantity = 1,它就可以正常工作。但如果我有不止一个,我总是会得到一个总结错误。代码是用瑞典语写的,可能有点难以理解,我在这里添加项目:

    $result=mysqli_query($connection,$query);
    if (mysqli_num_rows($result) > 0) {
        $i=0;              
        while($row=mysqli_fetch_array($result)){
              $bestallningrad[] = new Item();
              $bestallningrad[$i]->setName($row['Typ'])
                                 ->setDescription($row['Skick'])
                                 ->setCurrency('SEK')
                                 ->setQuantity($row['Antal'])
                                 ->setPrice($row['Radpris']);
              $i = $i + 1;
        }
    } else {
      mysqli_close($connection);
      $fel=2;
      echo "<SCRIPT>";
           echo "window.location.href=\"varukorg.php?Fel=$fel\";",PHP_EOL;
      echo "</SCRIPT>";
    }

    $varulista = new ItemList();
    $varulista->setItems($bestallningrad);

这里我创建了事务对象:

    $transaktioner = new Transaction();
    $transaktioner->setAmount($belopp)
                  ->setItemList($varulista)
                  ->setDescription("Beställning")
                  ->setInvoiceNumber($bid);

当我有 Quatity >1 我得到以下错误:

    JSON: {
           "intent": "sale","payer": {
           "payment_method": "paypal"
           },
           "redirect_urls": {
           "return_url": "https://teltec.se/teltecsvar.php?lyckad=true",
           "cancel_url": "https://teltec.se/varukorg.php?Fel=5"
           },
           "transactions": [
                            {
                             "amount": {
                                        "currency": "SEK",
                                        "total": "330",
                                        "details": {
                                        "shipping": "8",
                                        "tax": "2",
                                        "subtotal": "320"
                                        }
                            },
                             "item_list": {
                                           "items": [
                                                     {
                                                      "name": "EF 80",
                                                      "description": "Begagnat",
                                                      "currency": "SEK",
                                                      "quantity": "2",
                                                      "price": "320"
               }
           ]
       },
       "description": "Best\u00e4llning",
       "invoice_number": "37"
      }
     ]
    }

邪能:400 Beskrivning: {"name":"VALIDATION_ERROR","details":[{"field":"transactions[0]","issue":"项目金额必须加到指定金额小计(如果未指定金额详细信息,则为总计)"}],"message":"无效请求 - 查看详情","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"f771187267060"}

【问题讨论】:

  • 我通过将数据库中包含多个项目的一行拆分为多个 Item 对象来临时解决了这个问题。在 PayPal 方面看起来很奇怪,但它可以工作。

标签: paypal


【解决方案1】:

我认为您需要指定每件商品的价格(“价格”:“160”)。 例如。价格 * 数量应该等于小计。

【讨论】:

    猜你喜欢
    • 2013-08-08
    • 1970-01-01
    • 2011-12-04
    • 2015-09-20
    • 2015-11-18
    • 2014-04-29
    • 2018-02-17
    • 2012-11-21
    • 2017-03-23
    相关资源
    最近更新 更多