I have to implement Paypal into my application. Here I have added some products into the cart. If I click the cart, I have to pay the amount using Paypal.
When clicking the Paypal button, I am getting the following error:
The amounts specified for item price,tax,and shipping do not add up to the total amount.
Why am getting this error?
I am using the following code:
$.paypalWindow.addEventListener('open', function(){
var Paypal = require('ti.paypal');
var u = Ti.Android != undefined ? 'dp' : 0;
var status = Ti.UI.createLabel({ top: 20 + u, height: 50 + u, color: '#333', text: 'Loading, please wait...' });
$.paypalWindow.add(status); var price = totalamount;
var invoiceitemslist = JSON.stringify(data);
var button; function addButtonToWindow() {
if (button) { $.paypalWindow.remove(button); button = null; }
button = Paypal.createPaypalButton({ width: 194 + u, height: 37 + u, buttonStyle: Paypal.BUTTON_194x37, top: 20 + u,
language: 'en_US',
appID: 'APP-80W284485P519543T',
paypalEnvironment: Paypal.PAYPAL_ENV_SANDBOX,
feePaidByReceiver: false,
enableShipping: false,
payment: {
paymentType: Paypal.PAYMENT_TYPE_BUSINESS,
subtotal: price,
tax: 0.00,
shipping: 0.00,
currency: 'USD',
recipient: '[email protected]',
customID: 'anythingYouWant',
invoiceItems:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3},
],
ipnUrl: 'http://www.appcelerator.com/',
merchantName: 'EYMOBINS Insurance',
memo: 'For the insurance with EYMOBINS!'
}
});
button.addEventListener('paymentCancelled', function (e) {
alert('Payment cancelled. Please try again!');
addButtonToWindow();
});
button.addEventListener('paymentSuccess', function (e) {
alert('Payment successfull. Please get your Policy No.!'+" "+e.transactionID);
$.paypalWindow.remove(button);
//addButtonToWindow();
});
button.addEventListener('paymentError', function (e) {
alert('Payment Error. Please try again!');
addButtonToWindow();
});
button.addEventListener('buttonDisplayed', function () {
$.paypalWindow.remove(status);
//alert('Please pay '+Ti.App.totalcost+'$ with Paypal!')
});
button.addEventListener('buttonError', function () {
});
$.paypalWindow.add(button);
}
addButtonToWindow();
});
$.paypalWindow.open();
Please check the code and give me an idea to resolve the above issue.
EDIT:
Here I am facing one issue:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":999,"itemPrice":999,"itemCount":1},{"name":"Average2Excellent CBSE KG EVS MATHS ENG Educational CD ROMS","totalPrice":547,"itemPrice":547,"itemCount":1}]
Here the totalamount is 1546. Here I have printed the invoiceitems in the console, and I am getting the data like above.
So that I have given like:
invoiceItems:invoiceitems,
Like means am getting the issue (the amounts specified for item price, tax, and shipping do not add up to the total amount).
Same thing I have written the code like:
invoiceItems:[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":999,"itemPrice":999,"itemCount":1},{"name":"Average2Excellent CBSE KG EVS MATHS ENG Educational CD ROMS","totalPrice":547,"itemPrice":547,"itemCount":1}]
it's working perfectly.
It is not working dynamically when assigned the value. Can you please check the code and help?
EDIT:
If i have tried to run this code on android device, as am clicking the paypal button nothing happends. Why the login form is not open in the android device.