reactjs - React Stripe 结帐多个行项目
问题描述
我有一个带条带结帐的有效 React 应用程序。但我需要在结账时通过多个项目来付款。现在再次它只适用于一项。但是我有一组称为“项目”的对象,需要一次性支付。处理这个问题的最佳方法是什么?因此,如果您在我的代码中看到描述 Bounce House A 但项目数组可以有 [{description: 'Bounce House A', amount:200,qty:2},{description: 'Bounce House B', amount:250 ,数量:1}。
这是我当前的代码:
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)
export default async (req, res) => {
const { id, amount } = req.body
try {
const payment = await stripe.paymentIntents.create({
amount,
currency: 'USD',
description: 'Bounce House A',
payment_method: id,
confirm: true,
})
console.log(payment)
return res.status(200).json({
confirm: 'abc123',
})
} catch (error) {}
}
解决方案
您必须将这些数组存储在您的数据库中,并使用一个单一的“订单 ID”,您可以将其传递给 Stripe 的 PaymentIntent 下的metadata
. 这样,您可以使用您设计的自定义订单 ID 查找与 PaymentIntent 关联的项目。
Stripemetadata
只能存储字符串键值对,因此您不能在其中存储数组。您可能能够以某种一致的格式将数组存储为字符串,从而允许您将其反序列化回数组,但我不建议这样做。
推荐阅读
- sql-server - SSMS 导入/导出向导未加载
- c++ - LibZip C++ 未解析的外部符号
- r - 如何在 R 中的 `dplyr::across` 右侧应用 2 个或多个函数来查找 weighted.means 和方差?
- c# - 即使在 .NET Producer APP 中设置了 auto.enable.schemas=false 选项,Schema 也会在 Confluent-Cloud 中注册
- javascript - 使用 .map 函数在 react-multi-carousel 中加载数据会给出未定义错误的“长度”
- php - 限制 Woocommerce 描述中的字数(使用 php)
- sass - 在 NextJS 中使用带有样式 jsx 的组件上的 mixins
- python - Pandas:过滤值出现在对的任一端,但不是在组内
- typescript - 当不同网络上的对等点时,RTCPeerConnection 失败
- python - 如何访问驻留在包含的子模块中的 pytest 固定装置?