Paypal integration issue in titanium
Asked Answered
T

1

22

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.

Trichloromethane answered 4/5, 2015 at 11:53 Comment(2)
Can you provide the correlation id returned from the PayPal response ?Billowy
i didn't give the correlation id in my code anywhere.Where i have to create that id ? if you are having the tutorial please give me that for learningTrichloromethane
O
5

Why are you escaping the quotes in this code?

[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}

This is not valid JSON (or Javascript for that matter). Is this required by Paypal? I think it should look like this:

[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}

Edit:

I've had a closer look at your code sample. Can you confirm where totatamount is coming from? As the code sample stands it will be undefined, which would be consistent with the error message you have described. Can you confirm it is definitely the correct value IMMEDIATELY before you submit this data?

The ti.paypal spec has a nice code sample in the README file, which gives a good example of how to setup createPaypalButton. I would recommend looking at this if you haven't already.

button = Paypal.createPaypalButton({
    // NOTE: height/width only determine the size of the view that the button is embedded in - the actual button size
    // is determined by the buttonStyle property!
    width: 194 + u, height: 37 + u,
    buttonStyle: Paypal.BUTTON_194x37, // The style & size of the button
    bottom: 50 + u,

    language: 'en_US',
    textStyle: Paypal.PAYPAL_TEXT_DONATE, // Causes the button's text to change from "Pay" to "Donate"

    appID: '<<<YOUR APP ID HERE>>>', // The appID issued by Paypal for your application; for testing, feel free to delete this property entirely.
    paypalEnvironment: Paypal.PAYPAL_ENV_SANDBOX, // Sandbox, None or Live

    feePaidByReceiver: false, // This will only be applied when the transaction type is Personal
    enableShipping: false, // Whether or not to select/send shipping information

    advancedPayment: { // The payment itself
        payments: [
            {
                isPrimary: true, // Mark this as the primary vendor; this marks this as a chain payment.
                merchantName: 'Primary Vendor',
                paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
                paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
                subtotal: 13, // The total cost of the order, excluding tax and shipping
                tax: 0,
                shipping: 0,
                recipient: '<<<YOUR RECIPIENT HERE>>>',
                customID: 'anythingYouWant',
                invoiceItems: [
                    { name: 'Shoes', totalPrice: 8, itemPrice: 2, itemCount: 4 },
                    { name: 'Hats', totalPrice: 2, itemPrice: 0.5, itemCount: 4 },
                    { name: 'Coats', totalPrice: 3, itemPrice: 1, itemCount: 3 }
                ]
            },
            {
                merchantName: 'Vendor 1',
                paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
                paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
                subtotal: 10, // The total cost of the order, excluding tax and shipping
                tax: 0,
                shipping: 0,
                recipient: '<<<YOUR RECIPIENT HERE>>>',
                customID: 'anythingYouWant',
                invoiceItems: [
                    { name: 'Shoes', totalPrice: 8, itemPrice: 2, itemCount: 4 },
                    { name: 'Hats', totalPrice: 2, itemPrice: 0.5, itemCount: 4 }
                ]
            },
            {
                merchantName: 'Vendor 2',
                paymentType: Paypal.PAYMENT_TYPE_SERVICE, // The type of payment
                paymentSubtype: Paypal.PAYMENT_SUBTYPE_DONATIONS, // The subtype of the payment; you must be authorized for this by Paypal!
                subtotal: 3, // The total cost of the order, excluding tax and shipping
                tax: 0,
                shipping: 0,
                recipient: '<<<YOUR RECIPIENT HERE>>>',
                customID: 'anythingYouWant',
                invoiceItems: [
                    { name: 'Coats', totalPrice: 3, itemPrice: 1, itemCount: 3 }
                ]
            }
        ],
        ipnUrl: 'http://www.appcelerator.com/',
        currency: 'USD',
        memo: 'For the orphans and widows in the world!'
    }
});
Orchestral answered 13/5, 2015 at 21:57 Comment(5)
yes...now i have updated.am getting the same issue onlyTrichloromethane
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.Trichloromethane
Is it only on Android?Orchestral
yes only i have facing these problem only in android...iphone it's redirecting to paypal login formTrichloromethane
Does this module works with Ti SDK. 5.2.2 with Android API 22 and above?Drava

© 2022 - 2024 — McMap. All rights reserved.