Skip to main content
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

Give the ID of the variant. Whop charges the price of the variant.
Find variant IDs in the dashboard or with List Variants. 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:
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:
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:
Whop gives the purchase to the buyer with that email. Whop also sends the receipt to the 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.
The SDK calls Attach a buyer to an in-person payment. 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:
Whop returns it as metadata on the payment from Retrieve Payment. 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.

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

Build the payment screen

Show the progress and let the seller cancel.

Handle errors

Declines, network failures, and payments with an unknown result.