@sunbay/checkout-sdk-js 0.0.5 → 0.0.7

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, PublicSessionView, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressInfo, Appearance, CardElementOptions, CardFieldElementOptions, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ExpressCheckoutElementOptions, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PublicPaymentMethod, PublicProductLine, PublicSessionView, TxnStatus } from '@sunbay/checkout-sdk-protocol';
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';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -74,6 +74,15 @@ interface CheckoutElementOptions {
74
74
  */
75
75
  appearance?: Appearance;
76
76
  }
77
+ /** Options for {@link CheckoutElement.mount}. */
78
+ interface MountOptions {
79
+ /**
80
+ * Maximum time (ms) to wait for the Element to become ready. Defaults to 30000. On expiry the
81
+ * iframe is removed, the status becomes `loadError` and the promise rejects with
82
+ * `RUNTIME_LOAD_FAILED`.
83
+ */
84
+ timeoutMs?: number;
85
+ }
77
86
  declare class CheckoutElement {
78
87
  /** Unique Element id. */
79
88
  readonly elementId: string;
@@ -97,6 +106,11 @@ declare class CheckoutElement {
97
106
  /** Event handlers temporarily subscribed during mount (unbound after resolve/reject). */
98
107
  private readyHandler;
99
108
  private loadErrorHandler;
109
+ /**
110
+ * Cancels the in-flight mount (clears its timer/listeners and rejects its promise). Null when no
111
+ * mount is in flight. Used by `unmount()` / `destroy()` while the Element is still loading.
112
+ */
113
+ private abortMount;
100
114
  /**
101
115
  * expressCheckout only: a snapshot of each wallet's availability.
102
116
  * Initially from elementReady.availableWallets, then updated by expressAvailabilityChange.
@@ -104,6 +118,8 @@ declare class CheckoutElement {
104
118
  private availableWallets;
105
119
  /** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
106
120
  private availabilityHandler;
121
+ /** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
122
+ private readonly userListeners;
107
123
  /**
108
124
  * iframe auto-height: the window 'message' listener that stays resident during mount (unbound
109
125
  * when the iframe disappears/is destroyed). Keeps a reference so removeEventListener can be
@@ -128,13 +144,22 @@ declare class CheckoutElement {
128
144
  /**
129
145
  * Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
130
146
  *
147
+ * Failure modes: a hosted `loadError` / command failure rejects with that error; waiting longer
148
+ * than `opts.timeoutMs` (default 30000ms) removes the iframe and rejects `RUNTIME_LOAD_FAILED`;
149
+ * calling `unmount()` while loading rejects with `RUNTIME_LOAD_FAILED` ("mount cancelled");
150
+ * calling `destroy()` (or destroying the instance) while loading rejects `INSTANCE_DESTROYED`.
151
+ * A late `elementReady` after any of these is ignored and never flips the status to ready.
152
+ *
131
153
  * @param selectorOrEl - A CSS selector or an HTMLElement container; the container must be unique and empty.
154
+ * @param opts - Optional mount options (`timeoutMs`).
132
155
  * @returns Resolves after elementReady; on failure removes the node and rejects (loadError / INVALID_OPTIONS).
133
156
  * @throws INSTANCE_DESTROYED when already destroyed.
134
157
  * @example
135
- * await element.mount('#card-field');
158
+ * await element.mount('#card-field', { timeoutMs: 20000 });
136
159
  */
137
- mount(selectorOrEl: string | HTMLElement): Promise<void>;
160
+ mount(selectorOrEl: string | HTMLElement, opts?: MountOptions): Promise<void>;
161
+ /** Best-effort, fire-and-forget release of the hosted element registration; never throws. */
162
+ private releaseHostedElement;
138
163
  /**
139
164
  * Unmount: send destroyElement, remove the iframe; idempotent; keeps the handle and configuration.
140
165
  *
@@ -161,14 +186,14 @@ declare class CheckoutElement {
161
186
  * @param handler - Callback.
162
187
  * @throws INSTANCE_DESTROYED when already destroyed.
163
188
  */
164
- on(event: EventName, handler: (payload: unknown) => void): void;
189
+ on<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
165
190
  /**
166
191
  * Unregister an event handler (still safe to call after destruction).
167
192
  *
168
193
  * @param event - Event name.
169
194
  * @param handler - The previously registered callback.
170
195
  */
171
- off(event: EventName, handler: (payload: unknown) => void): void;
196
+ off<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
172
197
  /** Focus (input classes only, not provided by expressCheckout). */
173
198
  focus?: () => Promise<void>;
174
199
  /** Blur (input classes only, not provided by expressCheckout). */
@@ -191,7 +216,7 @@ declare class CheckoutElement {
191
216
  /** Resolve the mount container (the selector must uniquely match a single element). */
192
217
  private resolveContainer;
193
218
  /**
194
- * Resolve the iframe src: split fields go to /sdk/field/, the rest to /sdk/element/, with
219
+ * Resolve the iframe src: split fields go to /embed/sdk/field/, the rest to /embed/sdk/element/, with
195
220
  * checkoutId and elementId; if an initial colorScheme is provided, append `&colorScheme=<value>`
196
221
  * (no flash on the first frame); if the initial appearance contains variables or rules, append
197
222
  * `&appearance=<encodeURIComponent(JSON.stringify(appearance))>` (takes effect on the first
@@ -303,8 +328,23 @@ interface CheckoutInstanceOptions {
303
328
  */
304
329
  appearance?: Appearance;
305
330
  }
306
- /** Optional confirm parameters (aligned with ConfirmReq, minus the instance-generated operationId). */
307
- type ConfirmOptions = Omit<ConfirmReq, 'operationId'>;
331
+ /**
332
+ * Optional confirm parameters (aligned with ConfirmReq, minus the instance-generated operationId,
333
+ * plus two SDK-only options that are never sent to the runtime).
334
+ */
335
+ type ConfirmOptions = Omit<ConfirmReq, 'operationId'> & {
336
+ /**
337
+ * Called synchronously with the generated operationId, before the `confirm` command is sent.
338
+ * Lets the merchant persist the id early (e.g. to reconcile after a timeout or page reload).
339
+ */
340
+ onOperation?: (operationId: string) => void;
341
+ /**
342
+ * Per-call override of the result watchdog in milliseconds (default
343
+ * {@link CONFIRM_RESULT_DEADLINE_MS}). Must be a positive finite number, otherwise the default
344
+ * applies.
345
+ */
346
+ resultTimeoutMs?: number;
347
+ };
308
348
  declare class CheckoutInstance {
309
349
  /** Unique checkout id. */
310
350
  readonly checkoutId: string;
@@ -347,12 +387,36 @@ declare class CheckoutInstance {
347
387
  */
348
388
  create(type: ElementType, options?: ElementOptions): CheckoutElement;
349
389
  /**
350
- * Initiate a payment confirmation. Generates an operationId, sends the confirm command to obtain
351
- * accepted, and the returned Promise is fulfilled by a later paymentResult event with the same
352
- * operationId. Calling again while in progress → CHECKOUT_BUSY.
390
+ * Initiate a payment confirmation. Generates an operationId, sends the `confirm` command, and
391
+ * returns a Promise fulfilled by `paymentResult` events with the same operationId.
392
+ *
393
+ * Behavior changes in 0.0.7: previously the Promise resolved on the first `paymentResult`,
394
+ * including a non-final `pending` outcome. Now it resolves ONLY on a terminal outcome
395
+ * (`succeeded` | `failed` | `canceled`); a `pending` outcome keeps it waiting.
396
+ *
397
+ * Watchdog: if no terminal outcome arrives within `resultTimeoutMs` (default
398
+ * {@link CONFIRM_RESULT_DEADLINE_MS} = 120000ms) the Promise resolves
399
+ * `{ status: 'pending', operationId, txnId? }`. This is NOT a failure: the payment may still
400
+ * complete, so never treat it as failed and never retry blindly. Reconcile with
401
+ * `getPaymentStatus()` or the `paymentResult` event.
402
+ *
403
+ * Slot semantics (duplicate-submit protection): the confirm slot stays occupied until a
404
+ * terminal outcome arrives or `destroy()` is called. While it is occupied another `confirm()`
405
+ * rejects with `CHECKOUT_BUSY`; this also holds after the watchdog resolved `pending`, and later
406
+ * terminal outcomes are still delivered through `on('paymentResult', ...)`.
407
+ *
408
+ * If the `confirm` command is rejected by the runtime the payment was not started: the Promise
409
+ * rejects with that error and the slot is freed. If the command itself times out
410
+ * (`REQUEST_TIMEOUT`) the runtime may have started the payment: the Promise rejects with the
411
+ * error augmented with `paymentStateKnown: false`, the slot stays occupied and a later terminal
412
+ * `paymentResult` for this operation frees it. Do not retry; reconcile with `getPaymentStatus()`.
353
413
  *
354
- * @param opts - Optional parameters such as billing/shipping address, name, email, returnUrl.
355
- * @returns The terminal PaymentOutcome.
414
+ * `error` events with `paymentStateKnown === false` are informational and do not settle the
415
+ * Promise.
416
+ *
417
+ * @param opts - Optional billing/shipping address, name, email, returnUrl, plus `onOperation`
418
+ * and `resultTimeoutMs`.
419
+ * @returns The terminal PaymentOutcome, or `{ status: 'pending' }` when the watchdog fires.
356
420
  * @throws rejects INSTANCE_DESTROYED when destroyed; rejects CHECKOUT_BUSY when in progress.
357
421
  */
358
422
  confirm(opts?: ConfirmOptions): Promise<PaymentOutcome>;
@@ -394,14 +458,14 @@ declare class CheckoutInstance {
394
458
  * @param handler - Callback.
395
459
  * @throws INSTANCE_DESTROYED when destroyed.
396
460
  */
397
- on(event: EventName, handler: (payload: unknown) => void): void;
461
+ on<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
398
462
  /**
399
463
  * Unregister an event handler (safe to call after destruction).
400
464
  *
401
465
  * @param event - Event name.
402
466
  * @param handler - The previously registered callback.
403
467
  */
404
- off(event: EventName, handler: (payload: unknown) => void): void;
468
+ off<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
405
469
  /**
406
470
  * Destroy the instance: idempotent. Releases all Elements, unbinds the paymentResult listener,
407
471
  * rejects the pending confirm with INSTANCE_DESTROYED, sends the destroy command and destroys
@@ -422,6 +486,8 @@ declare class CheckoutInstance {
422
486
  private releaseElement;
423
487
  /** Handle the paymentResult event: fulfill the pending confirm by operationId; late/mismatched ones are ignored. */
424
488
  private handlePaymentResult;
489
+ /** Clear a pending confirm's watchdog timer (idempotent). */
490
+ private clearWatchdog;
425
491
  }
426
492
 
427
493
  /**
@@ -461,6 +527,12 @@ type TransportFactory = (args: {
461
527
  interface CreateCheckoutOptions {
462
528
  /** Checkout session id created by the backend (required). */
463
529
  sessionId: string;
530
+ /**
531
+ * Client secret of the session (required). Returned by the merchant backend's `create-session`
532
+ * call when `sessionType` is `embedded`. Hand it to the browser over an authenticated HTTPS
533
+ * response; never put it in a URL or write it to logs.
534
+ */
535
+ checkoutClientSecret: string;
464
536
  /** Runtime environment (dev/test/prod), defaults to prod. */
465
537
  env?: Env;
466
538
  /** Override the hosted origin (takes precedence over env). */
@@ -479,10 +551,15 @@ interface CreateCheckoutOptions {
479
551
  *
480
552
  * @param opts - Checkout parameters.
481
553
  * @returns A ready CheckoutInstance.
482
- * @throws reject RUNTIME_LOAD_FAILED (handshake timeout) / PROTOCOL_UNSUPPORTED (no common major
554
+ * @throws reject INVALID_OPTIONS (missing/blank/non-string checkoutClientSecret, before any iframe
555
+ * is created) / RUNTIME_LOAD_FAILED (handshake timeout) / PROTOCOL_UNSUPPORTED (no common major
483
556
  * version) / or the initialize business error.
484
557
  * @example
485
- * const checkout = await createCheckout({ sessionId: 'sess_x', env: 'prod' });
558
+ * const checkout = await createCheckout({
559
+ * sessionId: 'sess_x',
560
+ * checkoutClientSecret: 'ccs_x', // from your backend's create-session (sessionType: embedded)
561
+ * env: 'prod',
562
+ * });
486
563
  */
487
564
  declare function createCheckout(opts: CreateCheckoutOptions): Promise<CheckoutInstance>;
488
565
 
@@ -496,4 +573,4 @@ declare function createCheckout(opts: CreateCheckoutOptions): Promise<CheckoutIn
496
573
 
497
574
  declare const version: string;
498
575
 
499
- export { CheckoutElement, type CheckoutElementOptions, CheckoutInstance, type CheckoutInstanceOptions, type ConfirmOptions, type CreateCheckoutOptions, type ElementTransport, type Env, type InstanceTransport, type TransportFactory, createCheckout, version };
576
+ export { CheckoutElement, type CheckoutElementOptions, CheckoutInstance, type CheckoutInstanceOptions, type ConfirmOptions, type CreateCheckoutOptions, type ElementTransport, type Env, type InstanceTransport, type MountOptions, type TransportFactory, createCheckout, version };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ElementType, CommandName, EventName, ElementOptions, Appearance, ElementStatus, AvailableWallets, PublicSessionView, ConfirmReq, PaymentOutcome, GetPaymentStatusResp, PaymentMethodFilter } from '@sunbay/checkout-sdk-protocol';
2
- export { AddressElementOptions, AddressInfo, Appearance, CardElementOptions, CardFieldElementOptions, CheckoutError, CheckoutErrorCategory, ElementOptions, ElementStatus, ElementType, ErrorCode, ErrorCodeValue, ExpressCheckoutElementOptions, PaymentMethod, PaymentMethodFilter, PaymentOutcome, PublicPaymentMethod, PublicProductLine, PublicSessionView, TxnStatus } from '@sunbay/checkout-sdk-protocol';
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';
3
3
 
4
4
  /**
5
5
  * CheckoutElement — the merchant-side Element handle (spec 6).
@@ -74,6 +74,15 @@ interface CheckoutElementOptions {
74
74
  */
75
75
  appearance?: Appearance;
76
76
  }
77
+ /** Options for {@link CheckoutElement.mount}. */
78
+ interface MountOptions {
79
+ /**
80
+ * Maximum time (ms) to wait for the Element to become ready. Defaults to 30000. On expiry the
81
+ * iframe is removed, the status becomes `loadError` and the promise rejects with
82
+ * `RUNTIME_LOAD_FAILED`.
83
+ */
84
+ timeoutMs?: number;
85
+ }
77
86
  declare class CheckoutElement {
78
87
  /** Unique Element id. */
79
88
  readonly elementId: string;
@@ -97,6 +106,11 @@ declare class CheckoutElement {
97
106
  /** Event handlers temporarily subscribed during mount (unbound after resolve/reject). */
98
107
  private readyHandler;
99
108
  private loadErrorHandler;
109
+ /**
110
+ * Cancels the in-flight mount (clears its timer/listeners and rejects its promise). Null when no
111
+ * mount is in flight. Used by `unmount()` / `destroy()` while the Element is still loading.
112
+ */
113
+ private abortMount;
100
114
  /**
101
115
  * expressCheckout only: a snapshot of each wallet's availability.
102
116
  * Initially from elementReady.availableWallets, then updated by expressAvailabilityChange.
@@ -104,6 +118,8 @@ declare class CheckoutElement {
104
118
  private availableWallets;
105
119
  /** expressCheckout only: the persistently subscribed expressAvailabilityChange handler (unbound on destroy). */
106
120
  private availabilityHandler;
121
+ /** Merchant listeners registered via `on`: event → (original handler → transport wrapper). Cleared on destroy. */
122
+ private readonly userListeners;
107
123
  /**
108
124
  * iframe auto-height: the window 'message' listener that stays resident during mount (unbound
109
125
  * when the iframe disappears/is destroyed). Keeps a reference so removeEventListener can be
@@ -128,13 +144,22 @@ declare class CheckoutElement {
128
144
  /**
129
145
  * Mount at the merchant DOM target: insert a visible iframe, send createElement, await elementReady.
130
146
  *
147
+ * Failure modes: a hosted `loadError` / command failure rejects with that error; waiting longer
148
+ * than `opts.timeoutMs` (default 30000ms) removes the iframe and rejects `RUNTIME_LOAD_FAILED`;
149
+ * calling `unmount()` while loading rejects with `RUNTIME_LOAD_FAILED` ("mount cancelled");
150
+ * calling `destroy()` (or destroying the instance) while loading rejects `INSTANCE_DESTROYED`.
151
+ * A late `elementReady` after any of these is ignored and never flips the status to ready.
152
+ *
131
153
  * @param selectorOrEl - A CSS selector or an HTMLElement container; the container must be unique and empty.
154
+ * @param opts - Optional mount options (`timeoutMs`).
132
155
  * @returns Resolves after elementReady; on failure removes the node and rejects (loadError / INVALID_OPTIONS).
133
156
  * @throws INSTANCE_DESTROYED when already destroyed.
134
157
  * @example
135
- * await element.mount('#card-field');
158
+ * await element.mount('#card-field', { timeoutMs: 20000 });
136
159
  */
137
- mount(selectorOrEl: string | HTMLElement): Promise<void>;
160
+ mount(selectorOrEl: string | HTMLElement, opts?: MountOptions): Promise<void>;
161
+ /** Best-effort, fire-and-forget release of the hosted element registration; never throws. */
162
+ private releaseHostedElement;
138
163
  /**
139
164
  * Unmount: send destroyElement, remove the iframe; idempotent; keeps the handle and configuration.
140
165
  *
@@ -161,14 +186,14 @@ declare class CheckoutElement {
161
186
  * @param handler - Callback.
162
187
  * @throws INSTANCE_DESTROYED when already destroyed.
163
188
  */
164
- on(event: EventName, handler: (payload: unknown) => void): void;
189
+ on<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
165
190
  /**
166
191
  * Unregister an event handler (still safe to call after destruction).
167
192
  *
168
193
  * @param event - Event name.
169
194
  * @param handler - The previously registered callback.
170
195
  */
171
- off(event: EventName, handler: (payload: unknown) => void): void;
196
+ off<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
172
197
  /** Focus (input classes only, not provided by expressCheckout). */
173
198
  focus?: () => Promise<void>;
174
199
  /** Blur (input classes only, not provided by expressCheckout). */
@@ -191,7 +216,7 @@ declare class CheckoutElement {
191
216
  /** Resolve the mount container (the selector must uniquely match a single element). */
192
217
  private resolveContainer;
193
218
  /**
194
- * Resolve the iframe src: split fields go to /sdk/field/, the rest to /sdk/element/, with
219
+ * Resolve the iframe src: split fields go to /embed/sdk/field/, the rest to /embed/sdk/element/, with
195
220
  * checkoutId and elementId; if an initial colorScheme is provided, append `&colorScheme=<value>`
196
221
  * (no flash on the first frame); if the initial appearance contains variables or rules, append
197
222
  * `&appearance=<encodeURIComponent(JSON.stringify(appearance))>` (takes effect on the first
@@ -303,8 +328,23 @@ interface CheckoutInstanceOptions {
303
328
  */
304
329
  appearance?: Appearance;
305
330
  }
306
- /** Optional confirm parameters (aligned with ConfirmReq, minus the instance-generated operationId). */
307
- type ConfirmOptions = Omit<ConfirmReq, 'operationId'>;
331
+ /**
332
+ * Optional confirm parameters (aligned with ConfirmReq, minus the instance-generated operationId,
333
+ * plus two SDK-only options that are never sent to the runtime).
334
+ */
335
+ type ConfirmOptions = Omit<ConfirmReq, 'operationId'> & {
336
+ /**
337
+ * Called synchronously with the generated operationId, before the `confirm` command is sent.
338
+ * Lets the merchant persist the id early (e.g. to reconcile after a timeout or page reload).
339
+ */
340
+ onOperation?: (operationId: string) => void;
341
+ /**
342
+ * Per-call override of the result watchdog in milliseconds (default
343
+ * {@link CONFIRM_RESULT_DEADLINE_MS}). Must be a positive finite number, otherwise the default
344
+ * applies.
345
+ */
346
+ resultTimeoutMs?: number;
347
+ };
308
348
  declare class CheckoutInstance {
309
349
  /** Unique checkout id. */
310
350
  readonly checkoutId: string;
@@ -347,12 +387,36 @@ declare class CheckoutInstance {
347
387
  */
348
388
  create(type: ElementType, options?: ElementOptions): CheckoutElement;
349
389
  /**
350
- * Initiate a payment confirmation. Generates an operationId, sends the confirm command to obtain
351
- * accepted, and the returned Promise is fulfilled by a later paymentResult event with the same
352
- * operationId. Calling again while in progress → CHECKOUT_BUSY.
390
+ * Initiate a payment confirmation. Generates an operationId, sends the `confirm` command, and
391
+ * returns a Promise fulfilled by `paymentResult` events with the same operationId.
392
+ *
393
+ * Behavior changes in 0.0.7: previously the Promise resolved on the first `paymentResult`,
394
+ * including a non-final `pending` outcome. Now it resolves ONLY on a terminal outcome
395
+ * (`succeeded` | `failed` | `canceled`); a `pending` outcome keeps it waiting.
396
+ *
397
+ * Watchdog: if no terminal outcome arrives within `resultTimeoutMs` (default
398
+ * {@link CONFIRM_RESULT_DEADLINE_MS} = 120000ms) the Promise resolves
399
+ * `{ status: 'pending', operationId, txnId? }`. This is NOT a failure: the payment may still
400
+ * complete, so never treat it as failed and never retry blindly. Reconcile with
401
+ * `getPaymentStatus()` or the `paymentResult` event.
402
+ *
403
+ * Slot semantics (duplicate-submit protection): the confirm slot stays occupied until a
404
+ * terminal outcome arrives or `destroy()` is called. While it is occupied another `confirm()`
405
+ * rejects with `CHECKOUT_BUSY`; this also holds after the watchdog resolved `pending`, and later
406
+ * terminal outcomes are still delivered through `on('paymentResult', ...)`.
407
+ *
408
+ * If the `confirm` command is rejected by the runtime the payment was not started: the Promise
409
+ * rejects with that error and the slot is freed. If the command itself times out
410
+ * (`REQUEST_TIMEOUT`) the runtime may have started the payment: the Promise rejects with the
411
+ * error augmented with `paymentStateKnown: false`, the slot stays occupied and a later terminal
412
+ * `paymentResult` for this operation frees it. Do not retry; reconcile with `getPaymentStatus()`.
353
413
  *
354
- * @param opts - Optional parameters such as billing/shipping address, name, email, returnUrl.
355
- * @returns The terminal PaymentOutcome.
414
+ * `error` events with `paymentStateKnown === false` are informational and do not settle the
415
+ * Promise.
416
+ *
417
+ * @param opts - Optional billing/shipping address, name, email, returnUrl, plus `onOperation`
418
+ * and `resultTimeoutMs`.
419
+ * @returns The terminal PaymentOutcome, or `{ status: 'pending' }` when the watchdog fires.
356
420
  * @throws rejects INSTANCE_DESTROYED when destroyed; rejects CHECKOUT_BUSY when in progress.
357
421
  */
358
422
  confirm(opts?: ConfirmOptions): Promise<PaymentOutcome>;
@@ -394,14 +458,14 @@ declare class CheckoutInstance {
394
458
  * @param handler - Callback.
395
459
  * @throws INSTANCE_DESTROYED when destroyed.
396
460
  */
397
- on(event: EventName, handler: (payload: unknown) => void): void;
461
+ on<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
398
462
  /**
399
463
  * Unregister an event handler (safe to call after destruction).
400
464
  *
401
465
  * @param event - Event name.
402
466
  * @param handler - The previously registered callback.
403
467
  */
404
- off(event: EventName, handler: (payload: unknown) => void): void;
468
+ off<E extends EventName>(event: E, handler: (payload: EventPayloadMap[E]) => void): void;
405
469
  /**
406
470
  * Destroy the instance: idempotent. Releases all Elements, unbinds the paymentResult listener,
407
471
  * rejects the pending confirm with INSTANCE_DESTROYED, sends the destroy command and destroys
@@ -422,6 +486,8 @@ declare class CheckoutInstance {
422
486
  private releaseElement;
423
487
  /** Handle the paymentResult event: fulfill the pending confirm by operationId; late/mismatched ones are ignored. */
424
488
  private handlePaymentResult;
489
+ /** Clear a pending confirm's watchdog timer (idempotent). */
490
+ private clearWatchdog;
425
491
  }
426
492
 
427
493
  /**
@@ -461,6 +527,12 @@ type TransportFactory = (args: {
461
527
  interface CreateCheckoutOptions {
462
528
  /** Checkout session id created by the backend (required). */
463
529
  sessionId: string;
530
+ /**
531
+ * Client secret of the session (required). Returned by the merchant backend's `create-session`
532
+ * call when `sessionType` is `embedded`. Hand it to the browser over an authenticated HTTPS
533
+ * response; never put it in a URL or write it to logs.
534
+ */
535
+ checkoutClientSecret: string;
464
536
  /** Runtime environment (dev/test/prod), defaults to prod. */
465
537
  env?: Env;
466
538
  /** Override the hosted origin (takes precedence over env). */
@@ -479,10 +551,15 @@ interface CreateCheckoutOptions {
479
551
  *
480
552
  * @param opts - Checkout parameters.
481
553
  * @returns A ready CheckoutInstance.
482
- * @throws reject RUNTIME_LOAD_FAILED (handshake timeout) / PROTOCOL_UNSUPPORTED (no common major
554
+ * @throws reject INVALID_OPTIONS (missing/blank/non-string checkoutClientSecret, before any iframe
555
+ * is created) / RUNTIME_LOAD_FAILED (handshake timeout) / PROTOCOL_UNSUPPORTED (no common major
483
556
  * version) / or the initialize business error.
484
557
  * @example
485
- * const checkout = await createCheckout({ sessionId: 'sess_x', env: 'prod' });
558
+ * const checkout = await createCheckout({
559
+ * sessionId: 'sess_x',
560
+ * checkoutClientSecret: 'ccs_x', // from your backend's create-session (sessionType: embedded)
561
+ * env: 'prod',
562
+ * });
486
563
  */
487
564
  declare function createCheckout(opts: CreateCheckoutOptions): Promise<CheckoutInstance>;
488
565
 
@@ -496,4 +573,4 @@ declare function createCheckout(opts: CreateCheckoutOptions): Promise<CheckoutIn
496
573
 
497
574
  declare const version: string;
498
575
 
499
- export { CheckoutElement, type CheckoutElementOptions, CheckoutInstance, type CheckoutInstanceOptions, type ConfirmOptions, type CreateCheckoutOptions, type ElementTransport, type Env, type InstanceTransport, type TransportFactory, createCheckout, version };
576
+ export { CheckoutElement, type CheckoutElementOptions, CheckoutInstance, type CheckoutInstanceOptions, type ConfirmOptions, type CreateCheckoutOptions, type ElementTransport, type Env, type InstanceTransport, type MountOptions, type TransportFactory, createCheckout, version };