Reputation: 966
I've added Stripe into my React-Native/Expo (SDK 42) App. I am trying to make it so follow the "create payment" method laid out on stripes website, but it keeps throwing the following error:
undefined Unable to resolve module stripe from ../../../../.js stripe could not be found within the project.
I've tried calling Stripe, but I still keep getting the error.
Below is the code where the error lives:
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'
}
})
}
I adapted this from the Node.js version found here
Upvotes: 2
Views: 2057
Reputation: 2173
The code that you've included in your question is meant to be called server-side with Stripe's Node client library. It cannot be adapted to work client-side with the Stripe's React Native SDK.
Instead, you want to be calling the React Native equivalent of stripe.createPaymentMethod()
(see JS library ref). There's a quick example in the React Native library docs about how to do this here (it was originally written for folks migrating from the Tipsi library, but it should also work for your use case).
Upvotes: 3