@sunbay/checkout-sdk-js 0.0.8 → 0.0.9

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
@@ -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
 
@@ -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
 
@@ -171,7 +173,7 @@ challenges: it only emits the event. Your page must handle the action.
171
173
  - `unmount()` / `destroy()` while an element is loading rejects the in-flight `mount()`
172
174
  (`RUNTIME_LOAD_FAILED` / `INSTANCE_DESTROYED`). If you call `mount()` without
173
175
  `catch`/`await`, that surfaces as an **unhandled rejection**; always handle it.
174
- - `checkout.updateCheckout({ locale?, appearance? })` hot-switches locale/appearance.
176
+ - `checkout.updateCheckout({ locale?, appearance?, billingAddress?, shippingAddress? })` hot-switches locale/appearance and replaces the host-provided addresses.
175
177
  - `getSession()`, `refresh()`, `getPaymentStatus()` read session/payment state.
176
178
  - `checkout.destroy()` is idempotent, removes all iframes, and later calls reject/throw
177
179
  `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
  });
@@ -1004,6 +1005,7 @@ var CheckoutInstance = class {
1004
1005
  /** The current pending confirm (at most one at a time). */
1005
1006
  this.pendingConfirm = null;
1006
1007
  this.destroyed = false;
1008
+ this.pendingWarnings = opts.initialWarnings ? [...opts.initialWarnings] : [];
1007
1009
  this.checkoutId = opts.checkoutId;
1008
1010
  this.runtimeId = opts.runtimeId;
1009
1011
  this.capabilities = opts.capabilities;
@@ -1201,6 +1203,18 @@ var CheckoutInstance = class {
1201
1203
  on(event, handler) {
1202
1204
  this.assertAlive();
1203
1205
  this.transport.on(event, handler);
1206
+ if (event === "warning" && this.pendingWarnings.length > 0) {
1207
+ const pending = this.pendingWarnings;
1208
+ this.pendingWarnings = [];
1209
+ queueMicrotask(() => {
1210
+ if (this.destroyed) {
1211
+ return;
1212
+ }
1213
+ for (const w of pending) {
1214
+ handler(w);
1215
+ }
1216
+ });
1217
+ }
1204
1218
  }
1205
1219
  /**
1206
1220
  * Unregister an event handler (safe to call after destruction).
@@ -1396,7 +1410,9 @@ async function createCheckout(opts) {
1396
1410
  checkoutClientSecret: opts.checkoutClientSecret,
1397
1411
  locale: opts.locale,
1398
1412
  appearance: opts.appearance,
1399
- paymentMethods: opts.paymentMethods
1413
+ paymentMethods: opts.paymentMethods,
1414
+ billingAddress: opts.billingAddress,
1415
+ shippingAddress: opts.shippingAddress
1400
1416
  };
1401
1417
  let initResp;
1402
1418
  try {
@@ -1412,6 +1428,7 @@ async function createCheckout(opts) {
1412
1428
  transport,
1413
1429
  capabilities: initResp.capabilities,
1414
1430
  session: initResp.session,
1431
+ initialWarnings: initResp.warnings,
1415
1432
  appearance: opts.appearance
1416
1433
  });
1417
1434
  }
@@ -1442,12 +1459,13 @@ if (typeof window !== "undefined") {
1442
1459
  const w = window;
1443
1460
  w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
1444
1461
  }
1445
- var version = true ? "0.0.8" : "0.0.0";
1462
+ var version = true ? "0.0.9" : "0.0.0";
1446
1463
  // Annotate the CommonJS export names for ESM import in node:
1447
1464
  0 && (module.exports = {
1448
1465
  CheckoutElement,
1449
1466
  CheckoutInstance,
1450
1467
  ErrorCode,
1468
+ WARNING_CODES,
1451
1469
  createCheckout,
1452
1470
  version
1453
1471
  });