@amos.com/react-amos-js 0.11.23 → 0.11.25
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 +9 -9
- package/dist/index.d.ts +7 -11
- package/dist/index.js +1 -1
- package/dist/index.mjs +61 -66
- package/package.json +12 -12
- package/src/index.tsx +5 -33
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ It is a thin wrapper around [`@amos.com/amos-js`](../amos-js) that adapts the fr
|
|
|
10
10
|
npm install @amos.com/react-amos-js @amos.com/node
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
`@amos.com/node` is a **peer dependency** (requires `>=0.1.
|
|
13
|
+
`@amos.com/node` is a **peer dependency** (requires `>=0.1.65`). Install it in your app for OpenAPI schema types (for example `components["schemas"]["CreatePaymentIntentInput"]`) used in the examples below, and for your server-side Amos API client. React (`^17`, `^18`, or `^19`) is also a peer dependency.
|
|
14
14
|
|
|
15
15
|
## What it gives you
|
|
16
16
|
|
|
@@ -141,7 +141,7 @@ appearance={{
|
|
|
141
141
|
|
|
142
142
|
Rules override `themeVariables` for the properties they set (Stripe). `--input-height` / `--floating-input-height` are a **minimum**; `.Input` `padding`, `fontSize`, and `lineHeight` can grow the field. Rule values may reference allowlisted tokens as `var(--primary)` (no fallback argument).
|
|
143
143
|
|
|
144
|
-
The host skeleton (shown until `UPDATED_APPEARANCE`, or 1.5s after
|
|
144
|
+
The host skeleton (shown until `UPDATED_APPEARANCE`, or 1.5s after mount if appearance never acks) copies `themeVariables` and resting **`.Input` / `.Label`** declarations (the same allowlisted properties as iframe rules). The iframe stays `opacity: 0` at its default pixel height underneath, so the skeleton is the only thing visible and WebKit still runs iframe JS. It does not inject webfonts: it uses `--font-family` / `fontFamily` when that face is already on the host page, and falls back to `ui-sans-serif, system-ui, sans-serif`. Hover, invalid, placeholder, dropdown, and radio rules have no skeleton equivalent. Floating labels sit inside the control, so `.Label` / `.Label--floating` do not change skeleton height.
|
|
145
145
|
|
|
146
146
|
| Selector | Targets |
|
|
147
147
|
| --- | --- |
|
|
@@ -560,7 +560,7 @@ Focus a named control inside the card or bank iframe. No-op if the field is not
|
|
|
560
560
|
|
|
561
561
|
### `AmosCreditCardPaymentMethodForm`
|
|
562
562
|
|
|
563
|
-
Renders the secure credit card iframe form. A field-shaped skeleton
|
|
563
|
+
Renders the secure credit card iframe form. A field-shaped skeleton is shown immediately (sized from `appearance`, including resting `.Input` / `.Label` rules). The iframe stays `opacity: 0` at its default pixel height until appearance is applied, or for 1.5s after mount if appearance never acks.
|
|
564
564
|
|
|
565
565
|
**Required props:**
|
|
566
566
|
|
|
@@ -584,7 +584,7 @@ Enter in a card or bank iframe field submits the enclosing host `<form>` via `re
|
|
|
584
584
|
|
|
585
585
|
### `AmosBankAccountPaymentMethodForm`
|
|
586
586
|
|
|
587
|
-
Renders the secure bank account iframe form. A field-shaped skeleton
|
|
587
|
+
Renders the secure bank account iframe form. A field-shaped skeleton is shown immediately (sized from `appearance`, including resting `.Input` / `.Label` rules). The iframe stays `opacity: 0` at its default pixel height until appearance is applied, or for 1.5s after mount if appearance never acks.
|
|
588
588
|
|
|
589
589
|
When `requireAchVerification` is true (or `intent` is `"setup"`), and the render token allows verification, the SDK hides the routing/account iframe and mounts [Plaid Embedded Institution Search](https://plaid.com/docs/link/embedded-institution-search/) in the parent. A **350px pulse skeleton** covers that slot until Plaid's `onLoad` (1.5s fallback). Do not overlay a host loader. Hosts do not proxy Pay API (`GET /merchants`, `POST /plaid_link_tokens`); embed does that with `PAY_API_KEY`. Do not put Plaid secrets in the browser.
|
|
590
590
|
|
|
@@ -621,7 +621,7 @@ Setup (always Plaid, unless the render token disables verification):
|
|
|
621
621
|
|
|
622
622
|
### `AmosGooglePayButton`
|
|
623
623
|
|
|
624
|
-
Renders the secure Google Pay iframe button (express checkout flow). A button-shaped skeleton
|
|
624
|
+
Renders the secure Google Pay iframe button (express checkout flow). A button-shaped skeleton is shown immediately. The iframe stays `opacity: 0` at its default pixel height until appearance is applied, or for 1.5s after mount if appearance never acks.
|
|
625
625
|
|
|
626
626
|
**Required props:**
|
|
627
627
|
|
|
@@ -648,7 +648,7 @@ Renders the secure Google Pay iframe button (express checkout flow). A button-sh
|
|
|
648
648
|
|
|
649
649
|
### `AmosApplePayButton`
|
|
650
650
|
|
|
651
|
-
Renders the secure Apple Pay iframe button (express checkout flow). Same required props and callbacks as `AmosGooglePayButton`. A button-shaped skeleton
|
|
651
|
+
Renders the secure Apple Pay iframe button (express checkout flow). Same required props and callbacks as `AmosGooglePayButton`. A button-shaped skeleton is shown immediately. The iframe stays `opacity: 0` at its default pixel height until appearance is applied, or for 1.5s after mount if appearance never acks.
|
|
652
652
|
|
|
653
653
|
**Optional props:**
|
|
654
654
|
|
|
@@ -690,7 +690,7 @@ Re-exports of the same advanced helpers exposed by `@amos.com/amos-js`. Most int
|
|
|
690
690
|
|
|
691
691
|
Re-exports from `@amos.com/amos-js`. Build the iframe `src` URL for each form type. The React components call these for you.
|
|
692
692
|
|
|
693
|
-
Each URL includes the embed's canonical search params (`token`, `additionalFields`, `billingAddressRequirement`, `intent`) so the embed router does not 307 to fill in defaults. After the iframe `load` event, if `IFRAME_READY` never arrives (stale HTML, missing JS chunk), the SDK rewrites `src` once with `amosReload` so the next document is a real navigation. Appearance is applied after handshake via `UPDATE_APPEARANCE`. A host-page skeleton
|
|
693
|
+
Each URL includes the embed's canonical search params (`token`, `additionalFields`, `billingAddressRequirement`, `intent`) so the embed router does not 307 to fill in defaults. After the iframe `load` event, if `IFRAME_READY` never arrives (stale HTML, missing JS chunk), the SDK rewrites `src` once with `amosReload` so the next document is a real navigation. Appearance is applied after handshake via `UPDATE_APPEARANCE`. A host-page skeleton is shown until then. The iframe stays `opacity: 0` at its default pixel height, and is revealed 1.5s after mount if appearance never acks.
|
|
694
694
|
|
|
695
695
|
### `updateDefaultValues({ iframe, defaultValues })`
|
|
696
696
|
|
|
@@ -702,7 +702,7 @@ Re-export from `@amos.com/amos-js`. Fills omitted Inter `fonts` / `--font-family
|
|
|
702
702
|
|
|
703
703
|
### Exported types
|
|
704
704
|
|
|
705
|
-
`@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`.
|
|
705
|
+
`@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `ConfirmPaymentResult`, `ConfirmSetupResult`, `isConfirmTimeout`, `CONFIRM_TIMEOUT_MS`, `PaymentMethodFormValidityChangeEvent`, `CardBrand`, `PaymentMethodFormCardBrandChangeEvent`, `PaymentMethodFormPostalCodeChangeEvent`, `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`.
|
|
706
706
|
|
|
707
707
|
## Notes and potential gotchas
|
|
708
708
|
|
|
@@ -711,7 +711,7 @@ Re-export from `@amos.com/amos-js`. Fills omitted Inter `fonts` / `--font-family
|
|
|
711
711
|
- **Same components for payment vs setup intents**: `AmosCreditCardPaymentMethodForm` and `AmosBankAccountPaymentMethodForm` support both payment intents and setup intents. The flow differs only by which server call you make and which confirmation function you use (`confirmPayment` vs `confirmSetup`).
|
|
712
712
|
- **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`).
|
|
713
713
|
- **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`.
|
|
714
|
-
- **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
|
|
714
|
+
- **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 `opacity: 0` at its default pixel height until `UPDATED_APPEARANCE`, or for 1.5s after mount if appearance never acks. Embed messages match on origin plus `iframeName` when `contentWindow` identity changes.
|
|
715
715
|
- **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. After success the same slot is a connected-account row (institution name, mask, outline Disconnect) styled with existing `themeVariables`. Disconnect shows Institution Search again.
|
|
716
716
|
- **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.
|
|
717
717
|
- **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.
|
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, WalletCustomerCreateAttributes } from '@amos.com/amos-js';
|
|
2
|
+
import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmPaymentResult, ConfirmSetupResult, CreditCardAdditionalFields, GooglePayButtonElementProps, PaymentMethodFormDefaultValues, PaymentMethodFormField, PaymentMethodFormPostalCodeChangeEvent, 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';
|
|
@@ -67,10 +67,6 @@ export declare function focusField({ iframeRef, field, }: {
|
|
|
67
67
|
}): void;
|
|
68
68
|
type ForwardedIframeRef = Ref<HTMLIFrameElement> | undefined;
|
|
69
69
|
type IframePassthroughProps = Omit<ComponentProps<"iframe">, "src" | "title" | "name" | "role" | "allow">;
|
|
70
|
-
type PostalCodeChangeHandler = (event: {
|
|
71
|
-
postalCode: string | null;
|
|
72
|
-
country: string;
|
|
73
|
-
}) => void;
|
|
74
70
|
type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
75
71
|
renderToken: string;
|
|
76
72
|
appearance?: Appearance;
|
|
@@ -94,7 +90,7 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
94
90
|
* one. `postalCode` is null when a finished code becomes incomplete.
|
|
95
91
|
* Incomplete keystrokes and `defaultValues` writes are omitted.
|
|
96
92
|
*/
|
|
97
|
-
onPostalCodeChange?:
|
|
93
|
+
onPostalCodeChange?: (event: PaymentMethodFormPostalCodeChangeEvent) => void;
|
|
98
94
|
/**
|
|
99
95
|
* Called when the customer presses Escape in the iframe. PCI-safe —
|
|
100
96
|
* no field values. Use this to close a host modal that contains the
|
|
@@ -112,7 +108,7 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
112
108
|
*/
|
|
113
109
|
defaultValues?: PaymentMethodFormDefaultValues;
|
|
114
110
|
};
|
|
115
|
-
export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onCardBrandChanged, onPostalCodeChange, onEscapeKeyPressed, additionalFields, billingAddressRequirement, defaultValues, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import(
|
|
111
|
+
export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onCardBrandChanged, onPostalCodeChange, onEscapeKeyPressed, additionalFields, billingAddressRequirement, defaultValues, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import('react').JSX.Element;
|
|
116
112
|
type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
|
|
117
113
|
renderToken: string;
|
|
118
114
|
appearance?: Appearance;
|
|
@@ -137,7 +133,7 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
137
133
|
* one. `postalCode` is null when a finished code becomes incomplete.
|
|
138
134
|
* Incomplete keystrokes and `defaultValues` writes are omitted.
|
|
139
135
|
*/
|
|
140
|
-
onPostalCodeChange?:
|
|
136
|
+
onPostalCodeChange?: (event: PaymentMethodFormPostalCodeChangeEvent) => void;
|
|
141
137
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
142
138
|
/**
|
|
143
139
|
* Seed account holder name and billing address. Provided keys
|
|
@@ -167,7 +163,7 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
167
163
|
*/
|
|
168
164
|
intent?: "payment" | "setup";
|
|
169
165
|
};
|
|
170
|
-
export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onPostalCodeChange, onEscapeKeyPressed, billingAddressRequirement, defaultValues, requireAchVerification, intent, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import(
|
|
166
|
+
export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onPostalCodeChange, onEscapeKeyPressed, billingAddressRequirement, defaultValues, requireAchVerification, intent, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import('react').JSX.Element;
|
|
171
167
|
type AmosGooglePayButtonProps = {
|
|
172
168
|
ref?: ForwardedIframeRef;
|
|
173
169
|
renderToken: string;
|
|
@@ -220,7 +216,7 @@ type AmosGooglePayButtonProps = {
|
|
|
220
216
|
* skeleton is painted in the parent document on first render (including
|
|
221
217
|
* SSR) so the slot height is reserved before the iframe loads.
|
|
222
218
|
*/
|
|
223
|
-
export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, phoneRequired, shippingAddressRequired, iframeProps, onConfirm, }: AmosGooglePayButtonProps): import(
|
|
219
|
+
export declare function AmosGooglePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, phoneRequired, shippingAddressRequired, iframeProps, onConfirm, }: AmosGooglePayButtonProps): import('react').JSX.Element;
|
|
224
220
|
type AmosApplePayButtonProps = {
|
|
225
221
|
ref?: ForwardedIframeRef;
|
|
226
222
|
renderToken: string;
|
|
@@ -273,4 +269,4 @@ type AmosApplePayButtonProps = {
|
|
|
273
269
|
* skeleton is painted in the parent document on first render (including
|
|
274
270
|
* SSR) so the slot height is reserved before the iframe loads.
|
|
275
271
|
*/
|
|
276
|
-
export declare function AmosApplePayButton({ ref, renderToken, amount, merchantName, height, buttonProps, phoneRequired, shippingAddressRequired, iframeProps, onConfirm, }: AmosApplePayButtonProps): import(
|
|
272
|
+
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
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@amos.com/amos-js"),t=require("react"),n=require("react/jsx-runtime");function resolveIframe(e){var t;return e?(t=e.current)==null?null:t:null}function validateForm({iframeRef:t}){return(0,e.validateForm)({iframe:resolveIframe(t)})}function confirmPayment({iframeRef:t,token:n,defaultValues:r}){return(0,e.confirmPayment)({iframe:resolveIframe(t),token:n,defaultValues:r})}function confirmSetup({iframeRef:t,token:n,defaultValues:r}){return(0,e.confirmSetup)({iframe:resolveIframe(t),token:n,defaultValues:r})}function resetForm({iframeRef:t}){(0,e.resetForm)({iframe:resolveIframe(t)})}function focusField({iframeRef:t,field:n}){(0,e.focusField)({iframe:resolveIframe(t),field:n})}function setForwardedRef(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function applyIframePassthrough(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 useAmosEmbed({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,setForwardedRef(n,a.iframe),applyIframePassthrough(a.iframe,o),()=>{a.destroy(),c.current=null,setForwardedRef(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&&applyIframePassthrough(t,o)})}var r=`oklch(0.97 0 0)`;function WalletButtonSlot({height:i,borderRadius:a,containerRef:o}){return(0,t.useLayoutEffect)(()=>{(0,e.ensureSkeletonStyles)()},[]),(0,n.jsxs)(`div`,{style:{boxSizing:`border-box`,position:`relative`,width:`100%`,height:i,minHeight:i,overflow:`hidden`},children:[(0,n.jsx)(`div`,{className:`amos-js-form-skeleton-input amos-js-wallet-skeleton`,style:{position:`absolute`,inset:0,height:i,borderRadius:a,background:r,pointerEvents:`none`,zIndex:0},"aria-hidden":!0}),(0,n.jsx)(`div`,{ref:o,style:{position:`absolute`,inset:0,zIndex:1,width:`100%`,height:`100%`}})]})}function AmosCreditCardPaymentMethodForm({ref:r,renderToken:i,appearance:a,onValidityChange:o,onCardBrandChanged:s,onPostalCodeChange:c,onEscapeKeyPressed:l,additionalFields:u={cardholderName:!1},billingAddressRequirement:d=`country`,defaultValues:f,style:p,...m}){let h=(0,t.useRef)(null);return useAmosEmbed({containerRef:h,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:u,billingAddressRequirement:d,defaultValues:f,onValidityChange:o,onCardBrandChanged:s,onPostalCodeChange:c,onEscapeKeyPressed:l},remountDeps:[i,u.cardholderName,d],iframePassthrough:{style:p,...m},updateDeps:[a,u,d,f,o,s,c,l]}),(0,n.jsx)(`div`,{ref:h})}function AmosBankAccountPaymentMethodForm({ref:r,renderToken:i,appearance:a,onValidityChange:o,onPostalCodeChange:s,onEscapeKeyPressed:c,billingAddressRequirement:l=`country`,defaultValues:u,requireAchVerification:d=!1,intent:f=`payment`,style:p,...m}){let h=(0,t.useRef)(null);return useAmosEmbed({containerRef:h,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:l,defaultValues:u,requireAchVerification:d,intent:f,onValidityChange:o,onPostalCodeChange:s,onEscapeKeyPressed:c},remountDeps:[i,l,f],iframePassthrough:{style:p,...m},updateDeps:[a,l,u,d,f,o,s,c]}),(0,n.jsx)(`div`,{ref:h})}function AmosGooglePayButton({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,iframeProps:d,onConfirm:f}){let p=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:d==null?void 0:d.style,buttonProps:c});return useAmosEmbed({containerRef:p,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,onConfirm:f},remountDeps:[i],iframePassthrough:d==null?{}:d,updateDeps:[a,o,s,c,l,u,f]}),(0,n.jsx)(WalletButtonSlot,{height:s,borderRadius:m,containerRef:p})}function AmosApplePayButton({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,iframeProps:d,onConfirm:f}){let p=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:d==null?void 0:d.style,buttonProps:c});return useAmosEmbed({containerRef:p,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,phoneRequired:l,shippingAddressRequired:u,onConfirm:f},remountDeps:[i],iframePassthrough:d==null?{}:d,updateDeps:[a,o,s,c,l,u,f]}),(0,n.jsx)(WalletButtonSlot,{height:s,borderRadius:m,containerRef:p})}exports.AmosApplePayButton=AmosApplePayButton,exports.AmosBankAccountPaymentMethodForm=AmosBankAccountPaymentMethodForm,exports.AmosCreditCardPaymentMethodForm=AmosCreditCardPaymentMethodForm,exports.AmosGooglePayButton=AmosGooglePayButton,exports.confirmPayment=confirmPayment,exports.confirmSetup=confirmSetup,exports.focusField=focusField,exports.resetForm=resetForm,exports.validateForm=validateForm,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
|
@@ -2,52 +2,53 @@ import { confirmPayment as e, confirmSetup as t, ensureSkeletonStyles as n, focu
|
|
|
2
2
|
import { useEffect as d, useLayoutEffect as f, useRef as p } from "react";
|
|
3
3
|
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
4
4
|
export * from "@amos.com/amos-js";
|
|
5
|
+
//#endregion
|
|
5
6
|
//#region src/index.tsx
|
|
6
|
-
function
|
|
7
|
+
function resolveIframe(e) {
|
|
7
8
|
var t;
|
|
8
9
|
return e ? (t = e.current) == null ? null : t : null;
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
return u({ iframe:
|
|
11
|
+
function validateForm({ iframeRef: e }) {
|
|
12
|
+
return u({ iframe: resolveIframe(e) });
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function confirmPayment({ iframeRef: t, token: n, defaultValues: r }) {
|
|
14
15
|
return e({
|
|
15
|
-
iframe:
|
|
16
|
+
iframe: resolveIframe(t),
|
|
16
17
|
token: n,
|
|
17
18
|
defaultValues: r
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
+
function confirmSetup({ iframeRef: e, token: n, defaultValues: r }) {
|
|
21
22
|
return t({
|
|
22
|
-
iframe:
|
|
23
|
+
iframe: resolveIframe(e),
|
|
23
24
|
token: n,
|
|
24
25
|
defaultValues: r
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
c({ iframe:
|
|
28
|
+
function resetForm({ iframeRef: e }) {
|
|
29
|
+
c({ iframe: resolveIframe(e) });
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
+
function focusField({ iframeRef: e, field: t }) {
|
|
31
32
|
r({
|
|
32
|
-
iframe:
|
|
33
|
+
iframe: resolveIframe(e),
|
|
33
34
|
field: t
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
+
function setForwardedRef(e, t) {
|
|
37
38
|
typeof e == "function" ? e(t) : e && (e.current = t);
|
|
38
39
|
}
|
|
39
|
-
function
|
|
40
|
+
function applyIframePassthrough(e, { style: t, className: n, id: r, ...i }) {
|
|
40
41
|
n != null && (e.className = n), r != null && (e.id = r), Object.assign(e.style, t);
|
|
41
42
|
for (let [t, n] of Object.entries(i)) n != null && (t in e ? Reflect.set(e, t, n) : e.setAttribute(t, String(n)));
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function useAmosEmbed({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i, iframePassthrough: a, updateDeps: o }) {
|
|
44
45
|
let s = p(null);
|
|
45
46
|
f(() => {
|
|
46
47
|
let i = e.current;
|
|
47
48
|
if (!i) return;
|
|
48
49
|
let o = n(i, r);
|
|
49
|
-
return s.current = o,
|
|
50
|
-
o.destroy(), s.current = null,
|
|
50
|
+
return s.current = o, setForwardedRef(t, o.iframe), applyIframePassthrough(o.iframe, a), () => {
|
|
51
|
+
o.destroy(), s.current = null, setForwardedRef(t, null);
|
|
51
52
|
};
|
|
52
53
|
}, [...i]), d(() => {
|
|
53
54
|
var e;
|
|
@@ -55,11 +56,11 @@ function w({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i
|
|
|
55
56
|
}, [...o]), d(() => {
|
|
56
57
|
var e;
|
|
57
58
|
let t = (e = s.current) == null ? void 0 : e.iframe;
|
|
58
|
-
t &&
|
|
59
|
+
t && applyIframePassthrough(t, a);
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
var
|
|
62
|
-
function
|
|
62
|
+
var g = "oklch(0.97 0 0)";
|
|
63
|
+
function WalletButtonSlot({ height: e, borderRadius: t, containerRef: r }) {
|
|
63
64
|
return f(() => {
|
|
64
65
|
n();
|
|
65
66
|
}, []), /* @__PURE__ */ h("div", {
|
|
@@ -78,7 +79,7 @@ function E({ height: e, borderRadius: t, containerRef: r }) {
|
|
|
78
79
|
inset: 0,
|
|
79
80
|
height: e,
|
|
80
81
|
borderRadius: t,
|
|
81
|
-
background:
|
|
82
|
+
background: g,
|
|
82
83
|
pointerEvents: "none",
|
|
83
84
|
zIndex: 0
|
|
84
85
|
},
|
|
@@ -95,94 +96,88 @@ function E({ height: e, borderRadius: t, containerRef: r }) {
|
|
|
95
96
|
})]
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return a(e, t);
|
|
103
|
-
}
|
|
104
|
-
function k({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onCardBrandChanged: i, onPostalCodeChange: a, onEscapeKeyPressed: o, additionalFields: s = { cardholderName: !1 }, billingAddressRequirement: c = "country", defaultValues: l, style: u, ...d }) {
|
|
105
|
-
let f = p(null);
|
|
106
|
-
return w({
|
|
107
|
-
containerRef: f,
|
|
99
|
+
function AmosCreditCardPaymentMethodForm({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onCardBrandChanged: i, onPostalCodeChange: a, onEscapeKeyPressed: s, additionalFields: c = { cardholderName: !1 }, billingAddressRequirement: l = "country", defaultValues: u, style: d, ...f }) {
|
|
100
|
+
let h = p(null);
|
|
101
|
+
return useAmosEmbed({
|
|
102
|
+
containerRef: h,
|
|
108
103
|
iframeRef: e,
|
|
109
|
-
mount:
|
|
104
|
+
mount: o,
|
|
110
105
|
options: {
|
|
111
106
|
renderToken: t,
|
|
112
107
|
appearance: n,
|
|
113
|
-
additionalFields:
|
|
114
|
-
billingAddressRequirement:
|
|
115
|
-
defaultValues:
|
|
108
|
+
additionalFields: c,
|
|
109
|
+
billingAddressRequirement: l,
|
|
110
|
+
defaultValues: u,
|
|
116
111
|
onValidityChange: r,
|
|
117
112
|
onCardBrandChanged: i,
|
|
118
113
|
onPostalCodeChange: a,
|
|
119
|
-
onEscapeKeyPressed:
|
|
114
|
+
onEscapeKeyPressed: s
|
|
120
115
|
},
|
|
121
116
|
remountDeps: [
|
|
122
117
|
t,
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
c.cardholderName,
|
|
119
|
+
l
|
|
125
120
|
],
|
|
126
121
|
iframePassthrough: {
|
|
127
|
-
style:
|
|
128
|
-
...
|
|
122
|
+
style: d,
|
|
123
|
+
...f
|
|
129
124
|
},
|
|
130
125
|
updateDeps: [
|
|
131
126
|
n,
|
|
132
|
-
s,
|
|
133
127
|
c,
|
|
134
128
|
l,
|
|
129
|
+
u,
|
|
135
130
|
r,
|
|
136
131
|
i,
|
|
137
132
|
a,
|
|
138
|
-
|
|
133
|
+
s
|
|
139
134
|
]
|
|
140
|
-
}), /* @__PURE__ */ m("div", { ref:
|
|
135
|
+
}), /* @__PURE__ */ m("div", { ref: h });
|
|
141
136
|
}
|
|
142
|
-
function
|
|
143
|
-
let
|
|
144
|
-
return
|
|
145
|
-
containerRef:
|
|
137
|
+
function AmosBankAccountPaymentMethodForm({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onPostalCodeChange: i, onEscapeKeyPressed: o, billingAddressRequirement: s = "country", defaultValues: c, requireAchVerification: l = !1, intent: u = "payment", style: d, ...f }) {
|
|
138
|
+
let h = p(null);
|
|
139
|
+
return useAmosEmbed({
|
|
140
|
+
containerRef: h,
|
|
146
141
|
iframeRef: e,
|
|
147
|
-
mount:
|
|
142
|
+
mount: a,
|
|
148
143
|
options: {
|
|
149
144
|
renderToken: t,
|
|
150
145
|
appearance: n,
|
|
151
|
-
billingAddressRequirement:
|
|
152
|
-
defaultValues:
|
|
153
|
-
requireAchVerification:
|
|
154
|
-
intent:
|
|
146
|
+
billingAddressRequirement: s,
|
|
147
|
+
defaultValues: c,
|
|
148
|
+
requireAchVerification: l,
|
|
149
|
+
intent: u,
|
|
155
150
|
onValidityChange: r,
|
|
156
151
|
onPostalCodeChange: i,
|
|
157
|
-
onEscapeKeyPressed:
|
|
152
|
+
onEscapeKeyPressed: o
|
|
158
153
|
},
|
|
159
154
|
remountDeps: [
|
|
160
155
|
t,
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
s,
|
|
157
|
+
u
|
|
163
158
|
],
|
|
164
159
|
iframePassthrough: {
|
|
165
|
-
style:
|
|
166
|
-
...
|
|
160
|
+
style: d,
|
|
161
|
+
...f
|
|
167
162
|
},
|
|
168
163
|
updateDeps: [
|
|
169
164
|
n,
|
|
170
|
-
o,
|
|
171
165
|
s,
|
|
172
166
|
c,
|
|
173
167
|
l,
|
|
168
|
+
u,
|
|
174
169
|
r,
|
|
175
170
|
i,
|
|
176
|
-
|
|
171
|
+
o
|
|
177
172
|
]
|
|
178
|
-
}), /* @__PURE__ */ m("div", { ref:
|
|
173
|
+
}), /* @__PURE__ */ m("div", { ref: h });
|
|
179
174
|
}
|
|
180
|
-
function
|
|
175
|
+
function AmosGooglePayButton({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48px", buttonProps: a, phoneRequired: o, shippingAddressRequired: c, iframeProps: u, onConfirm: d }) {
|
|
181
176
|
let f = p(null), h = l({
|
|
182
177
|
iframeStyle: u == null ? void 0 : u.style,
|
|
183
178
|
buttonProps: a
|
|
184
179
|
});
|
|
185
|
-
return
|
|
180
|
+
return useAmosEmbed({
|
|
186
181
|
containerRef: f,
|
|
187
182
|
iframeRef: e,
|
|
188
183
|
mount: s,
|
|
@@ -207,18 +202,18 @@ function j({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48
|
|
|
207
202
|
c,
|
|
208
203
|
d
|
|
209
204
|
]
|
|
210
|
-
}), /* @__PURE__ */ m(
|
|
205
|
+
}), /* @__PURE__ */ m(WalletButtonSlot, {
|
|
211
206
|
height: i,
|
|
212
207
|
borderRadius: h,
|
|
213
208
|
containerRef: f
|
|
214
209
|
});
|
|
215
210
|
}
|
|
216
|
-
function
|
|
211
|
+
function AmosApplePayButton({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48px", buttonProps: o, phoneRequired: s, shippingAddressRequired: c, iframeProps: u, onConfirm: d }) {
|
|
217
212
|
let f = p(null), h = l({
|
|
218
213
|
iframeStyle: u == null ? void 0 : u.style,
|
|
219
214
|
buttonProps: o
|
|
220
215
|
});
|
|
221
|
-
return
|
|
216
|
+
return useAmosEmbed({
|
|
222
217
|
containerRef: f,
|
|
223
218
|
iframeRef: e,
|
|
224
219
|
mount: i,
|
|
@@ -243,11 +238,11 @@ function M({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48
|
|
|
243
238
|
c,
|
|
244
239
|
d
|
|
245
240
|
]
|
|
246
|
-
}), /* @__PURE__ */ m(
|
|
241
|
+
}), /* @__PURE__ */ m(WalletButtonSlot, {
|
|
247
242
|
height: a,
|
|
248
243
|
borderRadius: h,
|
|
249
244
|
containerRef: f
|
|
250
245
|
});
|
|
251
246
|
}
|
|
252
247
|
//#endregion
|
|
253
|
-
export {
|
|
248
|
+
export { AmosApplePayButton, AmosBankAccountPaymentMethodForm, AmosCreditCardPaymentMethodForm, AmosGooglePayButton, confirmPayment, confirmSetup, focusField, resetForm, validateForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amos.com/react-amos-js",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.25",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"watch": "vite build --watch",
|
|
28
28
|
"preview": "vite preview",
|
|
29
29
|
"test": "vitest",
|
|
30
|
-
"typecheck": "tsc --noEmit",
|
|
30
|
+
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit",
|
|
31
31
|
"prepack": "npm run build",
|
|
32
32
|
"changeset": "changeset",
|
|
33
33
|
"version": "changeset version",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
],
|
|
47
47
|
"description": "React SDK for embedding Amos payment methods via iframes. Wraps @amos.com/amos-js.",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@amos.com/node": "0.1.
|
|
50
|
-
"@biomejs/biome": "2.5.
|
|
51
|
-
"@changesets/cli": "
|
|
52
|
-
"@types/node": "26.
|
|
53
|
-
"@types/react": "19.
|
|
49
|
+
"@amos.com/node": "0.1.65",
|
|
50
|
+
"@biomejs/biome": "2.5.14",
|
|
51
|
+
"@changesets/cli": "3.0.3",
|
|
52
|
+
"@types/node": "26.6.2",
|
|
53
|
+
"@types/react": "19.3.0",
|
|
54
54
|
"@typescript/typescript6": "6.0.2",
|
|
55
55
|
"typescript": "7.0.2",
|
|
56
|
-
"vite": "8.
|
|
57
|
-
"vite-plugin-dts": "5.
|
|
56
|
+
"vite": "8.3.0",
|
|
57
|
+
"vite-plugin-dts": "5.1.1"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@amos.com/amos-js": "0.11.
|
|
61
|
-
"@types/googlepay": "0.7.
|
|
60
|
+
"@amos.com/amos-js": "0.11.27",
|
|
61
|
+
"@types/googlepay": "0.7.13"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"react": "^17 || ^18 || ^19",
|
|
65
|
-
"@amos.com/node": ">=0.1.
|
|
65
|
+
"@amos.com/node": ">=0.1.65"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/index.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
mountAmosGooglePayButton,
|
|
21
21
|
type PaymentMethodFormDefaultValues,
|
|
22
22
|
type PaymentMethodFormField,
|
|
23
|
+
type PaymentMethodFormPostalCodeChangeEvent,
|
|
23
24
|
resolveWalletButtonSkeletonBorderRadius,
|
|
24
25
|
type WalletCustomerCreateAttributes,
|
|
25
26
|
} from "@amos.com/amos-js";
|
|
@@ -296,35 +297,6 @@ function WalletButtonSlot({
|
|
|
296
297
|
);
|
|
297
298
|
}
|
|
298
299
|
|
|
299
|
-
type PostalCodeChangeHandler = (event: {
|
|
300
|
-
postalCode: string | null;
|
|
301
|
-
country: string;
|
|
302
|
-
}) => void;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* The installed `@amos.com/amos-js` types may not include
|
|
306
|
-
* `onPostalCodeChange` until that package is published. The mount
|
|
307
|
-
* parameter accepts the extra field; the runtime object still carries
|
|
308
|
-
* it into `attachPaymentMethodFormListeners`.
|
|
309
|
-
*/
|
|
310
|
-
function mountCreditCardPaymentMethodForm(
|
|
311
|
-
container: HTMLElement,
|
|
312
|
-
options: Parameters<typeof mountAmosCreditCardPaymentMethodForm>[1] & {
|
|
313
|
-
onPostalCodeChange?: PostalCodeChangeHandler;
|
|
314
|
-
},
|
|
315
|
-
) {
|
|
316
|
-
return mountAmosCreditCardPaymentMethodForm(container, options);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function mountBankAccountPaymentMethodForm(
|
|
320
|
-
container: HTMLElement,
|
|
321
|
-
options: Parameters<typeof mountAmosBankAccountPaymentMethodForm>[1] & {
|
|
322
|
-
onPostalCodeChange?: PostalCodeChangeHandler;
|
|
323
|
-
},
|
|
324
|
-
) {
|
|
325
|
-
return mountAmosBankAccountPaymentMethodForm(container, options);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
300
|
type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
329
301
|
renderToken: string;
|
|
330
302
|
appearance?: Appearance;
|
|
@@ -353,7 +325,7 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
353
325
|
* one. `postalCode` is null when a finished code becomes incomplete.
|
|
354
326
|
* Incomplete keystrokes and `defaultValues` writes are omitted.
|
|
355
327
|
*/
|
|
356
|
-
onPostalCodeChange?:
|
|
328
|
+
onPostalCodeChange?: (event: PaymentMethodFormPostalCodeChangeEvent) => void;
|
|
357
329
|
/**
|
|
358
330
|
* Called when the customer presses Escape in the iframe. PCI-safe —
|
|
359
331
|
* no field values. Use this to close a host modal that contains the
|
|
@@ -391,7 +363,7 @@ export function AmosCreditCardPaymentMethodForm({
|
|
|
391
363
|
useAmosEmbed({
|
|
392
364
|
containerRef,
|
|
393
365
|
iframeRef: ref as ForwardedIframeRef,
|
|
394
|
-
mount:
|
|
366
|
+
mount: mountAmosCreditCardPaymentMethodForm,
|
|
395
367
|
options: {
|
|
396
368
|
renderToken,
|
|
397
369
|
appearance,
|
|
@@ -446,7 +418,7 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
|
|
|
446
418
|
* one. `postalCode` is null when a finished code becomes incomplete.
|
|
447
419
|
* Incomplete keystrokes and `defaultValues` writes are omitted.
|
|
448
420
|
*/
|
|
449
|
-
onPostalCodeChange?:
|
|
421
|
+
onPostalCodeChange?: (event: PaymentMethodFormPostalCodeChangeEvent) => void;
|
|
450
422
|
billingAddressRequirement?: BillingAddressRequirement;
|
|
451
423
|
/**
|
|
452
424
|
* Seed account holder name and billing address. Provided keys
|
|
@@ -496,7 +468,7 @@ export function AmosBankAccountPaymentMethodForm({
|
|
|
496
468
|
useAmosEmbed({
|
|
497
469
|
containerRef,
|
|
498
470
|
iframeRef: ref as ForwardedIframeRef,
|
|
499
|
-
mount:
|
|
471
|
+
mount: mountAmosBankAccountPaymentMethodForm,
|
|
500
472
|
options: {
|
|
501
473
|
renderToken,
|
|
502
474
|
appearance,
|