@primer-io/primer-js 1.4.3 → 1.5.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.
@@ -440,6 +440,41 @@ export interface GooglePayClientOptions {
440
440
  */
441
441
  buttonBorderType?: GooglePayButtonBorderType;
442
442
  }
443
+ export interface ThreeDSAuthenticationData {
444
+ responseCode: "AUTH_SUCCESS" | "AUTH_FAILED" | "SKIPPED" | "CHALLENGE";
445
+ reasonCode?: string;
446
+ reasonText?: string;
447
+ protocolVersion: string;
448
+ challengeIssued: boolean;
449
+ }
450
+ export interface IPaymentMethodToken<T, U extends PaymentInstrumentType$1 = PaymentInstrumentType$1> {
451
+ token: string;
452
+ analyticsId: string;
453
+ tokenType: "SINGLE_USE" | "MULTI_USE";
454
+ paymentInstrumentData: T;
455
+ paymentInstrumentType: U;
456
+ threeDSecureAuthentication: ThreeDSAuthenticationData | null;
457
+ vaultData: {
458
+ customerId: string;
459
+ } | null;
460
+ }
461
+ export type PaymentCardToken = IPaymentMethodToken<{
462
+ last4Digits: string;
463
+ cardholderName: string;
464
+ network: string;
465
+ }, typeof PaymentInstrumentType$1.CARD>;
466
+ export interface UnmanagedPaymentToken {
467
+ token: string;
468
+ analyticsId: string;
469
+ tokenType: "SINGLE_USE" | "MULTI_USE";
470
+ paymentInstrumentType: string;
471
+ paymentInstrumentData: Record<string, unknown>;
472
+ vaultData: {
473
+ customerId: string;
474
+ } | null;
475
+ threeDSecureAuthentication: null;
476
+ }
477
+ export type PaymentMethodToken = PaymentCardToken | UnmanagedPaymentToken;
443
478
  /**
444
479
  * Minimal payment summary with reduced PII exposure.
445
480
  * Used in events for public data delivery.
@@ -564,6 +599,18 @@ export interface GenericVaultedPaymentMethodSummary extends BaseVaultedPaymentMe
564
599
  * Use the paymentInstrumentType field to narrow to specific types.
565
600
  */
566
601
  export type VaultedPaymentMethodSummary = CardVaultedPaymentMethodSummary | PayPalVaultedPaymentMethodSummary | KlarnaVaultedPaymentMethodSummary | ACHVaultedPaymentMethodSummary | GenericVaultedPaymentMethodSummary;
602
+ /**
603
+ * Data surfaced to the merchant when a MANUAL-approval `:pay` creates an
604
+ * attempt awaiting approval. The merchant sends clientSessionId +
605
+ * paymentAttemptId to its backend (which calls /approve or /abort), then calls
606
+ * continueFlow() to resume the SDK.
607
+ */
608
+ export interface PaymentApprovalRequiredData {
609
+ clientSessionId: string;
610
+ paymentAttemptId: string;
611
+ paymentMethodToken: PaymentMethodToken;
612
+ continueFlow: () => Promise<void>;
613
+ }
567
614
  export type APIVersionOption = "legacy" | "2.4";
