@funnelfox/billing 0.13.1 → 0.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelfox/billing",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "license": "MIT",
5
5
  "author": "Funnelfox",
6
6
  "description": "JavaScript SDK for Funnelfox billing with Primer integration",
@@ -26,7 +26,7 @@
26
26
  "scripts": {
27
27
  "build": "rm -rf dist && rollup -c",
28
28
  "build:watch": "rollup -c -w",
29
- "build:examples": "npm run build && npm pack && npm i ./funnelfox-billing-0.13.1.tgz --prefix examples/basic && npm run build --prefix examples/basic",
29
+ "build:examples": "npm run build && npm pack && npm i ./funnelfox-billing-0.14.0.tgz --prefix examples/basic && npm run build --prefix examples/basic",
30
30
  "version": "node scripts/sync-version.js",
31
31
  "release:patch": "npm version patch --no-git-tag-version",
32
32
  "release:minor": "npm version minor --no-git-tag-version",
package/src/types.d.ts CHANGED
@@ -308,17 +308,19 @@ export interface PrimerHandler {
308
308
  }
309
309
 
310
310
  // Error types
311
- export interface FunnefoxSDKError extends Error {
311
+ export declare class FunnefoxSDKError extends Error {
312
312
  code: string;
313
313
  details: unknown;
314
+ constructor(message: string, code?: string, details?: unknown);
314
315
  }
315
316
 
316
- export interface ValidationError extends FunnefoxSDKError {
317
+ export declare class ValidationError extends FunnefoxSDKError {
317
318
  field: string;
318
319
  value: unknown;
320
+ constructor(field: string, message: string, value?: unknown);
319
321
  }
320
322
 
321
- export interface APIError extends FunnefoxSDKError {
323
+ export declare class APIError extends FunnefoxSDKError {
322
324
  statusCode: number | null;
323
325
  errorCode: string | null;
324
326
  errorType: string | null;
@@ -326,21 +328,37 @@ export interface APIError extends FunnefoxSDKError {
326
328
  response: unknown;
327
329
  declineCode: string | null;
328
330
  declineCodeSource: DeclineCodeSource | null;
331
+ constructor(
332
+ message: string,
333
+ statusCode?: number | null,
334
+ options?: {
335
+ errorCode?: string | null;
336
+ errorType?: string | null;
337
+ requestId?: string | null;
338
+ response?: unknown;
339
+ declineCode?: string | null;
340
+ declineCodeSource?: DeclineCodeSource | null;
341
+ }
342
+ );
329
343
  }
330
344
 
331
- export interface PrimerError extends FunnefoxSDKError {
345
+ export declare class PrimerError extends FunnefoxSDKError {
332
346
  primerError: unknown;
347
+ constructor(message: string, primerError?: unknown);
333
348
  }
334
349
 
335
- export interface CheckoutError extends FunnefoxSDKError {
350
+ export declare class CheckoutError extends FunnefoxSDKError {
336
351
  phase: string | null;
352
+ constructor(message: string, phase?: string | null);
337
353
  }
338
354
 
339
- //eslint-disable-next-line @typescript-eslint/no-empty-object-type
340
- export interface ConfigurationError extends FunnefoxSDKError {}
355
+ export declare class ConfigurationError extends FunnefoxSDKError {
356
+ constructor(message: string);
357
+ }
341
358
 
342
- export interface NetworkError extends FunnefoxSDKError {
359
+ export declare class NetworkError extends FunnefoxSDKError {
343
360
  originalError: unknown;
361
+ constructor(message: string, originalError?: unknown);
344
362
  }
345
363
 
346
364
  // Function signatures
@@ -466,7 +484,10 @@ export interface SilentPurchaseOptions {
466
484
  initiationType?: 'cit' | 'mit';
467
485
  /** CIT card networks (sent only when set). `[]` = all networks. */
468
486
  citCardNetworks?: string[];
469
- /** Allow CIT for PAN_ONLY Google Pay (sent only when set). */
487
+ /**
488
+ * @deprecated Not sent any more: a saved Google Pay token is never charged as CIT, and the
489
+ * backend ignores the field. Wallet buyers confirm the upsell again with `mountWalletUpsell`.
490
+ */
470
491
  citGooglePayPanOnly?: boolean;
471
492
  }
472
493
 
@@ -477,17 +498,19 @@ export interface SilentPurchaseDetailedOptions extends SilentPurchaseOptions {
477
498
  /** Opt-in: run 3DS when the bank asks for it and resolve with a detailed result. */
478
499
  handle3DS: true;
479
500
  /**
480
- * Fired once when the one-click response carries a non-empty `action_required_token`,
481
- * before the challenge (keep the upsell button disabled until the promise resolves).
501
+ * Fired once when the 3DS window becomes visible to the customer (keep the upsell button
502
+ * disabled until the promise resolves). Primer cannot tell a frictionless check from a
503
+ * challenge, so the window stays hidden for the first 6 s of the 3DS step; a check that
504
+ * finishes within that time fires no hooks.
482
505
  */
483
506
  onThreeDSStart?: (info: { orderId: string }) => void;
484
507
  /** Fired exactly once per `onThreeDSStart`, after the 3DS step and before the promise resolves. */
485
508
  onThreeDSEnd?: (info: { result: ThreeDSResult }) => void;
486
509
  /**
487
- * Give up on the 3DS step after this many ms. Default 600000. Resolves `3ds_abandoned` if the
488
- * challenge was shown; `error` if it ran out before the challenge was shown (with
489
- * `failedRequest: 'create_client_session'` while that request was pending). Never aborts a
490
- * request that is already sent.
510
+ * Give up on the 3DS step after this many ms. Default 600000. Once the 3DS window is due, the
511
+ * count restarts when it is shown and ends in `3ds_abandoned`. Runs out before that as `error`
512
+ * (with `failedRequest: 'create_client_session'` while that request was pending). Never aborts
513
+ * a request that is already sent.
491
514
  */
492
515
  threeDSTimeoutMs?: number;
493
516
  }
@@ -509,9 +532,12 @@ export type OneClickFailedRequest =
509
532
 
510
533
  export interface OneClickResult {
511
534
  outcome: OneClickOutcome;
512
- /** `null` only when no order was created (error before/at one_click). */
535
+ /**
536
+ * `null` when no order is known: an error before or at one_click, or `processing` after
537
+ * `one_click` retries ran out (`error` and `failedRequest` are set then).
538
+ */
513
539
  orderId: string | null;
514
- /** The backend returned a non-empty `action_required_token`. */
540
+ /** The 3DS window was shown to the customer (`onThreeDSStart` fired). */
515
541
  threeDSChallenged: boolean;
516
542
  failedMessageForUser?: string | null;
517
543
  declineCode?: string | null;
@@ -525,6 +551,71 @@ export interface OneClickResult {
525
551
  failedRequest?: OneClickFailedRequest;
526
552
  }
527
553
 
554
+ export type WalletKind = 'APPLE_PAY' | 'GOOGLE_PAY';
555
+
556
+ export interface MountWalletUpsellOptions {
557
+ orgId: string;
558
+ priceId: string;
559
+ externalId: string;
560
+ clientMetadata?: Record<string, unknown>;
561
+ /** Default: the `configure()` value, else https://billing.funnelfox.com. */
562
+ baseUrl?: string;
563
+ style?: {
564
+ /** Default `plain`. A type the wallet does not have falls back to `plain`. */
565
+ buttonType?: 'plain' | 'buy' | 'pay' | 'continue';
566
+ /** Default `black`. Google Pay shows `white-outline` as `white`. */
567
+ buttonColor?: 'black' | 'white' | 'white-outline';
568
+ /** px, default 54. */
569
+ height?: number;
570
+ /** px, default 28. */
571
+ borderRadius?: number;
572
+ };
573
+ /** The customer tapped the button and the wallet sheet opens. */
574
+ onStart?: () => void;
575
+ /** Fired once when the 3DS window becomes visible, as in `silentPurchase({ handle3DS: true })`. */
576
+ onThreeDSStart?: (info: { orderId: string }) => void;
577
+ /** Fired exactly once per `onThreeDSStart`, before `onResult`. */
578
+ onThreeDSEnd?: (info: { result: ThreeDSResult }) => void;
579
+ /**
580
+ * Called exactly once per attempt. After `cancelled` the button stays active and can be
581
+ * tapped again; after any other outcome it is disabled for good.
582
+ */
583
+ onResult: (result: WalletUpsellResult) => void;
584
+ }
585
+
586
+ export type WalletUpsellMount =
587
+ | {
588
+ mounted: true;
589
+ wallet: WalletKind;
590
+ setDisabled(disabled: boolean): void;
591
+ destroy(): void;
592
+ }
593
+ /** The customer's saved method is not a Primer wallet: use `silentPurchase`. */
594
+ | { mounted: false; reason: 'not_wallet' }
595
+ /** This device cannot show the customer's wallet. */
596
+ | { mounted: false; reason: 'wallet_unavailable'; wallet: WalletKind }
597
+ | { mounted: false; reason: 'error'; error: Error };
598
+
599
+ /**
600
+ * `cancelled`: the customer closed the wallet sheet and nothing was charged. The other outcomes
601
+ * mean what they mean for `silentPurchase({ handle3DS: true })`.
602
+ */
603
+ export type WalletUpsellResult = Omit<OneClickResult, 'outcome'> & {
604
+ outcome: OneClickOutcome | 'cancelled';
605
+ };
606
+
607
+ /**
608
+ * One-click upsell confirmed in the Apple Pay / Google Pay sheet (wallet re-authentication):
609
+ * call when the upsell screen loads, not on tap. Mounts Primer's native wallet button into
610
+ * `container` for a customer whose saved method is a Primer wallet; the upsell is then charged
611
+ * with the fresh wallet token as a customer-initiated payment. Rejects only with
612
+ * `ValidationError`; with `mounted: false` nothing is left in `container`.
613
+ */
614
+ export declare function mountWalletUpsell(
615
+ container: HTMLElement,
616
+ options: MountWalletUpsellOptions
617
+ ): Promise<WalletUpsellMount>;
618
+
528
619
  /**
529
620
  * One-click purchase with the customer's saved payment method.
530
621
  * Legacy mode (no `handle3DS`): resolves `true` for any 2xx `status: 'success'` response
@@ -607,6 +698,7 @@ export declare const Billing: {
607
698
  createClientSession: typeof createClientSession;
608
699
  initMethod: typeof initMethod;
609
700
  silentPurchase: typeof silentPurchase;
701
+ mountWalletUpsell: typeof mountWalletUpsell;
610
702
  getAvailablePaymentMethods: typeof getAvailablePaymentMethods;
611
703
  stripe: {
612
704
  createCardForm: typeof createStripeCardForm;
@@ -744,6 +836,8 @@ export interface PaymentResponseData {
744
836
  decline_code?: string | null;
745
837
  decline_code_source?: DeclineCodeSource | null;
746
838
  order_id: string;
839
+ /** `one_click` only: the idempotency key was seen before, nothing new was charged. */
840
+ idempotent_replay?: boolean;
747
841
  }
748
842
 
749
843
  export interface CreatePaymentResponse {
@@ -811,5 +905,21 @@ export interface OneClickRequest {
811
905
  client_metadata: Record<string, string | number | boolean>;
812
906
  initiation_type?: 'cit' | 'mit';
813
907
  cit_card_networks?: string[];
814
- cit_google_pay_pan_only?: boolean;
908
+ idempotency_key?: string;
909
+ /** Wallet re-auth: the single-use token of the confirmed wallet sheet, with `session_id`. */
910
+ payment_method_token?: string;
911
+ session_id?: string;
912
+ }
913
+
914
+ export interface OneClickWalletSessionData {
915
+ wallet: WalletKind | null;
916
+ reason?: string | null;
917
+ client_token?: string | null;
918
+ session_id?: string | null;
919
+ order_id?: string | null;
920
+ /** Minor units, tax included when collected. */
921
+ amount?: number | null;
922
+ currency?: string | null;
923
+ /** UTC ISO. */
924
+ expires_at?: string | null;
815
925
  }