@sunbay/checkout-sdk-js 0.1.1 → 0.2.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 +2 -2
- package/dist/index.cjs +79 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.global.js +79 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.mjs +79 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ with a CSS selector or an empty `HTMLElement`.
|
|
|
59
59
|
| `expressCheckout` | `paymentMethods.applePay` / `googlePay` (`false` hides; or `{ buttonTheme, buttonType }`), `layout.maxColumns`, `buttonHeight` (30-64, default 40) | Singleton. Wallet buttons. |
|
|
60
60
|
|
|
61
61
|
Handle methods: `mount`, `unmount`, `update(patch)`, `destroy`, `getStatus`,
|
|
62
|
-
`getAvailableWallets` (express), `on`, `off`. A conflicting `create` throws `ELEMENT_CONFLICT`.
|
|
62
|
+
`getAvailableWallets` (express), `getState` (inputs), `on`, `off`. A conflicting `create` throws `ELEMENT_CONFLICT`.
|
|
63
63
|
|
|
64
64
|
## Events
|
|
65
65
|
|
|
@@ -177,7 +177,7 @@ challenges: it only emits the event. Your page must handle the action.
|
|
|
177
177
|
(`RUNTIME_LOAD_FAILED` / `INSTANCE_DESTROYED`). If you call `mount()` without
|
|
178
178
|
`catch`/`await`, that surfaces as an **unhandled rejection**; always handle it.
|
|
179
179
|
- `checkout.updateCheckout({ locale?, appearance?, billingAddress?, shippingAddress? })` hot-switches locale/appearance and replaces the host-provided addresses.
|
|
180
|
-
- `getSession()`, `refresh()`, `getPaymentStatus()` read session/payment state.
|
|
180
|
+
- `getSession()`, `refresh()`, `getPaymentStatus()` read session/payment state. `getPaymentMethods()` splits the methods into `express` (wallets, with device `available`) and `regular`.
|
|
181
181
|
- `checkout.destroy()` is idempotent, removes all iframes, and later calls reject/throw
|
|
182
182
|
`INSTANCE_DESTROYED`. Calling `destroy()` while a `confirm()` is pending rejects that
|
|
183
183
|
`confirm()` with `INSTANCE_DESTROYED`.
|
package/dist/index.cjs
CHANGED
|
@@ -445,6 +445,10 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
445
445
|
this.abortMount = null;
|
|
446
446
|
/** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
|
|
447
447
|
this.availabilityHandler = null;
|
|
448
|
+
/** Input Elements only: the last `change` snapshot, tracked from construction (never replayed to `on`). */
|
|
449
|
+
this.state = { empty: true, complete: false };
|
|
450
|
+
/** Input Elements only: the persistently subscribed `change` handler (unbound on destroy). */
|
|
451
|
+
this.stateHandler = null;
|
|
448
452
|
/** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
|
|
449
453
|
this.userListeners = /* @__PURE__ */ new Map();
|
|
450
454
|
/**
|
|
@@ -468,6 +472,7 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
468
472
|
this.onDestroy = opts.onDestroy;
|
|
469
473
|
this.installInputActions();
|
|
470
474
|
this.installExpressAvailability();
|
|
475
|
+
this.installInputState();
|
|
471
476
|
}
|
|
472
477
|
/** The current status (read-only snapshot, for external/test observation). */
|
|
473
478
|
getStatus() {
|
|
@@ -485,6 +490,21 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
485
490
|
getAvailableWallets() {
|
|
486
491
|
return this.availableWallets;
|
|
487
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Input Elements only: the last known `change` state (`empty`, `complete`, `brand?`, `error?`).
|
|
495
|
+
*
|
|
496
|
+
* `change` events are not replayed, so a handler registered after `mount()` resolves can miss
|
|
497
|
+
* changes (e.g. browser autofill). Read this to get the current value instead; it is tracked from
|
|
498
|
+
* construction. Starts as `{ empty: true, complete: false }`. Never contains values.
|
|
499
|
+
*
|
|
500
|
+
* @returns A copy of the snapshot; undefined for `expressCheckout`. Still readable after destroy.
|
|
501
|
+
*/
|
|
502
|
+
getState() {
|
|
503
|
+
if (!INPUT_TYPES.includes(this.type)) {
|
|
504
|
+
return void 0;
|
|
505
|
+
}
|
|
506
|
+
return { ...this.state };
|
|
507
|
+
}
|
|
488
508
|
/**
|
|
489
509
|
* Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
|
|
490
510
|
*
|
|
@@ -701,6 +721,10 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
701
721
|
this.transport.off("expressAvailabilityChange", this.availabilityHandler);
|
|
702
722
|
this.availabilityHandler = null;
|
|
703
723
|
}
|
|
724
|
+
if (this.stateHandler) {
|
|
725
|
+
this.transport.off("change", this.stateHandler);
|
|
726
|
+
this.stateHandler = null;
|
|
727
|
+
}
|
|
704
728
|
for (const [event, wrappers] of this.userListeners) {
|
|
705
729
|
for (const wrapper of wrappers.values()) {
|
|
706
730
|
this.transport.off(event, wrapper);
|
|
@@ -812,6 +836,31 @@ var CheckoutElement = class _CheckoutElement {
|
|
|
812
836
|
this.availabilityHandler = handler;
|
|
813
837
|
this.transport.on("expressAvailabilityChange", handler);
|
|
814
838
|
}
|
|
839
|
+
/** Input Elements only: keep the `change` snapshot current so `getState()` works without a listener. */
|
|
840
|
+
installInputState() {
|
|
841
|
+
if (!INPUT_TYPES.includes(this.type)) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const handler = (payload) => {
|
|
845
|
+
const change = payload;
|
|
846
|
+
if (!change || change.elementId !== this.elementId) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const next = {
|
|
850
|
+
empty: change.empty === true,
|
|
851
|
+
complete: change.complete === true
|
|
852
|
+
};
|
|
853
|
+
if (change.brand !== void 0) {
|
|
854
|
+
next.brand = change.brand;
|
|
855
|
+
}
|
|
856
|
+
if (change.error !== void 0) {
|
|
857
|
+
next.error = change.error;
|
|
858
|
+
}
|
|
859
|
+
this.state = next;
|
|
860
|
+
};
|
|
861
|
+
this.stateHandler = handler;
|
|
862
|
+
this.transport.on("change", handler);
|
|
863
|
+
}
|
|
815
864
|
/** Send one input-class action command (synchronously throws INSTANCE_DESTROYED after destruction). */
|
|
816
865
|
sendAction(name) {
|
|
817
866
|
this.assertAlive();
|
|
@@ -1170,6 +1219,35 @@ var CheckoutInstance = class {
|
|
|
1170
1219
|
this.session = resp;
|
|
1171
1220
|
return resp;
|
|
1172
1221
|
}
|
|
1222
|
+
/**
|
|
1223
|
+
* The session's payment methods split into quick wallets (`express`) and everything else
|
|
1224
|
+
* (`regular`), from the local session snapshot (already filtered by `paymentMethods`).
|
|
1225
|
+
*
|
|
1226
|
+
* Each express entry carries `available` from the `expressCheckout` Element's availability
|
|
1227
|
+
* snapshot; it is `undefined` while no such Element exists or it has not reported yet.
|
|
1228
|
+
*
|
|
1229
|
+
* @returns The split view.
|
|
1230
|
+
* @throws INSTANCE_DESTROYED when destroyed.
|
|
1231
|
+
*/
|
|
1232
|
+
getPaymentMethods() {
|
|
1233
|
+
this.assertAlive();
|
|
1234
|
+
let wallets;
|
|
1235
|
+
for (const element of this.elements.values()) {
|
|
1236
|
+
if (element.type === "expressCheckout") {
|
|
1237
|
+
wallets = element.getAvailableWallets();
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
const view = { express: [], regular: [] };
|
|
1241
|
+
for (const method of this.session.paymentMethods) {
|
|
1242
|
+
if (method.method === "APPLE_PAY" || method.method === "GOOGLE_PAY") {
|
|
1243
|
+
const available = wallets === void 0 ? void 0 : method.method === "APPLE_PAY" ? wallets.applePay : wallets.googlePay;
|
|
1244
|
+
view.express.push({ ...method, available });
|
|
1245
|
+
} else {
|
|
1246
|
+
view.regular.push({ ...method });
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return view;
|
|
1250
|
+
}
|
|
1173
1251
|
/**
|
|
1174
1252
|
* Refresh the session (passes through the refresh command and writes back the local snapshot).
|
|
1175
1253
|
*
|
|
@@ -1470,7 +1548,7 @@ if (typeof window !== "undefined") {
|
|
|
1470
1548
|
const w = window;
|
|
1471
1549
|
w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
|
|
1472
1550
|
}
|
|
1473
|
-
var version = true ? "0.
|
|
1551
|
+
var version = true ? "0.2.0" : "0.0.0";
|
|
1474
1552
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1475
1553
|
0 && (module.exports = {
|
|
1476
1554
|
CheckoutElement,
|