@amos.com/react-amos-js 0.9.9 → 0.9.10

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
@@ -172,6 +172,7 @@ import type { components } from "@amos.com/node";
172
172
 
173
173
  function CheckoutForm() {
174
174
  const iframeRef = useRef<HTMLIFrameElement>(null);
175
+ const [isValid, setIsValid] = useState(false);
175
176
  const [isProcessing, setIsProcessing] = useState(false);
176
177
  const [error, setError] = useState<string | null>(null);
177
178
 
@@ -222,6 +223,7 @@ function CheckoutForm() {
222
223
  ref={iframeRef}
223
224
  renderToken="the-render-token-that-you-created-on-dashboard.amos.com"
224
225
  additionalFields={{ cardholderName: true }}
226
+ onValidityChange={({ isValid }) => setIsValid(isValid)}
225
227
  onResult={(result) => {
226
228
  // Unlock UI. Verify settlement on your backend via webhooks.
227
229
  if (result.status === "succeeded") {
@@ -234,7 +236,7 @@ function CheckoutForm() {
234
236
  }}
235
237
  />
236
238
  {error ? <p>{error}</p> : null}
237
- <button type="submit" disabled={isProcessing}>
239
+ <button type="submit" disabled={!isValid || isProcessing}>
238
240
  {isProcessing ? "Processing..." : "Pay Now"}
239
241
  </button>
240
242
  </form>
@@ -428,6 +430,7 @@ Renders the secure credit card iframe form.
428
430
 
429
431
  - `additionalFields` (`{ cardholderName: boolean }`) — set `additionalFields={{ cardholderName: true }}` to render the cardholder name field in the iframe (`false` by default)
430
432
  - `billingAddressRequirement` (`"country" | "full"`, defaults to `"country"`) — how much billing address the iframe collects. `country` collects country / region and, for CA / PR / GB / US, a postal code (labeled ZIP for the United States). `full` shows a full street address form with Smarty autocomplete.
433
+ - `onValidityChange` (`(event: { isValid: boolean }) => void`) — called when form validity changes. `isValid` is true when all required fields are present and valid. Does not include PCI data. Use this to enable or disable your checkout button.
431
434
 
432
435
  **Also accepts:** standard iframe props (`React.ComponentProps<"iframe">`), minus `src`, `title`, `name`, and `role` (which are controlled by the SDK).
433
436
 
@@ -437,7 +440,7 @@ Renders the secure bank account iframe form.
437
440
 
438
441
  **Required props:** same as `AmosCreditCardPaymentMethodForm` — `renderToken`, `onResult`.
439
442
 
440
- **Optional props:** same as `AmosCreditCardPaymentMethodForm` — `appearance`, `billingAddressRequirement`.
443
+ **Optional props:** same as `AmosCreditCardPaymentMethodForm` — `appearance`, `billingAddressRequirement`, `onValidityChange`.
441
444
 
442
445
  **Also accepts:** standard iframe props.
443
446
 
@@ -510,7 +513,7 @@ Re-exports of the same advanced helpers exposed by `@amos.com/amos-js`. Most int
510
513
 
511
514
  ### Exported types
512
515
 
513
- `@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `ConfirmationResult`, `ConfirmationIncompleteReason`, `FormattedGooglePayPaymentData`, `Message`, `Appearance`, `ThemeVariable`, and the per-form `*Options` / `*Controller` types. For OpenAPI schema types (e.g. `PaymentIntent`, `CreatePaymentIntentInput`), import `components` from `@amos.com/node`.
516
+ `@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `ConfirmationResult`, `ConfirmationIncompleteReason`, `PaymentMethodFormValidityChangeEvent`, `FormattedGooglePayPaymentData`, `Message`, `Appearance`, `ThemeVariable`, and the per-form `*Options` / `*Controller` types. For OpenAPI schema types (e.g. `PaymentIntent`, `CreatePaymentIntentInput`), import `components` from `@amos.com/node`.
514
517
 
515
518
  ## Notes and potential gotchas
516
519
 
package/dist/index.d.ts CHANGED
@@ -45,17 +45,31 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
45
45
  renderToken: string;
46
46
  appearance?: Appearance;
47
47
  onResult: (result: ConfirmationResult) => void;
48
+ /**
49
+ * Called when form validity changes. `isValid` is true when all
50
+ * required fields are present and valid. Does not include PCI data.
51
+ */
52
+ onValidityChange?: (event: {
53
+ isValid: boolean;
54
+ }) => void;
48
55
  additionalFields?: CreditCardAdditionalFields;
49
56
  billingAddressRequirement?: BillingAddressRequirement;
50
57
  };
51
- export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onResult, additionalFields, billingAddressRequirement, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import("react").JSX.Element;
58
+ export declare function AmosCreditCardPaymentMethodForm({ ref, renderToken, appearance, onResult, onValidityChange, additionalFields, billingAddressRequirement, style, ...rest }: AmosCreditCardPaymentMethodFormProps): import("react").JSX.Element;
52
59
  type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
53
60
  renderToken: string;
54
61
  appearance?: Appearance;
55
62
  onResult: (result: ConfirmationResult) => void;
63
+ /**
64
+ * Called when form validity changes. `isValid` is true when all
65
+ * required fields are present and valid. Does not include PCI data.
66
+ */
67
+ onValidityChange?: (event: {
68
+ isValid: boolean;
69
+ }) => void;
56
70
  billingAddressRequirement?: BillingAddressRequirement;
57
71
  };
58
- export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onResult, billingAddressRequirement, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import("react").JSX.Element;
72
+ export declare function AmosBankAccountPaymentMethodForm({ ref, renderToken, appearance, onResult, onValidityChange, billingAddressRequirement, style, ...rest }: AmosBankAccountPaymentMethodFormProps): import("react").JSX.Element;
59
73
  type AmosGooglePayButtonProps = Omit<IframePassthroughProps, "style"> & GooglePayButtonElementProps & {
60
74
  renderToken: string;
61
75
  amount: 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}){(0,e.confirmPaymentIntent)({iframe:r(t),token:n})}function o({iframeRef:t,token:n}){(0,e.confirmSetupIntent)({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),t!=null&&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.useEffect)(()=>{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)})}function d({ref:r,renderToken:i,appearance:a,onResult:o,additionalFields:s={cardholderName:!1},billingAddressRequirement:c=`country`,style:l,...d}){let f=(0,t.useRef)(null);return u({containerRef:f,iframeRef:r,mount:e.mountAmosCreditCardPaymentMethodForm,options:{renderToken:i,appearance:a,additionalFields:s,billingAddressRequirement:c,onResult:o},remountDeps:[i,s.cardholderName,c],iframePassthrough:{style:l,...d},updateDeps:[a,s,c,o]}),(0,n.jsx)(`div`,{ref:f})}function f({ref:r,renderToken:i,appearance:a,onResult:o,billingAddressRequirement:s=`country`,style:c,...l}){let d=(0,t.useRef)(null);return u({containerRef:d,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:s,onResult:o},remountDeps:[i,s],iframePassthrough:{style:c,...l},updateDeps:[a,s,o]}),(0,n.jsx)(`div`,{ref:d})}function p({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonType:d,buttonColor:f,buttonRadius:p,buttonSizeMode:m,buttonLocale:h,buttonBorderType:g,style:_,...v}){let y=(0,t.useRef)(null);return u({containerRef:y,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonType:d,buttonColor:f,buttonRadius:p,buttonSizeMode:m,buttonLocale:h,buttonBorderType:g,style:_},remountDeps:[i],iframePassthrough:{...v},updateDeps:[a,o,s,c,l,d,f,p,m,h,g,_]}),(0,n.jsx)(`div`,{ref:y})}function m({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:f,locale:p,style:m,...h}){let g=(0,t.useRef)(null);return u({containerRef:g,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:f,locale:p,style:m},remountDeps:[i],iframePassthrough:{...h},updateDeps:[a,o,s,c,l,d,f,p,m]}),(0,n.jsx)(`div`,{ref:g})}exports.AmosApplePayButton=m,exports.AmosBankAccountPaymentMethodForm=f,exports.AmosCreditCardPaymentMethodForm=d,exports.AmosGooglePayButton=p,exports.confirmPaymentIntent=a,exports.confirmSetupIntent=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}){(0,e.confirmPaymentIntent)({iframe:r(t),token:n})}function o({iframeRef:t,token:n}){(0,e.confirmSetupIntent)({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),t!=null&&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.useEffect)(()=>{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)})}function d({ref:r,renderToken:i,appearance:a,onResult:o,onValidityChange: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,onResult:o,onValidityChange:s},remountDeps:[i,c.cardholderName,l],iframePassthrough:{style:d,...f},updateDeps:[a,c,l,o,s]}),(0,n.jsx)(`div`,{ref:p})}function f({ref:r,renderToken:i,appearance:a,onResult:o,onValidityChange:s,billingAddressRequirement:c=`country`,style:l,...d}){let f=(0,t.useRef)(null);return u({containerRef:f,iframeRef:r,mount:e.mountAmosBankAccountPaymentMethodForm,options:{renderToken:i,appearance:a,billingAddressRequirement:c,onResult:o,onValidityChange:s},remountDeps:[i,c],iframePassthrough:{style:l,...d},updateDeps:[a,c,o,s]}),(0,n.jsx)(`div`,{ref:f})}function p({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonType:d,buttonColor:f,buttonRadius:p,buttonSizeMode:m,buttonLocale:h,buttonBorderType:g,style:_,...v}){let y=(0,t.useRef)(null);return u({containerRef:y,iframeRef:r,mount:e.mountAmosGooglePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonType:d,buttonColor:f,buttonRadius:p,buttonSizeMode:m,buttonLocale:h,buttonBorderType:g,style:_},remountDeps:[i],iframePassthrough:{...v},updateDeps:[a,o,s,c,l,d,f,p,m,h,g,_]}),(0,n.jsx)(`div`,{ref:y})}function m({ref:r,renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:f,locale:p,style:m,...h}){let g=(0,t.useRef)(null);return u({containerRef:g,iframeRef:r,mount:e.mountAmosApplePayButton,options:{renderToken:i,amount:a,merchantName:o,appearance:s,onInitiatePaymentIntentRequest:c,onResult:l,buttonstyle:d,type:f,locale:p,style:m},remountDeps:[i],iframePassthrough:{...h},updateDeps:[a,o,s,c,l,d,f,p,m]}),(0,n.jsx)(`div`,{ref:g})}exports.AmosApplePayButton=m,exports.AmosBankAccountPaymentMethodForm=f,exports.AmosCreditCardPaymentMethodForm=d,exports.AmosGooglePayButton=p,exports.confirmPaymentIntent=a,exports.confirmSetupIntent=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]}})});
