I'm implementing Stripe in a React Native Expo app using the initStripe
method. Everything works fine on iOS, but on Android the PaymentSheet fails to open and logs the following error:
Error code: Failed PaymentConfiguration was not initialized. Call PaymentConfiguration.init().
Here’s the Checkout screen code:
useEffect(() => {
initStripe({
publishableKey: api.stripe_key,
urlScheme: "https://website.com/",
});
}, []);
const initializePaymentSheet = async (fee: number) => {
try {
const response = await fetch(api.STRIPE_URL + "/create_payment_intent", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
body: JSON.stringify({
amount: total.toFixed(2),
customer: customer,
application_fee_amount: appFee.toFixed(2),
business_acc_id: account,
}),
});
const { paymentIntent, ephemeralKey } = await response.json();
const { error } = await initPaymentSheet({
merchantDisplayName: "Lorem Ipsum",
customerId: customer,
customerEphemeralKeySecret: ephemeralKey,
paymentIntentClientSecret: paymentIntent,
allowsDelayedPaymentMethods: false,
defaultBillingDetails: {
name: 'Jhon Doe',
},
returnURL: "app://stripe-redirect",
});
if (!error) {
setLoading(true);
}
} catch (e) {
console.error(e);
}
};
const openPaymentSheet = async () => {
const { error } = await presentPaymentSheet();
if (error) {
console.log(`Error code: ${error.code}`, error.message);
} else {
console.log("Success", "Your order is confirmed!");
setModalVisible(true);
}
};
My package versions are as follows:
"expo": "^52.0.0",
"@stripe/stripe-react-native": "0.38.6",
I have also tested this on iOS (see screenshot), and it works as expected. Why is PaymentConfiguration not being initialized on Android and what steps can I take to fix it?