@sunbay/checkout-sdk-js 0.0.9 → 0.1.1

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
@@ -55,7 +55,7 @@ with a CSS selector or an empty `HTMLElement`.
55
55
  | --- | --- | --- |
56
56
  | `card` | `showBillingAddress`, `showShippingAddress`, `showPostalCode`, `appearance` | Combined card form. Exclusive with split fields. |
57
57
  | `cardNumber` / `cardExpiry` / `cardCvc` | `appearance` | Split fields. Exclusive with `card`. |
58
- | `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). |
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`,
@@ -91,6 +91,9 @@ registration. Handler exceptions are isolated and rethrown asynchronously (they
91
91
  - `pending` or any unknown state is **not a failure**. Do **not** retry or let the user
92
92
  pay again. Reconcile with `getPaymentStatus()` (`txnStatus`: `I|S|F|R`) and wait for the
93
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.
94
97
  - The confirm slot stays held (`CHECKOUT_BUSY`) until a terminal result arrives, or you
95
98
  call `destroy()` and create a new instance with `createCheckout`. This also applies
96
99
  after the watchdog resolved `pending`.
package/dist/index.cjs CHANGED
@@ -463,6 +463,7 @@ var CheckoutElement = class _CheckoutElement {
463
463
  this.options = opts.initialOptions;
464
464
  this.colorScheme = opts.colorScheme;
465
465
  this.appearance = opts.appearance;
466
+ this.locale = opts.locale;
466
467
  this.mode = opts.initialOptions?.mode;
467
468
  this.onDestroy = opts.onDestroy;
468
469
  this.installInputActions();
@@ -840,7 +841,8 @@ var CheckoutElement = class _CheckoutElement {
840
841
  * (no flash on the first frame); if the initial appearance contains variables or rules, append
841
842
  * `&appearance=<encodeURIComponent(JSON.stringify(appearance))>` (takes effect on the first
842
843
  * frame, no flash). An appearance containing only colorScheme (no variables/rules) is not
843
- * appended, to avoid an empty appearance string. For expressCheckout, additionally append the
844
+ * appended, to avoid an empty appearance string. If an initial locale is provided, append
845
+ * `&locale=<value>` (first frame renders in that language). For expressCheckout, additionally append the
844
846
  * wallet toggles / per-wallet buttonType / global buttonHeight (see {@link resolveExpressQuery}).
845
847
  *
846
848
  * elementId is sent with the src so the hosted child echoes it verbatim in iframe-resize
@@ -852,14 +854,20 @@ var CheckoutElement = class _CheckoutElement {
852
854
  let query = `?checkoutId=${encodeURIComponent(this.checkoutId)}`;
853
855
  query += `&elementId=${encodeURIComponent(this.elementId)}`;
854
856
  if (this.type === "address") {
855
- const mode = this.options?.mode;
857
+ const { mode, style } = this.options ?? {};
856
858
  if (mode) {
857
859
  query += `&mode=${encodeURIComponent(mode)}`;
858
860
  }
861
+ if (style === "simple" || style === "full") {
862
+ query += `&style=${style}`;
863
+ }
859
864
  }
860
865
  if (this.colorScheme) {
861
866
  query += `&colorScheme=${encodeURIComponent(this.colorScheme)}`;
862
867
  }
868
+ if (this.locale) {
869
+ query += `&locale=${encodeURIComponent(this.locale)}`;
870
+ }
863
871
  const effectiveAppearance = this.perElementAppearance() ?? this.appearance;
864
872
  if (effectiveAppearance && (effectiveAppearance.variables || effectiveAppearance.rules)) {
865
873
  query += `&appearance=${encodeURIComponent(JSON.stringify(effectiveAppearance))}`;
@@ -1013,6 +1021,7 @@ var CheckoutInstance = class {
1013
1021
  this.transport = opts.transport;
1014
1022
  this.session = opts.session;
1015
1023
  this.appearance = opts.appearance;
1024
+ this.locale = opts.locale;
1016
1025
  this.paymentResultHandler = (payload) => {
1017
1026
  this.handlePaymentResult(payload);
1018
1027
  };
@@ -1044,6 +1053,7 @@ var CheckoutInstance = class {
1044
1053
  initialOptions: options,
1045
1054
  colorScheme: this.appearance?.colorScheme,
1046
1055
  appearance: this.appearance,
1056
+ locale: this.locale,
1047
1057
  onDestroy: (id) => this.releaseElement(id)
1048
1058
  };
1049
1059
  const element = CheckoutElement.create(elementOpts);
@@ -1175,7 +1185,7 @@ var CheckoutInstance = class {
1175
1185
  /**
1176
1186
  * Query the payment status (returns TxnStatus as-is, no transformation).
1177
1187
  *
1178
- * @returns txnStatus (may include txnId).
1188
+ * @returns txnStatus (may be absent when the session is expired), sessionStatus and txnId.
1179
1189
  * @throws rejects INSTANCE_DESTROYED when destroyed.
1180
1190
  */
1181
1191
  async getPaymentStatus() {
@@ -1429,7 +1439,8 @@ async function createCheckout(opts) {
1429
1439
  capabilities: initResp.capabilities,
1430
1440
  session: initResp.session,
1431
1441
  initialWarnings: initResp.warnings,
1432
- appearance: opts.appearance
1442
+ appearance: opts.appearance,
1443
+ locale: opts.locale
1433
1444
  });
1434
1445
  }
1435
1446
  function waitForHello(transport) {
@@ -1459,7 +1470,7 @@ if (typeof window !== "undefined") {
1459
1470
  const w = window;
1460
1471
  w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
1461
1472
  }
1462
- var version = true ? "0.0.9" : "0.0.0";
1473
+ var version = true ? "0.1.1" : "0.0.0";
1463
1474
  // Annotate the CommonJS export names for ESM import in node:
1464
1475
  0 && (module.exports = {
1465
1476
  CheckoutElement,