Search code examples
javascriptangularstripe-paymentsangular7payment-gateway

How to call function if success stripe payment? In Angular


I'm try to put Stripe payment gateway to my project. I want to call API function "orderStatusUpdate" call if payment successfully done by customer. Can anyone to help me.

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")
}

Solution

  • This worked for me, change it to an arrow function:

    token: function (token: any) { to token: (token: any) => {