将购买的商品详细信息发送到 PayPal?
Sending purchased items details to the PayPal?
我需要发送购买的物品清单以及使用 Paypal 付款的物品清单,以便买家和供应商可以看到购买或出售了哪些产品。这是我所做的相同的片段,每次都遵循 Github code of PayPalCheckout but I get 。这是我的代码片段
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;
}
请指出这里的问题是什么?
所以您提供的 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 的格式。
实际上那些 b/c/d/f 等参数来自 PayPalPayment class。我只是给出了它的 Json 格式。
这是 PayPalPayment class 的样子-
已解决。上面的代码是正确的,价格值超过小数点后 7 位,给出了错误代码 400 (VALIDATION_ERROR)。但现在处理了。
我需要发送购买的物品清单以及使用 Paypal 付款的物品清单,以便买家和供应商可以看到购买或出售了哪些产品。这是我所做的相同的片段,每次都遵循 Github code of PayPalCheckout but I get
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;
}
请指出这里的问题是什么?
所以您提供的 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 的格式。
实际上那些 b/c/d/f 等参数来自 PayPalPayment class。我只是给出了它的 Json 格式。
这是 PayPalPayment class 的样子-
已解决。上面的代码是正确的,价格值超过小数点后 7 位,给出了错误代码 400 (VALIDATION_ERROR)。但现在处理了。