本文介绍了带 Angular 2 的 Stripe Checkout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use Stripe Checkout in my Angular 2 web application. Everything works fine until I try to call the createOrder function after I've received the card token.

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

The error is: EXCEPTION: this.createOrder is not a function

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

How am I able to call the createOrder function after I've received the token?

openCheckout() {
let handler = (<any>window).StripeCheckout.configure({
  key: 'pk_test_OtZkFKLIU1WBuonz6xbk6UQB',
  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: '[email protected]',
  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);
  });
}

推荐答案

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

这篇关于带 Angular 2 的 Stripe Checkout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 03:26