@amos.com/react-amos-js 0.11.4 → 0.11.5

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="googlepay" />
2
- import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmPaymentResult, ConfirmSetupResult, CreditCardAdditionalFields, GooglePayButtonElementProps } from '@amos.com/amos-js';
2
+ import { Appearance, ApplePayButtonElementProps, BillingAddressRequirement, ConfirmPaymentResult, ConfirmSetupResult, CreditCardAdditionalFields, GooglePayButtonElementProps, PaymentMethodFormDefaultValues, PaymentMethodFormField } 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';
@@ -20,8 +20,9 @@ export declare function validateForm({ iframeRef, }: {
20
20
  * Pass the embed JWT (`token`) returned by your server's
21
21
  * `POST /payment_intents` call.
22
22
  */
23
- export declare function confirmPayment({ iframeRef, token, }: {
23
+ export declare function confirmPayment({ iframeRef, token, defaultValues, }: {
24
24
  iframeRef: IframeRef;
25
+ defaultValues?: PaymentMethodFormDefaultValues;
25
26
  } & Pick<components["schemas"]["EmbedToken"], "token">): Promise<ConfirmPaymentResult>;
26
27
  /**
27
28
  * Confirm a setup intent in the embedded iframe flow. Use this when
@@ -30,8 +31,9 @@ export declare function confirmPayment({ iframeRef, token, }: {
30
31
  * Pass the embed JWT (`token`) returned by your server's
31
32
  * `POST /setup_intents` call.
32
33
  */
33
- export declare function confirmSetup({ iframeRef, token, }: {
34
+ export declare function confirmSetup({ iframeRef, token, defaultValues, }: {
34
35
  iframeRef: IframeRef;
36
+ defaultValues?: PaymentMethodFormDefaultValues;
35
37
  } & Pick<components["schemas"]["EmbedToken"], "token">): Promise<ConfirmSetupResult>;
36
38
  /**
37
39
  * Clear all field values and API errors in the embedded card/bank iframe
@@ -40,6 +42,15 @@ export declare function confirmSetup({ iframeRef, token, }: {
40
42
  export declare function resetForm({ iframeRef }: {
41
43
  iframeRef: IframeRef;
42
44
  }): void;
45
+ /**
46
+ * Focus a named control inside the embedded card/bank iframe. No-op if
47
+ * the field is not rendered, or while Plaid Embedded Institution Search
48
+ * is showing. Call from a click or keydown handler.
49
+ */
50
+ export declare function focusField({ iframeRef, field, }: {
51
+ iframeRef: IframeRef;
52
+ field: PaymentMethodFormField;
53
+ }): void;
43
54
  type ForwardedIframeRef = Ref<HTMLIFrameElement> | undefined;
44
55
  type IframePassthroughProps = Omit<ComponentProps<"iframe">, "src" | "title" | "name" | "role" | "allow">;
45
56
  type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
@@ -62,8 +73,14 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
62
73
  }) => void;
63
74
  additionalFields?: CreditCardAdditionalFields;
64
75
  billingAddressRequirement?: BillingAddressRequirement;
76
+ /**
77
+ * Seed cardholder name and billing address. Provided keys overwrite
78
+ * matching fields, including ones the customer already edited. Values
79
+ * are sent on confirm even when those inputs are hidden.
80
+ */
81
+ defaultValues?: PaymentMethodFormDefaultValues;
65
82
  };
66
- export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onCardBrandChanged, additionalFields, billingAddressRequirement, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import("react").JSX.Element;
83
+ export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, onCardBrandChanged, additionalFields, billingAddressRequirement, defaultValues, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import("react").JSX.Element;
67
84
  type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
68
85
  renderToken: string;
69
86
  appearance?: Appearance;
@@ -76,6 +93,12 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
76
93
  isValid: boolean;
77
94
  }) => void;
78
95
  billingAddressRequirement?: BillingAddressRequirement;
96
+ /**
97
+ * Seed account holder name and billing address. Provided keys
98
+ * overwrite matching fields, including ones the customer already
99
+ * edited.
100
+ */
101
+ defaultValues?: PaymentMethodFormDefaultValues;
79
102
  /**
80
103
  * When true, hide the routing/account iframe and mount Plaid Embedded
81
104
  * Institution Search in the parent. Ignored when `intent` is `"setup"`
@@ -94,7 +117,7 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
94
117
  */
95
118
  intent?: "payment" | "setup";
96
119
  };
