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.TapToPay.
Charge a custom amount
Give the amount as aDecimal in major units. Also give a three-letter currency code:
.requestFailed.
Know the buyer’s email
If you know the email of the buyer, give it tocharge. Whop attaches the purchase to that buyer. Whop also sends a receipt to the buyer by email:
Send a receipt after the payment
Frequently, buyers give their email only after they pay. Charge without an email. Then callattachBuyer(email:to:) with the payment that charge returned:
When you can attach a buyer
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,
canAttachBuyeristrue. - The same
TapToPayinstance charged the payment, in the same app session.
.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.Attach a buyer from your server
Attach a buyer from your server
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 twocharge methods accept metadata. This is a [String: String] dictionary that Whop saves on the payment:
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.
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.

