【发布时间】:2018-09-14 05:16:19
【问题描述】:
我在 Angular5 上使用 PayPal 结帐脚本。
我正在尝试拆分包含价格的字符串并将结果转换为浮点数,但出现以下错误:
{
"name": "VALIDATION_ERROR",
"details": [
{
"field": "transactions.amount",
"issue": "Currency amount must be non-negative number, may optionally contain exactly 2 decimal places separated by '.', optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"
}
],
"message": "Invalid request - see details",
"information_link": "https://developer.paypal.com/docs/api/payments/#errors",
"debug_id": "ea4b3e3713de"
}
request/</<@https://www.paypalobjects.com/api/checkout.js:14680:39
这是我的贝宝配置:
let price = parseFloat(this.objRate.split("$")[1]);
let amount = 1;
let total = price * amount;
this.payPalConfig = {
env: 'sandbox',
client: {
sandbox: '<key>',
production: '<key>'
},
commit: true,
payment: (data: any, actions: any) => {
return actions.payment.create({
payment: {
transactions: [{
amount: {
currency: "USD",
total: Number(total).toFixed(2)
}
}]
}
});
},
onAuthorize: (data: any, actions: any) => {
return actions.payment.execute().then((payment: any) => {
this.payPalSuccess = true;
});
}
提前致谢
【问题讨论】:
-
您是否尝试在“总计”字段中传递硬编码小数?
-
“硬编码十进制”是什么意思?
-
而不是“total: Number(total).toFixed(2)”传入“1.00”...
-
事实上,当我定义
let price =1.55时,它可以工作。为什么会这样? -
一定是这个问题 - parseFloat(this.objRate.split("$")[1]);尝试调试输入
标签: javascript angular paypal