Skip to main content
This page documents @whop/elements@1.8.0 and @whop/elements-react@1.8.0.
Since v1.0.0.
Create this Payments resource without mounting an element: whop.payments.paymentRequest.create({ … }) in vanilla or useWhop().payments.paymentRequest.create({ … }) in React.

Options

Pass these to whop.payments.paymentRequest.create({ … }).
string
required
Account ID, prefixed biz_, that scopes every client-side call.
string
required
Three-letter ISO 4217 payment currency code.
number
required
Payment amount in minor units. Change it later with update().
"off_session" | "on_session"
Set only after displaying save consent. Marks the token for off_session or on_session use.
boolean
Ask the sheet for the payer’s email — the confirmation token requires one. Defaults to true.
boolean
Ask the sheet for the payer’s phone number, delivered as payer.phone on the result — in E.164 where it parses against the country of the contact that supplied it, as the wallet gave it otherwise; payer.country is the billing country. Google Pay collects it through the billing address the sheet already asks for. Defaults to false.
boolean
Ask the sheet for a shipping address (and offer shippingOptions when given). PayPal always asks for an address, since it is the address tax is computed on, and returns it as shipping only when this is set. Defaults to false.
boolean
Offer the sheet’s own promo code field and answer onPromoCodeChange. Apple Pay shows the field on devices that support Apple Pay version 12 (iOS 15 and macOS 12); Google Pay shows it where the account’s Google Pay setup allows offers. Other devices open the sheet without it. Defaults to false. Since v1.5.0.
string
A promo code already applied to the charge, prefilled into the sheet so the buyer can see or remove it. Since v1.5.0.
string
What appliedPromoCode does, shown next to the code where the sheet captions applied codes (Google Pay). Since v1.5.0.
string
Account ISO 3166-1 alpha-2 country code for the Apple Pay sheet. Omit it to use the account’s published registration country. The sheet defaults to US when neither is available.
PaymentRequestLineItem[]
Line items the sheet lists under the total. Change it later with update().
PaymentRequestShippingOption[]
Shipping options the sheet offers when requestShipping is set. Display-only — update amount from your change handler. Change it later with update().

Methods

Call these on the resource.
Call show synchronously during user activation. Await prerequisites first.

canMakePayment

Returns availability for each wallet when the account offers it, the device supports it, and this page’s origin is approved for the account (first-party whop.com pages are pre-approved; a merchant page needs its domain registered and verified as a payment method domain, and offering Google Pay there is subject to the Google Pay API Terms of Service). On a page that is itself inside an iframe, Apple Pay checks the top-level page’s domain instead when the browser exposes it. Apple Pay on non-WebKit browsers is the desktop iPhone-handoff flow, so mobile devices there report it unavailable — native Apple Pay on iOS browsers is unaffected. order ranks the wallets by which sheet is native to the browser — Apple Pay first on Safari, Google Pay first elsewhere, PayPal last — so express buttons can stack best-first. payPal reports PayPal where the account offers it in this currency, the amount is within PayPal’s limits, the request neither sets setupFutureUsage nor asks for the payer’s phone, PayPal’s scripts load on this page, and this page’s origin is approved for the account like the other wallets’. A page with a Content Security Policy must allow PayPal’s hosts, which contentSecurityPolicy() includes. A page that already loads PayPal’s own v5 JavaScript SDK reports payPal: false. Pass types to check only the wallets you list; show(type) needs that wallet checked. wallets carries each available wallet’s official button art (light and dark color and image). This primes show(). Always await it first.Signature: (filter?: { types?: ("apple_pay" | "google_pay" | "paypal_express")[] | undefined; } | undefined) => Promise<WalletAvailability>

show

Open the selected wallet after awaiting canMakePayment(), synchronously in the press: Apple requires session creation within the gesture stack, and PayPal opens its window there — a pop-up on desktop, PayPal’s in-page window when the pop-up is blocked and on mobile. Pass email when your page already collected one — the wallet takes it and never asks for a second. With requestPayerEmail: false, passing one is required, and the wallet refuses to open without it because confirmation tokens require an email. While the sheet is open, update() throws: answer the change events to change it. Call synchronously during user activation. Await prerequisites first because browsers revoke activation across asynchronous steps.Signature: (type: "apple_pay" | "google_pay" | "paypal_express", provided?: { email?: string | undefined; } | undefined) => Promise<PaymentRequestResult>

update

Change amount, lineItems and shippingOptions on this instance. Every other option is fixed at create(): create a new instance to change it.Signature: (patch: { amount?: number | undefined; lineItems?: PaymentRequestLineItem[] | undefined; shippingOptions?: PaymentRequestShippingOption[] | undefined; }) => void

Events

Subscribe to events below. Each method returns an unsubscribe function.
Each event handler must call its documented reply method exactly once. A handler that throws or rejects before replying fails that update right away.

onShippingAddressChange

