@sunbay/checkout-sdk-js 0.0.8 → 0.1.0
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 +8 -3
- package/dist/index.cjs +25 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.global.js +40 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.mjs +26 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,7 +41,8 @@ const outcome = await checkout.confirm();
|
|
|
41
41
|
| `hostOrigin` | Overrides the hosted origin (takes precedence over `env`), e.g. `http://localhost:3000`. |
|
|
42
42
|
| `locale` | UI locale, e.g. `'en-US'`, `'zh-CN'`. |
|
|
43
43
|
| `appearance` | `{ variables, rules, colorScheme }` (whitelisted design variables, no arbitrary CSS). |
|
|
44
|
-
| `paymentMethods` | `{ hide?: string[]; order?: string[] }` - subtract/sort only. |
|
|
44
|
+
| `paymentMethods` | `{ hide?: string[]; order?: string[] }` - subtract/sort only, using backend identifiers (`CARD` = all card brands, `APPLE_PAY`, `GOOGLE_PAY`, or a raw method such as `AMEX`; case-sensitive). Unknown identifiers are ignored with a `warning` event. Not the same as the Express Element's `paymentMethods`. |
|
|
45
|
+
| `billingAddress` / `shippingAddress` | Optional host-collected addresses. When complete, Apple Pay / Google Pay do not ask the user again, and card `confirm()` uses them as the default. Ignored (with a `warning`) if our Address Element of that mode is used. See `docs/api/api.md`. |
|
|
45
46
|
|
|
46
47
|
The hosted runtime must serve `/embed/sdk/*` (SDK >= 0.0.7). Deploy the runtime before upgrading the SDK.
|
|
47
48
|
|
|
@@ -54,7 +55,7 @@ with a CSS selector or an empty `HTMLElement`.
|
|
|
54
55
|
| --- | --- | --- |
|
|
55
56
|
| `card` | `showBillingAddress`, `showShippingAddress`, `showPostalCode`, `appearance` | Combined card form. Exclusive with split fields. |
|
|
56
57
|
| `cardNumber` / `cardExpiry` / `cardCvc` | `appearance` | Split fields. Exclusive with `card`. |
|
|
57
|
-
| `address` | `mode: 'billing' \| 'shipping'` (required), `appearance` | One per mode. |
|
|
58
|
+
| `address` | `mode: 'billing' \| 'shipping'` (required), `style: 'full' \| 'simple'` (default `'full'`), `appearance` | One per mode. `simple` = country, address line 1, postal code (+ first and last name for shipping). |
|
|
58
59
|
| `expressCheckout` | `paymentMethods.applePay` / `googlePay` (`false` hides; or `{ buttonTheme, buttonType }`), `layout.maxColumns`, `buttonHeight` (30-64, default 40) | Singleton. Wallet buttons. |
|
|
59
60
|
|
|
60
61
|
Handle methods: `mount`, `unmount`, `update(patch)`, `destroy`, `getStatus`,
|
|
@@ -79,6 +80,7 @@ registration. Handler exceptions are isolated and rethrown asynchronously (they
|
|
|
79
80
|
| `paymentStateChange` | `{ operationId, method, state, action? }` | Intermediate state, e.g. requires action. |
|
|
80
81
|
| `paymentResult` | `{ operationId, method, outcome }` | A payment outcome was produced. |
|
|
81
82
|
| `error` | `{ operationId?, method?, stage?, error }` | Asynchronous error (wallet flows etc.). |
|
|
83
|
+
| `warning` | `{ code, ignored, reason }` | Non-fatal: merchant input was ignored. Codes are the cross-platform `WARNING_CODES` registry (see `docs/api/api.md`). Warnings raised during `createCheckout` are replayed to the first listener. |
|
|
82
84
|
|
|
83
85
|
## Payment result semantics
|
|
84
86
|
|
|
@@ -89,6 +91,9 @@ registration. Handler exceptions are isolated and rethrown asynchronously (they
|
|
|
89
91
|
- `pending` or any unknown state is **not a failure**. Do **not** retry or let the user
|
|
90
92
|
pay again. Reconcile with `getPaymentStatus()` (`txnStatus`: `I|S|F|R`) and wait for the
|
|
91
93
|
terminal `paymentResult` event.
|
|
94
|
+
- `failed` ends the attempt, not the session: on a multi-attempt session (created without
|
|
95
|
+
`transactionRequestId`) the buyer can retry, so one session may emit several
|
|
96
|
+
`paymentResult` events. De-duplicate by `operationId`; the first `succeeded` is final.
|
|
92
97
|
- The confirm slot stays held (`CHECKOUT_BUSY`) until a terminal result arrives, or you
|
|
93
98
|
call `destroy()` and create a new instance with `createCheckout`. This also applies
|
|
94
99
|
after the watchdog resolved `pending`.
|
|
@@ -171,7 +176,7 @@ challenges: it only emits the event. Your page must handle the action.
|
|
|
171
176
|
- `unmount()` / `destroy()` while an element is loading rejects the in-flight `mount()`
|
|
172
177
|
(`RUNTIME_LOAD_FAILED` / `INSTANCE_DESTROYED`). If you call `mount()` without
|
|
173
178
|
`catch`/`await`, that surfaces as an **unhandled rejection**; always handle it.
|
|
174
|
-
- `checkout.updateCheckout({ locale?, appearance? })` hot-switches locale/appearance.
|
|
179
|
+
- `checkout.updateCheckout({ locale?, appearance?, billingAddress?, shippingAddress? })` hot-switches locale/appearance and replaces the host-provided addresses.
|
|
175
180
|
- `getSession()`, `refresh()`, `getPaymentStatus()` read session/payment state.
|
|
176
181
|
- `checkout.destroy()` is idempotent, removes all iframes, and later calls reject/throw
|
|
177
182
|
`INSTANCE_DESTROYED`. Calling `destroy()` while a `confirm()` is pending rejects that
|
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
CheckoutElement: () => CheckoutElement,
|
|
24
24
|
CheckoutInstance: () => CheckoutInstance,
|
|
25
25
|
ErrorCode: () => import_checkout_sdk_protocol7.ErrorCode,
|
|
26
|
+
WARNING_CODES: () => import_checkout_sdk_protocol7.WARNING_CODES,
|
|
26
27
|
createCheckout: () => createCheckout,
|
|
27
28
|
version: () => version
|
|
28
29
|
});
|
|
@@ -851,10 +852,13 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
851
852
|
let query = `?checkoutId=${encodeURIComponent(this.checkoutId)}`;
|
|
852
853
|
query += `&elementId=${encodeURIComponent(this.elementId)}`;
|
|
853
854
|
if (this.type === "address") {
|
|
854
|
-
const mode = this.options
|
|
855
|
+
const { mode, style } = this.options ?? {};
|
|
855
856
|
if (mode) {
|
|
856
857
|
query += `&mode=${encodeURIComponent(mode)}`;
|
|
857
858
|
}
|
|
859
|
+
if (style === "simple" || style === "full") {
|
|
860
|
+
query += `&style=${style}`;
|
|
861
|
+
}
|
|
858
862
|
}
|
|
859
863
|
if (this.colorScheme) {
|
|
860
864
|
query += `&colorScheme=${encodeURIComponent(this.colorScheme)}`;
|
|
@@ -1004,6 +1008,7 @@ var CheckoutInstance = class {
|
|
|
1004
1008
|
/** The current pending confirm (at most one at a time). */
|
|
1005
1009
|
this.pendingConfirm = null;
|
|
1006
1010
|
this.destroyed = false;
|
|
1011
|
+
this.pendingWarnings = opts.initialWarnings ? [...opts.initialWarnings] : [];
|
|
1007
1012
|
this.checkoutId = opts.checkoutId;
|
|
1008
1013
|
this.runtimeId = opts.runtimeId;
|
|
1009
1014
|
this.capabilities = opts.capabilities;
|
|
@@ -1173,7 +1178,7 @@ var CheckoutInstance = class {
|
|
|
1173
1178
|
/**
|
|
1174
1179
|
* Query the payment status (returns TxnStatus as-is, no transformation).
|
|
1175
1180
|
*
|
|
1176
|
-
* @returns txnStatus (may
|
|
1181
|
+
* @returns txnStatus (may be absent when the session is expired), sessionStatus and txnId.
|
|
1177
1182
|
* @throws rejects INSTANCE_DESTROYED when destroyed.
|
|
1178
1183
|
*/
|
|
1179
1184
|
async getPaymentStatus() {
|
|
@@ -1201,6 +1206,18 @@ var CheckoutInstance = class {
|
|
|
1201
1206
|
on(event, handler) {
|
|
1202
1207
|
this.assertAlive();
|
|
1203
1208
|
this.transport.on(event, handler);
|
|
1209
|
+
if (event === "warning" && this.pendingWarnings.length > 0) {
|
|
1210
|
+
const pending = this.pendingWarnings;
|
|
1211
|
+
this.pendingWarnings = [];
|
|
1212
|
+
queueMicrotask(() => {
|
|
1213
|
+
if (this.destroyed) {
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
for (const w of pending) {
|
|
1217
|
+
handler(w);
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1204
1221
|
}
|
|
1205
1222
|
/**
|
|
1206
1223
|
* Unregister an event handler (safe to call after destruction).
|
|
@@ -1396,7 +1413,9 @@ async function createCheckout(opts) {
|
|
|
1396
1413
|
checkoutClientSecret: opts.checkoutClientSecret,
|
|
1397
1414
|
locale: opts.locale,
|
|
1398
1415
|
appearance: opts.appearance,
|
|
1399
|
-
paymentMethods: opts.paymentMethods
|
|
1416
|
+
paymentMethods: opts.paymentMethods,
|
|
1417
|
+
billingAddress: opts.billingAddress,
|
|
1418
|
+
shippingAddress: opts.shippingAddress
|
|
1400
1419
|
};
|
|
1401
1420
|
let initResp;
|
|
1402
1421
|
try {
|
|
@@ -1412,6 +1431,7 @@ async function createCheckout(opts) {
|
|
|
1412
1431
|
transport,
|
|
1413
1432
|
capabilities: initResp.capabilities,
|
|
1414
1433
|
session: initResp.session,
|
|
1434
|
+
initialWarnings: initResp.warnings,
|
|
1415
1435
|
appearance: opts.appearance
|
|
1416
1436
|
});
|
|
1417
1437
|
}
|
|
@@ -1442,12 +1462,13 @@ if (typeof window !== "undefined") {
|
|
|
1442
1462
|
const w = window;
|
|
1443
1463
|
w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
|
|
1444
1464
|
}
|
|
1445
|
-
var version = true ? "0.0
|
|
1465
|
+
var version = true ? "0.1.0" : "0.0.0";
|
|
1446
1466
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1447
1467
|
0 && (module.exports = {
|
|
1448
1468
|
CheckoutElement,
|
|
1449
1469
|
CheckoutInstance,
|
|
1450
1470
|
ErrorCode,
|
|
1471
|
+
WARNING_CODES,
|
|
1451
1472
|
createCheckout,
|
|
1452
1473
|
version
|
|
1453
1474
|
});
|