@amos.com/react-amos-js 0.11.17 → 0.11.19

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/README.md CHANGED
@@ -16,7 +16,7 @@ npm install @amos.com/react-amos-js @amos.com/node
16
16
 
17
17
  - React components for the iframe payment method forms: `AmosCreditCardPaymentMethodForm`, `AmosBankAccountPaymentMethodForm`, `AmosGooglePayButton`, `AmosApplePayButton`.
18
18
  - React-flavoured iframe message helpers that accept a React `ref`: `validateForm({ iframeRef })`, `confirmPayment({ iframeRef, token })`, `confirmSetup({ iframeRef, token })`, `resetForm({ iframeRef })`, `focusField({ iframeRef, field })`.
19
- - Re-exports of the `@amos.com/amos-js` helpers and types that come up in client code: `createMessage`, `decodeJwt`, `getEmbedOrigin`, `formatGooglePayPaymentData`, `resetForm`, `focusField`, `ConfirmPaymentResult`, `ConfirmSetupResult`, `FormattedGooglePayPaymentData`, `Appearance`, `FontSource`, `AppearanceRuleSelector`, `Message`, `PaymentMethodFormDefaultValues`, `PaymentMethodFormField`, etc.
19
+ - Re-exports of the `@amos.com/amos-js` helpers and types that come up in client code: `createMessage`, `decodeJwt`, `getEmbedOrigin`, `formatGooglePayPaymentData`, `resetForm`, `focusField`, `ConfirmPaymentResult`, `ConfirmSetupResult`, `FormattedGooglePayPaymentData`, `WalletCustomerCreateAttributes`, `WalletPostalAddress`, `WalletContactRequirements`, `Appearance`, `FontSource`, `AppearanceRuleSelector`, `Message`, `PaymentMethodFormDefaultValues`, `PaymentMethodFormField`, etc.
20
20
 
21
21
  > **Note:** `@amos.com/react-amos-js` is the client-side half of the Amos integration. For end-to-end payment processing you also need `@amos.com/node` on your server (creating payment intents, handling webhooks, etc.). The same `@amos.com/node` package is listed as a peer dependency so you can import its OpenAPI types in client-side TypeScript code.
22
22
 
@@ -319,6 +319,7 @@ import {
319
319
  AmosApplePayButton,
320
320
  AmosGooglePayButton,
321
321
  type ConfirmPaymentResult,
322
+ type WalletCustomerCreateAttributes,
322
323
  } from "@amos.com/react-amos-js";
323
324
  import type { components } from "@amos.com/node";
324
325
 
