2015-05-04 6 views
22

Я должен внедрить Paypal в свое приложение. Здесь я добавил некоторые товары в корзину. Если я нажму на корзину, я должен заплатить сумму, используя Paypal.Проблема интеграции Paypal в титане

При нажатии на кнопке Paypal, я получаю следующее сообщение об ошибке:

Суммы, указанной в цене товара, налог, стоимость доставки не добавить к общей сумме.

Почему возникает эта ошибка?

Я использую следующий код:

$.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(); 

Пожалуйста, проверьте код и дать мне представление о том, чтобы решить вышеуказанную проблему.

EDIT:

Здесь я столкнулся один вопрос:

[{"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}] 

Здесь totalamount в 1546. Здесь я напечатал invoiceitems в консоли, и я получаю данные, как выше ,

Так что я дал, как:

invoiceItems:invoiceitems, 

Как средство я получаю вопрос (суммы, указанные в цене товара, налог, стоимость доставки не добавить к общей сумме).

То же самое я написал такой код:

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}] 

это прекрасно работает.

Он не работает динамически при назначении значения. Можете ли вы проверить код и помочь?

EDIT:

Если я пытался запустить этот код на устройстве Android, как и я, нажав на кнопку Paypal ничего не будем бороться. Почему форма входа не открыта в устройстве Android.

+0

Можете ли вы предоставить идентификатор корреляции, возвращенный из ответа PayPal? – Eshan

+0

Я не дал идентификатор корреляции в моем коде где угодно. Где мне нужно создать этот идентификатор? если у вас есть учебное пособие, пожалуйста, дайте мне это для обучения –

ответ

5

Почему вы избегаете цитат из этого кода?

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

Это недопустимое JSON (или Javascript, если на то пошло). Это требуется Paypal? Я думаю, что это должно выглядеть следующим образом:

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

Edit:

У меня был близкий взгляд на ваш образец кода. Вы можете подтвердить, откуда totatamount? Поскольку образец кода будет стоять, это будет undefined, что согласуется с сообщением об ошибке, которое вы описали. Можете ли вы подтвердить, что это определенно правильное значение НЕМЕДЛЕННО, прежде чем отправлять эти данные?

Спецификация ti.paypal имеет хороший образец кода в README file, что дает хороший пример того, как настроить createPaypalButton. Я бы рекомендовал посмотреть на это, если вы еще этого не сделали.

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!' 
    } 
}); 
+0

yes ... теперь у меня есть обновленный.am, получающий только ту же самую проблему –

+0

Прочитайте мое обновление – garryp

+0

Если я попытался запустить этот код на Android-устройстве, Кнопка paypal ничего не происходит. Почему форма входа не открыта в устройстве Android. –

Смежные вопросы