> ## Documentation Index
> Fetch the complete documentation index at: https://docs.whop.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Whop Trends: market data across Whop (revenue, growth, average order value, and customers by industry, product category, and country). Read it with no API key at `GET https://api.whop.com/api/v1/stats/reports/platform_trends`, or through the MCP server operation `get_platform_trends_report`. Guide and use cases: https://docs.whop.com/developer/guides/trends.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# Handle Tap to Pay Errors

> All TapToPayError codes that the Tap to Pay SDK throws. The cause of each code, and the message to show the seller.

All throwing methods on `TapToPay` throw `TapToPayError` with Swift typed throws. Catch it with `do throws(TapToPayError)`. Then you can read the `code` of the error without a cast:

```swift theme={null}
do throws(TapToPayError) {
    let payment = try await tapToPay.charge(variantID: "plan_xxxxxxxxxxxxx")
    show("Paid \(payment.id)")
} catch {
    switch error.code {
    case .cancelled:
        break
    case .declined:
        show("Card declined. Try another card.")
    case .outcomeUnknown:
        show("Check payment \(error.paymentID ?? "") before charging again.")
    default:
        show(error.message)
    }
}
```

After a charge fails, `TapToPay.lastError` contains the same error until the next charge starts.

## Error properties

| Property | Type | Meaning |
| - | - | - |
| `code` | `TapToPayError.Code` | The type of failure. Use it to select the action. |
| `message` | `String` | An English sentence that you can show the seller. `localizedDescription` returns the same sentence. |
| `underlyingCode` | `Int?` | For a request that Whop refused, the HTTP status. For a reader failure, the numeric code of the reader. Record it and include it in support requests. |
| `paymentID` | `String?` | The Whop payment that the error is about, `pay_…`, after Whop created a payment. |

> [!NOTE]
>
> `message` is in English. To show a different language to the seller, map `code` to your localized strings.

## Error codes

| Code | Cause | Message to the seller | Try again |
| - | - | - | - |
| `.cancelled` | The seller or your code cancelled, or the seller closed the Apple terms. | No message, or "Payment cancelled." | Yes |
| `.declined` | The issuer or the reader declined the card. | "Card declined. Try another card." | With another card |
| `.outcomeUnknown` | The reader has the card, but the SDK could not confirm the result. | "Checking the payment…" Then find the payment. | Only after you examine the payment |
| `.network` | A request did not go to Whop. | "Check your connection and try again." | Yes |
| `.busy` | A different charge runs. | No message. Disable the button while `isBusy` is `true`. | After the other charge stops |
| `.notPrepared` | The reader lost its connection. | "Try again." | Yes |
| `.termsNotAccepted` | The seller did not accept the Apple terms for Tap to Pay on iPhone. | "Accept the Tap to Pay terms. Sign in to an Apple Account first." | After the seller accepts the terms |
| `.passcodeRequired` | The iPhone does not have a passcode. | "Add a passcode in Settings." | After the seller adds a passcode |
| `.unsupportedDevice` | This device cannot use Tap to Pay. | "This iPhone cannot use Tap to Pay." | No |
| `.readerUnavailable` | Tap to Pay is not available for this account on this device. | "Tap to Pay is not available. Contact support." | No |
| `.readerIncompatible` | The SDK version in the app cannot accept this payment. | "Update the app." | No. Release an update. |
| `.invalidCredentials` | Whop rejected the token. | "Sign in again." | After you correct the token |
| `.credentialsUnavailable` | The token provider failed, or the reader could not start a session. | "Could not connect to Whop. Try again." | Yes |
| `.invalidPayment` | The payment is not in the correct state for this call. | `error.message` | No |
| `.requestFailed` | Whop refused the request. | `error.message` | Refer to `underlyingCode` |
| `.unknown` | All other failures. | `error.message` | Yes, one time |

## Error details

> [accordion] cancelled
>
> One of these conditions occurred:
>
> * Your code called `cancel()` or stopped the `Task` that runs `charge`.
> * The seller closed the Tap to Pay screen of iOS.
> * The seller refused the Apple terms.
>
> If the reader did not have the card, the SDK voided the payment. Usually, you show no message.

> [accordion] declined
>
> The card issuer or the reader declined the card. `paymentID` identifies the payment. Ask the buyer for a different card. Then charge again. Each `charge` creates a new payment.

