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

标签 android paypal

我在我的 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/

相关文章:

ruby-on-rails - 为 Sandbox paypal (NVP/SOAP API) 打开 "Negative Testing"

php - 将数组的内容写入另一个文件?

paypal - 在 Paypal Merchant API 中调用 GetBalance 函数

android - Flutter APK 在手机中构建,但无法打开?

android - 更改 android.graphics.Path 在 Canvas 上的位置

android - 对 `cv::error(int, std::string const&, char const*, char const*, int)' 的 undefined reference

Paypal 与布伦特里说 "Merchant account not found"

java - 通过 REST 发送/接收图像

java - 无法为Android build.gradle文件添加其他Maven存储库

paypal - 如何停止用原件替换 Logo 文件的 prestashop paypal 模块?