@flopay/js 1.3.4 → 1.4.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/dist/index.d.cts CHANGED
@@ -41,7 +41,10 @@ declare class FloPayElements {
41
41
  declare class FloPay {
42
42
  private readonly provider;
43
43
  private readonly config;
44
+ private readonly telemetryReporter?;
44
45
  private currentElements;
46
+ private readonly cardThreeDsStartedAt;
47
+ private now;
45
48
  constructor(provider: PaymentProviderAdapter, config: FloPayConfig);
46
49
  /**
47
50
  * Creates a new `FloPayElements` group for mounting payment fields.
@@ -58,6 +61,9 @@ declare class FloPay {
58
61
  createPaymentMethod(billingDetails?: _flopay_shared.BillingDetails): Promise<CreatePaymentMethodResult>;
59
62
  /** Confirm a card payment with a known client secret and payment method ID. */
60
63
  confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>;
64
+ private trackCardThreeDsAttempt;
65
+ private takeCardThreeDsAttempt;
66
+ private pruneExpiredCardThreeDsAttempts;
61
67
  /**
62
68
  * Create a {@link CardCaptureAdapter} for collecting card details through the
63
69
  * backend-rendered hosted vault PCI widget instead of provider-owned (Stripe)
@@ -126,9 +132,10 @@ declare class FloPay {
126
132
  * It initializes the underlying payment provider (currently Stripe)
127
133
  * and returns a ready-to-use `FloPay` instance.
128
134
  *
129
- * Instances are cached per `publishableKey`, so calling `loadFloPay` twice
130
- * with the same key returns the same instance. Different keys produce
131
- * independent instances that can run side-by-side.
135
+ * Instances are cached per complete behavior-affecting configuration.
136
+ * Matching calls return the same instance; calls with different billing API,
137
+ * telemetry, locale, API version, or appearance options receive independent
138
+ * instances.
132
139
  *
133
140
  * @example
134
141
  * ```ts
@@ -152,6 +159,8 @@ declare class StripeAdapter implements PaymentProviderAdapter {
152
159
  readonly name = "stripe";
153
160
  private stripe;
154
161
  private elements;
162
+ private readonly pendingCardThreeDsAttempts;
163
+ private cardThreeDsAttemptSequence;
155
164
  private appliedAppearanceKey;
156
165
  initialize(config: FloPayConfig): Promise<void>;
157
166
  /** Lazily creates the Stripe Elements group for the given options. */
@@ -163,6 +172,13 @@ declare class StripeAdapter implements PaymentProviderAdapter {
163
172
  }>;
164
173
  createPaymentMethod(billingDetails?: BillingDetails): Promise<CreatePaymentMethodResult>;
165
174
  confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>;
175
+ /**
176
+ * Bind provider-observed 3DS milestones to the exact confirmation context.
177
+ * The sensitive client secret/payment method pair stays only in this private,
178
+ * in-memory key; callers and telemetry receive an unrelated opaque id.
179
+ */
180
+ private withCardThreeDsLifecycle;
181
+ private pruneExpiredCardThreeDsAttempts;
166
182
  confirmPayment(params: ConfirmPaymentParams): Promise<PaymentResult>;
167
183
  private extractPaymentMethodId;
168
184
  confirmPayPalPayment(params: {
@@ -295,6 +311,10 @@ interface RawCheckoutSession {
295
311
  testEventCode?: string | null;
296
312
  };
297
313
  }
314
+ interface PaymentAPIOptions {
315
+ /** Flo-owned privacy-safe telemetry is enabled by default; set false to opt out. */
316
+ telemetry?: boolean;
317
+ }
298
318
  /**
299
319
  * Client-side payment API service.
300
320
  *
@@ -304,7 +324,17 @@ interface RawCheckoutSession {
304
324
  */
305
325
  declare class PaymentAPI {
306
326
  private readonly baseUrl;
307
- constructor(billingApiUrl: string);
327
+ private readonly directTelemetry?;
328
+ private readonly telemetryHooks?;
329
+ private directTelemetryCheckoutId?;
330
+ constructor(billingApiUrl: string, options?: PaymentAPIOptions);
331
+ /** Dispose the reporter owned by direct public usage. Internal hooks are never disposed here. */
332
+ destroy(): void;
333
+ private reportDirectFailure;
334
+ private telemetryTimestamp;
335
+ private beginDirectTelemetryCheckout;
336
+ private beginDirectTelemetryOperation;
337
+ private adoptDirectTelemetryCheckout;
308
338
  /**
309
339
  * Fetch a raw checkout session by ID.
310
340
  *
@@ -493,6 +523,7 @@ declare class PaymentAPI {
493
523
  * Falls back to create + GET if the backend doesn't support `expand`.
494
524
  */
495
525
  createAndFetchSession(params: InlineSessionDraft): Promise<NormalizedCheckoutSession>;
526
+ private createAndFetchSessionRequest;
496
527
  waitForCheckoutSessionCompletion(checkoutSessionId: string, options?: {
497
528
  initialDelayMs?: number;
498
529
  timeoutMs?: number;
@@ -544,6 +575,8 @@ interface PciVaultCardCaptureConfig {
544
575
  * same-window in the Model-A flow).
545
576
  */
546
577
  expectedOrigin?: string;
578
+ /** Flo-owned privacy-safe telemetry is enabled by default; set false to opt out. */
579
+ telemetry?: boolean;
547
580
  }
548
581
  /**
549
582
  * {@link CardCaptureAdapter} backed by the backend-rendered PCIVault hosted
@@ -557,6 +590,9 @@ interface PciVaultCardCaptureConfig {
557
590
  declare class PciVaultCardCapture implements CardCaptureAdapter {
558
591
  readonly provider: CardCaptureProviderId;
559
592
  private readonly config;
593
+ private telemetryReporter?;
594
+ private readonly ownsTelemetryReporter;
595
+ private readonly requestedAt?;
560
596
  private container;
561
597
  private messageHandler;
562
598
  /**
@@ -587,9 +623,14 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
587
623
  /** Latest card-field order + autofocus directive to push into the widget. */
588
624
  private cardFieldOrder;
589
625
  private cardAutoFocus;
626
+ private captureRequestedAt;
627
+ private vaultReadyReported;
628
+ private submissionStarted;
629
+ private submissionStartedAt;
590
630
  private readonly listeners;
591
631
  constructor(config?: PciVaultCardCaptureConfig);
592
632
  mount(container: HTMLElement, options: CardCaptureMountOptions): Promise<void>;
633
+ private reportVaultLoadFailure;
593
634
  on(event: CardCaptureEventType, handler: (event: CardCaptureOutcomeEvent) => void): () => void;
594
635
  unmount(): void;
595
636
  /**
@@ -600,6 +641,7 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
600
641
  */
601
642
  private injectWidget;
602
643
  private attachMessageListener;
644
+ private reportOutcome;
603
645
  /**
604
646
  * Push merchant theme colors into the hosted widget (live). The host calls
605
647
  * this on a runtime theme switch; the widget applies them to its CSS variables
@@ -648,6 +690,7 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
648
690
  * waiting for the eventual provider webhook.
649
691
  */
650
692
  private postActionCompleted;
693
+ private abandonActionRequiredOverlay;
651
694
  private hideActionRequiredOverlay;
652
695
  /**
653
696
  * Size the hosted-widget iframe to the height reported by the form inside it.
@@ -659,37 +702,6 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
659
702
  private applyHeight;
660
703
  }
661
704
 
662
- /**
663
- * Creates a checkout session via the billing API and redirects the user
664
- * to the hosted checkout page.
665
- *
666
- * Mirrors `createCheckoutSession` from `clicktech-core-ui/modules`.
667
- *
668
- * - On 201: Redirects to `{checkoutBaseUrl}/secure?id={uuid}&...redirectParams`
669
- * - On 204: Redirects directly to `successUrl` (payment method already on file)
670
- * - On other: Returns `{ status }` without redirecting
671
- *
672
- * @example
673
- * ```ts
674
- * import { createCheckoutSession } from '@flopay/js';
675
- *
676
- * await createCheckoutSession({
677
- * billingApiUrl: 'https://billing.example.com',
678
- * checkoutBaseUrl: 'https://checkout.example.com',
679
- * clientId: 'client_123',
680
- * currency: 'USD',
681
- * items: [{
682
- * code: 'initial_charge',
683
- * quantity: 1,
684
- * metadata: { source: 'web' },
685
- * }],
686
- * account: { userId: 'user_1', email: 'user@example.com' },
687
- * successUrl: '/success',
688
- * cancelUrl: '/cancel',
689
- * redirectParams: { email: 'user@example.com', bg: 'courses', mode: 'confirm' },
690
- * });
691
- * ```
692
- */
693
705
  declare function createCheckoutSession(options: CreateSessionParams): Promise<CheckoutSessionResult>;
694
706
  /**
695
707
  * Creates a checkout session with automatic retry on timeout/abort errors.
package/dist/index.d.ts CHANGED
@@ -41,7 +41,10 @@ declare class FloPayElements {
41
41
  declare class FloPay {
42
42
  private readonly provider;
43
43
  private readonly config;
44
+ private readonly telemetryReporter?;
44
45
  private currentElements;
46
+ private readonly cardThreeDsStartedAt;
47
+ private now;
45
48
  constructor(provider: PaymentProviderAdapter, config: FloPayConfig);
46
49
  /**
47
50
  * Creates a new `FloPayElements` group for mounting payment fields.
@@ -58,6 +61,9 @@ declare class FloPay {
58
61
  createPaymentMethod(billingDetails?: _flopay_shared.BillingDetails): Promise<CreatePaymentMethodResult>;
59
62
  /** Confirm a card payment with a known client secret and payment method ID. */
60
63
  confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>;
64
+ private trackCardThreeDsAttempt;
65
+ private takeCardThreeDsAttempt;
66
+ private pruneExpiredCardThreeDsAttempts;
61
67
  /**
62
68
  * Create a {@link CardCaptureAdapter} for collecting card details through the
63
69
  * backend-rendered hosted vault PCI widget instead of provider-owned (Stripe)
@@ -126,9 +132,10 @@ declare class FloPay {
126
132
  * It initializes the underlying payment provider (currently Stripe)
127
133
  * and returns a ready-to-use `FloPay` instance.
128
134
  *
129
- * Instances are cached per `publishableKey`, so calling `loadFloPay` twice
130
- * with the same key returns the same instance. Different keys produce
131
- * independent instances that can run side-by-side.
135
+ * Instances are cached per complete behavior-affecting configuration.
136
+ * Matching calls return the same instance; calls with different billing API,
137
+ * telemetry, locale, API version, or appearance options receive independent
138
+ * instances.
132
139
  *
133
140
  * @example
134
141
  * ```ts
@@ -152,6 +159,8 @@ declare class StripeAdapter implements PaymentProviderAdapter {
152
159
  readonly name = "stripe";
153
160
  private stripe;
154
161
  private elements;
162
+ private readonly pendingCardThreeDsAttempts;
163
+ private cardThreeDsAttemptSequence;
155
164
  private appliedAppearanceKey;
156
165
  initialize(config: FloPayConfig): Promise<void>;
157
166
  /** Lazily creates the Stripe Elements group for the given options. */
@@ -163,6 +172,13 @@ declare class StripeAdapter implements PaymentProviderAdapter {
163
172
  }>;
164
173
  createPaymentMethod(billingDetails?: BillingDetails): Promise<CreatePaymentMethodResult>;
165
174
  confirmCardPayment(params: ConfirmCardPaymentParams): Promise<ConfirmCardPaymentResult>;
175
+ /**
176
+ * Bind provider-observed 3DS milestones to the exact confirmation context.
177
+ * The sensitive client secret/payment method pair stays only in this private,
178
+ * in-memory key; callers and telemetry receive an unrelated opaque id.
179
+ */
180
+ private withCardThreeDsLifecycle;
181
+ private pruneExpiredCardThreeDsAttempts;
166
182
  confirmPayment(params: ConfirmPaymentParams): Promise<PaymentResult>;
167
183
  private extractPaymentMethodId;
168
184
  confirmPayPalPayment(params: {
@@ -295,6 +311,10 @@ interface RawCheckoutSession {
295
311
  testEventCode?: string | null;
296
312
  };
297
313
  }
314
+ interface PaymentAPIOptions {
315
+ /** Flo-owned privacy-safe telemetry is enabled by default; set false to opt out. */
316
+ telemetry?: boolean;
317
+ }
298
318
  /**
299
319
  * Client-side payment API service.
300
320
  *
@@ -304,7 +324,17 @@ interface RawCheckoutSession {
304
324
  */
305
325
  declare class PaymentAPI {
306
326
  private readonly baseUrl;
307
- constructor(billingApiUrl: string);
327
+ private readonly directTelemetry?;
328
+ private readonly telemetryHooks?;
329
+ private directTelemetryCheckoutId?;
330
+ constructor(billingApiUrl: string, options?: PaymentAPIOptions);
331
+ /** Dispose the reporter owned by direct public usage. Internal hooks are never disposed here. */
332
+ destroy(): void;
333
+ private reportDirectFailure;
334
+ private telemetryTimestamp;
335
+ private beginDirectTelemetryCheckout;
336
+ private beginDirectTelemetryOperation;
337
+ private adoptDirectTelemetryCheckout;
308
338
  /**
309
339
  * Fetch a raw checkout session by ID.
310
340
  *
@@ -493,6 +523,7 @@ declare class PaymentAPI {
493
523
  * Falls back to create + GET if the backend doesn't support `expand`.
494
524
  */
495
525
  createAndFetchSession(params: InlineSessionDraft): Promise<NormalizedCheckoutSession>;
526
+ private createAndFetchSessionRequest;
496
527
  waitForCheckoutSessionCompletion(checkoutSessionId: string, options?: {
497
528
  initialDelayMs?: number;
498
529
  timeoutMs?: number;
@@ -544,6 +575,8 @@ interface PciVaultCardCaptureConfig {
544
575
  * same-window in the Model-A flow).
545
576
  */
546
577
  expectedOrigin?: string;
578
+ /** Flo-owned privacy-safe telemetry is enabled by default; set false to opt out. */
579
+ telemetry?: boolean;
547
580
  }
548
581
  /**
549
582
  * {@link CardCaptureAdapter} backed by the backend-rendered PCIVault hosted
@@ -557,6 +590,9 @@ interface PciVaultCardCaptureConfig {
557
590
  declare class PciVaultCardCapture implements CardCaptureAdapter {
558
591
  readonly provider: CardCaptureProviderId;
559
592
  private readonly config;
593
+ private telemetryReporter?;
594
+ private readonly ownsTelemetryReporter;
595
+ private readonly requestedAt?;
560
596
  private container;
561
597
  private messageHandler;
562
598
  /**
@@ -587,9 +623,14 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
587
623
  /** Latest card-field order + autofocus directive to push into the widget. */
588
624
  private cardFieldOrder;
589
625
  private cardAutoFocus;
626
+ private captureRequestedAt;
627
+ private vaultReadyReported;
628
+ private submissionStarted;
629
+ private submissionStartedAt;
590
630
  private readonly listeners;
591
631
  constructor(config?: PciVaultCardCaptureConfig);
592
632
  mount(container: HTMLElement, options: CardCaptureMountOptions): Promise<void>;
633
+ private reportVaultLoadFailure;
593
634
  on(event: CardCaptureEventType, handler: (event: CardCaptureOutcomeEvent) => void): () => void;
594
635
  unmount(): void;
595
636
  /**
@@ -600,6 +641,7 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
600
641
  */
601
642
  private injectWidget;
602
643
  private attachMessageListener;
644
+ private reportOutcome;
603
645
  /**
604
646
  * Push merchant theme colors into the hosted widget (live). The host calls
605
647
  * this on a runtime theme switch; the widget applies them to its CSS variables
@@ -648,6 +690,7 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
648
690
  * waiting for the eventual provider webhook.
649
691
  */
650
692
  private postActionCompleted;
693
+ private abandonActionRequiredOverlay;
651
694
  private hideActionRequiredOverlay;
652
695
  /**
653
696
  * Size the hosted-widget iframe to the height reported by the form inside it.
@@ -659,37 +702,6 @@ declare class PciVaultCardCapture implements CardCaptureAdapter {
659
702
  private applyHeight;
660
703
  }
661
704
 
662
- /**
663
- * Creates a checkout session via the billing API and redirects the user
664
- * to the hosted checkout page.
665
- *
666
- * Mirrors `createCheckoutSession` from `clicktech-core-ui/modules`.
667
- *
668
- * - On 201: Redirects to `{checkoutBaseUrl}/secure?id={uuid}&...redirectParams`
669
- * - On 204: Redirects directly to `successUrl` (payment method already on file)
670
- * - On other: Returns `{ status }` without redirecting
671
- *
672
- * @example
673
- * ```ts
674
- * import { createCheckoutSession } from '@flopay/js';
675
- *
676
- * await createCheckoutSession({
677
- * billingApiUrl: 'https://billing.example.com',
678
- * checkoutBaseUrl: 'https://checkout.example.com',
679
- * clientId: 'client_123',
680
- * currency: 'USD',
681
- * items: [{
682
- * code: 'initial_charge',
683
- * quantity: 1,
684
- * metadata: { source: 'web' },
685
- * }],
686
- * account: { userId: 'user_1', email: 'user@example.com' },
687
- * successUrl: '/success',
688
- * cancelUrl: '/cancel',
689
- * redirectParams: { email: 'user@example.com', bg: 'courses', mode: 'confirm' },
690
- * });
691
- * ```
692
- */
693
705
  declare function createCheckoutSession(options: CreateSessionParams): Promise<CheckoutSessionResult>;
694
706
  /**
695
707
  * Creates a checkout session with automatic retry on timeout/abort errors.