package/dist/index.mjs CHANGED
@@ -47,59 +47,63 @@ function v({ containerRef: e, iframeRef: t, mount: n, options: r, remountDeps: i
47
47
  e && _(e, a);
48
48
  });
49
49
  }
50
- function y({ ref: e, renderToken: t, appearance: n, onResult: r, additionalFields: a = { cardholderName: !1 }, billingAddressRequirement: o = "country", style: s, ...c }) {
51
- let d = l(null);
50
+ function y({ ref: e, renderToken: t, appearance: n, onResult: r, onValidityChange: a, additionalFields: o = { cardholderName: !1 }, billingAddressRequirement: s = "country", style: c, ...d }) {
51
+ let f = l(null);
52
52
  return v({
53
- containerRef: d,
53
+ containerRef: f,
54
54
  iframeRef: e,
55
55
  mount: i,
56
56
  options: {
57
57
  renderToken: t,
58
58
  appearance: n,
59
- additionalFields: a,
60
- billingAddressRequirement: o,
61
- onResult: r
59
+ additionalFields: o,
60
+ billingAddressRequirement: s,
61
+ onResult: r,
62
+ onValidityChange: a
62
63
  },
63
64
  remountDeps: [
64
65
  t,
65
- a.cardholderName,
66
- o
66
+ o.cardholderName,
67
+ s
67
68
  ],
68
69
  iframePassthrough: {
69
- style: s,
70
- ...c
70
+ style: c,
71
+ ...d
71
72
  },
72
73
  updateDeps: [
73
74
  n,
74
- a,
75
75
  o,
76
- r
76
+ s,
77
+ r,
78
+ a
77
79
  ]
78
- }), /* @__PURE__ */ u("div", { ref: d });
80
+ }), /* @__PURE__ */ u("div", { ref: f });
79
81
  }
