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

# Accept Tap to Pay Payments

> Charge a product variant or a custom amount with the Tap to Pay SDK. Attach metadata and send a receipt to the buyer by email.

`charge` creates the payment on Whop. If the reader of the iPhone is not connected, `charge` connects it. Then `charge` waits for the card of the buyer. It returns when Whop has the result. You can charge a product variant that you sell, or a one-time amount.

| | Charge a variant | Charge a custom amount |
| - | - | - |
| **Call** | `charge(variantID:)` | `charge(_:currency:)` |
| **Source of the price** | The variant on Whop | Your app |
| **The buyer receives** | The access that the variant gives, for example a membership | A one-time payment without a product |
| **Use for** | A fixed list of items or passes | Tips, custom prices, amounts that are not fixed |

## Charge a variant

Give the ID of the variant. Whop charges the price of the variant.

```swift theme={null}
let payment = try await tapToPay.charge(variantID: "plan_xxxxxxxxxxxxx")
```

Find variant IDs in the dashboard or with [List Variants](https://docs.whop.com/api-reference/variants/list-variants.md). The variant must be part of the account that you gave to `TapToPay`.

## Charge a custom amount

Give the amount as a `Decimal` in major units. Also give a three-letter currency code:

```swift theme={null}
let payment = try await tapToPay.charge(Decimal(string: "49.99")!, currency: "usd")
```

> [!WARNING]
>
> Make amounts with cents from a string, as in this example, or from integers. `Decimal(49.99)` uses a `Double`, and the result can be `49.990000000000002`. Literals are safe for whole numbers: `charge(25, currency: "usd")`.

The currency code can be in upper case or lower case. If the account cannot accept the currency in person, Whop refuses it with `.requestFailed`.

## Know the buyer's email

If you know the email of the buyer, give it to `charge`. Whop attaches the purchase to that buyer. Whop also sends a receipt to the buyer by email:

```swift Variant theme={null}
let payment = try await tapToPay.charge(
    variantID: "plan_xxxxxxxxxxxxx",
    email: "dana@shinetime.example"
)
```

```swift Custom amount theme={null}
let payment = try await tapToPay.charge(
    120,
    currency: "usd",
    email: "dana@shinetime.example"
)
```

If the email is an empty string, Whop does not use an email.

## Send a receipt after the payment

Frequently, buyers give their email only after they pay. Charge without an email. Then call `attachBuyer(email:to:)` with the payment that `charge` returned:

```swift theme={null}
let payment = try await tapToPay.charge(variantID: "plan_xxxxxxxxxxxxx")

if payment.canAttachBuyer {
    try await tapToPay.attachBuyer(email: "dana@shinetime.example", to: payment)
}
```

Whop gives the purchase to the buyer with that email. Whop also sends the receipt to the buyer.

> [accordion] When you can attach a buyer
>
> You can attach a buyer one time for each payment. You can do this only when these conditions are true:
>
> * You charged the payment without an email. Thus, `canAttachBuyer` is `true`.
> * The same `TapToPay` instance charged the payment, in the same app session.
>
> In all other conditions, the SDK throws `.invalidPayment`. The instance keeps its attachable payments only in memory. Thus, the instance loses them when the app stops. If the request fails, for example with `.network`, the payment stays attachable. Then you can call `attachBuyer` again.

> [accordion] Attach a buyer from your server
>
> The SDK calls [Attach a buyer to an in-person payment](https://docs.whop.com/api-reference/payments/attach-a-buyer-to-an-in-person-payment.md). Your server can also call this endpoint with the payment ID. Do this if the email comes to a location that is not the app.

## Add metadata

The two `charge` methods accept `metadata`. This is a `[String: String]` dictionary that Whop saves on the payment:

```swift theme={null}
let payment = try await tapToPay.charge(
    variantID: "plan_xxxxxxxxxxxxx",
    metadata: ["order_id": "ord_1042", "location": "east-austin-van"]
)
```

Whop returns it as `metadata` on the payment from [Retrieve Payment](https://docs.whop.com/api-reference/payments/retrieve-payment.md). Use it to find the sale in your records.

## Read the result

`charge` returns a `TapToPayPayment` only when Whop has the result of the payment. If the issuer declines the card or a different failure occurs, `charge` throws a `TapToPayError`. Refer to [Handle errors](https://docs.whop.com/tap-to-pay/errors.md).

| Property | Type | Meaning |
| - | - | - |
| `id` | `String` | The Whop payment ID, `pay_…`. Use it with the [Payments API](https://docs.whop.com/api-reference/payments/retrieve-payment.md). |
| `status` | `TapToPayPayment.Status` | `.succeeded`: Whop collected the payment. `.requiresCapture`: the card authorization holds the funds, and the payment must have a capture. Charges from the SDK usually return `.succeeded`. |
| `total` | `TapToPayAmount?` | The amount of the charge. `amount` is a `Decimal`, and `currency` is an upper-case code, for example `USD`. The value is `nil` if Whop did not return an amount. |
| `canAttachBuyer` | `Bool` | `true` if you can call `attachBuyer` for this payment. |

```swift theme={null}
if let total = payment.total {
    print("Charged \(total.amount.formatted(.currency(code: total.currency)))")
}
```

## What happens during a charge

**1. Whop creates the payment**

Whop creates the payment for the variant or amount that you gave. The payment contains your email and metadata.

**2. The reader connects**

This occurs only on the first charge or after the reader disconnects. On the first charge on a device, iOS tells the seller to accept the Apple terms for Tap to Pay on iPhone. The reader can also install an update at this time.

**3. The buyer taps**

iOS shows its Tap to Pay screen. iOS reads the card, phone, or watch.

**4. Whop confirms the result**

The SDK waits until Whop records the result. Then the SDK returns the payment or throws an error.

Sometimes a charge stops before the reader gets the card. For example, you call `cancel()`, the `Task` ends, or an error occurs. Then the SDK voids the payment that it created. Thus, the payment does not stay open or keep the stock of the variant. Only one charge can run on a device at a time. If you start a second `charge` while a charge runs, it throws `.busy`.

## Next steps

> [card] [Build the payment screen](https://docs.whop.com/tap-to-pay/payment-screen.md)
>
> Show the progress and let the seller cancel.

> [card] [Handle errors](https://docs.whop.com/tap-to-pay/errors.md)
>
> Declines, network failures, and payments with an unknown result.


## Related topics

- [Build the Tap to Pay Payment Screen](https://docs.whop.com/tap-to-pay/payment-screen.md)
- [Tap to Pay SDK Reference](https://docs.whop.com/tap-to-pay/reference.md)
- [Onboard Accounts to Tap to Pay](https://docs.whop.com/tap-to-pay/onboarding.md)
