@whop/elements 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/payments.d.ts CHANGED
@@ -39,10 +39,6 @@ export type PaymentsOptions = (
39
39
  * Wallet availability override for deterministic previews. Live checkouts probe the host.
40
40
  */
41
41
  previewWalletAvailability?: WalletAvailability;
42
- /**
43
- * Checkout session updated when a buyer signs in. Pass its `chs_`-prefixed `id` and `client_secret`. Without them, sign-in succeeds but the session does not record the buyer.
44
- */
45
- checkoutSession?: { id: string; clientSecret: string; };
46
42
  /**
47
43
  * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
48
44
  */
@@ -89,10 +85,6 @@ export type PaymentsOptions = (
89
85
  * Wallet availability override for deterministic previews. Live checkouts probe the host.
90
86
  */
91
87
  previewWalletAvailability?: WalletAvailability;
92
- /**
93
- * Checkout session updated when a buyer signs in. Pass its `chs_`-prefixed `id` and `client_secret`. Without them, sign-in succeeds but the session does not record the buyer.
94
- */
95
- checkoutSession?: { id: string; clientSecret: string; };
96
88
  /**
97
89
  * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
98
90
  */
@@ -143,10 +135,6 @@ export type PaymentsOptions = (
143
135
  * Wallet availability override for deterministic previews. Live checkouts probe the host.
144
136
  */
145
137
  previewWalletAvailability?: WalletAvailability;
146
- /**
147
- * Checkout session updated when a buyer signs in. Pass its `chs_`-prefixed `id` and `client_secret`. Without them, sign-in succeeds but the session does not record the buyer.
148
- */
149
- checkoutSession?: { id: string; clientSecret: string; };
150
138
  /**
151
139
  * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
152
140
  */
@@ -197,10 +185,6 @@ export type PaymentsOptions = (
197
185
  * Wallet availability override for deterministic previews. Live checkouts probe the host.
198
186
  */
199
187
  previewWalletAvailability?: WalletAvailability;
200
- /**
201
- * Checkout session updated when a buyer signs in. Pass its `chs_`-prefixed `id` and `client_secret`. Without them, sign-in succeeds but the session does not record the buyer.
202
- */
203
- checkoutSession?: { id: string; clientSecret: string; };
204
188
  /**
205
189
  * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
206
190
  */
@@ -370,6 +354,11 @@ export interface AddressElementProps {
370
354
  * @default "full"
371
355
  */
372
356
  layout?: "full" | "compact";
357
+ /**
358
+ * `above` (default) keeps each label outside its field: above it in the `full` layout, as its placeholder in `compact`. `floating` uses each label as the placeholder of its field, in either layout, then shows a small label above the typed text once the field has a value.
359
+ * @default "above"
360
+ */
361
+ labelMode?: "above" | "floating";
373
362
  /**
374
363
  * `full` (default) follows the selected country's complete address format. `minimal` collects only country and postal code. `name` independently adds required name fields. Set `name` to `none` to omit them. This element does not add fields required by a payment method. Card confirmation requires a name, country, and postal code, so keep `name` enabled or pass `billingDetails.name`.
375
364
  * @default "full"
@@ -466,6 +455,11 @@ export interface AddressElementCreateOptions {
466
455
  * @default "full"
467
456
  */
468
457
  layout?: "full" | "compact";
458
+ /**
459
+ * `above` (default) keeps each label outside its field: above it in the `full` layout, as its placeholder in `compact`. `floating` uses each label as the placeholder of its field, in either layout, then shows a small label above the typed text once the field has a value.
460
+ * @default "above"
461
+ */
462
+ labelMode?: "above" | "floating";
469
463
  /**
470
464
  * `full` (default) follows the selected country's complete address format. `minimal` collects only country and postal code. `name` independently adds required name fields. Set `name` to `none` to omit them. This element does not add fields required by a payment method. Card confirmation requires a name, country, and postal code, so keep `name` enabled or pass `billingDetails.name`.
471
465
  * @default "full"
@@ -591,13 +585,18 @@ export interface EmailElementProps {
591
585
  * @default true
592
586
  */
593
587
  label?: boolean;
588
+ /**
589
+ * `above` (default) shows the label above the input. `floating` uses the label text as the placeholder, then shows a small label above the typed text once the input has a value. Ignored when `label` is `false`.
590
+ * @default "above"
591
+ */
592
+ labelMode?: "above" | "floating";
594
593
  /**
595
594
  * Seed value applied once at mount.
596
595
  * @default ""
597
596
  */
598
597
  defaultValue?: string;
599
598
  /**
600
- * Placeholder text for the email input. Empty (default) renders `you@example.com`.
599
+ * Placeholder text for the email input. Empty (default) renders `you@example.com`. With floating labels the label text is the placeholder instead.
601
600
  * @default ""
602
601
  */
603
602
  placeholder?: string;
@@ -637,13 +636,18 @@ export interface EmailElementCreateOptions {
637
636
  * @default true
638
637
  */
639
638
  label?: boolean;
639
+ /**
640
+ * `above` (default) shows the label above the input. `floating` uses the label text as the placeholder, then shows a small label above the typed text once the input has a value. Ignored when `label` is `false`.
641
+ * @default "above"
642
+ */
643
+ labelMode?: "above" | "floating";
640
644
  /**
641
645
  * Seed value applied once at mount.
642
646
  * @default ""
643
647
  */
644
648
  defaultValue?: string;
645
649
  /**
646
- * Placeholder text for the email input. Empty (default) renders `you@example.com`.
650
+ * Placeholder text for the email input. Empty (default) renders `you@example.com`. With floating labels the label text is the placeholder instead.
647
651
  * @default ""
648
652
  */
649
653
  placeholder?: string;
@@ -1013,6 +1017,7 @@ export interface PaymentRequestResourceOptions {
1013
1017
  currency: string;
1014
1018
  /**
1015
1019
  * Payment amount in minor units.
1020
+ * Change it later with `update()`.
1016
1021
  */
1017
1022
  amount: number;
1018
1023
  /**
@@ -1030,63 +1035,88 @@ export interface PaymentRequestResourceOptions {
1030
1035
  */
1031
1036
  requestPayerPhone?: boolean;
1032
1037
  /**
1033
- * Ask the sheet for a shipping address (and offer `shippingOptions` when given).
1038
+ * 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.
1034
1039
  * @default false
1035
1040
  */
1036
1041
  requestShipping?: boolean;
1042
+ /**
1043
+ * 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.
1044
+ * @default false
1045
+ */
1046
+ requestPromoCode?: boolean;
1047
+ /**
1048
+ * A promo code already applied to the charge, prefilled into the sheet so the buyer can see or remove it.
1049
+ */
1050
+ appliedPromoCode?: string;
1051
+ /**
1052
+ * What `appliedPromoCode` does, shown next to the code where the sheet captions applied codes (Google Pay).
1053
+ */
1054
+ appliedPromoDescription?: string;
1037
1055
  /**
1038
1056
  * 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.
1039
1057
  */
1040
1058
  countryCode?: string;
1041
1059
  /**
1042
1060
  * Line items the sheet lists under the total.
1061
+ * Change it later with `update()`.
1043
1062
  */
1044
1063
  lineItems?: PaymentRequestLineItem[];
1045
1064
  /**
1046
1065
  * Shipping options the sheet offers when `requestShipping` is set. Display-only — update `amount` from your change handler.
1066
+ * Change it later with `update()`.
1047
1067
  */
1048
1068
  shippingOptions?: PaymentRequestShippingOption[];
1049
1069
  }
1050
1070
 
1051
1071
  /**
1052
- * A minted "paymentRequest" resource — returned by `whop.payments.paymentRequest.create()`. Low-level Apple Pay or Google Pay sheet for custom buttons, express checkout, and shipping callbacks. Wallet tiles automate this flow through `payments.createConfirmationToken`. Await `canMakePayment()` to check availability and prime the sheet, then call `show(type)` synchronously in the user-interaction handler. The resolved `ctok` is a `ctok_`-prefixed confirmation token. Confirm it server-side like an element-minted token.
1072
+ * A minted "paymentRequest" resource — returned by `whop.payments.paymentRequest.create()`. Low-level Apple Pay, Google Pay, or PayPal sheet for custom buttons, express checkout, and shipping callbacks. Wallet tiles automate this flow through `payments.createConfirmationToken`. Await `canMakePayment()` to check availability and prime the wallet, then call `show(type)` synchronously in the user-interaction handler. The resolved `ctok` is a `ctok_`-prefixed confirmation token. Confirm it server-side like an element-minted token. A PayPal token charges at most the total PayPal showed the buyer.
1053
1073
  * @see https://docs.whop.com/elements/latest/payments/paymentRequest
1054
1074
  */
1055
1075
  export interface PaymentRequestResource {
1056
1076
  /**
1057
- * 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](/api-reference/beta/payment-method-domains/payment-method-domain), and offering Google Pay there is subject to the [Google Pay API Terms of Service](https://payments.developers.google.com/terms/sellertos)). 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 — so express buttons can stack best-first. This primes `show()`. Always await it first.
1077
+ * 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](/api-reference/beta/payment-method-domains/payment-method-domain), and offering Google Pay there is subject to the [Google Pay API Terms of Service](https://payments.developers.google.com/terms/sellertos)). 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.
1058
1078
  */
1059
- canMakePayment: () => Promise<WalletAvailability>;
1079
+ canMakePayment: (filter?: { types?: ("apple_pay" | "google_pay" | "paypal_express")[] | undefined; } | undefined) => Promise<WalletAvailability>;
1060
1080
  /**
1061
- * Open the selected wallet sheet after awaiting `canMakePayment()`. Apple requires session creation within the gesture stack. Pass `email` when your page already collected one — the sheet takes it and never asks for a second. With `requestPayerEmail: false`, passing one is required, and the sheet refuses to open without it because confirmation tokens require an email.
1081
+ * 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.
1062
1082
  * Call synchronously during user activation. Await prerequisites first because browsers revoke activation across asynchronous steps.
1063
1083
  */
1064
- show: (type: "apple_pay" | "google_pay", provided?: { email?: string | undefined; } | undefined) => Promise<PaymentRequestResult>;
1084
+ show: (type: "apple_pay" | "google_pay" | "paypal_express", provided?: { email?: string | undefined; } | undefined) => Promise<PaymentRequestResult>;
1085
+ /**
1086
+ * Change `amount`, `lineItems` and `shippingOptions` on this instance. Every other option is fixed at `create()`: create a new instance to change it.
1087
+ */
1088
+ update: (patch: { amount?: number | undefined; lineItems?: PaymentRequestLineItem[] | undefined; shippingOptions?: PaymentRequestShippingOption[] | undefined; }) => void;
1065
1089
  /**
1066
- * 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.
1067
- * Call `updateWith(…)` exactly once per event or the flow waits until the vendor times out.
1090
+ * 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.
1091
+ * Call `updateWith(…)` exactly once per event. A handler that throws or rejects before calling it fails that update right away.
1068
1092
  * Returns the unsubscribe function.
1069
1093
  */
1070
1094
  onShippingAddressChange(handler: (ev: ShippingAddressChangeEvent) => void): () => void;
1071
1095
  /**
1072
- * The buyer picked a shipping option. Amount-only contract: `updateWith` carries amount/lineItems/shippingOptions/errors.
1073
- * Call `updateWith(…)` exactly once per event or the flow waits until the vendor times out.
1096
+ * 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.
1097
+ * Call `updateWith(…)` exactly once per event. A handler that throws or rejects before calling it fails that update right away.
1074
1098
  * Returns the unsubscribe function.
1075
1099
  */
1076
1100
  onShippingOptionChange(handler: (ev: ShippingOptionChangeEvent) => void): () => void;
1077
1101
  /**
1078
- * 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, or `updateWith({})` to keep the current total. Every event is answered exactly once: a slow, thrown, or superseded handler answers keep-current.
1079
- * Call `updateWith(…)` exactly once per event or the flow waits until the vendor times out.
1102
+ * 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.
1103
+ * Call `updateWith(…)` exactly once per event. A handler that throws or rejects before calling it fails that update right away.
1080
1104
  * Returns the unsubscribe function.
1081
1105
  */
1082
1106
  onBillingAddressChange(handler: (ev: BillingAddressChangeEvent) => void): () => void;
1107
+ /**
1108
+ * 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.
1109
+ * Call `updateWith(…)` exactly once per event. A handler that throws or rejects before calling it fails that update right away.
1110
+ * Returns the unsubscribe function.
1111
+ */
1112
+ onPromoCodeChange(handler: (ev: PromoCodeChangeEvent) => void): () => void;
1083
1113
  /**
1084
1114
  * The sheet created a confirmation token. This is the same result that `show()` returns.
1085
1115
  * Returns the unsubscribe function.
1086
1116
  */
1087
1117
  onConfirmationToken(handler: (ev: PaymentRequestResult) => void): () => void;
1088
1118
  /**
1089
- * The buyer dismissed the sheet.
1119
+ * The buyer dismissed the sheet or closed PayPal.
1090
1120
  * Returns the unsubscribe function.
1091
1121
  */
1092
1122
  onCancel(handler: () => void): () => void;
@@ -1154,12 +1184,36 @@ export interface PaymentsStatics {
1154
1184
  */
1155
1185
  handleNextAction: (input: { clientSecret: string; returnUrl?: string | undefined; pollIntervalMs?: number | undefined; }) => Promise<{ status: string; redirected: boolean; lastPaymentError: { code?: string | null | undefined; decline_code?: string | null | undefined; message?: string | null | undefined; } | null; }>;
1156
1186
  /**
1157
- * Low-level Apple Pay or Google Pay sheet for custom buttons, express checkout, and shipping callbacks. Wallet tiles automate this flow through `payments.createConfirmationToken`. Await `canMakePayment()` to check availability and prime the sheet, then call `show(type)` synchronously in the user-interaction handler. The resolved `ctok` is a `ctok_`-prefixed confirmation token. Confirm it server-side like an element-minted token.
1187
+ * Low-level Apple Pay, Google Pay, or PayPal sheet for custom buttons, express checkout, and shipping callbacks. Wallet tiles automate this flow through `payments.createConfirmationToken`. Await `canMakePayment()` to check availability and prime the wallet, then call `show(type)` synchronously in the user-interaction handler. The resolved `ctok` is a `ctok_`-prefixed confirmation token. Confirm it server-side like an element-minted token. A PayPal token charges at most the total PayPal showed the buyer.
1158
1188
  * Mint with `whop.payments.paymentRequest.create(options)` — nothing needs to be mounted.
1159
1189
  */
1160
1190
  paymentRequest: { create(options: PaymentRequestResourceOptions): PaymentRequestResource };
1161
1191
  }
1162
1192
 
1193
+ /**
1194
+ * Declared from the app's `WalletButtonArt`, referenced by a host-capability surface.
1195
+ */
1196
+ export interface WalletButtonArt {
1197
+ /**
1198
+ * For light pages.
1199
+ */
1200
+ light: { color: string; image: string; };
1201
+ /**
1202
+ * For dark pages.
1203
+ */
1204
+ dark: { color: string; image: string; };
1205
+ }
1206
+
1207
+ /**
1208
+ * Declared from the app's `WalletDetails`, referenced by a host-capability surface.
1209
+ */
1210
+ export interface WalletDetails {
1211
+ /**
1212
+ * The wallet's official button art. Absent when none is published.
1213
+ */
1214
+ button?: WalletButtonArt | undefined;
1215
+ }
1216
+
1163
1217
  /**
1164
1218
  * Host-probed wallet availability after checking offered methods, device capability, and Google Pay origin approval.
1165
1219
  * Declared from the app's `WalletAvailability`, referenced by a host-capability surface.
@@ -1167,10 +1221,15 @@ export interface PaymentsStatics {
1167
1221
  export interface WalletAvailability {
1168
1222
  applePay: boolean;
1169
1223
  googlePay: boolean;
1224
+ payPal?: boolean | undefined;
1225
+ /**
1226
+ * The wallets ranked by which sheet is native to this browser — Apple Pay first on WebKit, Google Pay first everywhere else, PayPal last — so express buttons can stack best-first. Absent on consumer-stated availability (previews) and on wires that predate it. An inline union, not payment-request's WalletSheetType: that module already imports this one.
1227
+ */
1228
+ order?: ("apple_pay" | "google_pay" | "paypal_express")[] | undefined;
1170
1229
  /**
1171
- * The wallets ranked by which sheet is native to this browser — Apple Pay first on WebKit, Google Pay first everywhere else — so express buttons can stack best-first. Absent on consumer-stated availability (previews) and on wires that predate it. An inline union, not payment-request's WalletSheetType: that module already imports this one.
1230
+ * Each available wallet's details, keyed by wallet type. Absent on consumer-stated availability (previews).
1172
1231
  */
1173
- order?: ("apple_pay" | "google_pay")[] | undefined;
1232
+ wallets?: { apple_pay?: WalletDetails | undefined; google_pay?: WalletDetails | undefined; paypal_express?: WalletDetails | undefined; } | undefined;
1174
1233
  }
1175
1234
 
1176
1235
  /**
@@ -1228,7 +1287,7 @@ export interface PaymentRequestResult {
1228
1287
  * Confirmation token ID, prefixed `ctok_`. Confirm it server-side with your secret key.
1229
1288
  */
1230
1289
  ctok: string;
1231
- type: "apple_pay" | "google_pay";
1290
+ type: "apple_pay" | "google_pay" | "paypal_express";
1232
1291
  payer: { email?: string | undefined; name?: string | undefined; phone?: string | undefined; country?: string | undefined; };
1233
1292
  shipping: { address?: PaymentRequestAddress | undefined; option?: PaymentRequestShippingOption | undefined; } | null;
1234
1293
  }
@@ -1289,7 +1348,39 @@ export interface BillingAddressChangeEvent {
1289
1348
  */
1290
1349
  address: PaymentRequestAddress;
1291
1350
  /**
1292
- * Call this exactly once. An event left unanswered keeps the current total when the reply deadline passes.
1351
+ * Call this exactly once. An event left unanswered for 10 seconds refuses the card, and the buyer picks another one.
1293
1352
  */
1294
1353
  updateWith: (update: PaymentRequestUpdate) => void;
1295
1354
  }
1355
+
1356
+ /**
1357
+ * Declared from the app's `PromoCodeUpdate`, referenced by a host-capability surface.
1358
+ */
1359
+ export interface PromoCodeUpdate {
1360
+ /**
1361
+ * The total under the code, in minor units.
1362
+ */
1363
+ amount?: number | undefined;
1364
+ /**
1365
+ * A caption for the applied code, where the sheet captions codes (Google Pay).
1366
+ */
1367
+ appliedDescription?: string | undefined;
1368
+ /**
1369
+ * Refuses the code. The sheet shows `message` next to its promo field.
1370
+ */
1371
+ error?: { message: string; } | undefined;
1372
+ }
1373
+
1374
+ /**
1375
+ * Declared from the app's `PromoCodeChangeEvent`, referenced by a host-capability surface.
1376
+ */
1377
+ export interface PromoCodeChangeEvent {
1378
+ /**
1379
+ * The code now in the sheet's promo field, or null when the buyer removed it.
1380
+ */
1381
+ code: string | null;
1382
+ /**
1383
+ * Answer exactly once: `error` refuses the code and keeps the totals, and any other answer applies it. `amount` reprices the sheet under the code, and `appliedDescription` captions the applied code where the sheet shows one (Google Pay). `updateWith({})` applies the code at the current total.
1384
+ */
1385
+ updateWith: (update: PromoCodeUpdate) => void;
1386
+ }