使用 reactJs 处理条带
Handling stripe with reactJs
我正在尝试使用 stripe 和 reactjs 处理信用卡支付。我正在学习这里的教程 https://github.com/stripe-archive/react-stripe-elements。请参阅入门部分。我遇到的唯一问题是我需要在代码所在的组件页面(创建的第一页)而不是 CheckoutForm 页面上提交信用卡表格。我该怎么做?
我尝试执行以下操作
var elements = useElements();
const card = elements.getElement(CardElement);
const result = await stripePromise.createToken(card);
if (result.error) {
console.dir(result.error.message);
} else {
console.dir(result.token);
}
但我无法在 class 组件中使用挂钩函数 useElements。
首先,您链接到的图书馆是 deprecated, the new version is this one。不过,由于您正在使用挂钩,因此您必须已经在使用新库。
如果您正在使用 Class 组件,文档提供了一个 alternate integration pattern 使用 <Elements>
提供程序和显式 <ElementsConsumer>
的示例。
我正在尝试使用 stripe 和 reactjs 处理信用卡支付。我正在学习这里的教程 https://github.com/stripe-archive/react-stripe-elements。请参阅入门部分。我遇到的唯一问题是我需要在代码所在的组件页面(创建的第一页)而不是 CheckoutForm 页面上提交信用卡表格。我该怎么做?
我尝试执行以下操作
var elements = useElements();
const card = elements.getElement(CardElement);
const result = await stripePromise.createToken(card);
if (result.error) {
console.dir(result.error.message);
} else {
console.dir(result.token);
}
但我无法在 class 组件中使用挂钩函数 useElements。
首先,您链接到的图书馆是 deprecated, the new version is this one。不过,由于您正在使用挂钩,因此您必须已经在使用新库。
如果您正在使用 Class 组件,文档提供了一个 alternate integration pattern 使用 <Elements>
提供程序和显式 <ElementsConsumer>
的示例。