`presentPaymentSheet` crashes the app in android
See original GitHub issueDescribe the bug
The app crashes after calling presentPaymentSheet
.
To Reproduce I followed the example in the integration guide here. My checkout page:
import React, { useState, useEffect } from "react";
import { useStripe } from '@stripe/stripe-react-native';
import useAPIError from '../../common/hooks/useAPIError';
import stripeSheet from '../../common/api/stripe';
import { Button, VStack, Text } from 'native-base';
export default function CheckoutScreen() {
const { initPaymentSheet, presentPaymentSheet } = useStripe();
const [loading, setLoading] = useState(false);
const [apiIntent, setApiIntent] = useState('');
const [apiCustomer, setApiCustomer] = useState('');
const [apiEphemeralKey, setApiEphemeralKey] = useState('');
// const [clientSecret, setClientSecret] = useState();
const { addError } = useAPIError();
const fetchPaymentSheetParams = async () => {
try{
const response = await stripeSheet(addError);
const { paymentIntent, ephemeralKey, customer } = response.result;
console.log(paymentIntent);
console.log(ephemeralKey);
console.log(customer);
setApiIntent(paymentIntent);
setApiEphemeralKey(ephemeralKey);
setApiCustomer(customer);
return {
paymentIntent,
ephemeralKey,
customer,
};
}catch(e){
// TODO: handle error
return {
paymentIntent: null,
ephemeralKey: null,
customer: null,
}
}
};
const initializePaymentSheet = async () => {
const {
paymentIntent,
ephemeralKey,
customer,
} = await fetchPaymentSheetParams();
const { error } = await initPaymentSheet({
customerId: customer,
customerEphemeralKeySecret: ephemeralKey,
paymentIntentClientSecret: paymentIntent,
});
if (!error) {
setLoading(true);
}else{
}
};
const openPaymentSheet = async () => {
const { error } = await presentPaymentSheet(); // app crashes here
if (error) {
addError(`Error code: ${error.code}`, error.message);
} else {
addError('Success', 'Your order is confirmed!');
}
};
useEffect(() => {
initializePaymentSheet();
}, []);
return (
<VStack>
<Button colorScheme="primary" onPress={initializePaymentSheet}>Retry</Button>
<Text>Disabled is {(!loading) + ''}</Text>
<Text>intent is {apiIntent}</Text>
<Text>customer is {apiCustomer}</Text>
<Text>ephemeralKey is {apiEphemeralKey}</Text>
<Button
colorScheme="primary"
disabled={!loading}
onPress={openPaymentSheet}
>Checkout</Button>
</VStack>
);
}
Screenshots
Smartphone (please complete the following information):
- Device: Android Huawei GR3 2017
- OS: Android 8.0
Additional context
Developing app with expo
and using nativebase
for UI (I tried pure react native UI but the issue is still there).
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
react native - PaymentSheet Crashing on Android in v.0.19.0
In stripe-react-native v0.19.0, on Android (13 and 10), presentPaymentSheet call crashes the app without any errors.
Read more >Detect and diagnose crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >App Center Crashes for React Native - Microsoft Learn
App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device's storage...
Read more >Stripe payment integration React Native. calling ...
Coding example for the question Stripe payment integration React Native. calling presentPaymentSheet function leads to app crash-React Native.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, I solved the issue by downgrading the package to
0.1.4
with:Then adding these missing args to
initPaymentSheet
:Expo does support the older version of this library (0.1.4), this means that there are differences in initializing the PaymentSheet. Please follow our example which points to this specific version: https://github.com/stripe/stripe-react-native/blob/v0.1.4/example/src/screens/PaymentsUICompleteScreen.tsx