Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 2 paypal plugin for multiple items

I am using ionic 2

i am having issue sending multiple items to PayPalPayment i have tried this below code it's working fine without items,

let payment = new PayPalPayment('3.33', 'USD', 'Description', 'sale');
PayPal.renderSinglePaymentUI(payment).then(() => {
  //response ...
});

but it's not working well if i put items in it

let payment = new PayPalPayment('3.33', 'USD', 'Description', 'sale');
let items: PayPalItem[];
/** 
  cart = [
      {
       name: 'pen', 
       qty: 12, 
       price: '2.00'}, 
      {
       name: 'pencil', 
       qty: 2, 
       price: '1.00'
      }, 
      {
       name: 'box', 
       qty: 1, 
       price: '20.00'
      }
   ];
 */
cart.forEach(x => {
  items.push(new PayPalItem(x.name, x.qty, x.price, "USD"));
});
payment.items = items;
PayPal.renderSinglePaymentUI(payment).then(() => {
  //response ...
});
like image 657
Abdul Rafay Avatar asked Jan 16 '17 14:01

Abdul Rafay


1 Answers

There is a problem in you code.

let payment = new PayPalPayment('3.33', 'USD', 'Description', 'sale');

Here in this code the total price i.e. '3.33' must be equal to the price of the cart array, i.e. in the cart array the sum of (qty*price) of all products must be equal to the price in the following part

let payment = new PayPalPayment('3.33', 'USD', 'Description', 'sale');
like image 171
Avik Nath Avatar answered Oct 06 '22 01:10

Avik Nath