使用 Angular 2 进行 Stripe Checkout

Mar*_*aug 5 stripe-payments typescript angular

我正在尝试在我的 Angular 2 Web 应用程序中使用 Stripe Checkout。一切正常,直到我在收到卡令牌后尝试调用 createOrder 函数。

错误是:EXCEPTION: this.createOrder is not a function

收到令牌后如何调用 createOrder 函数?

openCheckout() {
let handler = (<any>window).StripeCheckout.configure({
  key: 'pk_test_OtZk....xbk6UQB',
  locale: 'no',
  token: function (token: any) {
    this.createOrder(token, this.cart); //THIS IS WHERE THE ERROR OCCURS
  }
});

handler.open({
  name: 'Test Store',
  description: 'Test Description',
  amount: this.cart.totalAmount,
  currency: 'nok',
  email: 'test@test.no',
  image: '../../assets/images/test.png',
  ['allow-remember-me']: false
});

this.globalListener = this.renderer.listenGlobal('window', 'popstate', () => {
  handler.close();
});
}

createOrder(token, cart) {
this.ordersService.createOrder(token, this.cart).subscribe(
  res => {
    console.log(res);
  }, err => {
    console.log(err);
  });
}
Run Code Online (Sandbox Code Playgroud)

小智 0

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.createOrder(token, this.cart);)
      }
Run Code Online (Sandbox Code Playgroud)