Kri*_*eni 22 javascript android paypal titanium ios
我必须在我的应用程序中实现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: 'thaibusiness@gmail.com',
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();
Run Code Online (Sandbox Code Playgroud)
请检查代码并给我一个解决上述问题的想法.
编辑:
在这里,我面临一个问题:
[{"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}]
Run Code Online (Sandbox Code Playgroud)
这里的totalamount是1546.这里我在控制台中打印了invoiceitems,我得到的数据如上所述.
所以我已经给出了:
invoiceItems:invoiceitems,
Run Code Online (Sandbox Code Playgroud)
就像我收到问题的意思一样(为物品价格,税收和运输指定的金额不等于总金额).
同样的事情我写的代码如下:
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}]
Run Code Online (Sandbox Code Playgroud)
它工作得很好.
分配值时,它不会动态工作.你能检查一下代码并提供帮助吗?
编辑:
如果我试图在Android设备上运行此代码,因为我点击paypal按钮没有任何事情发生.为什么登录表单未在Android设备中打开.
你为什么要逃避这段代码中的引号?
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}
Run Code Online (Sandbox Code Playgroud)
这不是有效的JSON(或Javascript).这需要Paypal吗?我认为它应该是这样的:
[{"name":"Bajaj 200 mm Ultima PT01 Personal Fan","totalPrice":2997,"itemPrice":999,"itemCount":3}
Run Code Online (Sandbox Code Playgroud)
编辑:
我仔细看了一下你的代码示例.你能确认一下totatamount来自哪里吗?正如代码示例所示undefined,它将与您描述的错误消息一致.在提交此数据之前,您能否立即确认它肯定是正确的值?
ti.paypal规范在README文件中有一个很好的代码示例,它给出了如何设置的一个很好的例子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!'
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
467 次 |
| 最近记录: |