Skip to main content
This page documents WhopTTP 1.0.0. import WhopTTP adds all the types on this page.

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

String
required
The account of the seller, biz_…. Tokens from tokenProvider must be for this account.
TapToPayEnvironment
default:".production"
Production or sandbox. Refer to TapToPayEnvironment.
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.

Charge methods

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.
String
required
The variant to sell. Whop charges the price of the variant.
Decimal
required
The amount in major units, for example 25 or Decimal(string: "49.99")!.
String
required
A three-letter currency code, for example "usd". You can use upper case or lower case.
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 later.
[String: String]
default:"[:]"
Your key-value data. Whop saves it on the payment as metadata.

attachBuyer(email:to:)

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()

Reads if the account can use Tap to Pay on iPhone. Refer to Onboard accounts.

prepare()

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.

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

TapToPay.Phase
The current step of the charge or prepare() that runs. The value is .idle when no operation runs.
Bool
true when phase is not .idle.
TapToPayError?
The error from the last charge that failed. The SDK clears it when the next charge starts.
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

TapToPayPayment

String
The Whop payment ID, pay_….
TapToPayPayment.Status
The result of the payment.
TapToPayAmount?
The amount of the charge, or nil if Whop did not return an amount.
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

TapToPayReadiness.Status
Tells if the account can use Tap to Pay.
[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

TapToPayError

TapToPayError.Code
The type of failure.
String
An English description that you can show. errorDescription returns the same text.
Int?
The HTTP status for a refused request, or the numeric code of the reader for a reader failure.
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.