Skip to Content
Docs

Link out to a web checkout

Send a customer from your app to a checkout in the browser, when the App Store's rules allow it for what they're buying, and learn how they came back.

PayLinkOut 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.
import PayLinkOut

// On the customer's tap. prepare never throws.
let preparation = await PayLinkOut.prepare(PayLinkOutPurchase(type: .digital))
guard preparation.isAllowed else { return } // Don't offer the web checkout.

// Your server creates the checkout for this preparation and returns its URL.
let url = try await backend.createCheckout(
    clientState: preparation.clientState,
    tappedAt: preparation.tappedAt,
    storeTokens: preparation.storeTokens
)

switch try await PayLinkOut.open(url, preparation: preparation, presenter: self) {
case let .returned(sessionID, _):
    await backend.checkSession(sessionID)
case .resumed:
    await backend.checkLinkOut(preparation.clientState)
case .dismissed:
    break // 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 product, your Info.plist, and your return link before your first link-out.

  1. Link the PayLinkOut product of the pay-com-ios package. It's a standalone product with no SDK dependencies and runs on iOS 15 or later.
  2. List the hosts of your checkout URLs in your app's Info.plist, under PayLinkOutAllowedHosts, 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 a universal link to your app, and pass the URLs your app is opened with to PayLinkOut.handleReturn(_:).
<key>PayLinkOutAllowedHosts</key>
<array>
    <string>checkout.example.com</string>
</array>

When the web offer can show

prepare(_:) decides from what's being bought and the customer's App Store storefront, 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 Apple for it.

What's being boughtPayPurchaseTypeWhere prepare allows it
Digital goods and content used in the app.digital, the defaultThe United States App Store storefront, on iOS 15 or later. The checkout opens in the browser app.
Physical goods.physicalEvery storefront
Services used outside the app.serviceEvery storefront
Financial services.financialEvery storefront
Donations.donationEvery storefront
Gambling.gamblingEvery storefront
Live services between two people.liveOneToOneNowhere
A reader app's account link.readerNowhere

A digital purchase isn't allowed either when the storefront is unknown, or when the bundled rules are missing, unreadable, or expired. The rules in each SDK version expire about six months after its release. Update the SDK to keep offering digital purchases on the web.

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

open(_:preparation:presentation:presenter:) opens the URL and returns once the customer is back. There's no timeout, so the customer can take as long as they like.

ParameterTypeRequiredDescription
urlURLYesThe checkout URL your server created for this preparation.
preparationPayLinkOutPreparationYesThe preparation from prepare, unchanged.
presentationPayLinkOutPresentation?NoWhere the checkout opens. Defaults to nil, which uses the first allowed entry in the preparation's presentations (.browser, the browser app).
presenterUIViewControllerYesA view controller in a window. Where a store requires a notice before the customer leaves the app, the notice shows over it.
  • 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.

PayLinkOut.handleReturn(_:) takes a URL your app was opened with. It returns true when the URL carries the pending link-out's client_state, and a waiting open then returns .returned. 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.

.onOpenURL { url in
    if PayLinkOut.handleReturn(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 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().

A return link that arrives while no open is waiting still makes handleReturn return true, 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 PayLinkOutAllowedHosts, 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(_:) replaces the bundled rules with a table of your own, in debug builds only. A release build throws unsupported. Its preparations report rulesVersion 0. Pass nil to go back to the bundled rules.

The table has the bundled rules' shape:

{
  "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 Swift enum, and you call these members on it directly.

MemberDescription
prepare(_ purchase: PayLinkOutPurchase = PayLinkOutPurchase()) async -> PayLinkOutPreparationDecides whether the web offer may show. Never throws. Anything missing makes a digital purchase not allowed.
open(_:preparation:presentation:presenter:) async throws(PayLinkOutError) -> PayLinkOutResultOpens the checkout. See Open the checkout.
handleReturn(_ url: URL) -> BoolTakes a URL your app was opened with. See Handle the return link.
pendingLinkOut: PayLinkOutPending?The link-out that was opened and hasn't ended in a waiting open, kept across launches.
clearPending()Forgets the pending link-out, once your server has answered for it.
registerLaunch() async -> [PayStoreToken]The store tokens a store program wants at app launch, for your server. Empty when no program wants any.
useSandboxRules(_ json: Data?) throws(PayLinkOutError)Replaces the bundled rules in debug builds. See Test with your own rules.

PayLinkOutPreparation

prepare returns a PayLinkOutPreparation.

PropertyTypeDescription
decisionDecision.allowed, or .notAllowed(reason:), whose reason is for your logs.
isAllowedBoolWhether to show the web offer.
purchasePayLinkOutPurchaseThe purchase you passed to prepare. Its type is a PayPurchaseType.
storeStringapple, or none for a purchase no store program covers.
storefrontString?The App Store storefront's country, as an ISO 3166 alpha-3 code such as USA. nil when it's unknown.
programStringThe store program the link-out runs under, such as us_link, or none.
storeTokens[PayStoreToken]Tokens the store program wants your server to have. Empty for us_link and exempt purchases.
tappedAtDateWhen the customer tapped, to the millisecond.
clientStateStringA random value, 192 bits in base64url, that names this link-out. The return link carries it back as client_state.
presentations[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
platformPlatform.apple or .google.
typeString?The token's type, for Apple acquisition or services.
valueStringThe token. PayLinkOut never logs it, and its description hides it.

PayLinkOutPending

pendingLinkOut holds a PayLinkOutPending, or nil.

PropertyTypeDescription
clientStateStringThe link-out's clientState.
tappedAtDateWhen the customer tapped.
openedAtDateWhen the checkout opened.

PayLinkOutError

Each error has a code.

ErrorcodeWhen
.invalidURLinvalid_urlThe URL isn't https, its host isn't in PayLinkOutAllowedHosts, 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 presenter isn't in a window.
.linkOutInProgresslink_out_in_progressAnother link-out is open.
.unsupported(_:)unsupportedThe system couldn't open the link, or the sandbox rules aren't valid or are used in a release build.

Next steps

Was this page helpful?