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.
- 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.
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.
- Link the
PayLinkOutproduct of thepay-com-iospackage. It's a standalone product with no SDK dependencies and runs on iOS 15 or later. - List the hosts of your checkout URLs in your app's
Info.plist, underPayLinkOutAllowedHosts, 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 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 bought | PayPurchaseType | Where prepare allows it |
|---|---|---|
| Digital goods and content used in the app | .digital, the default | The United States App Store storefront, on iOS 15 or later. The checkout opens in the browser app. |
| Physical goods | .physical | Every storefront |
| Services used outside the app | .service | Every storefront |
| Financial services | .financial | Every storefront |
| Donations | .donation | Every storefront |
| Gambling | .gambling | Every storefront |
| Live services between two people | .liveOneToOne | Nowhere |
| A reader app's account link | .reader | Nowhere |
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | URL | 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 nil, which uses the first allowed entry in the preparation's presentations (.browser, the browser app). |
presenter | UIViewController | Yes | A 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:
| 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.
Handle the return link
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:
| 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 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 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(_:) 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.
| Member | Description |
|---|---|
prepare(_ purchase: PayLinkOutPurchase = PayLinkOutPurchase()) async -> PayLinkOutPreparation | Decides whether the web offer may show. Never throws. Anything missing makes a digital purchase not allowed. |
open(_:preparation:presentation:presenter:) async throws(PayLinkOutError) -> PayLinkOutResult | Opens the checkout. See Open the checkout. |
handleReturn(_ url: URL) -> Bool | Takes 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.
| Property | Type | Description |
|---|---|---|
decision | Decision | .allowed, or .notAllowed(reason:), whose reason is for your logs. |
isAllowed | Bool | Whether to show the web offer. |
purchase | PayLinkOutPurchase | The purchase you passed to prepare. Its type is a PayPurchaseType. |
store | String | apple, or none for a purchase no store program covers. |
storefront | String? | The App Store storefront's country, as an ISO 3166 alpha-3 code such as USA. nil when it's unknown. |
program | String | The 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. |
tappedAt | Date | When the customer tapped, to the millisecond. |
clientState | String | A 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. |
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. |
value | String | The token. PayLinkOut never logs it, and its description hides it. |
PayLinkOutPending
pendingLinkOut holds a PayLinkOutPending, or nil.
| Property | Type | Description |
|---|---|---|
clientState | String | The link-out's clientState. |
tappedAt | Date | When the customer tapped. |
openedAt | Date | When the checkout opened. |
PayLinkOutError
Each error has a code.
| Error | code | When |
|---|---|---|
.invalidURL | invalid_url | The URL isn't https, its host isn't in PayLinkOutAllowedHosts, 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 presenter isn't in a window. |
.linkOutInProgress | link_out_in_progress | Another link-out is open. |
.unsupported(_:) | unsupported | The system couldn't open the link, or the sandbox rules aren't valid or are used in a release build. |
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.