要将购买的商品详细信息发送到PayPal?

时间:2018-11-27 12:49:27

标签: java android paypal paypal-sandbox

我需要发送购买的物品清单以及正在使用贝宝(Paypal)完成付款的物品清单,以便买方和卖方都能看到购买或出售了哪些产品。这是我所做的摘要,通过遵循 Github code of PayPalCheckout,但每次我得到We'are sorry dialog来实现。这是我的代码段

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;
}

请提出这里的问题?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

解决了。上面的代码是正确的,价格值是十进制后的7位以上,并给出了错误代码400(VALIDATION_ERROR)。但是现在处理了。

答案 2 :(得分:0)

因此,您提供的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 / etc在哪里?参数名称来自何处?

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