stripe-react-native
stripe-react-native copied to clipboard
PaymentConfiguration was not initialized. Call PaymentConfiguration.init()
trafficstars
Describe the bug the openPaymentSheet return the error : "PaymentConfiguration was not initialized. Call PaymentConfiguration.init()"
To Reproduce Steps to reproduce the behavior:
The file which i implement
import {
initPaymentSheet,
presentPaymentSheet,
} from "@stripe/stripe-react-native";
import { supabase } from "./supabase";
const fetchStripekeys = async () => {
const { data, error } = await supabase.functions.invoke("stripe-subscription");
if (error) {
return false;
}
return data;
};
export const setupStripePaymentSheet = async (totalAmount) => {
try {
const { subscriptionId, clientSecret } = await fetchStripekeys(totalAmount);
if (!subscriptionId || !clientSecret) {
return false;
}
const { error } = await initPaymentSheet({ paymentIntentClientSecret: clientSecret, customerId: subscriptionId, merchantDisplayName: "My Company" });
if (error) {
return false;
}
return true;
} catch (error) {
return false;
}
};
export const openStripeCheckout = async () => {
const { error } = await presentPaymentSheet();
if (error) {
return false;
}
return true;
};
In the file which i want to use Payment sheet of stripe
async function handleEditPaymentMethod() {
console.log("handleEditPaymentMethod");
const success = await setupStripePaymentSheet();
if (success) {
await openStripeCheckout();
}
}
<ButtonExtend onPress={handleEditPaymentMethod} >
<Text>
Upgrade
</Text>
</ButtonExtend>
In the file App.js :
<StripeProvider publishableKey={process.env.EXPO_PUBLIC_STRIPE_PUBLISHABLE_KEY} >
<NavigationContainer theme={MyTheme}>
<RootNavigation />
</NavigationContainer>
</StripeProvider>
The error i get is in the function openStripeCheckout which is the openPaymentSheet
Smartphone (please complete the following information):
- Device: samsung A04s
- OS: android 14
Additional context I search on internet and solution is to modify the native code of android which is add the PaymentConfiguration to file MainApplication . Does anyone know other way to fix this without modifying the native code ?
thank you so much in advance