【发布时间】:2021-11-08 22:38:25
【问题描述】:
我已将 Stripe 添加到我的 React-Native/Expo (SDK 42) 应用程序中。我正在尝试使其遵循条纹网站上列出的“创建付款”方法,但它不断抛出以下错误:
undefined Unable to resolve module stripe from ../../../../.js stripe could not be found within the project.
我已尝试调用 Stripe,但仍然不断收到错误消息。
以下是错误所在的代码:
import { CardField, useStripe, StripeProvider, Stripe } from '@stripe/stripe-react-native'
const stripe = require('stripe')('testKey')
const paymentMethod = async() => {
await stripe.paymentMethods.create({
type: 'card',
card:{
number: '4242424242424242',
exp_month: 9,
exp_year: 2022,
cvc: '314'
}
})
}
我改编自找到的 Node.js 版本 here
【问题讨论】:
-
您使用的是哪个版本的
stripe-react-native? -
@joachimwedin 我们在 Expo SDK 42 上使用 "@stripe/stripe-react-native": "^0.2.1"
-
你改编的代码被称为服务器端的,不能与 Stripe 的 React Native SDK 一起使用。您想适应
stripe.createPaymentMethod()调用 (stripe.com/docs/js/payment_methods/create_payment_method)。 -
这里有一个关于如何使用
createPaymentMethod的快速示例,供从这里的 Tipsi 库迁移的人使用 (github.com/stripe/stripe-react-native/blob/…),以防万一 -
@karbi 前几天我也在 Reddit 上发布了这个帖子,收到了同样的回复,这让我感觉好多了,谢谢。如果您想要 Stack 积分,请回复此帖子,我将接受它
标签: javascript node.js react-native expo stripe-payments