首页 > 解决方案 > PayPal 正在使用沙盒,但不使用实时,使用 Rest API

问题描述

我已经将 PayPal 与我的 Angular 2 应用程序与 REST API 应用程序集成在一起。它可以在沙盒环境中顺利运行,但不能在实时环境中运行。分享我使用的代码:

paypalConfig = {
env: 'production',
client: {
  sandbox: 'my_sandbox_client_key',
  production: 'my_live_client_key'
},
commit: true,
style: {
  color: 'gold',   // 'gold, 'blue', 'silver', 'black'
  size:  'medium', // 'medium', 'small', 'large', 'responsive'
  shape: 'pill'    // 'rect', 'pill'
},
payment: (data, actions) => {
  return actions.payment.create({
    payment: {
      transactions: [
        { amount: { total: this.finalAmount, currency: 'USD' } }
      ]
    }
  });
},
onAuthorize: (data, actions) => {
  return actions.payment.execute().then((payment) => {
    //Do something when payment is successful.
    alert('Payment Successful, Thank You!');
  })
}};

ngAfterViewChecked(): void {
  if (!this.addScript) {
      this.addPaypalScript().then(() => {
            paypal.Button.render(this.paypalConfig, '#paypal-checkout-btn');
            this.paypalLoad = false;
        })
    }
}

addPaypalScript() {
    this.addScript = true;
    return new Promise((resolve, reject) => {
        let scripttagElement = document.createElement('script');
        scripttagElement.src = 'https://www.paypalobjects.com/api/checkout.js';
        scripttagElement.onload = resolve;
        document.body.appendChild(scripttagElement);
    })
}

这是我收到的失败消息:

PayPal美国账户实盘交易失败截图

提前致谢。

标签: angularpaypalpaypal-sandbox

解决方案


推荐阅读