首页 > 解决方案 > 如何将 Angular 8 中的条带与定期付款(即订阅)集成

问题描述

我正在尝试将 Stripe 与定期付款相结合。

我点击了这个链接https://stripe.com/docs/payments/checkout/subscriptions/starting

我知道我必须首先创建一个结帐会话,然后我应该传递会话 ID 以进行进一步处理。

我能够根据文档创建所有 API,并且我也能够获取会话 ID。

但是我被困在如何集成到前端(即 Angular 8)中,因为您的文档仅提供给纯 js。

请让我知道如何集成以创建结帐会话并在 Angular 8 中重定向结帐。

另一个疑问是,如何在结帐会话创建之前知道已经有客户或新客户。

请给我你的建议

标签: stripe-paymentsangular8

解决方案


import { loadStripe } from '@stripe/stripe-js'; // this is typescript

stripePromise = loadStripe('pk_test_yourpublickeyshglhglglkdgjlrs')  

// Call your backend to create the Checkout session.

// When the customer clicks on the button, redirect them to Checkout.

async checkout() {
  const stripe = await this.stripePromise;
  const { error } = await stripe.redirectToCheckout({
    mode: 'payment',  
    lineItems: [{ price: this.plan, quantity: this.quantity }],
    successUrl: `${window.location.href}/success`,
    cancelUrl: `${window.location.href}/failure`,
  });

  if (error) {
    console.log(error);
  }
}
```

推荐阅读