【问题标题】:Sending purchased items details to the PayPal?将购买的商品详细信息发送到 PayPal?
【发布时间】:2019-04-29 05:16:55
【问题描述】:

我需要发送购买的物品清单以及正在使用 Paypal 完成付款的物品,以便买家和供应商可以看到购买或出售了哪些产品。这是我为同样做的事情的 sn-p,遵循 Github code of PayPalCheckout,但我每次都得到。这是我的代码 sn-p

private PayPalPayment prepareFinalCart() {

    List<PayPalItem> productsInCart = new ArrayList<>();
    double price;


    for (Program program : mPrograms) {
        if (null != program.programPrices.get(program.selectedPriceIndex).priceAfterDiscount) {
            price = program.programPrices.get(program.selectedPriceIndex).priceAfterDiscount;
        } else {
            price = program.programPrices.get(program.selectedPriceIndex).price;
        }
        PayPalItem item = new PayPalItem(program.type, 1, //Quantity
                new BigDecimal(price), //price
                Config.DEFAULT_CURRENCY, // currency
                 + String.valueOf(program.id)); // stock keeping unit

        productsInCart.add(item);
    }


    if (App.sCouponDetails != null) {
        App.sCouponDetails.calculateDiscount(mFinalCost);
    }


    PayPalItem[] items = new PayPalItem[productsInCart.size()];
    items = productsInCart.toArray(items);

    // Total amount
    BigDecimal subtotal = new BigDecimal(mFinalCost);

    // If you have shipping cost, add it here
    BigDecimal shipping = new BigDecimal("0.0");

    // If you have tax, add it here
    BigDecimal tax = new BigDecimal("0.0");

    PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);

    BigDecimal amount = subtotal.add(shipping).add(tax);


    // Getting Purchased Programs type
    StringBuilder programsType = new StringBuilder();
    for (int i = 0; i < mPrograms.size(); i++) {
        if (i == mPrograms.size() - 1) {
            programsType.append(mPrograms.get(i).type);
        } else {
            programsType.append(mPrograms.get(i).type).append(",");
        }
    }

    PayPalPayment payment = new PayPalPayment(amount, Config.DEFAULT_CURRENCY, "Total Amount: "/*programsType.toString()*/, Config.PAYMENT_INTENT);


    payment.items(items).paymentDetails(paymentDetails);


    // Custom field like invoice_number etc.,
    //payment.custom("This is text that will be associated with the payment that the app can use.");

    return payment;
}

请提出这里有什么问题?

【问题讨论】:

  • 需要查看从该代码生成并发送到 PayPal 的原始请求。
  • 这些是在 PayPalPayment 中添加的项目。 PayPalItem(name=Chinx Tier, quantity=1, price=79.950000, currency=USD, sku-2086)
  • 好的,但这不是我要求的。我们需要准确了解发送到 PayPal 的内容。也许 PayPalItem 函数对数据做了一些有趣的事情。也许其他东西正在以某种方式过滤数据,并且请求正在其中获取 PayPal 不喜欢的时髦数据。解决此问题的第一步是准确查看我们发送给 PayPal 的内容。不是我们认为我们发送到 PayPal 的内容。如果原始请求看起来不错,那么我们可以进行下一步,但这是第一步。
  • 这是 PayPalPayment 的 Json 字符串,然后将其发送到 Paypal 的 PaymentActivity。 {"b":28.8629,"c":"USD","d":"Ching Flix,Syncers Flix","f":{"b":28.8629,"c":0.0,"d":0.0},"g":"sale","h":[{"b":"Ching Flix","c":1,"d":12,"e":"USD","f":"sku-6167"},{"b":"Syncers Flix","c":1,"d":20.0700,"e":"USD","f":"sku-6498"}],"i":false}
  • 这不是 PayPal 接受的格式。你有 a/b/c/d 作为参数名称..??

标签: java android paypal paypal-sandbox


【解决方案1】:

实际上那些 b/c/d/f 等参数来自 PayPalPayment 类。我刚刚给出了它的 Json 格式。 这是 PayPalPayment 类的样子-

【讨论】:

  • error-` 请求失败,服务器响应:{"name":"VALIDATION_ERROR","details":[{"field":"transactions.item_list.items","issue":"Currency金额必须是非负数,可以选择包含精确的 2 位小数,用 '.' 分隔,可选的千位分隔符 ',',限制为小数点前 7 位,货币是有效的 ISO 货币代码"}]," message":"无效请求 - 查看详细信息","information_link":"developer.paypal.com/docs/api/payments/…"}`
【解决方案2】:

解决了。上面的代码是正确的,价格值超过小数点后 7 位,给出错误代码 400 (VALIDATION_ERROR)。不过现在处理好了。

【讨论】:

    【解决方案3】:

    所以你提供的 JSON 字符串是:

    {
       "b":28.8629,
       "c":"USD",
       "d":"Ching Flix,Syncers Flix",
       "f":{
          "b":28.8629,
          "c":0.0,
          "d":0.0
       },
       "g":"sale",
       "h":[
          {
             "b":"Ching Flix",
             "c":1,
             "d":12,
             "e":"USD",
             "f":"sku-6167"
          },
          {
             "b":"Syncers Flix",
             "c":1,
             "d":20.0700,
             "e":"USD",
             "f":"sku-6498"
          }
       ],
       "i":false
    }
    

    这不是 PayPal 接受的格式。这些 b/c/d/f/等在哪里?参数名称来自哪里?

    您需要修正该请求,使其与 PayPal 的格式相匹配。

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 2018-09-14
      • 2013-10-14
      • 2021-09-12
      • 2011-06-11
      • 2014-11-19
      • 2018-06-09
      • 1970-01-01
      • 2018-12-17
      相关资源
      最近更新 更多