97
- export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, billingAddressRequirement, requireAchVerification, intent, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import("react").JSX.Element;
120
+ export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onValidityChange, billingAddressRequirement, defaultValues, requireAchVerification, intent, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import("react").JSX.Element;
98
121
  type AmosGooglePayButtonProps = {
99
122
  ref?: ForwardedIframeRef;
100
123
  renderToken: string;
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){return e?e.current??null:null}function i({iframeRef:t}){return(0,e.validateForm)({iframe:r(t)})}function a({iframeRef:t,token:n}){return(0,e.confirmPayment)({iframe:r(t),token:n})}function o({iframeRef:t,token:n}){return(0,e.confirmSetup)({iframe:r(t),token:n})}function s({iframeRef:t}){(0,e.resetForm)({iframe:r(t)})}function c(e,t){typeof e==`function`?e(t):e&&(e.current=t)}function l(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 u({containerRef:e,iframeRef:n,mount:r,options:i,remountDeps:a,iframePassthrough:o,updateDeps:s}){let u=(0,t.useRef)(null);(0,t.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let a=r(t,i);return u.current=a,c(n,a.iframe),l(a.iframe,o),()=>{a.destroy(),u.current=null,c(n,null)}},[...a]),(0,t.useEffect)(()=>{u.current?.update(i)},[...s]),(0,t.useEffect)(()=>{let e=u.current?.iframe;e&&l(e,o)})}var d=`oklch(0.97 0 0)`;function f({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:d,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 p({ref:r,renderToken:i,appearance:a,onValidityChange:o,onCardBrandChanged:s,additionalFields:c={cardholderName:!1},billingAddressRequirement:l=`country`,style:d,...f}){let p=(0,t.useRef)(null);return u({containerRef:p,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:c,billingAddressRequirement:l,onValidityChange:o,onCardBrandChanged:s},remountDeps:[i,c.cardholderName,l],iframePassthrough:{style:d,...f},updateDeps:[a,c,l,o,s]}),(0,n.jsx)(`div`,{ref:p})}function m({ref:r,renderToken:i,appearance:a,onValidityChange:o,billingAddressRequirement:s=`country`,requireAchVerification:c=!1,intent:l=`payment`,style:d,...f}){let p=(0,t.useRef)(null);return u({containerRef:p,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:s,requireAchVerification:c,intent:l,onValidityChange:o},remountDeps:[i,s,l],iframePassthrough:{style:d,...f},updateDeps:[a,s,c,l,o]}),(0,n.jsx)(`div`,{ref:p})}function h({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,iframeProps:l,onConfirm:d}){let p=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:l?.style,buttonProps:c});return u({containerRef:p,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,onConfirm:d},remountDeps:[i],iframePassthrough:l??{},updateDeps:[a,o,s,c,d]}),(0,n.jsx)(f,{height:s,borderRadius:m,containerRef:p})}function g({ref:r,renderToken:i,amount:a,merchantName:o,height:s=`48px`,buttonProps:c,iframeProps:l,onConfirm:d}){let p=(0,t.useRef)(null),m=(0,e.resolveWalletButtonSkeletonBorderRadius)({iframeStyle:l?.style,buttonProps:c});return u({containerRef:p,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,height:s,buttonProps:c,onConfirm:d},remountDeps:[i],iframePassthrough:l??{},updateDeps:[a,o,s,c,d]}),(0,n.jsx)(f,{height:s,borderRadius:m,containerRef:p})}exports.AmosApplePayButton=g,exports.AmosBankAccountPaymentMethodForm=m,exports.AmosCreditCardPaymentMethodForm=p,exports.AmosGooglePayButton=h,exports.confirmPayment=a,exports.confirmSetup=o,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){return e?e.current??null: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)(()=>{c.current?.update(i)},[...s]),(0,t.useEffect)(()=>{let e=c.current?.iframe;e&&u(e,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,additionalFields:c={cardholderName:!1},billingAddressRequirement:l=`country`,defaultValues:u,style:f,...p}){let m=(0,t.useRef)(null);return d({containerRef:m,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:c,billingAddressRequirement:l,defaultValues:u,onValidityChange:o,onCardBrandChanged:s},remountDeps:[i,c.cardholderName,l],iframePassthrough:{style:f,...p},updateDeps:[a,c,l,u,o,s]}),(0,n.jsx)(`div`,{ref:m})}function h({ref:r,renderToken:i,appearance:a,onValidityChange:o,billingAddressRequirement:s=`country`,defaultValues:c,requireAchVerification:l=!1,intent:u=`payment`,style:f,...p}){let m=(0,t.useRef)(null);return d({containerRef:m,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:s,defaultValues:c,requireAchVerification:l,intent:u,onValidityChange:o},remountDeps:[i,s,u],iframePassthrough:{style:f,...p},updateDeps:[a,s,c,l,u,o]}),(0,n.jsx)(`div`,{ref:m})}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?.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??{},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?.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??{},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]}})});
package/dist/index.mjs CHANGED
@@ -1,57 +1,65 @@
1
- import { confirmPayment as e, confirmSetup as t, ensureSkeletonStyles as n, mountAmosApplePayButton as r, mountAmosBankAccountPaymentMethodForm as i, mountAmosCreditCardPaymentMethodForm as a, mountAmosGooglePayButton as o, resetForm as s, resolveWalletButtonSkeletonBorderRadius as c, validateForm as l } from "@amos.com/amos-js";
2
- import { useEffect as u, useLayoutEffect as d, useRef as f } from "react";
3
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
1
+ import { confirmPayment as e, confirmSetup as t, ensureSkeletonStyles as n, focusField as r, mountAmosApplePayButton as i, mountAmosBankAccountPaymentMethodForm as a, mountAmosCreditCardPaymentMethodForm as o, mountAmosGooglePayButton as s, resetForm as c, resolveWalletButtonSkeletonBorderRadius as l, validateForm as u } from "@amos.com/amos-js";
2
+ import { useEffect as d, useLayoutEffect as f, useRef as p } from "react";
3
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
4
4
  export * from "@amos.com/amos-js";
