Skip to main content
The Tap to Pay SDK does not receive your API key. Your server keeps the key. Your server creates a short-lived access token for the account of the seller. The app gets that token with a closure that you give to TapToPay. This closure is the token provider.
Do not put a Whop API key in your app. This also applies to a restricted key. A person who downloads the app can remove the key from the bundle.

Create the token on your server

Call Create Access Token with: The API key must have the two permissions on that account. The token cannot have more permissions than the key.
The response contains the token in token. Return only that string to the app.
Put your own login before this endpoint. A person who can call the endpoint can accept payments on the account until the token expires.

Pass a token provider to the SDK

The token provider is an async throws closure. It returns the token string:
In the closure, get the token from your endpoint:
TapToPayTokens.swift
The SDK calls the provider before its first request. Then the SDK keeps the token. The SDK calls the provider again only when Whop rejects the token, for example after the token expires. Then the SDK sends that request one more time with the new token. You do not have to monitor the expiry time.Each TapToPay instance keeps its own token.
If the provider throws an error or returns an empty string, the charge fails with TapToPayError code .credentialsUnavailable. If the provider throws a TapToPayError, the SDK gives you that error without a change.If Whop also rejects a new token, the charge fails with .invalidCredentials. Usually, the cause is a token from the other environment. If the token does not have the correct permissions, the charge fails with .requestFailed and an underlyingCode of 403.
Stop the creation of tokens for the device. The last token of the device expires automatically, a maximum of three hours after its creation. To stop a device sooner, use a short expires_at.

Choose an environment

TapToPay uses production if you do not select a different environment:
Each environment rejects tokens from the other environment. TapToPayEnvironment has only these two cases. Thus, the SDK cannot send your token to a different server.

Next steps

Accept payments

Charge a variant or a custom amount.

Test in sandbox

Do a test of the full procedure without real money.