如何在Angular中成功完成Stripe支付后调用函数?

huangapple go评论79阅读模式
英文:

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 = (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");
}

英文:

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

答案1

得分: 1

这个 对我有用,将它改为箭头函数:

token: function (token: any) { 改为 token: (token: any) => {

英文:

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

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

答案2

得分: 0

let that = this;
var handler = (<any>window).StripeCheckout.configure({
key: '可发布的密钥',
locale: '自动',
token: async function (token: any) {
    console.log(token)
    //在此处尝试放置函数("that.orderStatusUpdate")
}
英文:
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")
}

huangapple
  • 本文由 发表于 2020年1月7日 01:23:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定