Handle the return URL
Bring the customer back to the app after a redirect payment method, and hand the SDK a return URL that reaches the app outside React Native's Linking.
Redirect payment methods and app switches end at the session's return URL (returnUrl passed to PayCheckout.create(), such as myshop://pay). While checkout.pay() or checkout.presentDropIn() runs, the SDK listens to React Native's Linking and hands these URLs to the native SDK itself. So the app needs only React Native's usual deep link setup, described below.
Call PayCheckout.handleReturn() yourself only for a URL that reaches the app some other way, for example through native code of your own that doesn't pass it on to Linking.
const handled = await PayCheckout.handleReturn(url)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | A URL the app was opened with. |
Returns
A promise that resolves with true when the URL belonged to a Pay.com flow in progress, and with false otherwise. Any URL is safe to pass. The SDK ignores the ones that aren't its own.
Set up deep links
Register the return URL with the app, and let React Native's Linking see the URLs the app is opened with. Your server must create the session with return_url set to the same URL as returnUrl.
Add the URL's scheme to the app's Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myshop</string>
</array>
</dict>
</array>Then pass the URLs the app is opened with to RCTLinkingManager. In a scene delegate:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
RCTLinkingManager.scene(scene, openURLContexts: URLContexts)
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
RCTLinkingManager.scene(scene, continue: userActivity)
}In an app delegate, call RCTLinkingManager.application(_:open:options:) from application(_:open:options:) instead.
A universal link or an App Link works too. Set it up as for any other link that opens the app. For more, see React Native's Linking guide.
Example
import { PayCheckout } from '@pay-com/react-native'
// Your own native code calls this with each URL the app is opened with.
export async function onOpenUrl(url: string) {
if (await PayCheckout.handleReturn(url)) return // it finished a Pay.com redirect
openDeepLink(url) // route the URL in your app
}Next steps
- Start a checkout: Pass the return URL as
returnUrl. - Create a payment session: Set the same URL as the session's
return_url. - checkout.pay(): Pay with a redirect method.