80
- function b({ ref: e, renderToken: t, appearance: n, onResult: i, billingAddressRequirement: a = "country", style: o, ...s }) {
81
- let c = l(null);
82
+ function b({ ref: e, renderToken: t, appearance: n, onResult: i, onValidityChange: a, billingAddressRequirement: o = "country", style: s, ...c }) {
83
+ let d = l(null);
82
84
  return v({
83
- containerRef: c,
85
+ containerRef: d,
84
86
  iframeRef: e,
85
87
  mount: r,
86
88
  options: {
87
89
  renderToken: t,
88
90
  appearance: n,
89
- billingAddressRequirement: a,
90
- onResult: i
91
+ billingAddressRequirement: o,
92
+ onResult: i,
93
+ onValidityChange: a
91
94
  },
92
- remountDeps: [t, a],
95
+ remountDeps: [t, o],
93
96
  iframePassthrough: {
94
- style: o,
95
- ...s
97
+ style: s,
98
+ ...c
96
99
  },
97
100
  updateDeps: [
98
101
  n,
99
- a,
100
- i
102
+ o,
103
+ i,
104
+ a
101
105
  ]
102
- }), /* @__PURE__ */ u("div", { ref: c });
106
+ }), /* @__PURE__ */ u("div", { ref: d });
103
107
  }
