stripe-payments - 如何将 Angular 8 中的条带与定期付款(即订阅)集成
问题描述
我正在尝试将 Stripe 与定期付款相结合。
我点击了这个链接https://stripe.com/docs/payments/checkout/subscriptions/starting
我知道我必须首先创建一个结帐会话,然后我应该传递会话 ID 以进行进一步处理。
我能够根据文档创建所有 API,并且我也能够获取会话 ID。
但是我被困在如何集成到前端(即 Angular 8)中,因为您的文档仅提供给纯 js。
请让我知道如何集成以创建结帐会话并在 Angular 8 中重定向结帐。
另一个疑问是,如何在结帐会话创建之前知道已经有客户或新客户。
请给我你的建议
解决方案
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);
}
}
```
推荐阅读
- javascript - 在 Chart.js 中制作一个带有反映 X 轴标签的图例的条形图
- docker - Nginx 反向代理 docker 容器 LAN
- php - 使用 Laravel Dusk 测试 ReCaptcha
- nginx - Nginx 无法处理大量请求
- excel - 运行时错误 1004(使用循环将公式添加到单元格区域)
- javascript - Vuetify:颜色不适用于 UI 组件
- nextcloud - NextCloud:仅附加?
- css - 无法用我的 css 属性覆盖角度材质主题
- angular5 - 角度 ag 网格不适用于角度 5
- java - 如何获取 ActiveMQ 的入队计数?