paypal结账时的验证错误

时间:2018-04-04 15:06:03

标签: javascript angular paypal

我在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;
    });
  }

提前致谢

1 个答案:

答案 0 :(得分:0)

我已经通过将配置paypal checkout中的变量total替换为另一个名称total1来解决此问题。显然,配置json的密钥和同名变量之间存在冲突。

相关问题