We are trying to integrate Stripe into a react native app using @stripe/stripe-react-native. We followed this tutorial https://www.youtube.com/watch?v=DZlAET7Tgx4 https://www.youtube.com/watch?v=DZlAET7Tgx4 for reference.
Our API call is returning an undefined object. We think it might have to do with the API url but we've tried everything (localhost, ip address of computer, ip address of wifi) and nothing is working. We try to console log within the post method but nothing prints which makes us think it's not being called properly. We have a server running using express. Any help would be greatly greatly appreciated :)
This is our post method:
app.post('/create-payment-intent', async (req, res) => {
console.log("test place 1")
try {
const paymentIntent = await stripe.paymentIntents.create(
{
amount: 1099,
currency: "usd",
payment_method_types: ["card"],
}
);
const clientSecret = paymentIntent.client_secret;
res.send({
clientSecret: clientSecret,
});
} catch (e) {
res.json({ error: e.message });
}
})
And this is when we call it:
const API_URL = "http://10.49.40.160:8000"
const StripeApp = props => {
const [email, setEmail] = useState();
const [cardDetails, setCardDetails] = useState();
const { confirmPayment, loading } = useConfirmPayment();
const fetchPaymentIntentClientSecret = async () => {
const response = await fetch(`${API_URL}/
create-payment-intent`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
paymentMethodType: 'card',
currency: 'usd',
}),
});
const { clientSecret, error } = await response.json();
return { clientSecret, error };
}
Thank you so much!