【问题标题】:Order multiple items using PayPal in android在 android 中使用 PayPal 订购多件商品
【发布时间】:2015-05-16 08:08:45
【问题描述】:

我在我的 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);

【问题讨论】:

    标签: android paypal


    【解决方案1】:

    请参阅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;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 1970-01-01
      • 2018-09-20
      • 2019-05-29
      • 2016-08-19
      • 2010-10-09
      • 2011-06-12
      • 2013-10-29
      • 2017-01-29
      相关资源
      最近更新 更多