@amos.com/react-amos-js 0.11.14 → 0.11.15

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
@@ -43,8 +43,8 @@ The following flow is for credit card and bank account payment method types only
43
43
  3. **User clicks "Pay now" or presses Enter in the iframe**: call `validateForm({ iframeRef })`, which returns `Promise<true>` if the embedded form is valid and `Promise<false>` otherwise.
44
44
  4. **Create payment intent on your server**: use your server-side Amos client to call `POST /payment_intents`. You may also associate this payment intent with a new or existing customer via `POST /customers`. This must be server-side because it uses your private API key.
45
45
  5. **Return the payment intent token to the browser**: your backend responds with the embed token (`components["schemas"]["EmbedToken"]`) needed for confirmation.
46
- 6. **Confirm the payment intent from the client**: `await confirmPayment({ iframeRef, token })`. It resolves `{ status: "succeeded", paymentIntent }` or `{ status: "failed", paymentIntent? }`.
47
- 7. **Handle UX**: show the user a "processing" state while awaiting `confirmPayment`. Do not treat `{ status: "succeeded" }` as settlement proof — verify payment success on your backend via webhooks. Recoverable field errors stay in the iframe; `confirmPayment` still resolves `{ status: "failed" }` (with `paymentIntent` when the confirm API returned a body, including `last_payment_error` on declines).
46
+ 6. **Confirm the payment intent from the client**: `await confirmPayment({ iframeRef, token })`. It resolves `{ status: "succeeded", paymentIntent }`, `{ status: "failed", paymentIntent? }` on decline, or `{ status: "failed", error: "timeout" }` if the iframe does not respond within 15 seconds (`isConfirmTimeout(result)`).
47
+ 7. **Handle UX**: show the user a "processing" state while awaiting `confirmPayment`. Do not treat `{ status: "succeeded" }` as settlement proof — verify payment success on your backend via webhooks. Recoverable field errors stay in the iframe; a processor decline still resolves `{ status: "failed" }` (with `paymentIntent` when the confirm API returned a body, including `last_payment_error`). A timeout is **not** a decline — the charge may still settle; do not retry as a new payment.
48
48
 
49
49
  ### Google Pay & Apple Pay
50
50
 
@@ -508,7 +508,7 @@ Validates the embedded card/bank iframe form before payment confirmation.
508
508
 
509
509
  ### `confirmPayment({ iframeRef, token, defaultValues? })`
510
510
 
511
- Confirms a payment intent in the embedded iframe flow. Resolves `{ status: "succeeded", paymentIntent }` or `{ status: "failed", paymentIntent? }`. Optional `defaultValues` are applied immediately before building the payment method (including hidden name and extra billing fields) and do not replace the last `defaultValues` prop used by `resetForm`.
511
+ Confirms a payment intent in the embedded iframe flow. Resolves `{ status: "succeeded", paymentIntent }`, `{ status: "failed", paymentIntent? }` on decline, or `{ status: "failed", error: "timeout" }` if the iframe does not respond within 15 seconds (`CONFIRM_TIMEOUT_MS`). Optional `defaultValues` are applied immediately before building the payment method (including hidden name and extra billing fields) and do not replace the last `defaultValues` prop used by `resetForm`.
512
512
 
513
513
  **Parameters:**
514
514
 
@@ -516,11 +516,11 @@ Confirms a payment intent in the embedded iframe flow. Resolves `{ status: "succ
516
516
  - `token` (typed as `Pick<components["schemas"]["EmbedToken"], "token">` — the embed JWT string returned by your server)
517
517
  - `defaultValues` (`PaymentMethodFormDefaultValues`, optional)
518
518
 
519
- **Returns:** `Promise<ConfirmPaymentResult>`
519
+ **Returns:** `Promise<ConfirmPaymentResult>` — use `isConfirmTimeout(result)` to treat a timeout as uncertain (do not retry). Embed aborts hung `/confirm` at 10s and posts the same timeout result; the SDK wait is strictly above that.
520
520
 
521
521
  ### `confirmSetup({ iframeRef, token, defaultValues? })`
522
522
 
523
- Confirms a setup intent in the embedded iframe flow. Use this when saving a payment method for future use. Optional `defaultValues` behave the same as on `confirmPayment`.
523
+ Confirms a setup intent in the embedded iframe flow. Use this when saving a payment method for future use. Optional `defaultValues` behave the same as on `confirmPayment`. Same 15-second timeout window and `isConfirmTimeout` rule as `confirmPayment`.
524
524
 
525
525
  **Parameters:**
526
526
 
@@ -695,7 +695,7 @@ Re-export from `@amos.com/amos-js`. Fills omitted Inter `fonts` / `--font-family
695
695
  ## Notes and potential gotchas
696
696
 
697
697
  - **`ref` / `iframeRef`**: for card and bank forms, pass `ref={iframeRef}` to the form component. The same `iframeRef` must be used when calling `validateForm`, `confirmPayment`, `confirmSetup`, `resetForm`, or `focusField`. The component forwards the ref to the inner iframe.
