In this blog,
I have shown where to add the discount price in PayPal standard payment android SDK.
There is a method called getStuffToBuy to add the item calculating the total amount to pay with PayPal.
And the product items are added like this,
1 2 3 4 5 6 7 8 9 |
PayPalItem[] items = { new PayPalItem("item #1", 3, new BigDecimal("80.50"), "USD", "sku-12345"), new PayPalItem("item #2", 2, new BigDecimal("10.00"), "USD", "sku-311231"), new PayPalItem("item #3", 1, new BigDecimal("3.99"), "USD", "sku-222111") }; |
And if you want to simply add the discount then simply add the discount also like item with the negative price(that will be the discounted price).
1 2 3 4 5 6 7 8 9 10 11 12 |
PayPalItem[] items = { new PayPalItem("item #1", 3, new BigDecimal("80.50"), "USD", "sku-12345"), new PayPalItem("item #2", 2, new BigDecimal("10.00"), "USD", "sku-311231"), new PayPalItem("item #3", 1, new BigDecimal("3.99"), "USD", "sku-222111"), // add this line for the discount new PayPalItem("Discount #4", 5, new BigDecimal("-3.00"), "USD", "sku-000000") }; |
So the final code,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private PayPalPayment getStuffToBuy(String paymentIntent) { PayPalItem[] items = { new PayPalItem("item #1", 3, new BigDecimal("80.50"), "USD", "sku-12345"), new PayPalItem("item #2", 2, new BigDecimal("10.00"), "USD", "sku-311231"), new PayPalItem("item #3", 1, new BigDecimal("3.99"), "USD", "sku-222111"), new PayPalItem("Discount #4", 5, new BigDecimal("-3.00"), "USD", "sku-000000") }; BigDecimal subtotal = PayPalItem.getItemTotal(items); BigDecimal shipping = new BigDecimal("17.30"); BigDecimal tax = new BigDecimal("3.47"); PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax); BigDecimal amount = subtotal.add(shipping).add(tax); PayPalPayment payment = new PayPalPayment(amount, "USD", "items", paymentIntent); payment.items(items).paymentDetails(paymentDetails); payment.custom("This is text that will be associated with the payment that the app can use."); return payment; } |