我正在尝试在 ReactJS 中实现 Stripe 功能“重定向到结账”。
我环顾四周,似乎没有任何软件包可以帮助做到这一点。
const stripe =
Stripe('key');
stripe.redirectToCheckout({
items: [
// Replace with the ID of your SKU
{sku: 'sku_123', quantity: 1}
],
successUrl: 'https://your-website.com/success',
cancelUrl: 'https://your-website.com/canceled',
}).then(({error}) => {
// If `redirectToCheckout` fails due to a browser or
network
// error, display the localized error message to your
customer
// using `error.message`.
});
这是我得到这个源代码的地方:https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout
Stripe JS似乎只支持标准结帐,不接收产品SKU作为参数
当我读完新书后stripe-js
docs https://stripe.com/docs/stripe-js/react https://stripe.com/docs/stripe-js/react我发现这可能对你有用
相反使用stripe
, 安装@stripe/stripe-js
那么这项工作可以通过以下方式完成
import { loadStripe } from "@stripe/stripe-js";
...
const stripePromise = loadStripe(
"pk_.........."
);
const stripe = await stripePromise;
stripe.redirectToCheckout({
...
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)