@@ -327,12 +328,14 @@ async function createPaymentIntentToken({
327
328
  customerCreateAttributes,
328
329
  }: {
329
330
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
330
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
331
+ customerCreateAttributes: WalletCustomerCreateAttributes;
331
332
  }): Promise<string> {
332
333
  const response = await fetch("/api/payment-intents", {
333
334
  method: "POST",
334
335
  headers: { "Content-Type": "application/json" },
335
336
  body: JSON.stringify({
337
+ // Map WalletCustomerCreateAttributes on your server — it is not
338
+ // CreateCustomerInput.
336
339
  customer: customerCreateAttributes,
337
340
  paymentIntent: paymentIntentCreateAttributes,
338
341
  }),
@@ -353,7 +356,7 @@ function CheckoutWallets({ renderToken }: { renderToken: string }) {
353
356
  confirmPayment,
354
357
  }: {
355
358
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
356
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
359
+ customerCreateAttributes: WalletCustomerCreateAttributes;
357
360
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
358
361
  }): Promise<ConfirmPaymentResult> {
359
362
  try {
@@ -398,7 +401,9 @@ function CheckoutWallets({ renderToken }: { renderToken: string }) {
398
401
  }
399
402
  ```
400
403
 
401
- Do not call `validateForm` from the host in an express flow — create a payment intent inside `onConfirm`, then `await confirmPayment(token)`. Size the mount slot; omitted `buttonProps` keep paint defaults and fill the iframe.
404
+ Do not call `validateForm` from the host in an express flow — create a payment intent inside `onConfirm`, then `await confirmPayment(token)`. Size the mount slot; omitted `buttonProps` keep paint defaults and fill the iframe. Name, email, and billing address are always collected. Pass `phoneRequired: true` if you still need a phone (Apple Pay previously always collected one). Pass `shippingAddressRequired: true` to collect a shipping postal address.
405
+
406
+ `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not `CreateCustomerInput`. Nested `billingAddress` / `shippingAddress` use Amos billing field names (`address_line1`, `state`, `postal_code`). Top-level `line1` / `line2` / `city` / `region` / `postalCode` / `country` still duplicate billing so existing Apple Pay hosts keep working — prefer `billingAddress`. `phone` and `shippingAddress` are omitted unless you opted in.
402
407
 
403
408
  On Safari, Apple Pay uses the native payment sheet. On other browsers, Apple's QR handoff opens in a popup (`pay.apple.com`); while that popup is open, the SDK shows a waiting overlay with **Cancel payment**. After the buyer authorizes, Cancel is removed and the overlay shows **Completing your payment…** until `onConfirm` settles.
404
409
 
@@ -586,7 +591,7 @@ When `requireAchVerification` is true (or `intent` is `"setup"`), and the render
586
591
 
587
592
  **Optional props:** same as `AmosCreditCardPaymentMethodForm` — `appearance`, `billingAddressRequirement`, `defaultValues`, `onValidityChange` (`isValid` is also true after Plaid returns credentials), `onEscapeKeyPressed` — plus:
588
593
 
589
- - `requireAchVerification` (`boolean`, defaults to `false`) — when true, show Plaid Embedded Link instead of routing/account fields. Ignored for `intent="setup"` (always Plaid) and when the render token has bank `verification: false`. Hosts that still have an ACH threshold should compute this themselves and pass a new value when the charge changes.
594
+ - `requireAchVerification` (`boolean`, defaults to `false`) — when true, show Plaid Embedded Link instead of routing/account fields. Ignored for `intent="setup"` (always Plaid) and when the render token has bank `verification: false`. Hosts that still have an ACH threshold should compute this themselves and pass a new value when the charge changes. Changing this prop hides or shows Link; it does not remount the bank form or destroy the Embedded handler.
590
595
  - `intent` (`"payment" | "setup"`, defaults to `"payment"`) — `"setup"` always shows Plaid unless the render token disables verification. Use this when saving a bank account for later charges.
591
596
 
592
597
  ```tsx
@@ -620,12 +625,14 @@ Renders the secure Google Pay iframe button (express checkout flow). A button-sh
620
625
  - `renderToken` (`string`)
621
626
  - `amount` (`string`) — major-currency decimal string shown in the wallet sheet (e.g. `"50.00"` for $50.00). The iframe converts this to cents in `paymentIntentCreateAttributes.amount`.
622
627
  - `merchantName` (`string`)
623
- - `onConfirm` (callback receiving `{ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment }`. Create a payment intent, then `return confirmPayment(token)` — `Promise<ConfirmPaymentResult>`)
628
+ - `onConfirm` (callback receiving `{ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment }`. Create a payment intent, then `return confirmPayment(token)` — `Promise<ConfirmPaymentResult>`). `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not `CreateCustomerInput` — map it on your server. Nested `billingAddress` / `shippingAddress` use Amos billing field names (`address_line1`, `state`, `postal_code`). Top-level `line1` / `line2` / `city` / `region` / `postalCode` / `country` still duplicate billing for existing Apple Pay hosts; prefer `billingAddress`. `phone` and `shippingAddress` are omitted unless you passed `phoneRequired` / `shippingAddressRequired`.
624
629
 
625
630
  **Optional props:**
626
631
 
627
632
  - `height` (`string`, defaults to `"48px"`) — painted button height. CSS length (e.g. `"48px"`).
628
633
  - `buttonProps` — native Google Pay button options. Omitted fields keep `"plain"` / `"fill"`. The button fills the iframe; size the mount slot, not the button. Compact: `buttonProps={{ buttonSizeMode: "static", style: { width: "240px" } }}`.
634
+ - `phoneRequired` (`boolean`, defaults to `false`) — collect a phone number in the Google Pay sheet.
635
+ - `shippingAddressRequired` (`boolean`, defaults to `false`) — collect a shipping postal address. Name, email, and billing address are always required.
629
636
  - `iframeProps` — applied to the host-page `<iframe>` (e.g. `className`, `style`, `id`). Use CSS lengths with units in `style` (`{ borderRadius: "8px" }`). Amos does not ship Tailwind — `className` only works if the host page defines those classes.
630
637
 
631
638
  ```tsx
@@ -640,10 +647,12 @@ Renders the secure Google Pay iframe button (express checkout flow). A button-sh
640
647
 
641
648
  Renders the secure Apple Pay iframe button (express checkout flow). Same required props and callbacks as `AmosGooglePayButton`. A button-shaped skeleton is shown immediately and replaced by the iframe once appearance is applied.
642
649
 
643
- **Optional visual props:**
650
+ **Optional props:**
644
651
 
645
652
  - `height` (`string`, defaults to `"48px"`) — painted button height. CSS length (e.g. `"48px"`). Apple ignores CSS `height`; Amos maps this for you.
646
653
  - `buttonProps` — native `<apple-pay-button>` attributes. Omitted fields keep Apple's `black` / `plain` / `en-US`. The button fills the iframe; size the mount slot, not the button. `style.width` also updates `--apple-pay-button-width` unless you set that custom property yourself.
654
+ - `phoneRequired` (`boolean`, defaults to `false`) — collect a phone number in the Apple Pay sheet. Pass `true` to keep the previous Apple Pay behavior of always collecting a phone.
655
+ - `shippingAddressRequired` (`boolean`, defaults to `false`) — collect a shipping postal address. Name, email, and billing address are always required.
647
656
  - `iframeProps` — host-page `<iframe>` chrome (same as Google Pay).
648
657
 
649
658
  ```tsx
@@ -662,7 +671,7 @@ Only Amos domains need Apple merchant registration. The button and `ApplePaySess
662
671
 
663
672
  ### `formatGooglePayPaymentData({ paymentData })`
664
673
 
665
- Transforms Google Pay payment data into an Amos-compatible `paymentMethod` payload. Use this when integrating with the raw Google Pay API (e.g. `@google-pay/button-react`) instead of `AmosGooglePayButton` — `AmosGooglePayButton` handles payment data internally and does not require this helper.
674
+ Transforms Google Pay payment data into an Amos-compatible `paymentMethod` payload. Use this when integrating with the raw Google Pay API (e.g. `@google-pay/button-react`) instead of `AmosGooglePayButton` — `AmosGooglePayButton` handles payment data internally and does not require this helper. Street and name come from CARD `billingAddress`; email from the top-level field; phone from shipping when present, otherwise billing.
666
675
 
667
676
  **Parameters:**
668
677
 
@@ -690,7 +699,7 @@ Re-export from `@amos.com/amos-js`. Fills omitted Inter `fonts` / `--font-family
690
699
 
691
700
  ### Exported types
692
701
 
693
- `@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `ConfirmPaymentResult`, `ConfirmSetupResult`, `PaymentMethodFormValidityChangeEvent`, `CardBrand`, `PaymentMethodFormCardBrandChangeEvent`, `FormattedGooglePayPaymentData`, `Message`, `Appearance`, `ThemeVariable`, `FontSource`, `CssFontSource`, `CustomFontSource`, `AppearanceRuleSelector`, `AppearanceRuleDeclarations`, `PaymentMethodFormDefaultValues`, `PaymentMethodFormField`, and the per-form `*Options` / `*Controller` types. For OpenAPI schema types (e.g. `PaymentIntent`, `CreatePaymentIntentInput`), import `components` from `@amos.com/node`.
702
+ `@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `ConfirmPaymentResult`, `ConfirmSetupResult`, `PaymentMethodFormValidityChangeEvent`, `CardBrand`, `PaymentMethodFormCardBrandChangeEvent`, `FormattedGooglePayPaymentData`, `WalletCustomerCreateAttributes`, `WalletPostalAddress`, `WalletContactRequirements`, `Message`, `Appearance`, `ThemeVariable`, `FontSource`, `CssFontSource`, `CustomFontSource`, `AppearanceRuleSelector`, `AppearanceRuleDeclarations`, `PaymentMethodFormDefaultValues`, `PaymentMethodFormField`, and the per-form `*Options` / `*Controller` types. For OpenAPI schema types (e.g. `PaymentIntent`, `CreatePaymentIntentInput`), import `components` from `@amos.com/node`.
694
703
 
695
704
  ## Notes and potential gotchas
696
705
 
@@ -700,7 +709,7 @@ Re-export from `@amos.com/amos-js`. Fills omitted Inter `fonts` / `--font-family
700
709
  - **Amount format**: for `AmosGooglePayButton` and `AmosApplePayButton`, `amount` is a major-currency decimal string (e.g. `"50.00"` for $50.00). For `components["schemas"]["CreatePaymentIntentInput"]` on the server (card/bank create, and the object the wallet iframe sends to `onConfirm`), `amount` is a number in cents (e.g. `5000`).
701
710
  - **Embed host / CSP**: iframes load from `https://js.amos.com` (production) and `https://js-sandbox.amos.com` (sandbox) via `getEmbedOrigin`. Parent pages that pin CSP must allow `frame-src https://js.amos.com https://js-sandbox.amos.com` (and `Permissions-Policy payment=` for those origins) **before** upgrading this package. Older SDK versions still load `embed.amos.com` / `embed-sandbox.amos.com`.
702
711
  - **Iframe handshake**: iframe URLs include canonical search params so the embed does not 307. If the document loads but never posts `IFRAME_READY`, the SDK rewrites `src` once with `amosReload`. Appearance is applied after handshake; the iframe stays hidden until `UPDATED_APPEARANCE`, or for 1.5s after `IFRAME_READY` if appearance never acks.
703
- - **Plaid Embedded Link (ACH verification)**: load `cdn.plaid.com` from the **parent** document (see CSP on `AmosBankAccountPaymentMethodForm`). Merchants do not proxy Pay API; the bank iframe mints link tokens. Pass `requireAchVerification` when the host wants Plaid, or `intent="setup"` to always show it, unless the render token disables verification. Confirm still goes through the bank iframe so Amos can attach `plaid` to the payment method. While Link loads, the SDK shows a 350px pulse skeleton until `onLoad` (1.5s fallback) — do not overlay a host loader.
712
+ - **Plaid Embedded Link (ACH verification)**: load `cdn.plaid.com` from the **parent** document (see CSP on `AmosBankAccountPaymentMethodForm`). Merchants do not proxy Pay API; the bank iframe mints link tokens. Pass `requireAchVerification` when the host wants Plaid, or `intent="setup"` to always show it, unless the render token disables verification. Toggling that prop hides or shows the existing Embedded handler — it does not reload Institution Search. Confirm still goes through the bank iframe so Amos can attach `plaid` to the payment method. While Link loads, the SDK shows a 350px pulse skeleton until `onLoad` (1.5s fallback) — do not overlay a host loader.
704
713
  - **Apple Pay waiting overlay**: on browsers where Apple's QR handoff opens in a popup (non-Safari), `AmosApplePayButton` shows a fixed full-viewport overlay on the host page. **Cancel payment** is available until the buyer authorizes; after that the overlay shows **Completing your payment…** with no Cancel, then hides when `onConfirm` settles. Avoid stacking other fixed UI above it.
705
714
  - **Going framework-free**: if you need to use Amos outside of React (vanilla JS, another framework, etc.), use [`@amos.com/amos-js`](../amos-js) directly.
706
715
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="googlepay" />
2
- import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmPaymentResult, ConfirmSetupResult, CreditCardAdditionalFields, GooglePayButtonElementProps, PaymentMethodFormDefaultValues, PaymentMethodFormField } from '@amos.com/amos-js';
2
+ import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmPaymentResult, ConfirmSetupResult, CreditCardAdditionalFields, GooglePayButtonElementProps, PaymentMethodFormDefaultValues, PaymentMethodFormField, WalletCustomerCreateAttributes } from '@amos.com/amos-js';
3
3
  import { components } from '@amos.com/node';
4
4
  import { ComponentProps, Ref, RefObject } from 'react';
5
5
  export * from '@amos.com/amos-js';
@@ -136,6 +136,9 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
136
136
  * is `"setup"` (setup always shows Plaid) or when the render token
137
137
  * disables verification.
138
138
  *
139
+ * Changing this prop hides or shows Link; it does not remount the
140
+ * bank form or destroy the Embedded handler.
141
+ *
139
142
  * @default false
140
143
  */
141
144
  requireAchVerification?: boolean;
@@ -171,15 +174,28 @@ type AmosGooglePayButtonProps = {
171
174
  * mount slot, not the button.
172
175
  */
173
176
  buttonProps?: GooglePayButtonElementProps;
177
+ /**
178
+ * Collect a phone number in the Google Pay sheet.
179
+ * @default false
180
+ */
181
+ phoneRequired?: boolean;
182
+ /**
183
+ * Collect a shipping postal address. Name, email, and billing
184
+ * address are always required.
185
+ * @default false
186
+ */
187
+ shippingAddressRequired?: boolean;
174
188
  /** Props applied to the host-page `<iframe>` element. */
175
189
  iframeProps?: IframePassthroughProps;
176
190
  /**
177
191
  * Called when the buyer authorizes in the Google Pay sheet. Create a
178
192
  * payment intent on your server, then `await confirmPayment(token)`.
193
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
194
+ * Amos `CreateCustomerInput`.
179
195
  */
180
196
  onConfirm: ({ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment, }: {
181
197
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
182
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
198
+ customerCreateAttributes: WalletCustomerCreateAttributes;
183
199
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
184
200
  }) => Promise<ConfirmPaymentResult>;
185
201
  };
@@ -188,7 +204,7 @@ type AmosGooglePayButtonProps = {
188
204
  * skeleton is painted in the parent document on first render (including
189
205
  * SSR) so the slot height is reserved before the iframe loads.
190
206
  */
191
- export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, iframeProps, onConfirm, }: AmosGooglePayButtonProps): import("react").JSX.Element;
207
+ export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, phoneRequired, shippingAddressRequired, iframeProps, onConfirm, }: AmosGooglePayButtonProps): import("react").JSX.Element;
192
208
  type AmosApplePayButtonProps = {
193
209
  ref?: ForwardedIframeRef;
194
210
  renderToken: string;
@@ -211,15 +227,28 @@ type AmosApplePayButtonProps = {
211
227
  * button fills the iframe — size the mount slot, not the button.
212
228
  */
213
229
  buttonProps?: ApplePayButtonElementProps;
230
+ /**
231
+ * Collect a phone number in the Apple Pay sheet.
232
+ * @default false
233
+ */
234
+ phoneRequired?: boolean;
235
+ /**
236
+ * Collect a shipping postal address. Name, email, and billing
237
+ * address are always required.
238
+ * @default false
239
+ */
240
+ shippingAddressRequired?: boolean;
214
241
  /** Props applied to the host-page `<iframe>` element. */
215
242
  iframeProps?: IframePassthroughProps;
216
243
  /**
217
244
  * Called when the buyer authorizes in the Apple Pay sheet. Create a
218
245
  * payment intent on your server, then `await confirmPayment(token)`.
246
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
247
+ * Amos `CreateCustomerInput`.
219
248
  */
220
249
  onConfirm: ({ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment, }: {
221
250
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
222
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
251
+ customerCreateAttributes: WalletCustomerCreateAttributes;
223
252
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
224
253
  }) => Promise<ConfirmPaymentResult>;
225
254
  };
@@ -228,4 +257,4 @@ type AmosApplePayButtonProps = {
228
257
  * skeleton is painted in the parent document on first render (including
229
258
  * SSR) so the slot height is reserved before the iframe loads.
230
259
  */
231
- export declare function AmosApplePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, iframeProps, onConfirm, }: AmosApplePayButtonProps): import("react").JSX.Element;
260
+ export declare function AmosApplePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, phoneRequired, shippingAddressRequired, iframeProps, onConfirm, }: AmosApplePayButtonProps): import("react").JSX.Element;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@amos.com/amos-js"),t=require("react"),n=require("react/jsx-runtime");function r(e){var t;return e?(t=e.current)==null?null:t:null}function i({iframeRef:t}){return(0,e.validateForm)({iframe:r(t)})}function a({iframeRef:t,token:n,defaultValues:i}){return(0,e.confirmPayment)({iframe:r(t),token:n,defaultValues:i})}function o({iframeRef:t,token:n,defaultValues:i}){return(0,e.confirmSetup)({iframe:r(t),token:n,defaultValues:i})}function s({iframeRef:t}){(0,e.resetForm)({iframe:r(t)})}function c({iframeRef:t,field:n}){(0,e.focusField)({iframe:r(t),field:n})}function l(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function u(e,{style:t,className:n,id:r,...i}){n!=null&&(e.className=n),r!=null&&(e.id=r),Object.assign(e.style,t);for(let[t,n]of Object.entries(i))n!=null&&(t in e?Reflect.set(e,t,n):e.setAttribute(t,String(n)))}function d({containerRef:e,iframeRef:n,mount:r,options:i,remountDeps:a,iframePassthrough:o,updateDeps:s}){let c=(0,t.useRef)(null);(0,t.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let a=r(t,i);return c.current=a,l(n,a.iframe),u(a.iframe,o),()=>{a.destroy(),c.current=null,l(n,null)}},[...a]),(0,t.useEffect)(()=>{var e;(e=c.current)==null||e.update(i)},[...s]),(0,t.useEffect)(()=>{var e;let t=(e=c.current)==null?void 0:e.iframe;t&&u(t,o)})}var f=`oklch(0.97 0 0)`;function p({height:r,borderRadius:i,containerRef:a}){return(0,t.useLayoutEffect)(()=>{(0,e.ensureSkeletonStyles)()},[]),(0,n.jsxs)(`div`,{style:{boxSizing:`border-box`,position:`relative`,width:`100%`,height:r,minHeight:r,overflow:`hidden`},children:[(0,n.jsx)(`div`,{className:`amos-js-form-skeleton-input amos-js-wallet-skeleton`,style:{position:`absolute`,inset:0,height:r,borderRadius:i,background:f,pointerEvents:`none`,zIndex:0},"aria-hidden":!0}),(0,n.jsx)(`div`,{ref:a,style:{position:`absolute`,inset:0,zIndex:1,width:`100%`,height:`100%`}})]})}function m({ref:r,renderToken:i,appearance:a,onValidityChange:o,onCardBrandChanged:s,onEscapeKeyPressed:c,additionalFields:l={cardholderName:!1},billingAddressRequirement:u=`country`,defaultValues:f,style:p,...m}){let h=(0,t.useRef)(null);return d({containerRef:h,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:l,billingAddressRequirement:u,defaultValues:f,onValidityChange:o,onCardBrandChanged:s,onEscapeKeyPressed:c},remountDeps:[i,l.cardholderName,u],iframePassthrough:{style:p,...m},updateDeps:[a,l,u,f,o,s,c]}),(0,n.jsx)(`div`,{ref:h})}function h({ref:r,renderToken:i,appearance:a,onValidityChange:o,onEscapeKeyPressed:s,billingAddressRequirement:c=`country`,defaultValues:l,requireAchVerification:u=!1,intent:f=`payment`,style:p,...m}){let h=(0,t.useRef)(null);return d({containerRef:h,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:c,defaultValues:l,requireAchVerification:u,intent:f,onValidityChange:o,onEscapeKeyPressed:s},remountDeps:[i,c,f],iframePassthrough:{style:p,...m},updateDeps:[a,c,l,u,f,o,s]}),(0,n.jsx)(`div`,{ref:h})}function g({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,iframeProps:l,onConfirm:u}){let f=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:l==null?void 0:l.style,buttonProps:c});return d({containerRef:f,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,onConfirm:u},remountDeps:[i],iframePassthrough:l==null?{}:l,updateDeps:[a,o,s,c,u]}),(0,n.jsx)(p,{height:s,borderRadius:m,containerRef:f})}function _({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,iframeProps:l,onConfirm:u}){let f=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:l==null?void 0:l.style,buttonProps:c});return d({containerRef:f,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,onConfirm:u},remountDeps:[i],iframePassthrough:l==null?{}:l,updateDeps:[a,o,s,c,u]}),(0,n.jsx)(p,{height:s,borderRadius:m,containerRef:f})}exports.AmosApplePayButton=_,exports.AmosBankAccountPaymentMethodForm=h,exports.AmosCreditCardPaymentMethodForm=m,exports.AmosGooglePayButton=g,exports.confirmPayment=a,exports.confirmSetup=o,exports.focusField=c,exports.resetForm=s,exports.validateForm=i,Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@amos.com/amos-js"),t=require("react"),n=require("react/jsx-runtime");function r(e){var t;return e?(t=e.current)==null?null:t:null}function i({iframeRef:t}){return(0,e.validateForm)({iframe:r(t)})}function a({iframeRef:t,token:n,defaultValues:i}){return(0,e.confirmPayment)({iframe:r(t),token:n,defaultValues:i})}function o({iframeRef:t,token:n,defaultValues:i}){return(0,e.confirmSetup)({iframe:r(t),token:n,defaultValues:i})}function s({iframeRef:t}){(0,e.resetForm)({iframe:r(t)})}function c({iframeRef:t,field:n}){(0,e.focusField)({iframe:r(t),field:n})}function l(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function u(e,{style:t,className:n,id:r,...i}){n!=null&&(e.className=n),r!=null&&(e.id=r),Object.assign(e.style,t);for(let[t,n]of Object.entries(i))n!=null&&(t in e?Reflect.set(e,t,n):e.setAttribute(t,String(n)))}function d({containerRef:e,iframeRef:n,mount:r,options:i,remountDeps:a,iframePassthrough:o,updateDeps:s}){let c=(0,t.useRef)(null);(0,t.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let a=r(t,i);return c.current=a,l(n,a.iframe),u(a.iframe,o),()=>{a.destroy(),c.current=null,l(n,null)}},[...a]),(0,t.useEffect)(()=>{var e;(e=c.current)==null||e.update(i)},[...s]),(0,t.useEffect)(()=>{var e;let t=(e=c.current)==null?void 0:e.iframe;t&&u(t,o)})}var f=`oklch(0.97 0 0)`;function p({height:r,borderRadius:i,containerRef:a}){return(0,t.useLayoutEffect)(()=>{(0,e.ensureSkeletonStyles)()},[]),(0,n.jsxs)(`div`,{style:{boxSizing:`border-box`,position:`relative`,width:`100%`,height:r,minHeight:r,overflow:`hidden`},children:[(0,n.jsx)(`div`,{className:`amos-js-form-skeleton-input amos-js-wallet-skeleton`,style:{position:`absolute`,inset:0,height:r,borderRadius:i,background:f,pointerEvents:`none`,zIndex:0},"aria-hidden":!0}),(0,n.jsx)(`div`,{ref:a,style:{position:`absolute`,inset:0,zIndex:1,width:`100%`,height:`100%`}})]})}function m({ref:r,renderToken:i,appearance:a,onValidityChange:o,onCardBrandChanged:s,onEscapeKeyPressed:c,additionalFields:l={cardholderName:!1},billingAddressRequirement:u=`country`,defaultValues:f,style:p,...m}){let h=(0,t.useRef)(null);return d({containerRef:h,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:l,billingAddressRequirement:u,defaultValues:f,onValidityChange:o,onCardBrandChanged:s,onEscapeKeyPressed:c},remountDeps:[i,l.cardholderName,u],iframePassthrough:{style:p,...m},updateDeps:[a,l,u,f,o,s,c]}),(0,n.jsx)(`div`,{ref:h})}function h({ref:r,renderToken:i,appearance:a,onValidityChange:o,onEscapeKeyPressed:s,billingAddressRequirement:c=`country`,defaultValues:l,requireAchVerification:u=!1,intent:f=`payment`,style:p,...m}){let h=(0,t.useRef)(null);return d({containerRef:h,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:c,defaultValues:l,requireAchVerification:u,intent:f,onValidityChange:o,onEscapeKeyPressed:s},remountDeps:[i,c,f],iframePassthrough:{style:p,...m},updateDeps:[a,c,l,u,f,o,s]}),(0,n.jsx)(`div`,{ref:h})}function g({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,iframeProps:f,onConfirm:m}){let h=(0,t.useRef)(null),g=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:f==null?void 0:f.style,buttonProps:c});return d({containerRef:h,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,onConfirm:m},remountDeps:[i],iframePassthrough:f==null?{}:f,updateDeps:[a,o,s,c,l,u,m]}),(0,n.jsx)(p,{height:s,borderRadius:g,containerRef:h})}function _({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,iframeProps:f,onConfirm:m}){let h=(0,t.useRef)(null),g=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:f==null?void 0:f.style,buttonProps:c});return d({containerRef:h,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,onConfirm:m},remountDeps:[i],iframePassthrough:f==null?{}:f,updateDeps:[a,o,s,c,l,u,m]}),(0,n.jsx)(p,{height:s,borderRadius:g,containerRef:h})}exports.AmosApplePayButton=_,exports.AmosBankAccountPaymentMethodForm=h,exports.AmosCreditCardPaymentMethodForm=m,exports.AmosGooglePayButton=g,exports.confirmPayment=a,exports.confirmSetup=o,exports.focusField=c,exports.resetForm=s,exports.validateForm=i,Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
package/dist/index.mjs CHANGED
@@ -167,13 +167,13 @@ function O({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onEscap
167
167
  ]
168
168
  }), /* @__PURE__ */ m("div", { ref: f });
