Payclave developers
Mobile SDK integration
React Native and Expo setup, options, errors, app lifecycle, Swift, Kotlin, and Flutter integration.
Keep payment creation on your backend
The mobile app asks your authenticated backend to create checkout for an order ID. Your backend authorizes that order, calculates its amount, and returns the checkout session ID and checkout URL. The app opens hosted checkout in the system browser. Your backend fulfills the order after verifying the signed invoice.paid webhook.
Publishable status reads drive the app's progress screen. They do not replace your backend's fulfillment checks. Keep the app's key in the same test or live mode as the server key that created the session. A secret key embedded in an app can be extracted from its binary.
Install the React Native package
Use React Native 0.76 or later and expo-web-browser 14 or later. Expo projects can install the browser dependency with expo install. Bare React Native apps need Expo modules configured before using expo-web-browser. Swift, Kotlin, and Flutter integrations below use the system browser directly; there are no separate Payclave native SDK packages to install for those examples.
Create the mobile checkout session
Implement order authentication and price lookup on your server. The shared server example returns checkoutUrl; for the mobile SDK, also return the created session's id to the app. Save the checkout and invoice IDs against the order before sending that response. Reuse the same idempotency key after a timeout.
Open checkout and handle the result
createCheckoutOnYourBackend in this example is your authenticated order endpoint. The UI helpers are placeholders for your app's own screens. Disable the pay button while one checkout is open, and store the order ID so you can refresh it after app suspension or restart.
SDK options
Pass options to openPayclaveCheckout. Keep API origin overrides restricted to an API you control; the client sends its publishable credential to that origin.
| Option | Behavior |
|---|---|
| publicKey | Required pk_test_ or pk_live_ key. Secret keys are rejected. |
| checkoutSessionId | Required ID returned by your server's creation request. |
| pollIntervalMs | Defaults to 3000 ms; minimum 1000 ms. |
| onStatusChange | Called after the first check and when status, collectionState, or customerAmountPaid changes. Callback errors do not interrupt checkout. |
| signal | AbortSignal stops checking and closes checkout on iOS. Handle the ABORTED error. |
| timeoutMs | Per-request timeout; defaults to 15000 ms. |
| apiBaseUrl / fetcher | Optional trusted API origin or fetch implementation for your runtime and tests. |
Outcomes and payment states
The SDK returns outcome and the latest session. paid means the session reports payment completion; ended means checkout expired, failed, or was cancelled; dismissed means the customer returned before completion. A session already paid or ended resolves without opening a new browser view.
Underpaid sessions remain open because the invoice still has a remainder. A dismissed result can include a processing or underpaid session. A payment sent just before expiry can confirm later. Show the latest order state from your backend and keep webhook processing active after the customer leaves the app.
Errors and interrupted requests
Before checkout opens, handle INVALID_PUBLIC_KEY, INVALID_CHECKOUT_SESSION_ID, INVALID_POLL_INTERVAL, CHECKOUT_IN_PROGRESS, API errors, and NETWORK_ERROR. During checkout, handle ABORTED and BROWSER_UNAVAILABLE. Fix invalid configuration before offering a retry.
Temporary status-read failures while the browser is open retry with a growing delay up to 30 seconds. If the final check fails temporarily after the customer returns, the SDK resolves dismissed with the last known session. A permanent final API error rejects. Keep the order available for a later backend refresh.
iOS and Android lifecycle differences
On iOS, the SDK uses SFSafariViewController and can close it when payment confirms. If the session fails or expires, the browser stays open so the customer can read the result, then resolves when they close it.
On Android, JavaScript can pause while the Chrome Custom Tab is in front. Status callbacks resume when the customer returns, and the result comes from the final check then. Your app cannot close a Chrome Custom Tab. Do not depend on background JavaScript to finish a payment or fulfill an order.
Return links, cancellation, and app restarts
Your backend controls successUrl and cancelUrl. Use HTTPS URLs on the reviewed website origin. If you support verified universal links or Android app links on that origin, refresh the order when the app receives the link. Keep a browser fallback page and a way for customers to return manually; automatic app return behavior differs by platform.
A return link is navigation input, not proof of payment. Do not put secrets or trusted order prices in its query string. Aborting SDK status tracking does not reverse a transaction the customer already submitted. After cancellation or app restart, read your stored order and its existing checkout state before offering another payment attempt.
The native browser examples below use your existing controller or activity and a server-provided checkoutUrl. Implement the status-check helper with a publishable key, and authorize fulfillment only on your backend. The examples demonstrate browser presentation and lifecycle hooks rather than a complete native application.
iOS with Swift
Present checkout in SFSafariViewController. Your app can close it as soon as the status is paid. The safariViewControllerDidFinish delegate method runs when the customer taps Done, so check the status once more there.
Android with Kotlin
Open checkout in a Chrome Custom Tab from the androidx.browser library. Your app cannot close a Custom Tab, so the tab stays open until the customer closes it. Check the status while the tab is open, and again in onResume when the customer returns to your activity.
Flutter
Open checkout with the url_launcher package in LaunchMode.inAppBrowserView, which uses the system browser view on each platform. Close it once the status is paid where the platform supports closing, and check the status again when the app lifecycle state returns to resumed.
Test the app lifecycle before release
Test double taps, closing checkout early, switching to a wallet app, losing network access, returning after expiry, and restarting the app during a payment. Restore the order from your backend after each interruption instead of creating another checkout blindly.
Verify that test and live keys cannot read each other's records. Replay a signed webhook and confirm your backend fulfills once. Test invalid signatures and synthetic events. Confirm that no secret key appears in the app bundle, device logs, crash reports, or deep-link parameters.