PayrailsPaymentLauncher.
Prerequisites
- An active Payrails session (see Quick Start)
- The
Sessionreference returned byPayrails.createSession(...) - The
com.payrails.android:checkoutdependency (see Quick Start) - For the encrypted-card path: a card payload already encrypted by your client-side encryption library (the SDK exposes no encryption API — see Why no encryption API)
Steps
1. Create the launcher early
The launcher registers a Google Pay Activity Result contract, so it must be created before the host reaches theSTARTED state. In Compose, call the factory during composition:
onCreate:
2. Draw your own method selector and Pay button
This is your UI — style it however you like. Track the selected method in your own state:3. Trigger the payment
Call the matchingauthorize(...) overload from your button. The SDK opens whatever UI the method
needs:
4. Handle the result
Eachauthorize(...) resolves to exactly one ActionResult,
delivered to the callback you supplied in step 1:
Full example — custom dropdown + single Pay button
Troubleshooting
Problem: The launcher throws when created Solution:Payrails.createPaymentLauncher(...) must be called from Activity.onCreate.
Registering the Google Pay Activity Result contract after the activity is STARTED is not
allowed by the Android Activity Result API.
Problem: A card that needs 3DS does not complete
Solution: 3DS is handled automatically by the launcher (it owns the Custom Tab) — you do
not branch on it. The terminal ActionResult arrives after the challenge resolves. There is no
separate “headless” card call to choose; launcher.authorize(encryptedCardData = …) covers
both frictionless and 3DS.
Problem: ActionResult.Failed with code == UNKNOWN_ERROR (rawError unsupportedPayment)
Solution: The selected method is not configured on the session. Confirm availability with
session.getPaymentMethodConfig()
before calling authorize(...).
Problem: Google Pay never opens
Solution: Check device capability with session.isGooglePayAvailable(context) and confirm
Google Pay is configured on the session.
See also
PayrailsPaymentLauncher API Reference — every method and factory
- Custom UI: Launcher vs Client — how the launcher and the internal networking client relate
- How to Execute a Payment Without an SDK Button (Headless) — the same launcher flow framed for headless/ViewModel-driven checkouts
ActionResultAPI Reference — every terminal payment outcome