568
615
  declare enum HeadlessManagerType {
569
616
  CARD = "CARD",
@@ -868,7 +915,7 @@ export interface IVaultedPaymentMethod<B extends BasePaymentInstrumentData = Bas
868
915
  paymentInstrumentData: B;
869
916
  paymentInstrumentType: I;
870
917
  paymentMethodType: T;
871
- threeDSecureAuthentication?: ThreeDSAuthenticationData | null;
918
+ threeDSecureAuthentication?: ThreeDSAuthenticationData$1 | null;
872
919
  vaultData?: VaultData | null;
873
920
  userDescription?: string;
874
921
  isVaulted?: boolean;
@@ -1214,7 +1261,7 @@ export interface CheckoutStyle {
1214
1261
  processingIndicator?: Record<string, unknown>;
1215
1262
  focusCheckoutOnInit?: boolean;
1216
1263
  }
1217
- export interface ThreeDSAuthenticationData {
1264
+ interface ThreeDSAuthenticationData$1 {
1218
1265
  responseCode: "AUTH_SUCCESS" | "AUTH_FAILED" | "SKIPPED" | "CHALLENGE";
1219
1266
  reasonCode?: string;
1220
1267
  reasonText?: string;
@@ -1316,6 +1363,12 @@ export interface HeadlessUniversalCheckoutOptions {
1316
1363
  };
1317
1364
  } & Record<string, unknown>;
1318
1365
  onAvailablePaymentMethodsLoad: (paymentMethods: PaymentMethodInfo[]) => void;
1366
+ /**
1367
+ * Fires after each successful `refreshClientSession` when the available
1368
+ * payment methods changed as a result of the backend re-evaluating
1369
+ * visibility rules against the updated client session metadata.
1370
+ */
1371
+ onAvailablePaymentMethodsRefresh?: (paymentMethods: PaymentMethodInfo[]) => void;
1319
1372
  clientSessionCachingEnabled?: boolean;
1320
1373
  apiVersion?: APIVersionOption;
1321
1374
  onCheckoutComplete?: (data: {
@@ -1335,6 +1388,7 @@ export interface HeadlessUniversalCheckoutOptions {
1335
1388
  abortPaymentCreation: () => void;
1336
1389
  }) => void;
1337
1390
  onPaymentCreationStart?: () => void;
1391
+ onPaymentApprovalRequired?: (data: PaymentApprovalRequiredData) => void;
1338
1392
  onPaymentMethodAction?: (data: "PAYMENT_METHOD_SELECTED" | "PAYMENT_METHOD_UNSELECTED", handler: {
1339
1393
  payment?: Payment;
1340
1394
  paymentMethodType: PaymentMethodType | null;
@@ -1346,7 +1400,7 @@ export interface HeadlessUniversalCheckoutOptions {
1346
1400
  }) => boolean | Promise<boolean>;
1347
1401
  onTokenizeDidNotStart?: (reason: string) => void;
1348
1402
  onTokenizeStart?: () => void;
1349
- onTokenizeSuccess?: (data: PaymentMethodToken, handler: {
1403
+ onTokenizeSuccess?: (data: PaymentMethodToken$1, handler: {
1350
1404
  handleSuccess(): unknown;
1351
1405
  handleFailure(errorMessage?: string): unknown;
1352
1406
  continueWithNewClientToken(clientToken: string): unknown;
@@ -1368,13 +1422,13 @@ export interface HeadlessUniversalCheckoutOptions {
1368
1422
  }) => void;
1369
1423
  onResumeError?: (error: PrimerClientError) => void;
1370
1424
  }
1371
- export interface PaymentMethodToken {
1425
+ interface PaymentMethodToken$1 {
1372
1426
  token: string;
1373
1427
  analyticsId: string;
1374
1428
  tokenType: "SINGLE_USE" | "MULTI_USE";
1375
1429
  paymentInstrumentData: BasePaymentInstrumentData;
1376
1430
  paymentInstrumentType: PaymentInstrumentType;
1377
- threeDSecureAuthentication: ThreeDSAuthenticationData | null;
1431
+ threeDSecureAuthentication: ThreeDSAuthenticationData$1 | null;
1378
1432
  vaultData: VaultData | null;
1379
1433
  }
1380
1434
  export interface ApplePayOptions {
@@ -2066,6 +2120,16 @@ export type CardNetworksContextType = {
2066
2120
  export type SdkState = {
2067
2121
  isSuccessful: boolean;
2068
2122
  isProcessing: boolean;
2123
+ /**
2124
+ * MANUAL approval-mode flag: a `:pay` attempt has been created and is
2125
+ * awaiting merchant approval (202 response). Drives the loading UI while
2126
+ * the merchant approves/aborts. Distinct from `isProcessing` ("a payment is
2127
+ * being created/processed") because the downstream locking and continueFlow
2128
+ * functionalities need to tell the two phases apart.
2129
+ * Exactly one of `isProcessing` / `isAwaitingApproval` is true at a time.
2130
+ * Exited by continueFlow()/safety polling.
2131
+ */
2132
+ isAwaitingApproval: boolean;
2069
2133
  /**
2070
2134
  * SDK/component initialization errors.
2071
2135
  * This represents errors from the Primer JS layer itself (e.g., configuration errors,
@@ -2320,6 +2384,7 @@ export declare class PrimerJS {
2320
2384
  private headlessInstance;
2321
2385
  private paymentMethods;
2322
2386
  private vaultController;
2387
+ private isPaymentInProgress;
2323
2388
  /**
2324
2389
  * Vault namespace providing programmatic access to vaulted payment method operations.
2325
2390
  * Use for building custom vault UIs with headless flows.
@@ -2440,6 +2505,13 @@ export declare class PrimerJS {
2440
2505
  * @internal
2441
2506
  */
2442
2507
  setVaultController(controller: VaultManagerController | null): void;
2508
+ /**
2509
+ * Internal method to wire the payment-in-progress check.
2510
+ * Called during initialization so `refreshSession()` can guard against
2511
+ * running while a payment is in flight.
2512
+ * @internal
2513
+ */
2514
+ setPaymentInProgressCheck(check: () => boolean): void;
2443
2515
  /**
2444
2516
  * Internal implementation of createCvvInput.
2445
2517
  * @internal
@@ -2481,12 +2553,25 @@ export declare class PrimerJS {
2481
2553
  }): Promise<void>;
2482
2554
  /**
2483
2555
  * Refetches a new client session from merchant backend.
2556
+ *
2557
+ * No-op if a payment is currently in progress: refreshing mid-flow could
2558
+ * re-evaluate visibility rules and yank the in-use payment method out from
2559
+ * under the user. A `[PRIMER]` warning is logged (visible to integrators in
2560
+ * the console) so the no-op is observable during local development — e.g.
2561
+ * if `refreshSession()` is called from a `primer:payment-start` handler.
2484
2562
  */
2485
2563
  refreshSession(): Promise<void>;
2486
2564
  /**
2487
2565
  * Returns the cached list of payment methods.
2488
2566
  */
2489
2567
  getPaymentMethods(): PaymentMethodInfo[];
2568
+ /**
2569
+ * Internal accessor that returns the initialized payment methods (with their
2570
+ * managers), used by the refresh path to preserve manager identity across
2571
+ * client-session refreshes.
2572
+ * @internal
2573
+ */
2574
+ getInitializedPaymentMethods(): InitializedPaymentMethod[];
2490
2575
  /**
2491
2576
  * Internal method to handle the onPaymentStart callback
2492
2577
  * @internal - This is only used internally by the SDK
@@ -2585,6 +2670,9 @@ export interface PrimerEvents {
2585
2670
  paymentMethodType: PaymentMethodType | null;
2586
2671
  timestamp: number;
2587
2672
  }>;
2673
+ "primer:payment-approval-required": CustomEvent<PaymentApprovalRequiredData & {
2674
+ timestamp: number;
2675
+ }>;
2588
2676
  "primer:vault-methods-update": CustomEvent<{
2589
2677
  vaultedPayments: VaultedPaymentMethodSummary[];
2590
2678
  cvvRecapture: boolean;
@@ -2656,6 +2744,14 @@ declare class PrimerEventsController {
2656
2744
  diagnosticsId?: string;
2657
2745
  data?: Record<string, unknown>;
2658
2746
  }, paymentMethodType: PaymentMethodType | undefined, payment?: Payment): void;
2747
+ /**
2748
+ * Dispatch payment approval required event (MANUAL approval flow).
2749
+ * Called when `:pay` returns 202 and the attempt awaits merchant approval.
2750
+ *
2751
+ * The detail carries clientSessionId + paymentAttemptId for the merchant's
2752
+ * backend to call /approve or /abort, and continueFlow() to resume the SDK.
2753
+ */
2754
+ dispatchPaymentApprovalRequired(detail: PaymentApprovalRequiredData): void;
2659
2755
  /**
2660
2756
  * Dispatch vault methods update event.
2661
2757
  * Called when vaulted payment methods are loaded or updated.
@@ -2830,6 +2926,14 @@ declare class HeadlessSdkController implements ReactiveController {
2830
2926
  private clearLoadingTimeout;
2831
2927
  private cleanupResources;
2832
2928
  private _loadV2Sdk;
2929
+ /**
2930
+ * MANUAL approval flow: on a `:pay` 202, sdk-core invokes this. Enter the
2931
+ * awaiting-approval state (so the checkout shows its loading UI while the
2932
+ * merchant approves/aborts), then surface the approval request to the
2933
+ * merchant. State is set BEFORE dispatching so listeners that synchronously
2934
+ * read state see `isAwaitingApproval: true`.
2935
+ */
2936
+ private handlePaymentApprovalRequired;
2833
2937
  initializeHeadless(): ([clientToken, options]: readonly [
2834
2938
  string | null,
2835
2939
  PrimerCheckoutOptions | null
@@ -2841,6 +2945,8 @@ declare class HeadlessSdkController implements ReactiveController {
2841
2945
  * @param cardNetworks - The new card networks context
2842
2946
  */
2843
2947
  private updateCardNetworksState;
2948
+ get isProcessing(): boolean;
2949
+ private onMethodsRefreshed;
2844
2950
  }
2845
2951
  /**
2846
2952
  * PrimerCheckoutComponent implements the main checkout experience.