如何将PayPal Express Checkout集成到angular2打字稿项目中 [英] How to integrate PayPal express checkout into angular2 typescript project

查看:89
本文介绍了如何将PayPal Express Checkout集成到angular2打字稿项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Paypal提供了一种易于集成的方式它的快速结帐解决方案,但是在以打字稿编写的angular2项目中使用此解决方案的最佳解决方案是什么?

Paypal provides an easy way to integrate its express checkout solution but what is the best solution to use this solution in an angular2 project working written in typescript?

推荐答案

我使用了这样的解决方案:

I've used a solution like this:

加载外部脚本的方法

  private loadExternalScript(scriptUrl: string) {
    return new Promise((resolve, reject) => {
      const scriptElement = document.createElement('script')
      scriptElement.src = scriptUrl
      scriptElement.onload = resolve
      document.body.appendChild(scriptElement)
  })

组件代码

  ngAfterViewInit(): void {
    this.loadExternalScript("https://www.paypalobjects.com/api/checkout.js").then(() => {
      paypal.Button.render({
        env: 'sandbox',
        client: {
          production: '',
          sandbox: ''
        },
        commit: true,
        payment: function (data, actions) {
          return actions.payment.create({
            payment: {
              transactions: [
                {
                  amount: { total: '1.00', currency: 'USD' }
                }
              ]
            }
          })
        },
        onAuthorize: function(data, actions) {
          return actions.payment.execute().then(function(payment) {
            // TODO
          })
        }
      }, '#paypal-button');
    });
  }

信用

Andrei Odri在这里的答案:

Andrei Odri's answer here: script tag in angular2 template / hook when template dom is loaded

这篇关于如何将PayPal Express Checkout集成到angular2打字稿项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