为什么PayPal按钮无法呈现?

时间:2019-05-19 19:38:18

标签: javascript angular paypal

我正在尝试将PayPal智能按钮添加到我的角度应用here is the link of the PayPal instruction how to add

我已经尝试过在我的角度组件中添加脚本。

 ngAfterViewChecked(): void {
        if (!this.addScript) {
        this.addPaypalScript().then(() => {
        console.log('paypal',paypal)
        paypal.Buttons({

          // Set up the transaction
          createOrder: function(data, actions) {
              return actions.order.create({
                  purchase_units: [{
                      amount: {
                          value: '0.01'
                      }
                  }]
              });
          },

          // Finalize the transaction
          onApprove: function(data, actions) {
              return actions.order.capture().then(function(details) {
                  // Show a success message to the buyer
                  alert('Transaction completed by ' + details.payer.name.given_name + '!');
              });
          }


      }, '#paypal-checkout-btn');
        this.addScript = true;
      })
    }
  }
addPaypalScript() {
    this.addScript = true;
    return new Promise((resolve, reject) => {
      let scripttagElement = document.createElement('script');    
      scripttagElement.src = 'https://www.paypal.com/sdk/js?client-id=sb';
      scripttagElement.onload = resolve;
      document.body.appendChild(scripttagElement);
    })
  }

`

its not showing any thing

0 个答案:

没有答案