5
5
  //#region src/index.tsx
6
- function h(e) {
6
+ function g(e) {
7
7
  return e ? e.current ?? null : null;
8
8
  }
9
- function g({ iframeRef: e }) {
10
- return l({ iframe: h(e) });
9
+ function _({ iframeRef: e }) {
10
+ return u({ iframe: g(e) });
11
11
  }
12
- function _({ iframeRef: t, token: n }) {
12
+ function v({ iframeRef: t, token: n, defaultValues: r }) {
13
13
  return e({
14
- iframe: h(t),
15
- token: n
14
+ iframe: g(t),
15
+ token: n,
16
+ defaultValues: r
16
17
  });
17
18
  }
18
- function v({ iframeRef: e, token: n }) {
19
+ function y({ iframeRef: e, token: n, defaultValues: r }) {
19
20
  return t({
20
- iframe: h(e),
21
- token: n
21
+ iframe: g(e),
22
+ token: n,
23
+ defaultValues: r
22
24
  });
23
25
  }
24
- function y({ iframeRef: e }) {
25
- s({ iframe: h(e) });
26
+ function b({ iframeRef: e }) {
27
+ c({ iframe: g(e) });
26
28
  }
27
- function b(e, t) {
29
+ function x({ iframeRef: e, field: t }) {
30
+ r({
31
+ iframe: g(e),
32
+ field: t
33
+ });
34
+ }
35
+ function S(e, t) {
28
36
  typeof e == "function" ? e(t) : e && (e.current = t);
29
37
  }
30
- function x(e, { style: t, className: n, id: r, ...i }) {
38
+ function C(e, { style: t, className: n, id: r, ...i }) {
31
39
  n != null && (e.className = n), r != null && (e.id = r), Object.assign(e.style, t);
32
40
  for (let [t, n] of Object.entries(i)) n != null && (t in e ? Reflect.set(e, t, n) : e.setAttribute(t, String(n)));
33
41
  }
34
- function S({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i, iframePassthrough: a, updateDeps: o }) {
35
- let s = f(null);
36
- d(() => {
42
+ function w({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i, iframePassthrough: a, updateDeps: o }) {
43
+ let s = p(null);
44
+ f(() => {
37
45
  let i = e.current;
38
46
  if (!i) return;
39
47
  let o = n(i, r);
40
- return s.current = o, b(t, o.iframe), x(o.iframe, a), () => {
41
- o.destroy(), s.current = null, b(t, null);
48
+ return s.current = o, S(t, o.iframe), C(o.iframe, a), () => {
49
+ o.destroy(), s.current = null, S(t, null);
42
50
  };
43
- }, [...i]), u(() => {
51
+ }, [...i]), d(() => {
44
52
  s.current?.update(r);
45
- }, [...o]), u(() => {
53
+ }, [...o]), d(() => {
46
54
  let e = s.current?.iframe;
47
- e && x(e, a);
55
+ e && C(e, a);
48
56
  });
49
57
  }
50
- var C = "oklch(0.97 0 0)";
51
- function w({ height: e, borderRadius: t, containerRef: r }) {
52
- return d(() => {
58
+ var T = "oklch(0.97 0 0)";
59
+ function E({ height: e, borderRadius: t, containerRef: r }) {
60
+ return f(() => {
53
61
  n();
54
- }, []), /* @__PURE__ */ m("div", {
62
+ }, []), /* @__PURE__ */ h("div", {
55
63
  style: {
56
64
  boxSizing: "border-box",
57
65
  position: "relative",
@@ -60,19 +68,19 @@ function w({ height: e, borderRadius: t, containerRef: r }) {
60
68
  minHeight: e,
61
69
  overflow: "hidden"
62
70
  },
63
- children: [/* @__PURE__ */ p("div", {
71
+ children: [/* @__PURE__ */ m("div", {
64
72
  className: "amos-js-form-skeleton-input amos-js-wallet-skeleton",
65
73
  style: {
66
74
  position: "absolute",
67
75
  inset: 0,
68
76
  height: e,
69
77
  borderRadius: t,
70
- background: C,
78
+ background: T,
71
79
  pointerEvents: "none",
72
80
  zIndex: 0
73
81
  },
74
82
  "aria-hidden": !0
75
- }), /* @__PURE__ */ p("div", {
83
+ }), /* @__PURE__ */ m("div", {
76
84
  ref: r,
77
85
  style: {
78
86
  position: "absolute",
@@ -84,133 +92,137 @@ function w({ height: e, borderRadius: t, containerRef: r }) {
84
92
  })]
85
93
  });
86
94
  }
87
- function T({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onCardBrandChanged: i, additionalFields: o = { cardholderName: !1 }, billingAddressRequirement: s = "country", style: c, ...l }) {
88
- let u = f(null);
89
- return S({
90
- containerRef: u,
95
+ function D({ ref: e, renderToken: t, appearance: n, onValidityChange: r, onCardBrandChanged: i, additionalFields: a = { cardholderName: !1 }, billingAddressRequirement: s = "country", defaultValues: c, style: l, ...u }) {
96
+ let d = p(null);
97
+ return w({
98
+ containerRef: d,
91
99
  iframeRef: e,
92
- mount: a,
100
+ mount: o,
93
101
  options: {
94
102
  renderToken: t,
95
103
  appearance: n,
96
- additionalFields: o,
104
+ additionalFields: a,
97
105
  billingAddressRequirement: s,
106
+ defaultValues: c,
98
107
  onValidityChange: r,
99
108
  onCardBrandChanged: i
100
109
  },
101
110
  remountDeps: [
102
111
  t,
103
- o.cardholderName,
112
+ a.cardholderName,
104
113
  s
105
114
  ],
106
115
  iframePassthrough: {
107
- style: c,
108
- ...l
116
+ style: l,
117
+ ...u
109
118
  },
110
119
  updateDeps: [
111
120
  n,
112
- o,
121
+ a,
113
122
  s,
123
+ c,
114
124
  r,
115
125
  i
116
126
  ]
117
- }), /* @__PURE__ */ p("div", { ref: u });
127
+ }), /* @__PURE__ */ m("div", { ref: d });
118
128
  }
119
- function E({ ref: e, renderToken: t, appearance: n, onValidityChange: r, billingAddressRequirement: a = "country", requireAchVerification: o = !1, intent: s = "payment", style: c, ...l }) {
120
- let u = f(null);
121
- return S({
122
- containerRef: u,
129
+ function O({ ref: e, renderToken: t, appearance: n, onValidityChange: r, billingAddressRequirement: i = "country", defaultValues: o, requireAchVerification: s = !1, intent: c = "payment", style: l, ...u }) {
130
+ let d = p(null);
131
+ return w({
132
+ containerRef: d,
123
133
  iframeRef: e,
124
- mount: i,
134
+ mount: a,
125
135
  options: {
126
136
  renderToken: t,
127
137
  appearance: n,
128
- billingAddressRequirement: a,
129
- requireAchVerification: o,
130
- intent: s,
138
+ billingAddressRequirement: i,
139
+ defaultValues: o,
140
+ requireAchVerification: s,
141
+ intent: c,
131
142
  onValidityChange: r
132
143
  },
133
144
  remountDeps: [
134
145
  t,
135
- a,
136
- s
146
+ i,
147
+ c
137
148
  ],
138
149
  iframePassthrough: {
139
- style: c,
140
- ...l
150
+ style: l,
151
+ ...u
141
152
  },
142
153
  updateDeps: [
143
154
  n,
144
- a,
155
+ i,
145
156
  o,
146
157
  s,
158
+ c,
147
159
  r
148
160
  ]
149
- }), /* @__PURE__ */ p("div", { ref: u });
161
+ }), /* @__PURE__ */ m("div", { ref: d });
150
162
  }
151
- function D({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48px", buttonProps: a, iframeProps: s, onConfirm: l }) {
152
- let u = f(null), d = c({
153
- iframeStyle: s?.style,
163
+ function k({ ref: e, renderToken: t, amount: n, merchantName: r, height: i = "48px", buttonProps: a, iframeProps: o, onConfirm: c }) {
164
+ let u = p(null), d = l({
165
+ iframeStyle: o?.style,
154
166
  buttonProps: a
155
167
  });
156
- return S({
168
+ return w({
157
169
  containerRef: u,
158
170
  iframeRef: e,
159
- mount: o,
171
+ mount: s,
160
172
  options: {
161
173
  renderToken: t,
162
174
  amount: n,
163
175
  merchantName: r,
164
176
  height: i,
165
177
  buttonProps: a,
166
- onConfirm: l
178
+ onConfirm: c
167
179
  },
168
180
  remountDeps: [t],
169
- iframePassthrough: s ?? {},
181
+ iframePassthrough: o ?? {},
170
182
  updateDeps: [
171
183
  n,
172
184
  r,
173
185
  i,
174
186
  a,
175
- l
187
+ c
176
188
  ]
177
- }), /* @__PURE__ */ p(w, {
189
+ }), /* @__PURE__ */ m(E, {
178
190
  height: i,
179
191
  borderRadius: d,
180
192
  containerRef: u
181
193
  });
182
194
  }
183
- function O({ ref: e, renderToken: t, amount: n, merchantName: i, height: a = "48px", buttonProps: o, iframeProps: s, onConfirm: l }) {
184
- let u = f(null), d = c({
195
+ function A({ ref: e, renderToken: t, amount: n, merchantName: r, height: a = "48px", buttonProps: o, iframeProps: s, onConfirm: c }) {
196
+ let u = p(null), d = l({
185
197
  iframeStyle: s?.style,
186
198
  buttonProps: o
187
199
  });
188
- return S({
200
+ return w({
189
201
  containerRef: u,
190
202
  iframeRef: e,
191
- mount: r,
203
+ mount: i,
192
204
  options: {
193
205
  renderToken: t,
194
206
  amount: n,
195
- merchantName: i,
207
+ merchantName: r,
196
208
  height: a,
197
209
  buttonProps: o,
198
- onConfirm: l
210
+ onConfirm: c
199
211
  },
200
212
  remountDeps: [t],
201
213
  iframePassthrough: s ?? {},
202
214
  updateDeps: [
203
215
  n,
204
- i,
216
+ r,
205
217
  a,
206
218
  o,
207
- l
219
+ c
208
220
  ]
209
- }), /* @__PURE__ */ p(w, {
221
+ }), /* @__PURE__ */ m(E, {
210
222
  height: a,
211
223
  borderRadius: d,
212
224
  containerRef: u
213
225
  });
214
226
  }
215
227
  //#endregion
216
- export { O as AmosApplePayButton, E as AmosBankAccountPaymentMethodForm, T as AmosCreditCardPaymentMethodForm, D as AmosGooglePayButton, _ as confirmPayment, v as confirmSetup, y as resetForm, g as validateForm };
228
+ export { A as AmosApplePayButton, O as AmosBankAccountPaymentMethodForm, D as AmosCreditCardPaymentMethodForm, k as AmosGooglePayButton, v as confirmPayment, y as confirmSetup, x as focusField, b as resetForm, _ as validateForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/react-amos-js",
3
- "version": "0.11.4",
3
+ "version": "0.11.5",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,7 +48,7 @@
48
48
  "vite-plugin-dts": "5.0.3"
49
49
  },
50
50
  "dependencies": {
51
- "@amos.com/amos-js": "0.11.5",
51
+ "@amos.com/amos-js": "0.11.6",
52
52
  "@types/googlepay": "0.7.12"
53
53
  },
54
54
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type ApplePayButtonElementProps,
6
6
  confirmPayment as amosConfirmPayment,
7
7
  confirmSetup as amosConfirmSetup,
8
+ focusField as amosFocusField,
8
9
  resetForm as amosResetForm,
9
10
  validateForm as amosValidateForm,
10
11
  type BillingAddressRequirement,
@@ -17,6 +18,8 @@ import {
17
18
  mountAmosBankAccountPaymentMethodForm,
18
19
  mountAmosCreditCardPaymentMethodForm,
19
20
  mountAmosGooglePayButton,
21
+ type PaymentMethodFormDefaultValues,
22
+ type PaymentMethodFormField,
20
23
  resolveWalletButtonSkeletonBorderRadius,
21
24
  } from "@amos.com/amos-js";
22
25
  import type { components } from "@amos.com/node";
@@ -64,13 +67,19 @@ export function validateForm({
64
67
  export function confirmPayment({
65
68
  iframeRef,
66
69
  token,
70
+ defaultValues,
67
71
  }: {
68
72
  iframeRef: IframeRef;
73
+ defaultValues?: PaymentMethodFormDefaultValues;
69
74
  } & Pick<
70
75
  components["schemas"]["EmbedToken"],
71
76
  "token"
72
77
  >): Promise<ConfirmPaymentResult> {
73
- return amosConfirmPayment({ iframe: resolveIframe(iframeRef), token });
78
+ return amosConfirmPayment({
79
+ iframe: resolveIframe(iframeRef),
80
+ token,
81
+ defaultValues,
82
+ });
74
83
  }
75
84
 
76
85
  /**
@@ -83,13 +92,19 @@ export function confirmPayment({
83
92
  export function confirmSetup({
84
93
  iframeRef,
85
94
  token,
95
+ defaultValues,
86
96
  }: {
87
97
  iframeRef: IframeRef;
98
+ defaultValues?: PaymentMethodFormDefaultValues;
88
99
  } & Pick<
89
100
  components["schemas"]["EmbedToken"],
90
101
  "token"
91
102
  >): Promise<ConfirmSetupResult> {
92
- return amosConfirmSetup({ iframe: resolveIframe(iframeRef), token });
103
+ return amosConfirmSetup({
104
+ iframe: resolveIframe(iframeRef),
105
+ token,
106
+ defaultValues,
107
+ });
93
108
  }
94
109
 
95
110
  /**
@@ -100,6 +115,21 @@ export function resetForm({ iframeRef }: { iframeRef: IframeRef }): void {
100
115
  amosResetForm({ iframe: resolveIframe(iframeRef) });
101
116
  }
102
117
 
118
+ /**
119
+ * Focus a named control inside the embedded card/bank iframe. No-op if
120
+ * the field is not rendered, or while Plaid Embedded Institution Search
121
+ * is showing. Call from a click or keydown handler.
122
+ */
123
+ export function focusField({
124
+ iframeRef,
125
+ field,
126
+ }: {
127
+ iframeRef: IframeRef;
128
+ field: PaymentMethodFormField;
129
+ }): void {
130
+ amosFocusField({ iframe: resolveIframe(iframeRef), field });
131
+ }
132
+
103
133
  type ForwardedIframeRef = Ref<HTMLIFrameElement> | undefined;
104
134
 
105
135
  function setForwardedRef(
@@ -276,6 +306,12 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
276
306
  }) => void;
277
307
  additionalFields?: CreditCardAdditionalFields;
278
308
  billingAddressRequirement?: BillingAddressRequirement;
309
+ /**
310
+ * Seed cardholder name and billing address. Provided keys overwrite
311
+ * matching fields, including ones the customer already edited. Values
312
+ * are sent on confirm even when those inputs are hidden.
313
+ */
314
+ defaultValues?: PaymentMethodFormDefaultValues;
279
315
  };
280
316
 
281
317
  export function AmosCreditCardPaymentMethodForm({
@@ -286,6 +322,7 @@ export function AmosCreditCardPaymentMethodForm({
286
322
  onCardBrandChanged,
287
323
  additionalFields = { cardholderName: false },
288
324
  billingAddressRequirement = "country",
325
+ defaultValues,
289
326
  style,
290
327
  ...rest
291
328
  }: AmosCreditCardPaymentMethodFormProps) {
@@ -300,6 +337,7 @@ export function AmosCreditCardPaymentMethodForm({
300
337
  appearance,
301
338
  additionalFields,
302
339
  billingAddressRequirement,
340
+ defaultValues,
303
341
  onValidityChange,
304
342
  onCardBrandChanged,
305
343
  },
@@ -313,6 +351,7 @@ export function AmosCreditCardPaymentMethodForm({
313
351
  appearance,
314
352
  additionalFields,
315
353
  billingAddressRequirement,
354
+ defaultValues,
316
355
  onValidityChange,
317
356
  onCardBrandChanged,
318
357
  ],
@@ -331,6 +370,12 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
331
370
  */
332
371
  onValidityChange?: (event: { isValid: boolean }) => void;
333
372
  billingAddressRequirement?: BillingAddressRequirement;
373
+ /**
374
+ * Seed account holder name and billing address. Provided keys
375
+ * overwrite matching fields, including ones the customer already
376
+ * edited.
377
+ */
378
+ defaultValues?: PaymentMethodFormDefaultValues;
334
379
  /**
335
380
  * When true, hide the routing/account iframe and mount Plaid Embedded
336
381
  * Institution Search in the parent. Ignored when `intent` is `"setup"`
@@ -356,6 +401,7 @@ export function AmosBankAccountPaymentMethodForm({
356
401
  appearance,
357
402
  onValidityChange,
358
403
  billingAddressRequirement = "country",
404
+ defaultValues,
359
405
  requireAchVerification = false,
360
406
  intent = "payment",
361
407
  style,
@@ -371,6 +417,7 @@ export function AmosBankAccountPaymentMethodForm({
371
417
  renderToken,
372
418
  appearance,
373
419
  billingAddressRequirement,
420
+ defaultValues,
374
421
  requireAchVerification,
375
422
  intent,
376
423
  onValidityChange,
@@ -380,6 +427,7 @@ export function AmosBankAccountPaymentMethodForm({
380
427
  updateDeps: [
381
428
  appearance,
382
429
  billingAddressRequirement,
430
+ defaultValues,
383
431
  requireAchVerification,
384
432
  intent,
385
433
  onValidityChange,