> [accordion] outcomeUnknown
>
> The reader has the card, but the SDK could not confirm the result in the time limit. Usually, the cause is a network failure immediately after the tap. Whop possibly charged the buyer.
>
> **Do not charge again before you know the result.** Find the payment with `error.paymentID`. Use [Retrieve Payment](https://docs.whop.com/api-reference/payments/retrieve-payment.md) from your server, or use the dashboard. If the payment is successful, the sale is complete. If it is not successful, charge again.
>
> For this failure only, the SDK does not void the payment, because Whop possibly charged the card.

> [accordion] network
>
> A request to Whop failed after the SDK tried it again. Or, Whop was busy with an earlier attempt of the same request. Examine the connection and try again. Whop possibly created a payment before the failure. In this condition, the SDK voids the payment at the start of the next charge, if the app still runs. Thus, a new attempt does not keep duplicate payments open.

> [accordion] busy
>
> Only one charge or `prepare()` can run on a device at a time, for all `TapToPay` instances. If a `charge` starts while a different charge or a `prepare()` runs, it throws `.busy`. The running operation does not change. Disable your charge button while `isBusy` is `true`.

> [accordion] notPrepared
>
> The reader lost its connection, or its session expired. The next `charge` connects again. Thus, let the seller try again.

> [accordion] termsNotAccepted
>
> The seller must accept the Apple terms for Tap to Pay on iPhone one time on each device. For this, the seller must sign in to an Apple Account on the iPhone. iOS shows the terms on the first charge. If the seller did not sign in, or the terms do not open, the seller must sign in under **Settings**. Then try again.

> [accordion] passcodeRequired
>
> Tap to Pay on iPhone must have a device passcode. Tell the seller to add a passcode in **Settings**. Then try again.

> [accordion] unsupportedDevice
>
> The device cannot use Tap to Pay, for example an older iPhone. Before you show a charge option, examine `isSupported`. Then sellers do not get this error.

> [accordion] readerUnavailable
>
> Apple or Whop does not let this account use Tap to Pay on this device. For example, Apple or Whop blocked the device or the account, or the reader setup failed. A new attempt does not help. Tell the seller to contact Whop support with `underlyingCode`.

> [accordion] readerIncompatible
>
> Your app has a version of the SDK that Whop does not accept for this account. Or, the versions of the two SDK packages in your app are different. Update the `WhopTTP` package. Then release a new build. Refer to [Troubleshooting](https://docs.whop.com/tap-to-pay/troubleshooting.md).

> [accordion] invalidCredentials
>
> Whop rejected the token, also after the SDK got a new token. Usually, the cause is a token from the other environment, for example a sandbox token in a `.production` `TapToPay`. Make sure that your server uses the API key for the same environment. Refer to [Authentication](https://docs.whop.com/tap-to-pay/authentication.md#choose-an-environment).

> [accordion] credentialsUnavailable
>
> Your token provider threw an error or returned an empty string. Or, the reader could not start its session with Whop. Examine your token endpoint. Then try again.

> [accordion] invalidPayment
>
> The call is not correct for the payment. `attachBuyer` throws this error in these conditions:
>
> * The payment has a buyer.
> * You charged the payment with an email.
> * A different `TapToPay` instance charged the payment.
>
> `charge` throws this error when the Whop payment does not wait for a card. `message` gives the cause.

> [accordion] requestFailed
>
> Whop refused a request. `underlyingCode` is the HTTP status. `message` is the explanation from Whop.
>
> | `underlyingCode` | Usual cause |
> | - | - |
> | `400`, `422` | An input that is not valid, for example an unknown variant or a currency that the account cannot accept. |
> | `403` | The token does not have `payment:charge` or `payment:basic:read` on the account. Or, the account cannot use Tap to Pay. Examine the [readiness](https://docs.whop.com/tap-to-pay/onboarding.md). |
> | `404` | The variant or account is not in this environment. |
> | `429` | Too many requests. The SDK tried two more times. Wait, then try again. |
> | `502`, `503`, `504` | Whop was temporarily not available. The SDK tried two more times. Try again after a short time. |
> | `500` and other `5xx` | A Whop error. The SDK does not try these requests again. Try again one time. Then contact Whop support with `underlyingCode`. |

> [accordion] unknown
>
> The SDK could not identify the type of this error. Show `message`. Record `underlyingCode`. Let the seller try one more time. If the error occurs again, contact Whop support.

## Next steps

> [card] [Troubleshooting](https://docs.whop.com/tap-to-pay/troubleshooting.md)
>
> Solutions for setup problems, and answers to frequent questions.

> [card] [SDK reference](https://docs.whop.com/tap-to-pay/reference.md)
>
> All public types and members.


## Related topics

- [Tap to Pay SDK Reference](https://docs.whop.com/tap-to-pay/reference.md)
- [Tap to Pay Troubleshooting and FAQ](https://docs.whop.com/tap-to-pay/troubleshooting.md)
- [Build the Tap to Pay Payment Screen](https://docs.whop.com/tap-to-pay/payment-screen.md)
