gpt4 book ai didi

android - 在 android 中使用 PayPal 订购多个项目

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:30 25 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 PayPal。当我订购单件商品时,该应用程序运行良好。但是当我将多个项目添加到购物车并按下订单按钮时​​,应用程序崩溃了。我的问题是如何将多个项目及其详细信息传递给 PayPal 以进行订购。为此,我的一段代码是。

String price = res.getString("FoodPrice");
totalprice = totalprice + Integer.parseInt(price);
String title = res.getString("FoodTitle");
int quantity = Integer.parseInt(res.getString("quantity"));
PayPalItem ppi = new PayPalItem(title, quantity,
new BigDecimal(price), "USD", "sku");
ppis = new PayPalItem[length];
ppis[i] = ppi;

}

} catch (JSONException e) {
e.printStackTrace();
}

PayPalPaymentDetails pd = new PayPalPaymentDetails(
PayPalItem.getItemTotal(ppis), // price
new BigDecimal(10.0), // shipment costs
new BigDecimal(0));
thingToBuy = new PayPalPayment(new BigDecimal(
totalprice), "USD", "shortDescription",
PayPalPayment.PAYMENT_INTENT_SALE);
thingToBuy.items(ppis);
thingToBuy.paymentDetails(pd);

Intent intent = new Intent(FoodActivity.this,
PaymentActivity.class);

intent.putExtra(
PayPalService.EXTRA_PAYPAL_CONFIGURATION,
config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT,
thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);

最佳答案

请参阅 here 提供的示例以使用可选的付款详细信息和项目列表。

    private PayPalPayment getStuffToBuy(String paymentIntent) {
//--- include an item list, payment amount details
PayPalItem[] items =
{
new PayPalItem("sample item #1", 2, new BigDecimal("87.50"), "USD",
"sku-12345678"),
new PayPalItem("free sample item #2", 1, new BigDecimal("0.00"),
"USD", "sku-zero-price"),
new PayPalItem("sample item #3 with a longer name", 6, new BigDecimal("37.99"),
"USD", "sku-33333")
};
BigDecimal subtotal = PayPalItem.getItemTotal(items);
BigDecimal shipping = new BigDecimal("7.21");
BigDecimal tax = new BigDecimal("4.67");
PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
BigDecimal amount = subtotal.add(shipping).add(tax);
PayPalPayment payment = new PayPalPayment(amount, "USD", "sample item", paymentIntent);
payment.items(items).paymentDetails(paymentDetails);

//--- set other optional fields like invoice_number, custom field, and soft_descriptor
payment.custom("This is text that will be associated with the payment that the app can use.");

return payment;
}

关于android - 在 android 中使用 PayPal 订购多个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30273311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com