The sheet’s shipping address changed (redacted pre-authorization: city/state/postal/country only). An error in the answer that names a field (city, state, postal_code, country) marks that field in Apple Pay; Google Pay shows the message alone. PayPal fires it with the address the buyer picks, and an error naming a field refuses that part of the address inside PayPal. Call updateWith(…) exactly once per event. A handler that throws or rejects before calling it fails that update right away. Returns the unsubscribe function.Signature: (handler: (ev: ShippingAddressChangeEvent) => void) => () => void

onShippingOptionChange

The buyer picked a shipping option. Amount-only contract: updateWith carries amount/lineItems/shippingOptions/errors. Apple Pay has no error slot for a shipping option: an answer with errors keeps the last accepted total, and the first error’s message shows when the buyer taps Pay, until they pick an option your handler accepts. Google Pay shows the message when the option is picked. Call updateWith(…) exactly once per event. A handler that throws or rejects before calling it fails that update right away. Returns the unsubscribe function.Signature: (handler: (ev: ShippingOptionChangeEvent) => void) => () => void

onBillingAddressChange

Fires at sheet open and on card switches with the selected card’s redacted billing address (city/state/postal/country only) — reprice the total for the address the charge taxes off. Answer updateWith({ amount }) in minor units, updateWith({}) to keep the current total, or updateWith({ errors }) to refuse the card. Every event is answered exactly once: a handler that throws, rejects, or doesn’t answer within 10 seconds refuses the card, so the buyer picks another one. PayPal fires it with each shipping address the buyer picks in PayPal, which is the address its token bills and taxes on, and a refusal there refuses that address inside PayPal. Call updateWith(…) exactly once per event. A handler that throws or rejects before calling it fails that update right away. Returns the unsubscribe function.Signature: (handler: (ev: BillingAddressChangeEvent) => void) => () => void

onPromoCodeChange

The buyer typed, changed, or removed a code in the sheet’s promo field (requestPromoCode). Answer updateWith({ amount }) to apply the code at a new total, updateWith({}) to apply it at the current total, or updateWith({ error }) to refuse it in place. A removal arrives with code null and is answered the same way. A handler that throws, rejects, or doesn’t answer within 10 seconds refuses the code. Call updateWith(…) exactly once per event. A handler that throws or rejects before calling it fails that update right away. Returns the unsubscribe function.Signature: (handler: (ev: PromoCodeChangeEvent) => void) => () => void

onConfirmationToken

The sheet created a confirmation token. This is the same result that show() returns. Returns the unsubscribe function.Signature: (handler: (ev: PaymentRequestResult) => void) => () => void

onCancel

The buyer dismissed the sheet or closed PayPal. Returns the unsubscribe function.Signature: (handler: () => void) => () => void

Content security policy

This resource runs on your page, not in a frame. A page with a Content Security Policy needs these sources. contentSecurityPolicy() from @whop/elements returns every source in this table. The sandbox source applies with environment: "sandbox".
No element and no controller: an object you drive yourself, for an express checkout button above the form. canMakePayment() primes the sheet, show() resolves to the same ctok_ an element mints, and the sheet stays open until complete(success:) reports what your server said.

Usage

Parameters

String
required
The account the charge belongs to, prefixed biz_.
WhopElementsConfiguration
environment, returnURL and locale behave as they do everywhere else. Defaults to WhopElementsConfiguration().
WhopCharge
required
.plan(id:) or .amount(minorUnits:currency:). Settable later; the next canMakePayment() re-resolves it.
WhopSetupFutureUsage?
.offSession or .onSession. Set only after showing save consent.
WhopPaymentRequest.Options
requestPayerEmail and requestBillingAddress ask the sheet for what you did not supply (both default to true), and label overrides the line item shown above the total.

WhopConfirmationToken

What a selection hands back:
  • id: String: the ctok_ to confirm server-side
  • paymentMethodType: WhopPaymentMethodType: apple_pay on this lane

States

canMakePayment() returns false when the device cannot pay, when the account has no Apple Pay merchant registered, or when the charge fails to resolve; lastError says which. isPresenting is true while the sheet is up. show() throws walletUnavailable rather than failing silently, and its message distinguishes a buyer who dismissed the sheet from a sheet that could not open at all. Retrying after a refused confirm is safe: a new show() supersedes the sheet the previous one left behind.

Good to know

  • show() is a plain async call, so you can await whatever the charge needs before presenting the sheet.
  • Pair it with WhopApplePayButton, which is Apple’s own PKPaymentButton. Apple’s guidelines require the system control rather than a drawn imitation.
  • The sheet is asked for an email and a billing address exactly when you did not supply them, and its answers fill only the gaps.
  • The Apple Pay merchant is the one registered on the Whop account. Your app supplies nothing and needs no In-App Payments capability.

Install

WhopPaymentRequest needs no scope and no mounted element, so it is the one payments surface that does not require WhopBrandingElement on screen. Show the merchant-of-record line yourself. The module is Elements, not the wallet SDK’s WhopElements. See Getting started.