@amos.com/react-amos-js 0.11.18 → 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
 
@@ -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
 
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';
@@ -174,15 +174,28 @@ type AmosGooglePayButtonProps = {
174
174
  * mount slot, not the button.
175
175
  */
176
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;
177
188
  /** Props applied to the host-page `<iframe>` element. */
178
189
  iframeProps?: IframePassthroughProps;
179
190
  /**
180
191
  * Called when the buyer authorizes in the Google Pay sheet. Create a
181
192
  * payment intent on your server, then `await confirmPayment(token)`.
193
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
194
+ * Amos `CreateCustomerInput`.
182
195
  */
183
196
  onConfirm: ({ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment, }: {
184
197
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
185
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
198
+ customerCreateAttributes: WalletCustomerCreateAttributes;
186
199
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
187
200
  }) => Promise<ConfirmPaymentResult>;
188
201
  };
@@ -191,7 +204,7 @@ type AmosGooglePayButtonProps = {
191
204
  * skeleton is painted in the parent document on first render (including
192
205
  * SSR) so the slot height is reserved before the iframe loads.
193
206
  */
194
- 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;
195
208
  type AmosApplePayButtonProps = {
196
209
  ref?: ForwardedIframeRef;
197
210
  renderToken: string;
@@ -214,15 +227,28 @@ type AmosApplePayButtonProps = {
214
227
  * button fills the iframe — size the mount slot, not the button.
215
228
  */
216
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;
217
241
  /** Props applied to the host-page `<iframe>` element. */
218
242
  iframeProps?: IframePassthroughProps;
219
243
  /**
220
244
  * Called when the buyer authorizes in the Apple Pay sheet. Create a
221
245
  * payment intent on your server, then `await confirmPayment(token)`.
246
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
247
+ * Amos `CreateCustomerInput`.
222
248
  */
223
249
  onConfirm: ({ paymentIntentCreateAttributes, customerCreateAttributes, confirmPayment, }: {
224
250
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
225
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
251
+ customerCreateAttributes: WalletCustomerCreateAttributes;
226
252
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
227
253
  }) => Promise<ConfirmPaymentResult>;
228
254
  };
@@ -231,4 +257,4 @@ type AmosApplePayButtonProps = {
231
257
  * skeleton is painted in the parent document on first render (including
232
258
  * SSR) so the slot height is reserved before the iframe loads.
233
259
  */
234
- 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.18",
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.18",
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 {
@@ -501,11 +502,24 @@ type AmosGooglePayButtonProps = {
501
502
  * mount slot, not the button.
502
503
  */
503
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;
504
516
  /** Props applied to the host-page `<iframe>` element. */
505
517
  iframeProps?: IframePassthroughProps;
506
518
  /**
507
519
  * Called when the buyer authorizes in the Google Pay sheet. Create a
508
520
  * payment intent on your server, then `await confirmPayment(token)`.
521
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
522
+ * Amos `CreateCustomerInput`.
509
523
  */
510
524
  onConfirm: ({
511
525
  paymentIntentCreateAttributes,
@@ -513,7 +527,7 @@ type AmosGooglePayButtonProps = {
513
527
  confirmPayment,
514
528
  }: {
515
529
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
516
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
530
+ customerCreateAttributes: WalletCustomerCreateAttributes;
517
531
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
518
532
  }) => Promise<ConfirmPaymentResult>;
519
533
  };
@@ -530,6 +544,8 @@ export function AmosGooglePayButton({
530
544
  merchantName,
531
545
  height = "48px",
532
546
  buttonProps,
547
+ phoneRequired,
548
+ shippingAddressRequired,
533
549
  iframeProps,
534
550
  onConfirm,
535
551
  }: AmosGooglePayButtonProps) {
@@ -549,11 +565,21 @@ export function AmosGooglePayButton({
549
565
  merchantName,
550
566
  height,
551
567
  buttonProps,
568
+ phoneRequired,
569
+ shippingAddressRequired,
552
570
  onConfirm,
553
571
  },
554
572
  remountDeps: [renderToken],
555
573
  iframePassthrough: iframeProps ?? {},
556
- updateDeps: [amount, merchantName, height, buttonProps, onConfirm],
574
+ updateDeps: [
575
+ amount,
576
+ merchantName,
577
+ height,
578
+ buttonProps,
579
+ phoneRequired,
580
+ shippingAddressRequired,
581
+ onConfirm,
582
+ ],
557
583
  });
558
584
 
559
585
  return (
@@ -587,11 +613,24 @@ type AmosApplePayButtonProps = {
587
613
  * button fills the iframe — size the mount slot, not the button.
588
614
  */
589
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;
590
627
  /** Props applied to the host-page `<iframe>` element. */
591
628
  iframeProps?: IframePassthroughProps;
592
629
  /**
593
630
  * Called when the buyer authorizes in the Apple Pay sheet. Create a
594
631
  * payment intent on your server, then `await confirmPayment(token)`.
632
+ * `customerCreateAttributes` is `WalletCustomerCreateAttributes`, not
633
+ * Amos `CreateCustomerInput`.
595
634
  */
596
635
  onConfirm: ({
597
636
  paymentIntentCreateAttributes,
@@ -599,7 +638,7 @@ type AmosApplePayButtonProps = {
599
638
  confirmPayment,
600
639
  }: {
601
640
  paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"];
602
- customerCreateAttributes: components["schemas"]["CreateCustomerInput"];
641
+ customerCreateAttributes: WalletCustomerCreateAttributes;
603
642
  confirmPayment: (token: string) => Promise<ConfirmPaymentResult>;
604
643
  }) => Promise<ConfirmPaymentResult>;
605
644
  };
@@ -616,6 +655,8 @@ export function AmosApplePayButton({
616
655
  merchantName,
617
656
  height = "48px",
618
657
  buttonProps,
658
+ phoneRequired,
659
+ shippingAddressRequired,
619
660
  iframeProps,
620
661
  onConfirm,
621
662
  }: AmosApplePayButtonProps) {
@@ -635,11 +676,21 @@ export function AmosApplePayButton({
635
676
  merchantName,
636
677
  height,
637
678
  buttonProps,
679
+ phoneRequired,
680
+ shippingAddressRequired,
638
681
  onConfirm,
639
682
  },
640
683
  remountDeps: [renderToken],
641
684
  iframePassthrough: iframeProps ?? {},
642
- updateDeps: [amount, merchantName, height, buttonProps, onConfirm],
685
+ updateDeps: [
686
+ amount,
687
+ merchantName,
688
+ height,
689
+ buttonProps,
690
+ phoneRequired,
691
+ shippingAddressRequired,
692
+ onConfirm,
693
+ ],
643
694
  });
644
695
 
645
696
  return (