104
108
  function x({ ref: e, renderToken: t, amount: n, merchantName: r, appearance: i, onInitiatePaymentIntentRequest: o, onResult: s, buttonType: c, buttonColor: d, buttonRadius: f, buttonSizeMode: p, buttonLocale: m, buttonBorderType: h, style: g, ..._ }) {
105
109
  let y = l(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/react-amos-js",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
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.9.10",
51
+ "@amos.com/amos-js": "0.9.11",
52
52
  "@types/googlepay": "0.7.11"
53
53
  },
54
54
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -194,6 +194,11 @@ type AmosCreditCardPaymentMethodFormProps = IframePassthroughProps & {
194
194
  renderToken: string;
195
195
  appearance?: Appearance;
196
196
  onResult: (result: ConfirmationResult) => void;
197
+ /**
198
+ * Called when form validity changes. `isValid` is true when all
199
+ * required fields are present and valid. Does not include PCI data.
200
+ */
201
+ onValidityChange?: (event: { isValid: boolean }) => void;
197
202
  additionalFields?: CreditCardAdditionalFields;
198
203
  billingAddressRequirement?: BillingAddressRequirement;
199
204
  };
@@ -203,6 +208,7 @@ export function AmosCreditCardPaymentMethodForm({
203
208
  renderToken,
204
209
  appearance,
205
210
  onResult,
211
+ onValidityChange,
206
212
  additionalFields = { cardholderName: false },
207
213
  billingAddressRequirement = "country",
208
214
  style,
@@ -220,6 +226,7 @@ export function AmosCreditCardPaymentMethodForm({
220
226
  additionalFields,
221
227
  billingAddressRequirement,
222
228
  onResult,
229
+ onValidityChange,
223
230
  },
224
231
  remountDeps: [
225
232
  renderToken,
@@ -232,6 +239,7 @@ export function AmosCreditCardPaymentMethodForm({
232
239
  additionalFields,
233
240
  billingAddressRequirement,
234
241
  onResult,
242
+ onValidityChange,
235
243
  ],
236
244
  });
237
245
 
@@ -242,6 +250,11 @@ type AmosBankAccountPaymentMethodFormProps = IframePassthroughProps & {
242
250
  renderToken: string;
243
251
  appearance?: Appearance;
244
252
  onResult: (result: ConfirmationResult) => void;
253
+ /**
254
+ * Called when form validity changes. `isValid` is true when all
255
+ * required fields are present and valid. Does not include PCI data.
256
+ */
257
+ onValidityChange?: (event: { isValid: boolean }) => void;
245
258
  billingAddressRequirement?: BillingAddressRequirement;
246
259
  };
247
260
 
@@ -250,6 +263,7 @@ export function AmosBankAccountPaymentMethodForm({
250
263
  renderToken,
251
264
  appearance,
252
265
  onResult,
266
+ onValidityChange,
253
267
  billingAddressRequirement = "country",
254
268
  style,
255
269
  ...rest
@@ -265,10 +279,16 @@ export function AmosBankAccountPaymentMethodForm({
265
279
  appearance,
266
280
  billingAddressRequirement,
267
281
  onResult,
282
+ onValidityChange,
268
283
  },
269
284
  remountDeps: [renderToken, billingAddressRequirement],
270
285
  iframePassthrough: { style, ...rest },
271
- updateDeps: [appearance, billingAddressRequirement, onResult],
286
+ updateDeps: [
287
+ appearance,
288
+ billingAddressRequirement,
289
+ onResult,
290
+ onValidityChange,
291
+ ],
272
292
  });
273
293
 
274
294
  return <div ref={containerRef} />;