java - 将购买的商品详细信息发送到 PayPal?
问题描述
我需要发送购买的物品清单以及正在使用 Paypal 完成付款的物品,以便买家和供应商可以看到购买或出售了哪些产品。这是我为相同所做的片段,通过遵循PayPalCheckout 的 Github 代码,但我每次都得到。这是我的代码片段
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;
}
请建议这里有什么问题?
解决方案
推荐阅读
- javascript - 如何在键入时修改输入并使 Blazor 看到更改
- android - Expo未在本地主机中启动任何开发工具
- html - 为什么@media 屏幕无法在我的网络上运行?
- python - 在神经网络中使用使用 softmax 函数的反向传播算法
- css - 使用内容时不显示 Font Awesome
- flutter - 返回列表
来自 Firestore 收藏 - python - 在具有日期时间值的日期帧上应用 DatetimeIndex 作为过滤器
- typescript - 如何使用 quicktype 在 TypeScript 中生成以数字为键的索引签名类型?
- react-native - 在 React Native 中构建自定义秒和分钟输入?
- python - 如何迭代地呈现预序(二叉树)?