@flopay/js 1.3.1 → 1.3.2

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
@@ -432,6 +432,9 @@ declare class PaymentAPI {
432
432
  };
433
433
  avsCheck?: boolean;
434
434
  avsConfig?: Record<string, unknown>;
435
+ }, options?: {
436
+ signal?: AbortSignal;
437
+ timeoutMs?: number;
435
438
  }): Promise<void>;
436
439
  /**
437
440
  * Create a PaymentIntent on the backend.
package/dist/index.d.ts CHANGED
@@ -432,6 +432,9 @@ declare class PaymentAPI {
432
432
  };
433
433
  avsCheck?: boolean;
434
434
  avsConfig?: Record<string, unknown>;
435
+ }, options?: {
436
+ signal?: AbortSignal;
437
+ timeoutMs?: number;
435
438
  }): Promise<void>;
436
439
  /**
437
440
  * Create a PaymentIntent on the backend.
package/dist/index.mjs CHANGED
@@ -593,6 +593,7 @@ var DEFAULT_PROCESSING_RETRY_AFTER_MS = 1e3;
593
593
  var MIN_PROCESSING_RETRY_AFTER_MS = 500;
594
594
  var DEFAULT_PROCESSING_TIMEOUT_MS = 15e3;
595
595
  var MAX_PROCESSING_RETRY_AFTER_MS = 3e3;
596
+ var DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS = 1e4;
596
597
  function isRecord(value) {
597
598
  return typeof value === "object" && value !== null;
598
599
  }
@@ -815,18 +816,33 @@ var PaymentAPI = class {
815
816
  * pre-pay PATCH would silently leave AVS unsent and cause an
816
817
  * AVS-protected charge to decline downstream.
817
818
  */
818
- async patchAccountSnapshot(sessionId, nonce, body) {
819
- const response = await fetchWithNetworkRetry(
820
- `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
821
- {
822
- method: "PATCH",
823
- headers: {
824
- "Content-Type": "application/json",
825
- "x-checkout-session-token": nonce
826
- },
827
- body: JSON.stringify(body)
828
- }
829
- );
819
+ async patchAccountSnapshot(sessionId, nonce, body, options) {
820
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS;
821
+ const controller = new AbortController();
822
+ const onCallerAbort = () => controller.abort();
823
+ if (options?.signal) {
824
+ if (options.signal.aborted) controller.abort();
825
+ else options.signal.addEventListener("abort", onCallerAbort, { once: true });
826
+ }
827
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
828
+ let response;
829
+ try {
830
+ response = await fetchWithNetworkRetry(
831
+ `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
832
+ {
833
+ method: "PATCH",
834
+ headers: {
835
+ "Content-Type": "application/json",
836
+ "x-checkout-session-token": nonce
837
+ },
838
+ body: JSON.stringify(body),
839
+ signal: controller.signal
840
+ }
841
+ );
842
+ } finally {
843
+ clearTimeout(timer);
844
+ options?.signal?.removeEventListener("abort", onCallerAbort);
845
+ }
830
846
  if (!response.ok) {
831
847
  throw await buildApiErrorFromResponse(response, "Failed to persist account snapshot");
832
848
  }