Closed jongbelegen closed 6 months ago
Change your StripeHandleUrl
to be a component that prevents rendering under the deep link URL is resolved..
export function StripeHandleUrl({ children }) {
const { handleURLCallback } = useStripe();
const [urlHandled, setUrlHandled] = useState(false)
const handleDeepLink = useCallback(
async (url: string | null) => {
if (url) {
const stripeHandled = await handleURLCallback(url);
if (stripeHandled) {
router.nativgate('/') // Navigate to where you need to
}
setUrlHandled(true) // Otherwise just render the children
}
},
[handleURLCallback]
);
useEffect(() => {
const getUrlAsync = async () => {
const initialUrl = await Linking.getInitialURL();
handleDeepLink(initialUrl);
};
getUrlAsync();
const deepLinkListener = Linking.addEventListener(
'url',
(event: { url: string }) => {
handleDeepLink(event.url);
}
);
return () => deepLinkListener.remove();
}, [handleDeepLink]);
return urlHandled ? <>{children}</> : null
}
Then in your root _layout
, it now wraps your childre instead of being a sibling.
<StripeHandleUrl>
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{headerShown: false}}/>
<Stack.Screen name="modal" options={{presentation: 'modal'}}/>
</Stack>
</ThemeProvider>
</StripeHandleUrl>
Minimal reproducible example
https://github.com/jongbelegen/expo-router-stripe-safepay
Which package manager are you using? (Yarn is recommended)
pnpm
If the issue is web-related, please select the bundler (
web.bundler
in theapp.json
)metro
Summary
When making a payment with Stripe that requires leaving the app (e.g., using iDeal). Stripe uses a return URL to catch some details of the payment made (https://docs.stripe.com/payments/accept-a-payment?platform=react-native&ui=payment-sheet#react-native-set-up-return-url).
The Expo router tries to navigate to this route and shows a 404.
It is not desired that the expo router tries to navigate to this page.
Environment