有没有人遇到过这个错误:未捕获的类型错误:无法读取未定义的属性"创建付款方式"



我目前使用的是Stripe.js V2和V3,需要使用Stripe.createPaymentMethod((方法。当我尝试使用以下代码时,我得到了一个错误,如下所示:

const {paymentMethod, error} = await stripe.createPaymentMethod({
type: 'card',
card: this.refs.creditCardForm,
billing_details: {
name: 'Jenny Rosen',
},
});

错误:未捕获的类型错误:无法读取未定义的属性"createPaymentMethod">

顺便说一句,当我使用JS而不是React:时,我会得到同样的错误

Stripe.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: {
name: values.payment.creditCardHolderName,
}
}).then(function(result) {
// handle result
});

欢迎提供任何信息/经验。

我在为组件创建单元测试时遇到了这种情况。我在调用createPaymentMethod之前添加了一个验证if(this.stripe(,它解决了这个问题。希望能有所帮助。

最新更新