Skip to Content
Docs

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.

  1. When the customer taps your web offer, prepare decides whether it may show, and gives what your server needs.
  2. Your app sends the preparation's clientState, tappedAt, and storeTokens to your server, which creates the checkout and returns its URL.
  3. open opens the URL in the browser app, and returns when the customer comes back.
  4. 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.

  1. Depend on pay-linkout. It's a standalone module with no SDK dependencies and runs on minSdk 24 (Android 7.0) or later.
  2. List the hosts of your checkout URLs in your manifest, comma-separated, in the com.pay.sdk.linkout.ALLOWED_HOSTS meta-data (PayLinkOut.ALLOWED_HOSTS), with an international name in punycode. open opens only https URLs on these hosts, matched exactly, with no port or user info.
  3. 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 boughtPayPurchaseTypeAllowed
Digital goods and content used in the appDIGITAL, the defaultNo
Physical goodsPHYSICALYes
Services used outside the appSERVICEYes
Financial servicesFINANCIALYes
DonationsDONATIONYes
GamblingGAMBLINGYes
Live services between two peopleLIVE_ONE_TO_ONENo
A reader app's account linkREADERNo

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.

ParameterTypeRequiredDescription
activityComponentActivityYesA started activity that isn't finishing. Where a store requires a notice before the customer leaves the app, the notice shows over it.
urlStringYesThe checkout URL your server created for this preparation.
preparationPayLinkOutPreparationYesThe preparation from prepare, unchanged.
presentationPayLinkOutPresentation?NoWhere 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:

ResultWhen
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.
ResumedYour app came back to the foreground and no return link arrived within 1.5 seconds, or the return link had no session_id.
DismissedThe 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)
        }
    }
}

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:

ParameterDescription
client_stateThe preparation's clientState, exactly once.
session_idThe ID of the checkout's session.
outcomeOptional. 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 its clientState, so you can answer for a pending link-out.
  • Refuse a preparation whose rulesVersion is 0 for 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.

MemberDescription
suspend fun prepare(context: Context, purchase: PayLinkOutPurchase = PayLinkOutPurchase()): PayLinkOutPreparationDecides whether the web offer may show. Never throws.
suspend fun open(activity: ComponentActivity, url: String, preparation: PayLinkOutPreparation, presentation: PayLinkOutPresentation? = null): PayLinkOutResultOpens the checkout. See Open the checkout.
fun handleReturn(context: Context, url: String): BooleanTakes 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: StringThe name of the manifest meta-data that lists your checkout hosts.

PayLinkOutPreparation

prepare returns a PayLinkOutPreparation.

PropertyTypeDescription
decisionDecisionDecision.Allowed, or Decision.NotAllowed(reason), whose reason is for your logs.
isAllowedBooleanWhether to show the web offer.
purchasePayLinkOutPurchaseThe purchase you passed to prepare. Its type is a PayPurchaseType.
storeStringgoogle when Google Play installed your app, otherwise none.
storefrontString?The store's country, as an ISO 3166 alpha-3 code. null when it's unknown.
programStringThe store program the link-out runs under, or none.
storeTokensList<PayStoreToken>Tokens the store program wants your server to have. Empty for exempt purchases.
tappedAtLongWhen the customer tapped, in milliseconds since the epoch.
clientStateStringA random value, 192 bits in base64url, that names this link-out. The return link carries it back as client_state.
presentationsList<PayLinkOutPresentation>Where the checkout may open. The first is the default.
rulesVersionIntThe version of the rules that decided. 0 with sandbox rules.

PayStoreToken

A PayStoreToken is a token a store program wants your server to have.

PropertyTypeDescription
platformPlatformAPPLE or GOOGLE.
typeString?The token's type, for Apple acquisition or services. null for Google.
valueStringThe token. PayLinkOut never logs it.

PayLinkOutPending

pendingLinkOut returns a PayLinkOutPending, or null.

PropertyTypeDescription
clientStateStringThe link-out's clientState.
tappedAtLongWhen the customer tapped, in milliseconds since the epoch.
openedAtLongWhen the checkout opened, in milliseconds since the epoch.

PayLinkOutError

Each error has a code.

ErrorcodeWhen
InvalidUrlinvalid_urlThe URL isn't https, its host isn't in ALLOWED_HOSTS, or it has a port or user info.
NotAllowed(reason)not_allowedThe preparation wasn't allowed, or the presentation isn't allowed here.
PreparationExpiredpreparation_expiredThe 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.
NoScreenno_screenThe activity is finishing or destroyed.
LinkOutInProgresslink_out_in_progressAnother link-out is open.
Unsupported(detail)unsupportedNo browser could open the link, or the sandbox rules aren't valid or are used in a build that isn't debuggable.

Next steps

Was this page helpful?