stripe-react-native: PaymentSheet Crashing on Android in v.0.19.0
Describe the bug
In v0.19.0, on Android (13 and 10), presentPaymentSheet call crashes the app without any errors. After installing Sentry I see a IllegalStateException: ViewTreeLifecycleOwner not found
On iOS everything works perfectly.
To Reproduce I’m just following this Stripe Developers video about Accept a payment:
export default function TestPaymentScreen(props) {
const [ready, setReady] = useState(false);
const {initPaymentSheet, presentPaymentSheet, loading} = usePaymentSheet();
useEffect(() => {
initializePaymentSheet();
}, []);
const initializePaymentSheet = async () => {
const {paymentIntent, ephemeralKey, customer} =
await fetchPaymentSheetParams();
const {error} = await initPaymentSheet({
customerId: customer,
customerEphemeralKeySecret: ephemeralKey,
paymentIntentClientSecret: paymentIntent,
merchantDisplayName: 'MyApp',
allowsDelayedPaymentMethods: true,
returnURL: 'stripe-example://stripe-redirect',
});
if (error) {
Alert.alert(`Error codes: ${error.code}`, error.message);
} else {
setReady(true);
}
};
const fetchPaymentSheetParams = async () => {
const response = await fetch(`http://192.168.1.67:8000/checkout`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
const {paymentIntent, ephemeralKey, customer} = await response.json();
return {
paymentIntent,
ephemeralKey,
customer,
};
};
async function buy() {
const {error} = await presentPaymentSheet();
if (error) {
Alert.alert(`Error code: ${error.code}`, error.message);
} else {
Alert.alert('Success', 'The payment was confirmed successfully');
setReady(false);
}
}
/* ... */
}
When openPaymentSheet()
is called pressing the button, the android app crashes without any error in the Metro server console.
The Sentry dashboard shows:
IllegalStateException
ViewTreeLifecycleOwner not found from androidx.coordinatorlayout.widget.CoordinatorLayout{5876b97 V.E...... ......I. 0,0-0,0 #7f0800cf app:id/coordinator}
Expected behavior Payment sheet opening
Smartphone
- Device: Pixel 4
- OS: Android
- Version 13
I attach the following files: android:app:build.gradle.txt android:build.gradle.txt package.json.txt
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19
Awesome! Glad to hear it, hopefully that addresses it for the remainder of folks experiencing random payment sheet crashes in this issue. Thanks for posting here!
@Ace090 why do you have
implementation(project(':stripe_stripe-react-native')) { exclude module: 'appcompat' }
in yourapp/build.gradle
?If you can try to reproduce this in a blank project, that would be helpful. Otherwise, my I think this is specific to your project and could have to do with that
Hi, I haven’t been able to reproduce this so far. Can someone who is able to trigger this crash please run it while running
adb logcat
and find the fatal exception there and share it here? thanks!