@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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, TxnStatus, WalletErrorStage } from '@sunbay/checkout-sdk-protocol';
1
+ import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
+ export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -318,6 +318,11 @@ interface CheckoutInstanceOptions {
318
318
  capabilities: string[];
319
319
  /** The initial session view returned by initialize. */
320
320
  session: PublicSessionView;
321
+ /**
322
+ * Warnings produced during initialize (the instance did not exist yet, so they could not be
323
+ * delivered as events). Replayed once to the first `warning` listener.
324
+ */
325
+ initialWarnings?: WarningEvent[];
321
326
  /**
322
327
  * Initial appearance customization (from createCheckout's appearance).
323
328
  * Passed through to every created Element and serialized into its iframe src (no flash on the
@@ -371,6 +376,8 @@ declare class CheckoutInstance {
371
376
  /** The paymentResult event subscription handler (unbound on destroy). */
372
377
  private readonly paymentResultHandler;
373
378
  private destroyed;
379
+ /** Warnings from initialize not yet delivered to any `warning` listener. */
380
+ private pendingWarnings;
374
381
  constructor(opts: CheckoutInstanceOptions);
375
382
  /**
376
383
  * Create an Element handle (not auto-mounted; a mutual-exclusion conflict throws ELEMENT_CONFLICT).
@@ -437,7 +444,7 @@ declare class CheckoutInstance {
437
444
  /**
438
445
  * Query the payment status (returns TxnStatus as-is, no transformation).
439
446
  *
440
- * @returns txnStatus (may include txnId).
447
+ * @returns txnStatus (may be absent when the session is expired), sessionStatus and txnId.
441
448
  * @throws rejects INSTANCE_DESTROYED when destroyed.
442
449
  */
443
450
  getPaymentStatus(): Promise<GetPaymentStatusResp>;
@@ -450,6 +457,8 @@ declare class CheckoutInstance {
450
457
  updateCheckout(patch: {
451
458
  locale?: string;
452
459
  appearance?: Appearance;
460
+ billingAddress?: AddressInfo;
461
+ shippingAddress?: AddressInfo;
453
462
  }): Promise<void>;
454
463
  /**
455
464
  * Register a Checkout-level event handler (passes through the transport).
@@ -543,6 +552,13 @@ interface CreateCheckoutOptions {
543
552
  appearance?: Appearance;
544
553
  /** Payment method filter (subtractive/reordering only). */
545
554
  paymentMethods?: PaymentMethodFilter;
555
+ /**
556
+ * Host-collected billing address. When complete, Apple Pay / Google Pay do not ask the user for
557
+ * it again, and it is used as the default for card `confirm()`.
558
+ */
559
+ billingAddress?: AddressInfo;
560
+ /** Host-collected shipping address (complete = address + name + phone). Same rules as above. */
561
+ shippingAddress?: AddressInfo;
546
562
  /** Internal injection point: custom transport factory (test use; not part of the public API contract). */
547
563
  __transportFactory?: TransportFactory;
548
564
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, TxnStatus, WalletErrorStage } from '@sunbay/checkout-sdk-protocol';
1
+ import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, EventPayloadMap, PublicSessionView, WarningEvent, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, AddressInfo, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
+ export { AddressElementOptions, AddressFormStyle, AddressInfo, Appearance, AppearanceRuleStyle, AppearanceRuleTarget, AppearanceVariables, ApplePayButtonTheme, ApplePayButtonType, ApplePayOptions, AvailableWallets, BlurEvent, CardElementOptions, CardFieldElementOptions, ChangeEvent, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementReadyEvent, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ErrorEvent, EventName, EventPayloadMap, ExpressAvailabilityChangeEvent, ExpressCheckoutElementOptions, FocusEvent, GooglePayButtonTheme, GooglePayButtonType, GooglePayOptions, LoadErrorEvent, PaymentAction, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PaymentResultEvent, PaymentStateChangeEvent, PublicPaymentMethod, PublicProductLine, PublicSessionView, ReadyEvent, SessionStatus, TxnStatus, WARNING_CODES, WalletErrorStage, WarningCode, WarningEvent } from '@sunbay/checkout-sdk-protocol';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -318,6 +318,11 @@ interface CheckoutInstanceOptions {
318
318
  capabilities: string[];
319
319
  /** The initial session view returned by initialize. */
320
320
  session: PublicSessionView;
321
+ /**
322
+ * Warnings produced during initialize (the instance did not exist yet, so they could not be
323
+ * delivered as events). Replayed once to the first `warning` listener.
324
+ */
325
+ initialWarnings?: WarningEvent[];
321
326
  /**
322
327
  * Initial appearance customization (from createCheckout's appearance).
323
328
  * Passed through to every created Element and serialized into its iframe src (no flash on the
@@ -371,6 +376,8 @@ declare class CheckoutInstance {
371
376
  /** The paymentResult event subscription handler (unbound on destroy). */
372
377
  private readonly paymentResultHandler;
373
378
  private destroyed;
379
+ /** Warnings from initialize not yet delivered to any `warning` listener. */
380
+ private pendingWarnings;
374
381
  constructor(opts: CheckoutInstanceOptions);
375
382
  /**
376
383
  * Create an Element handle (not auto-mounted; a mutual-exclusion conflict throws ELEMENT_CONFLICT).
@@ -437,7 +444,7 @@ declare class CheckoutInstance {
437
444
  /**
438
445
  * Query the payment status (returns TxnStatus as-is, no transformation).
439
446
  *
440
- * @returns txnStatus (may include txnId).
447
+ * @returns txnStatus (may be absent when the session is expired), sessionStatus and txnId.
441
448
  * @throws rejects INSTANCE_DESTROYED when destroyed.
442
449
  */
443
450
  getPaymentStatus(): Promise<GetPaymentStatusResp>;
@@ -450,6 +457,8 @@ declare class CheckoutInstance {
450
457
  updateCheckout(patch: {
451
458
  locale?: string;
452
459
  appearance?: Appearance;
460
+ billingAddress?: AddressInfo;
461
+ shippingAddress?: AddressInfo;
453
462
  }): Promise<void>;
454
463
  /**
455
464
  * Register a Checkout-level event handler (passes through the transport).
@@ -543,6 +552,13 @@ interface CreateCheckoutOptions {
543
552
  appearance?: Appearance;
544
553
  /** Payment method filter (subtractive/reordering only). */
545
554
  paymentMethods?: PaymentMethodFilter;
555
+ /**
556
+ * Host-collected billing address. When complete, Apple Pay / Google Pay do not ask the user for
557
+ * it again, and it is used as the default for card `confirm()`.
558
+ */
559
+ billingAddress?: AddressInfo;
560
+ /** Host-collected shipping address (complete = address + name + phone). Same rules as above. */
561
+ shippingAddress?: AddressInfo;
546
562
  /** Internal injection point: custom transport factory (test use; not part of the public API contract). */
547
563
  __transportFactory?: TransportFactory;
548
564
  }
@@ -24,6 +24,7 @@ var SunbayCheckout = (() => {
24
24
  CheckoutElement: () => CheckoutElement,
25
25
  CheckoutInstance: () => CheckoutInstance,
26
26
  ErrorCode: () => ErrorCode,
27
+ WARNING_CODES: () => WARNING_CODES,
27
28
  createCheckout: () => createCheckout,
28
29
  version: () => version
29
30
  });
@@ -128,6 +129,22 @@ var SunbayCheckout = (() => {
128
129
  PAYMENT_FLOW_ERROR: "PAYMENT_FLOW_ERROR",
129
130
  UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY"
130
131
  };
132
+ var WARNING_CODES = {
133
+ /** A `paymentMethods` filter identifier matched nothing (unknown / not offered). */
134
+ PAYMENT_METHOD_FILTER_IGNORED: "PAYMENT_METHOD_FILTER_IGNORED",
135
+ /** An expressCheckout option was not whitelisted or had an invalid value. */
136
+ EXPRESS_OPTION_IGNORED: "EXPRESS_OPTION_IGNORED",
137
+ /** A host-provided billing/shipping address was incomplete, so it was treated as not provided. */
138
+ ADDRESS_INCOMPLETE: "ADDRESS_INCOMPLETE",
139
+ /** A host-provided address was ignored because our Address Element owns that mode. */
140
+ ADDRESS_ENTRY_IGNORED: "ADDRESS_ENTRY_IGNORED",
141
+ /**
142
+ * The wallet (Apple Pay / Google Pay) payment parameters delivered by the session were missing
143
+ * or invalid, so that wallet is not offered. Registered for the native SDKs (iOS first); the Web
144
+ * runtime currently only logs this condition and does not emit the event.
145
+ */
146
+ WALLET_PARAMS_INVALID: "WALLET_PARAMS_INVALID"
147
+ };
131
148
  var IFRAME_RESIZE_MESSAGE_TYPE = "sunbay:checkout:iframe-resize";
132
149
  function isIframeResizeMessage(data) {
133
150
  if (typeof data !== "object" || data === null) {
@@ -954,10 +971,13 @@ var SunbayCheckout = (() => {
954
971
  let query = `?checkoutId=${encodeURIComponent(this.checkoutId)}`;
955
972
  query += `&elementId=${encodeURIComponent(this.elementId)}`;
956
973
  if (this.type === "address") {
957
- const mode = this.options?.mode;
974
+ const { mode, style } = this.options ?? {};
958
975
  if (mode) {
959
976
  query += `&mode=${encodeURIComponent(mode)}`;
960
977
  }
978
+ if (style === "simple" || style === "full") {
979
+ query += `&style=${style}`;
980
+ }
961
981
  }
962
982
  if (this.colorScheme) {
963
983
  query += `&colorScheme=${encodeURIComponent(this.colorScheme)}`;
@@ -1106,6 +1126,7 @@ var SunbayCheckout = (() => {
1106
1126
  /** The current pending confirm (at most one at a time). */
1107
1127
  this.pendingConfirm = null;
1108
1128
  this.destroyed = false;
1129
+ this.pendingWarnings = opts.initialWarnings ? [...opts.initialWarnings] : [];
1109
1130
  this.checkoutId = opts.checkoutId;
1110
1131
  this.runtimeId = opts.runtimeId;
1111
1132
  this.capabilities = opts.capabilities;
@@ -1275,7 +1296,7 @@ var SunbayCheckout = (() => {
1275
1296
  /**
1276
1297
  * Query the payment status (returns TxnStatus as-is, no transformation).
1277
1298
  *
1278
- * @returns txnStatus (may include txnId).
1299
+ * @returns txnStatus (may be absent when the session is expired), sessionStatus and txnId.
1279
1300
  * @throws rejects INSTANCE_DESTROYED when destroyed.
1280
1301
  */
1281
1302
  async getPaymentStatus() {
@@ -1303,6 +1324,18 @@ var SunbayCheckout = (() => {
1303
1324
  on(event, handler) {
1304
1325
  this.assertAlive();
1305
1326
  this.transport.on(event, handler);
1327
+ if (event === "warning" && this.pendingWarnings.length > 0) {
1328
+ const pending = this.pendingWarnings;
1329
+ this.pendingWarnings = [];
1330
+ queueMicrotask(() => {
1331
+ if (this.destroyed) {
1332
+ return;
1333
+ }
1334
+ for (const w of pending) {
1335
+ handler(w);
1336
+ }
1337
+ });
1338
+ }
1306
1339
  }
1307
1340
  /**
1308
1341
  * Unregister an event handler (safe to call after destruction).
@@ -1497,7 +1530,9 @@ var SunbayCheckout = (() => {
1497
1530
  checkoutClientSecret: opts.checkoutClientSecret,
1498
1531
  locale: opts.locale,
1499
1532
  appearance: opts.appearance,
1500
- paymentMethods: opts.paymentMethods
1533
+ paymentMethods: opts.paymentMethods,
1534
+ billingAddress: opts.billingAddress,
1535
+ shippingAddress: opts.shippingAddress
1501
1536
  };
1502
1537
  let initResp;
1503
1538
  try {
@@ -1513,6 +1548,7 @@ var SunbayCheckout = (() => {
1513
1548
  transport,
1514
1549
  capabilities: initResp.capabilities,
1515
1550
  session: initResp.session,
1551
+ initialWarnings: initResp.warnings,
1516
1552
  appearance: opts.appearance
1517
1553
  });
1518
1554
  }
@@ -1542,7 +1578,7 @@ var SunbayCheckout = (() => {
1542
1578
  const w = window;
1543
1579
  w.SunbayCheckout = { ...w.SunbayCheckout ?? {}, createCheckout };
1544
1580
  }
1545
- var version = true ? "0.0.8" : "0.0.0";
1581
+ var version = true ? "0.1.0" : "0.0.0";
1546
1582
  return __toCommonJS(index_exports);
1547
1583
  })();
1548
1584
  //# sourceMappingURL=index.global.js.map