698
- - **`confirmPayment` / `confirmSetup` are not settlement proof**: `{ status: "succeeded" }` means authorization succeeded (capture may still finish asynchronously). Verify payment or setup success on your backend via webhooks. Recoverable field errors stay in the iframe; the Promise still resolves `{ status: "failed" }`. Declined confirms include the intent so you can read `last_payment_error` without a follow-up GET.
698
+ - **`confirmPayment` / `confirmSetup` are not settlement proof**: `{ status: "succeeded" }` means authorization succeeded (capture may still finish asynchronously). Verify payment or setup success on your backend via webhooks. Recoverable field errors stay in the iframe; a processor decline still resolves `{ status: "failed" }`. Declined confirms include the intent so you can read `last_payment_error` without a follow-up GET. If the iframe never answers, the Promise resolves `{ status: "failed", error: "timeout" }` after 15 seconds (`CONFIRM_TIMEOUT_MS`, `isConfirmTimeout`) — that is uncertain, not a decline; do not retry as a new payment.
699
699
  - **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`).
700
700
  - **Amount format**: for `AmosGooglePayButton` and `AmosApplePayButton`, `amount` is a major-currency decimal string (e.g. `"50.00"` for $50.00). For `components["schemas"]["CreatePaymentIntentInput"]` on the server (card/bank create, and the object the wallet iframe sends to `onConfirm`), `amount` is a number in cents (e.g. `5000`).
701
701
  - **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`.
package/dist/index.d.ts CHANGED
@@ -19,6 +19,14 @@ export declare function validateForm({ iframeRef, }: {
19
19
  *
20
20
  * Pass the embed JWT (`token`) returned by your server's
21
21
  * `POST /payment_intents` call.
22
+ *
23
+ * Resolves `{ status: "succeeded", paymentIntent }` after authorization,
24
+ * `{ status: "failed", paymentIntent? }` on decline, or
25
+ * `{ status: "failed", error: "timeout" }` if the iframe does not post
26
+ * `CONFIRMATION_RESULT` within 15 seconds (`CONFIRM_TIMEOUT_MS`). Use
27
+ * `isConfirmTimeout(result)` — a timeout is not a decline; the charge
28
+ * may still settle. Embed `/confirm` aborts at 10s and posts the same
29
+ * timeout result.
22
30
  */
23
31
  export declare function confirmPayment({ iframeRef, token, defaultValues, }: {
24
32
  iframeRef: IframeRef;
@@ -30,6 +38,12 @@ export declare function confirmPayment({ iframeRef, token, defaultValues, }: {
30
38
  *
31
39
  * Pass the embed JWT (`token`) returned by your server's
32
40
  * `POST /setup_intents` call.
41
+ *
42
+ * Resolves `{ status: "succeeded", setupIntent }` after verification,
43
+ * `{ status: "failed", setupIntent? }` on decline, or
44
+ * `{ status: "failed", error: "timeout" }` if the iframe does not
45
+ * respond within 15 seconds. Same `isConfirmTimeout` rule as
46
+ * {@link confirmPayment}.
33
47
  */
34
48
  export declare function confirmSetup({ iframeRef, token, defaultValues, }: {
35
49
  iframeRef: IframeRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amos.com/react-amos-js",
3
- "version": "0.11.14",
3
+ "version": "0.11.15",
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.15",
60
+ "@amos.com/amos-js": "0.11.16",
61
61
  "@types/googlepay": "0.7.12"
62
62
  },
63
63
  "peerDependencies": {
package/src/index.tsx CHANGED
@@ -63,6 +63,14 @@ export function validateForm({
63
63
  *
64
64
  * Pass the embed JWT (`token`) returned by your server's
65
65
  * `POST /payment_intents` call.
66
+ *
67
+ * Resolves `{ status: "succeeded", paymentIntent }` after authorization,
68
+ * `{ status: "failed", paymentIntent? }` on decline, or
69
+ * `{ status: "failed", error: "timeout" }` if the iframe does not post
70
+ * `CONFIRMATION_RESULT` within 15 seconds (`CONFIRM_TIMEOUT_MS`). Use
71
+ * `isConfirmTimeout(result)` — a timeout is not a decline; the charge
72
+ * may still settle. Embed `/confirm` aborts at 10s and posts the same
73
+ * timeout result.
66
74
  */
67
75
  export function confirmPayment({
68
76
  iframeRef,
@@ -88,6 +96,12 @@ export function confirmPayment({
88
96
  *
89
97
  * Pass the embed JWT (`token`) returned by your server's
90
98
  * `POST /setup_intents` call.
99
+ *
100
+ * Resolves `{ status: "succeeded", setupIntent }` after verification,
101
+ * `{ status: "failed", setupIntent? }` on decline, or
102
+ * `{ status: "failed", error: "timeout" }` if the iframe does not
103
+ * respond within 15 seconds. Same `isConfirmTimeout` rule as
104
+ * {@link confirmPayment}.
91
105
  */
92
106
  export function confirmSetup({
93
107
  iframeRef,