> ## 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.

# Tap to Pay SDK Reference

> All public types and members of the WhopTTP Swift package: TapToPay, its phases, payments, readiness, environments, and errors.

> [!NOTE]
>
> This page documents `WhopTTP` 1.0.0. `import WhopTTP` adds all the types on this page.

## `TapToPay`

```swift theme={null}
@MainActor @Observable
public final class TapToPay
```

Accepts Tap to Pay payments for one Whop account. Its state updates on the main actor. Thus, SwiftUI observes it directly.

### Create an instance

```swift theme={null}
public convenience nonisolated init(
    accountID: String,
    environment: TapToPayEnvironment = .production,
    tokenProvider: @escaping TokenProvider
)
```

**accountID** `String` *required*

The account of the seller, `biz_…`. Tokens from `tokenProvider` must be for this account.

**environment** `TapToPayEnvironment` (default: .production)

Production or sandbox. Refer to [`TapToPayEnvironment`](#taptopayenvironment).

**tokenProvider** `TokenProvider` *required*

Returns an access token for `accountID`, with the `payment:charge` and `payment:basic:read` scopes. The SDK calls it before its first request. The SDK calls it again only when Whop rejects the current token. Refer to [Authentication](https://docs.whop.com/tap-to-pay/authentication.md).

```swift theme={null}
public typealias TokenProvider = @Sendable () async throws -> String
```

### Charge methods

```swift theme={null}
public func charge(
    variantID: String,
    email: String? = nil,
    metadata: [String: String] = [:]
) async throws(TapToPayError) -> TapToPayPayment

public func charge(
    _ amount: Decimal,
    currency: String,
    email: String? = nil,
    metadata: [String: String] = [:]
) async throws(TapToPayError) -> TapToPayPayment
```

Creates a payment, connects the reader if necessary, and reads the card. Returns when Whop has the result. The SDK voids a payment if the reader did not get the card.

**variantID** `String` *required*

The variant to sell. Whop charges the price of the variant.

**amount** `Decimal` *required*

The amount in major units, for example `25` or `Decimal(string: "49.99")!`.

**currency** `String` *required*

A three-letter currency code, for example `"usd"`. You can use upper case or lower case.

**email** `String?` (default: nil)

The email of the buyer. Whop attaches the purchase to that buyer and sends a receipt by email. If the value is `nil` or an empty string, you can use [`attachBuyer`](https://docs.whop.com/tap-to-pay/accept-payments#send-a-receipt-after-the-payment) later.

**metadata** `[String: String]` (default: \[:])

Your key-value data. Whop saves it on the payment as `metadata`.

### `attachBuyer(email:to:)`

```swift theme={null}
public func attachBuyer(email: String, to payment: TapToPayPayment) async throws(TapToPayError)
```

Gives the purchase to the buyer with this email and sends the receipt to the buyer. You can use it one time, on a payment that this instance charged without an email, while the app runs. In other conditions, it throws `.invalidPayment`.

### `readiness()`

```swift theme={null}
public func readiness() async throws(TapToPayError) -> TapToPayReadiness
```

Reads if the account can use Tap to Pay on iPhone. Refer to [Onboard accounts](https://docs.whop.com/tap-to-pay/onboarding.md).

### `prepare()`

```swift theme={null}
public func prepare() async throws(TapToPayError)
```

Connects the reader before a sale. Thus, the Tap to Pay screen shows sooner. On the first connection on a device, iOS shows the Apple terms for Tap to Pay on iPhone. `charge` connects automatically, thus this call is optional. Refer to [Prepare the reader](https://docs.whop.com/tap-to-pay/payment-screen.md#prepare-the-reader).

### `cancel()`

```swift theme={null}
public nonisolated func cancel()
```

Stops the charge or `prepare()` that this instance runs. That call then throws `.cancelled`. If no charge runs, `cancel()` does nothing. If you cancel the `Task` that called `charge`, the result is the same.

### State

**phase** `TapToPay.Phase`

The current step of the charge or `prepare()` that runs. The value is `.idle` when no operation runs.

**isBusy** `Bool`

`true` when `phase` is not `.idle`.

**lastError** `TapToPayError?`

The error from the last charge that failed. The SDK clears it when the next charge starts.

**isSupported** `Bool`

`true` if this device can use Tap to Pay with this SDK. It is `nonisolated`. Thus, you can read it from all threads.

## `TapToPay.Phase`

```swift theme={null}
public enum Phase: Sendable, Equatable {
    case idle
    case connecting
    case updatingReader(progress: Double)
    case waitingForCard
    case processing
}
```

| Case | Meaning |
| - | - |
| `idle` | No charge runs. |
| `connecting` | A charge started, and the reader connects. |
| `updatingReader(progress:)` | The reader installs an update. `progress` increases from `0` to `1`. |
| `waitingForCard` | iOS shows its Tap to Pay screen. |
| `processing` | The reader has the card, and Whop confirms the payment. |

## `TapToPayPayment`

```swift theme={null}
public struct TapToPayPayment: Sendable, Equatable
```

**id** `String`

The Whop payment ID, `pay_…`.

**status** `TapToPayPayment.Status`

The result of the payment.

**Status cases**

**succeeded**

Whop collected the payment.

**requiresCapture**

The card authorization holds the funds, and the payment must have a capture.

**total** `TapToPayAmount?`

The amount of the charge, or `nil` if Whop did not return an amount.

**TapToPayAmount properties**

**amount** `Decimal`

The amount in major units.

**currency** `String`

The upper-case currency code, for example `USD`.

**canAttachBuyer** `Bool`

`true` when you charged without an email and did not attach a buyer after the charge.

For SwiftUI previews and tests, the two types have a public `init`: `TapToPayPayment(id:status:total:canAttachBuyer:)` and `TapToPayAmount(amount:currency:)`.

## `TapToPayReadiness`

```swift theme={null}
public struct TapToPayReadiness: Sendable, Equatable
```

**status** `TapToPayReadiness.Status`

Tells if the account can use Tap to Pay.

**Status cases**

**active**

The account can accept payments.

**needsOnboarding**

The account is eligible, but Tap to Pay is not active.

**pending**

Whop enables card payments on the account.

**unsupported**

The account cannot use Tap to Pay on iPhone.

**supportedCountries** `[String]`

Two-letter codes of the countries where Tap to Pay on iPhone is available.

It also has a public `init`, `TapToPayReadiness(status:supportedCountries:)`.

## `TapToPayEnvironment`

```swift theme={null}
public enum TapToPayEnvironment: String, Sendable, CaseIterable {
    case production
    case sandbox
}
```

| Case | API host |
| - | - |
| `production` | `https://api.whop.com` |
| `sandbox` | `https://sandbox-api.whop.com` |

## `TapToPayError`

```swift theme={null}
public struct TapToPayError: Error, Sendable, Equatable, LocalizedError
```

**code** `TapToPayError.Code`

The type of failure.

**Code cases**

`unsupportedDevice`, `readerIncompatible`, `notPrepared`, `busy`, `invalidCredentials`, `credentialsUnavailable`, `invalidPayment`, `requestFailed`, `termsNotAccepted`, `passcodeRequired`, `cancelled`, `declined`, `outcomeUnknown`, `network`, `readerUnavailable`, `unknown`. Refer to [Handle errors](https://docs.whop.com/tap-to-pay/errors.md) for each code.

**message** `String`

An English description that you can show. `errorDescription` returns the same text.

**underlyingCode** `Int?`

The HTTP status for a refused request, or the numeric code of the reader for a reader failure.

**paymentID** `String?`

The Whop payment that the error is about, after Whop created a payment.

`TapToPayError.Code` is a `String`-backed enum. Thus, `error.code.rawValue` gives a name that does not change, for logs. A token provider can use the public `init`, `TapToPayError(code:message:underlyingCode:paymentID:)`, to throw an error. The SDK gives you that error without a change.


## Related topics

- [Authenticate the Tap to Pay SDK](https://docs.whop.com/tap-to-pay/authentication.md)
- [Handle Tap to Pay Errors](https://docs.whop.com/tap-to-pay/errors.md)
- [Tap to Pay SwiftUI Example](https://docs.whop.com/tap-to-pay/example-app.md)
