Link out to a web checkout
Send a customer from your app to a checkout in the browser, when the store's rules allow it for what they're buying, and learn how they came back.
PayLinkOut, in the pay-linkout module, opens a checkout that your server created in the browser app when the store's rules allow it and reports how the customer came back. PayLinkOut runs locally without calling Pay.com APIs. Confirm payment status on your server using signed webhooks or Retrieve a payment session.
- When the customer taps your web offer,
preparedecides whether it may show, and gives what your server needs. - Your app sends the preparation's
clientState,tappedAt, andstoreTokensto your server, which creates the checkout and returns its URL. openopens the URL in the browser app, and returns when the customer comes back.- Your app asks your server whether the customer paid.
// On the customer's tap. prepare never throws.
val preparation = PayLinkOut.prepare(context, PayLinkOutPurchase(PayPurchaseType.PHYSICAL))
if (!preparation.isAllowed) return // Don't offer the web checkout.
// Your server creates the checkout for this preparation and returns its URL.
val url = backend.createCheckout(preparation.clientState, preparation.tappedAt, preparation.storeTokens)
when (val result = PayLinkOut.open(activity, url, preparation)) {
is PayLinkOutResult.Returned -> backend.checkSession(result.sessionId)
PayLinkOutResult.Resumed -> backend.checkLinkOut(preparation.clientState)
PayLinkOutResult.Dismissed -> Unit // The customer canceled the store's notice. Nothing opened.
}backend stands for your app's client for your own server.
Set up
Set up the module, your manifest, and your return link before your first link-out.
- Depend on
pay-linkout. It's a standalone module with no SDK dependencies and runs onminSdk24 (Android 7.0) or later. - List the hosts of your checkout URLs in your manifest, comma-separated, in the
com.pay.sdk.linkout.ALLOWED_HOSTSmeta-data (PayLinkOut.ALLOWED_HOSTS), with an international name in punycode.openopens onlyhttpsURLs on these hosts, matched exactly, with no port or user info. - Make your checkout's return link an App Link to your app, and pass the URLs your activity is opened with to
PayLinkOut.handleReturn().
dependencies {
implementation("com.pay.sdk:pay-linkout:0.1.0")
}<application>
<meta-data
android:name="com.pay.sdk.linkout.ALLOWED_HOSTS"
android:value="checkout.example.com" />
</application>When the web offer can show
prepare() decides from what's being bought, with rules bundled in the SDK. Your server sets the purchase type for what it sells, and your app passes the same type. PayLinkOut can't check it, so you're responsible to the store for it.
On Android, prepare allows the purchase types that no store program covers:
| What's being bought | PayPurchaseType | Allowed |
|---|---|---|
| Digital goods and content used in the app | DIGITAL, the default | No |
| Physical goods | PHYSICAL | Yes |
| Services used outside the app | SERVICE | Yes |
| Financial services | FINANCIAL | Yes |
| Donations | DONATION | Yes |
| Gambling | GAMBLING | Yes |
| Live services between two people | LIVE_ONE_TO_ONE | No |
| A reader app's account link | READER | No |
The rules in each SDK version expire about six months after its release. Expired, missing, or unreadable rules never allow a digital purchase.
A preparation that isn't allowed has a reason for your logs. Don't show it to customers. Hide the web offer instead.
Open the checkout
PayLinkOut.open() is a suspend function. It opens the URL in the default browser, even when your app handles the checkout host's App Links, and returns once the customer is back. There's no timeout, so the customer can take as long as they like.
| Parameter | Type | Required | Description |
|---|---|---|---|
activity | ComponentActivity | Yes | A started activity that isn't finishing. Where a store requires a notice before the customer leaves the app, the notice shows over it. |
url | String | Yes | The checkout URL your server created for this preparation. |
preparation | PayLinkOutPreparation | Yes | The preparation from prepare, unchanged. |
presentation | PayLinkOutPresentation? | No | Where the checkout opens. Defaults to null, which uses the first allowed entry in the preparation's presentations (BROWSER, the browser app). |
- Each preparation opens once, and only in the app process that prepared it. For another attempt, prepare again.
- A preparation with store tokens expires 10 minutes after the tap.
- One link-out runs at a time.
open throws a PayLinkOutError only when nothing opened. Otherwise it returns a PayLinkOutResult:
| Result | When |
|---|---|
Returned(sessionId, outcomeHint) | Your return link came back with this link-out's client_state. sessionId is its session_id, and outcomeHint its outcome, for example succeeded, canceled, or expired. Use the hint for your UI only. |
Resumed | Your app came back to the foreground and no return link arrived within 1.5 seconds, or the return link had no session_id. |
Dismissed | The customer canceled the store's notice. Nothing opened. |
After Returned or Resumed, confirm payment status on your server.
When the activity is destroyed
If the activity is destroyed while the customer is away, for example on rotation, the open call ends with it, and the link-out goes on. Every result also arrives on PayLinkOut.results, a SharedFlow of PayLinkOutEvent instances, each with its link-out's clientState and result. It replays the latest result to a new collector, such as the recreated activity. Match it by clientState.
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
PayLinkOut.results.collect { event ->
if (event.clientState == pendingClientState) showResult(event.result)
}
}
}Handle the return link
PayLinkOut.handleReturn(context, url) takes a URL your activity was opened with. Call it in onCreate and onNewIntent. It returns true when the URL carries the pending link-out's client_state, and the result goes to a waiting open and to results. Other URLs, and states that are stale or forged, return false and change nothing, so you can pass every URL and handle the rest yourself.
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val url = intent.dataString ?: return
if (PayLinkOut.handleReturn(this, url)) return
// Not a link-out's return: handle your own link.
}handleReturn reads these query parameters of the return link:
| Parameter | Description |
|---|---|
client_state | The preparation's clientState, exactly once. |
session_id | The ID of the checkout's session. |
outcome | Optional. How the checkout ended, for example succeeded, canceled, or expired. |
If your app was killed
PayLinkOut.pendingLinkOut(context) is the link-out that was opened and hasn't ended in a waiting open. It's kept across app launches. When your app starts and it's set, ask your server about its clientState, then call PayLinkOut.clearPending(context).
A return link that arrives while no open is waiting still makes handleReturn return true, sends its result on results, and leaves the pending link-out for you to clear.
On your server
Your server does three things for a link-out.
- Create the checkout for the preparation, with a URL on a host your app lists in
ALLOWED_HOSTS, and keep itsclientState, so you can answer for a pending link-out. - Refuse a preparation whose
rulesVersionis0for a live payment, because it was made with sandbox rules. - Confirm the payment from Pay.com's signed webhooks or by retrieving the session, never from the return link's
outcome.
Test with your own rules
PayLinkOut.useSandboxRules(context, json) replaces the bundled rules with a table of your own, in debuggable builds only. Other builds throw Unsupported. Its preparations report rulesVersion 0. Pass null to go back to the bundled rules.
The table has the shape of the bundled rules, which are the same on iOS and Android. On Android, a test table matches only a rule whose store is "google":
{
"version": 1,
"issuedAt": "2026-11-23",
"expiresAt": "2027-05-23",
"rules": [
{
"store": "apple",
"storefronts": ["USA"],
"types": ["digital"],
"program": "us_link",
"tokens": [],
"notice": false,
"presentations": ["browser"],
"minOS": "15.0"
}
],
"restrictions": []
}Reference
PayLinkOut
PayLinkOut is a Kotlin object, and you call these members on it directly.
| Member | Description |
|---|---|
suspend fun prepare(context: Context, purchase: PayLinkOutPurchase = PayLinkOutPurchase()): PayLinkOutPreparation | Decides whether the web offer may show. Never throws. |
suspend fun open(activity: ComponentActivity, url: String, preparation: PayLinkOutPreparation, presentation: PayLinkOutPresentation? = null): PayLinkOutResult | Opens the checkout. See Open the checkout. |
fun handleReturn(context: Context, url: String): Boolean | Takes a URL your activity was opened with. See Handle the return link. |
val results: SharedFlow<PayLinkOutEvent> | Every result, with its link-out's clientState. |
fun pendingLinkOut(context: Context): PayLinkOutPending? | The link-out that was opened and hasn't ended in a waiting open, kept across launches. |
fun clearPending(context: Context) | Forgets the pending link-out, once your server has answered for it. |
suspend fun registerLaunch(context: Context): List<PayStoreToken> | The store tokens a store program wants at app launch, for your server. Empty when no program wants any. |
fun useSandboxRules(context: Context, json: String?) | Replaces the bundled rules in debuggable builds. See Test with your own rules. |
const val ALLOWED_HOSTS: String | The name of the manifest meta-data that lists your checkout hosts. |
PayLinkOutPreparation
prepare returns a PayLinkOutPreparation.
| Property | Type | Description |
|---|---|---|
decision | Decision | Decision.Allowed, or Decision.NotAllowed(reason), whose reason is for your logs. |
isAllowed | Boolean | Whether to show the web offer. |
purchase | PayLinkOutPurchase | The purchase you passed to prepare. Its type is a PayPurchaseType. |
store | String | google when Google Play installed your app, otherwise none. |
storefront | String? | The store's country, as an ISO 3166 alpha-3 code. null when it's unknown. |
program | String | The store program the link-out runs under, or none. |
storeTokens | List<PayStoreToken> | Tokens the store program wants your server to have. Empty for exempt purchases. |
tappedAt | Long | When the customer tapped, in milliseconds since the epoch. |
clientState | String | A random value, 192 bits in base64url, that names this link-out. The return link carries it back as client_state. |
presentations | List<PayLinkOutPresentation> | Where the checkout may open. The first is the default. |
rulesVersion | Int | The version of the rules that decided. 0 with sandbox rules. |
PayStoreToken
A PayStoreToken is a token a store program wants your server to have.
| Property | Type | Description |
|---|---|---|
platform | Platform | APPLE or GOOGLE. |
type | String? | The token's type, for Apple acquisition or services. null for Google. |
value | String | The token. PayLinkOut never logs it. |
PayLinkOutPending
pendingLinkOut returns a PayLinkOutPending, or null.
| Property | Type | Description |
|---|---|---|
clientState | String | The link-out's clientState. |
tappedAt | Long | When the customer tapped, in milliseconds since the epoch. |
openedAt | Long | When the checkout opened, in milliseconds since the epoch. |
PayLinkOutError
Each error has a code.
| Error | code | When |
|---|---|---|
InvalidUrl | invalid_url | The URL isn't https, its host isn't in ALLOWED_HOSTS, or it has a port or user info. |
NotAllowed(reason) | not_allowed | The preparation wasn't allowed, or the presentation isn't allowed here. |
PreparationExpired | preparation_expired | The preparation wasn't made by this app process, was changed or already used, or its store tokens are more than 10 minutes old. Prepare again. |
NoScreen | no_screen | The activity is finishing or destroyed. |
LinkOutInProgress | link_out_in_progress | Another link-out is open. |
Unsupported(detail) | unsupported | No browser could open the link, or the sandbox rules aren't valid or are used in a build that isn't debuggable. |
Next steps
- Webhooks: Learn on your server when a payment succeeds.
- Retrieve a payment session: Check a session's status after the customer comes back.