我正在尝试在后端 Nest.js 中实现 Stripe API 付款流程。
我正在使用 stripe 包,我实现的场景是
1- 将创建付款方式
2-创建付款意向
3-确认付款意向
4-捕获付款意图
我在创建付款方式的第一步中遇到问题(我正在为第二步中使用的付款 ID 创建付款方式),但出现错误。
为了创建付款方式,我使用了这个
const paymentMethod = await this.stripe.paymentMethods.create({
type: 'card',
card: {
token: token.id,
},
});
为了创建令牌,我使用了这个
const token = await stripe.tokens.create({
card: {
number: '4242424242424242',
exp_month: 10,
exp_year: 2024,
cvc: '314',
},
});
但我面临这个错误
Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing. To enable raw card data APIs in test mode, see https://support.stripe.com/questions/enabling-access-to-raw-card-data-api
用户 Stripe 卡信息(号码、CVV、到期年份、到期月份)存储在数据库中,因此我将用这些信息替换测试卡信息。
经过一番研究,我发现可以借助 Stripe Elements 和 strip.js 库在前端生成令牌 Id。
如何解决这个问题?我应该从前端获取令牌吗?
如有任何帮助,我们将不胜感激。
您应该阅读错误中链接的支持文章。
如果您只是为了测试而执行此操作,则可以使用链接的测试卡及其付款方式 ID,如
pm_card_visa
等。
如果这就是您计划实际操作的方式,您需要了解 PCI 影响并联系 Stripe 的支持团队:https://support.stripe.com/contact