169
169
  }
170
- function k({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48px", buttonProps: a, iframeProps: o, onConfirm: c }) {
171
- let u = p(null), d = l({
172
- iframeStyle: o == null ? void 0 : o.style,
170
+ function k({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48px", buttonProps: a, phoneRequired: o, shippingAddressRequired: c, iframeProps: u, onConfirm: d }) {
171
+ let f = p(null), h = l({
172
+ iframeStyle: u == null ? void 0 : u.style,
173
173
  buttonProps: a
174
174
  });
175
175
  return w({
176
- containerRef: u,
176
+ containerRef: f,
177
177
  iframeRef: e,
178
178
  mount: s,
179
179
  options: {
@@ -182,30 +182,34 @@ function k({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48
182
182
  merchantName: r,
183
183
  height: i,
184
184
  buttonProps: a,
185
- onConfirm: c
185
+ phoneRequired: o,
186
+ shippingAddressRequired: c,
187
+ onConfirm: d
186
188
  },
187
189
  remountDeps: [t],
188
- iframePassthrough: o == null ? {} : o,
190
+ iframePassthrough: u == null ? {} : u,
189
191
  updateDeps: [
190
192
  n,
191
193
  r,
192
194
  i,
193
195
  a,
194
- c
196
+ o,
197
+ c,
198
+ d
195
199
  ]
196
200
  }), /* @__PURE__ */ m(E, {
197
201
  height: i,
198
- borderRadius: d,
199
- containerRef: u
202
+ borderRadius: h,
203
+ containerRef: f
200
204
  });
201
205
  }
202
- function A({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48px", buttonProps: o, iframeProps: s, onConfirm: c }) {
203
- let u = p(null), d = l({
204
- iframeStyle: s == null ? void 0 : s.style,
206
+ function A({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48px", buttonProps: o, phoneRequired: s, shippingAddressRequired: c, iframeProps: u, onConfirm: d }) {
207
+ let f = p(null), h = l({
208
+ iframeStyle: u == null ? void 0 : u.style,
205
209
  buttonProps: o
206
210
  });
207
211
  return w({
208
- containerRef: u,
212
+ containerRef: f,
209
213
  iframeRef: e,
210
214
  mount: i,
211
215
  options: {
@@ -214,21 +218,25 @@ function A({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48
214
218
  merchantName: r,
215
219
  height: a,
216
220
  buttonProps: o,
217
- onConfirm: c
221
+ phoneRequired: s,
222
+ shippingAddressRequired: c,
223
+ onConfirm: d
218
224
  },
219
225
  remountDeps: [t],
220
- iframePassthrough: s == null ? {} : s,
226
+ iframePassthrough: u == null ? {} : u,
221
227
  updateDeps: [
222
228
  n,
223
229
  r,
224
230
  a,
225
231
  o,
226
- c
232
+ s,
233
+ c,
234
+ d
227
235
  ]
228
236
  }), /* @__PURE__ */ m(E, {
229
237
  height: a,
230
- borderRadius: d,
231
- containerRef: u
238
+ borderRadius: h,
239
+ containerRef: f
232
240
  });
233
241
  }
234
242
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/react-amos-js",
3
- "version": "0.11.17",
3
+ "version": "0.11.19",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,7 +57,7 @@
57
57
  "vite-plugin-dts": "5.0.3"
58
58
  },
59
59
  "dependencies": {
60
- "@amos.com/amos-js": "0.11.17",
60
+ "@amos.com/amos-js": "0.11.20",
61
61
  "@types/googlepay": "0.7.12"
62
62
  },
63
63
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  type PaymentMethodFormDefaultValues,
22
22
  type PaymentMethodFormField,
23
23
  resolveWalletButtonSkeletonBorderRadius,
24
+ type WalletCustomerCreateAttributes,
24
25
  } from "@amos.com/amos-js";
25
26
  import type { components } from "@amos.com/node";
26
27
  import {
@@ -416,6 +417,9 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
416
417
  * is `"setup"` (setup always shows Plaid) or when the render token
417
418
  * disables verification.
418
419
  *
420
+ * Changing this prop hides or shows Link; it does not remount the
421
+ * bank form or destroy the Embedded handler.
422
+ *
419
423
  * @default false
420
424
  */
421
425
  requireAchVerification?: boolean;
@@ -458,6 +462,8 @@ export function AmosBankAccountPaymentMethodForm({
458
462
  onValidityChange,
459
463
  onEscapeKeyPressed,
460
464
  },
465
+ // `requireAchVerification` is an update, not a remount: amos-js hides
466
+ // Embedded Link instead of destroying it when the flag flips.
461
467
  remountDeps: [renderToken, billingAddressRequirement, intent],
462
468
  iframePassthrough: { style, ...rest },
463
469
  updateDeps: [
@@ -496,11 +502,24 @@ type AmosGooglePayButtonProps = {
496
502
  * mount slot, not the button.
497
503
  */
498
504
  buttonProps?: GooglePayButtonElementProps;
505
+ /**
506
+ * Collect a phone number in the Google Pay sheet.
507
+ * @default false
508
+ */
509
+ phoneRequired?: boolean;
510
+ /**
511
+ * Collect a shipping postal address. Name, email, and billing
512
+ * address are always required.
513
+ * @default false
514
+ */
515
+ shippingAddressRequired?: boolean;
499
516
  /** Props applied to the host-page `<iframe>` element. */
500
517
  iframeProps?: IframePassthroughProps;
501
518
  /**
502
519
  * Called when the buyer authorizes in the Google Pay sheet. Create a
503
520
  * payment intent on your server, then `await confirmPayment(token)`.
521
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
522
+ * Amos `CreateCustomerInput`.
504
523
  */
505
524
  onConfirm: ({
506
525
  paymentIntentCreateAttributes,
@@ -508,7 +527,7 @@ type AmosGooglePayButtonProps = {
508
527
  confirmPayment,
509
528
  }: {
510
529
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
511
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
530
+ customerCreateAttributes: WalletCustomerCreateAttributes;
512
531
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
513
532
  }) => Promise<ConfirmPaymentResult>;
514
533
  };
@@ -525,6 +544,8 @@ export function AmosGooglePayButton({
525
544
  merchantName,
526
545
  height = "48px",
527
546
  buttonProps,
547
+ phoneRequired,
548
+ shippingAddressRequired,
528
549
  iframeProps,
529
550
  onConfirm,
530
551
  }: AmosGooglePayButtonProps) {
@@ -544,11 +565,21 @@ export function AmosGooglePayButton({
544
565
  merchantName,
545
566
  height,
546
567
  buttonProps,
568
+ phoneRequired,
569
+ shippingAddressRequired,
547
570
  onConfirm,
548
571
  },
549
572
  remountDeps: [renderToken],
550
573
  iframePassthrough: iframeProps ?? {},
551
- updateDeps: [amount, merchantName, height, buttonProps, onConfirm],
574
+ updateDeps: [
575
+ amount,
576
+ merchantName,
577
+ height,
578
+ buttonProps,
579
+ phoneRequired,
580
+ shippingAddressRequired,
581
+ onConfirm,
582
+ ],
552
583
  });
553
584
 
554
585
  return (
@@ -582,11 +613,24 @@ type AmosApplePayButtonProps = {
582
613
  * button fills the iframe — size the mount slot, not the button.
583
614
  */
584
615
  buttonProps?: ApplePayButtonElementProps;
616
+ /**
617
+ * Collect a phone number in the Apple Pay sheet.
618
+ * @default false
619
+ */
620
+ phoneRequired?: boolean;
621
+ /**
622
+ * Collect a shipping postal address. Name, email, and billing
623
+ * address are always required.
624
+ * @default false
625
+ */
626
+ shippingAddressRequired?: boolean;
585
627
  /** Props applied to the host-page `<iframe>` element. */
586
628
  iframeProps?: IframePassthroughProps;
587
629
  /**
588
630
  * Called when the buyer authorizes in the Apple Pay sheet. Create a
589
631
  * payment intent on your server, then `await confirmPayment(token)`.
632
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
633
+ * Amos `CreateCustomerInput`.
590
634
  */
591
635
  onConfirm: ({
592
636
  paymentIntentCreateAttributes,
@@ -594,7 +638,7 @@ type AmosApplePayButtonProps = {
594
638
  confirmPayment,
595
639
  }: {
596
640
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
597
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
641
+ customerCreateAttributes: WalletCustomerCreateAttributes;
598
642
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
599
643
  }) => Promise<ConfirmPaymentResult>;
600
644
  };
@@ -611,6 +655,8 @@ export function AmosApplePayButton({
611
655
  merchantName,
612
656
  height = "48px",
613
657
  buttonProps,
658
+ phoneRequired,
659
+ shippingAddressRequired,
614
660
  iframeProps,
615
661
  onConfirm,
616
662
  }: AmosApplePayButtonProps) {
@@ -630,11 +676,21 @@ export function AmosApplePayButton({
630
676
  merchantName,
631
677
  height,
632
678
  buttonProps,
679
+ phoneRequired,
680
+ shippingAddressRequired,
633
681
  onConfirm,
634
682
  },
635
683
  remountDeps: [renderToken],
636
684
  iframePassthrough: iframeProps ?? {},
637
- updateDeps: [amount, merchantName, height, buttonProps, onConfirm],
685
+ updateDeps: [
686
+ amount,
687
+ merchantName,
688
+ height,
689
+ buttonProps,
690
+ phoneRequired,
691
+ shippingAddressRequired,
692
+ onConfirm,
693
+ ],
638
694
  });
639
695
 
640
696
  return (