@amos.com/react-amos-js 0.9.0 → 0.9.3
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 +33 -18
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @amos.com/react-amos-js
|
|
|
14
14
|
|
|
15
15
|
- React components for the iframe payment method forms: `AmosCreditCardPaymentMethodForm`, `AmosBankAccountPaymentMethodForm`, `AmosGooglePayButton`, `AmosApplePayButton`.
|
|
16
16
|
- React-flavoured iframe message helpers that accept a React `ref`: `validateForm({ iframeRef })`, `confirmPaymentIntent({ iframeRef, token })`, `confirmSetupIntent({ iframeRef, token })`.
|
|
17
|
-
- Re-exports of the `@amos.com/amos-js` helpers and types that come up in client code: `createMessage`, `decodeJwt`, `getEmbedOrigin`, `formatGooglePayPaymentData`, `FormattedGooglePayPaymentData`, `Appearance`, `Message`, etc.
|
|
17
|
+
- Re-exports of the `@amos.com/amos-js` helpers and types that come up in client code: `createMessage`, `decodeJwt`, `getEmbedOrigin`, `formatGooglePayPaymentData`, `ConfirmationResult`, `ConfirmationIncompleteReason`, `FormattedGooglePayPaymentData`, `Appearance`, `Message`, etc.
|
|
18
18
|
|
|
19
19
|
> **Note:** A server-side SDK (for example `@amos.com/node`) must be used alongside `@amos.com/react-amos-js` for end-to-end payment processing. `@amos.com/react-amos-js` is the client-side half.
|
|
20
20
|
|
|
@@ -42,7 +42,7 @@ The following flow is for credit card and bank account payment method types only
|
|
|
42
42
|
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.
|
|
43
43
|
5. **Return the payment intent token to the browser**: your backend responds with the embed token (`components["schemas"]["EmbedToken"]`) needed for confirmation.
|
|
44
44
|
6. **Confirm the payment intent from the client**: call `confirmPaymentIntent({ iframeRef, token })` to continue the payment flow.
|
|
45
|
-
7. **Handle UX**: show the user a "processing" state when the "Pay now" button is clicked, and handle `onResult`.
|
|
45
|
+
7. **Handle UX**: show the user a "processing" state when the "Pay now" button is clicked, and handle `onResult`. Do not treat `onResult` as settlement proof — verify payment success on your backend via webhooks. Recoverable field errors are shown in the iframe (`status: "incomplete"` with `reason`: `"field_errors"` or `"validation_failed"`).
|
|
46
46
|
|
|
47
47
|
### Google Pay & Apple Pay
|
|
48
48
|
|
|
@@ -93,7 +93,8 @@ Every component accepts an optional `appearance` prop that controls the look of
|
|
|
93
93
|
},
|
|
94
94
|
}}
|
|
95
95
|
onResult={(result) => {
|
|
96
|
-
if (result.status === "failed") setError(result.errorMessage)
|
|
96
|
+
if (result.status === "failed") setError(result.errorMessage);
|
|
97
|
+
if (result.status === "incomplete") setError(null);
|
|
97
98
|
}}
|
|
98
99
|
/>
|
|
99
100
|
```
|
|
@@ -199,11 +200,16 @@ function CheckoutForm() {
|
|
|
199
200
|
ref={iframeRef}
|
|
200
201
|
renderToken="the-render-token-that-you-created-on-dashboard.amos.com"
|
|
201
202
|
additionalFields={{ cardholderName: true }}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
203
|
onResult={(result) => {
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
// Unlock UI. Verify settlement on your backend via webhooks.
|
|
205
|
+
if (result.status === "succeeded") {
|
|
206
|
+
console.log("Confirm returned:", result);
|
|
207
|
+
} else if (result.status === "failed") {
|
|
208
|
+
console.error("Confirm failed:", result.errorMessage);
|
|
209
|
+
} else if (result.status === "incomplete") {
|
|
210
|
+
console.log("Recoverable:", result.reason);
|
|
211
|
+
}
|
|
212
|
+
}}
|
|
207
213
|
/>
|
|
208
214
|
{error ? <p>{error}</p> : null}
|
|
209
215
|
<button type="submit" disabled={isProcessing}>
|
|
@@ -249,10 +255,15 @@ function CheckoutGooglePay() {
|
|
|
249
255
|
const { token } = await response.json();
|
|
250
256
|
return token;
|
|
251
257
|
}}
|
|
252
|
-
}
|
|
253
258
|
onResult={(result) => {
|
|
254
|
-
if (result.status === "
|
|
255
|
-
|
|
259
|
+
if (result.status === "succeeded") {
|
|
260
|
+
console.log("Confirm returned:", result);
|
|
261
|
+
} else if (result.status === "failed") {
|
|
262
|
+
console.error("Confirm failed:", result.errorMessage);
|
|
263
|
+
} else if (result.status === "incomplete") {
|
|
264
|
+
console.log("Recoverable:", result.reason);
|
|
265
|
+
}
|
|
266
|
+
}}
|
|
256
267
|
/>
|
|
257
268
|
{error ? <p>{error}</p> : null}
|
|
258
269
|
</>
|
|
@@ -317,11 +328,15 @@ function SavePaymentMethodForm() {
|
|
|
317
328
|
<AmosCreditCardPaymentMethodForm
|
|
318
329
|
ref={iframeRef}
|
|
319
330
|
renderToken="the-render-token-that-you-created-on-dashboard.amos.com"
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
331
|
onResult={(result) => {
|
|
323
|
-
if (result.status === "
|
|
324
|
-
|
|
332
|
+
if (result.status === "succeeded") {
|
|
333
|
+
console.log("Confirm returned:", result);
|
|
334
|
+
} else if (result.status === "failed") {
|
|
335
|
+
console.error("Confirm failed:", result.errorMessage);
|
|
336
|
+
} else if (result.status === "incomplete") {
|
|
337
|
+
console.log("Recoverable:", result.reason);
|
|
338
|
+
}
|
|
339
|
+
}}
|
|
325
340
|
/>
|
|
326
341
|
{error ? <p>{error}</p> : null}
|
|
327
342
|
<button type="submit" disabled={isProcessing}>
|
|
@@ -373,13 +388,12 @@ Renders the secure credit card iframe form.
|
|
|
373
388
|
**Required props:**
|
|
374
389
|
|
|
375
390
|
- `renderToken` (`string`)
|
|
376
|
-
- `onResult` (`(result: ConfirmationResult) => void`) — required
|
|
391
|
+
- `onResult` (`(result: ConfirmationResult) => void`) — required. Called when the interactive confirmation attempt finishes (`succeeded`, `failed`, or `incomplete` with `reason`). Not settlement proof; verify via webhooks.
|
|
377
392
|
|
|
378
393
|
**Optional props:**
|
|
379
394
|
|
|
380
395
|
- `appearance` (`{ themeVariables?: Partial<Record<ThemeVariable, string>>; labels?: "above" | "floating" | "placeholder" }`) — appearance overrides for the iframe UI (see [Appearance](#appearance))
|
|
381
396
|
|
|
382
|
-
|
|
383
397
|
- `additionalFields` (`{ cardholderName: boolean }`) — set `additionalFields={{ cardholderName: true }}` to render the cardholder name field in the iframe (`false` by default)
|
|
384
398
|
- `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.
|
|
385
399
|
|
|
@@ -406,7 +420,7 @@ Renders the secure Google Pay iframe button (express checkout flow).
|
|
|
406
420
|
- `merchantName` (`string`)
|
|
407
421
|
- `onInitiatePaymentIntentRequest` (callback receiving `{ paymentIntentCreateAttributes: components["schemas"]["CreatePaymentIntentInput"]; customerCreateAttributes: components["schemas"]["CreateCustomerInput"] }`, returns `Promise<components["schemas"]["EmbedToken"]["token"]>` — the embed JWT string for confirmation)
|
|
408
422
|
|
|
409
|
-
- `onResult` (`(result: ConfirmationResult) => void`) — required
|
|
423
|
+
- `onResult` (`(result: ConfirmationResult) => void`) — required. Called when the interactive confirmation attempt finishes (`succeeded`, `failed`, or `incomplete` with `reason`). Not settlement proof; verify via webhooks.
|
|
410
424
|
|
|
411
425
|
**Optional props:**
|
|
412
426
|
|
|
@@ -436,11 +450,12 @@ Re-exports of the same advanced helpers exposed by `@amos.com/amos-js`. Most int
|
|
|
436
450
|
|
|
437
451
|
### Exported types
|
|
438
452
|
|
|
439
|
-
`@amos.com/react-amos-js` re-exports everything from `@amos.com/amos-js`, including `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`.
|
|
453
|
+
`@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`.
|
|
440
454
|
|
|
441
455
|
## Notes and potential gotchas
|
|
442
456
|
|
|
443
457
|
- **`ref` / `iframeRef`**: for card and bank forms, pass `ref={iframeRef}` to the form component. The same `iframeRef` must be used when calling `validateForm`, `confirmPaymentIntent`, or `confirmSetupIntent`. The component forwards the ref to the inner iframe.
|
|
458
|
+
- **`onResult` is not settlement proof**: `onResult` tells you when to stop waiting (e.g. dismiss a spinner). Verify payment or setup success on your backend via webhooks. On `status: "incomplete"`, unlock your UI — the customer can fix fields in the iframe and retry. Use `result.reason` (`"field_errors"` or `"validation_failed"`) to distinguish recoverable states.
|
|
444
459
|
- **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 (`confirmPaymentIntent` vs `confirmSetupIntent`). Handle both payment and setup outcomes via `onResult`.
|
|
445
460
|
- **Amount format**: for `AmosGooglePayButton` and `AmosApplePayButton`, `amount` is a string (e.g. `"5000"` for $50.00). For `components["schemas"]["CreatePaymentIntentInput"]` on the server, `amount` is a number in cents (e.g. `5000`).
|
|
446
461
|
- **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 until payment completes, the popup closes, or the user clicks **Cancel payment**. Avoid stacking other fixed UI above it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amos.com/react-amos-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"description": "React SDK for embedding Amos payment methods via iframes. Wraps @amos.com/amos-js.",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@biomejs/biome": "2.5.
|
|
39
|
+
"@biomejs/biome": "2.5.7",
|
|
40
40
|
"@changesets/cli": "2.31.1",
|
|
41
|
-
"@types/node": "26.1.
|
|
42
|
-
"@types/react": "19.2.
|
|
41
|
+
"@types/node": "26.1.2",
|
|
42
|
+
"@types/react": "19.2.18",
|
|
43
43
|
"@typescript/typescript6": "6.0.2",
|
|
44
44
|
"typescript": "7.0.2",
|
|
45
|
-
"vite": "8.
|
|
45
|
+
"vite": "8.2.0",
|
|
46
46
|
"vite-plugin-dts": "5.0.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@amos.com/amos-js": "0.9.
|
|
50
|
-
"@amos.com/node": "0.1.
|
|
49
|
+
"@amos.com/amos-js": "0.9.2",
|
|
50
|
+
"@amos.com/node": "0.1.35",
|
|
51
51
|
"@types/googlepay": "0.7.11"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|