【问题标题】:How to call function if success stripe payment? In Angular支付成功后如何调用函数?在角
【发布时间】:2020-04-24 05:59:26
【问题描述】:

我正在尝试将 Stripe 支付网关添加到我的项目中。如果客户付款成功,我想调用 API 函数“orderStatusUpdate”调用。任何人都可以帮助我。

loadStripe() { 
  if(!window.document.getElementById('stripe-script')) {
    var s = window.document.createElement("script");
    s.id = "stripe-script";
    s.type = "text/javascript";
    s.src = "https://checkout.stripe.com/checkout.js";
    window.document.body.appendChild(s);
  }
}

pay(amount) { 
    var handler = (<any>window).StripeCheckout.configure({
      key: 'Publishable key',
      locale: 'auto',
      token: async function (token: any) { 
        console.log(token)  
      //IN HERE i try to put function ("this.orderStatusUpdate"), but it will give error. 
      }
    });
    this.orderStatusUpdate()

    handler.open({
      name: 'Project',
      description: 'Online payment API',
      amount: amount * 100,
      currency : '$'
    });  
}




orderStatusUpdate() {
 alert("Testing")
}

【问题讨论】:

  • Stripe Checkout 是远离您页面的重定向。有一些建议的方式来完成订单in the Stripe docs
  • 我想触发我的功能。 :(

标签: javascript angular stripe-payments angular7 payment-gateway


【解决方案1】:

This 为我工作,将其更改为箭头函数:

token: function (token: any) {token: (token: any) =&gt; {

【讨论】:

    【解决方案2】:
    let that = this;
    var handler = (<any>window).StripeCheckout.configure({
    key: 'Publishable key',
    locale: 'auto',
    token: async function (token: any) { 
        console.log(token)  
    //IN HERE try to put function (" that.orderStatusUpdate")
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 2014-05-23
      • 2017-08-04
      • 2011-08-25
      • 2013-01-24
      相关资源
      最近更新 更多