我在Angular5上使用PayPal结帐脚本。
我正在尝试拆分包含价格的字符串并将结果转换为float,但是我收到以下错误:
{
"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
这是我的paypal配置:
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;
});
}
提前致谢
答案 0 :(得分:0)
我已经通过将配置paypal checkout中的变量total
替换为另一个名称total1
来解决此问题。显然,配置json的密钥和同名变量之间存在冲突。