@flopay/js 1.0.3 → 1.1.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _flopay_shared from '@flopay/shared';
2
- import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, BillingProvider, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
2
+ import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, CheckoutGateways, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
3
3
 
4
4
  /**
5
5
  * Manages the creation and lifecycle of payment elements.
@@ -106,8 +106,7 @@ declare class FloPay {
106
106
  *
107
107
  * Instances are cached per `publishableKey`, so calling `loadFloPay` twice
108
108
  * with the same key returns the same instance. Different keys produce
109
- * independent instances that can run side-by-side (used for the dedicated
110
- * PayPal Stripe account).
109
+ * independent instances that can run side-by-side.
111
110
  *
112
111
  * @example
113
112
  * ```ts
@@ -226,11 +225,10 @@ declare function clearSessionDisplayData(sessionId: string): void;
226
225
  interface BillingResponse<T> {
227
226
  data: T;
228
227
  }
229
- /** Raw checkout session from the billing API (includes gateway field). */
228
+ /** Raw checkout session from the billing API. */
230
229
  interface RawCheckoutSession {
231
230
  uuid: string;
232
231
  nonce: string;
233
- gateway?: BillingProvider;
234
232
  status: 'pending' | 'completed' | 'expired';
235
233
  successUrl: string;
236
234
  cancelUrl: string;
@@ -286,11 +284,7 @@ interface RawCheckoutSession {
286
284
  }>;
287
285
  coupons?: string[];
288
286
  checkoutMode?: 'full' | 'auto' | 'confirm';
289
- gatewayData: {
290
- publishableKey?: string | null;
291
- stripeClientSecret?: string | null;
292
- paypalPublishableKey?: string | null;
293
- };
287
+ gateways?: CheckoutGateways;
294
288
  accountData: {
295
289
  userId: string;
296
290
  firstName: string;
@@ -352,9 +346,9 @@ declare class PaymentAPI {
352
346
  /**
353
347
  * Fetch and normalize a checkout session.
354
348
  *
355
- * Reads the backend's `gateway` field to determine the provider,
356
- * then wraps the session in a `NormalizedCheckoutSession` for
357
- * provider-agnostic consumption.
349
+ * Reads the backend's `gateways` map to enumerate provider-specific data,
350
+ * then wraps the session in a `NormalizedCheckoutSession` for provider-
351
+ * agnostic consumption.
358
352
  */
359
353
  getUnifiedCheckoutSession(checkoutSessionId: string): Promise<NormalizedCheckoutSession>;
360
354
  /**
@@ -362,8 +356,13 @@ declare class PaymentAPI {
362
356
  *
363
357
  * The backend will either succeed, return `type: '3ds_required'`
364
358
  * (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
359
+ *
360
+ * @param userId Vestigial — backend's GatewayInterceptor routes via session,
361
+ * not headers, so this value is no longer sent on the wire. Kept in the
362
+ * signature for back-compat with existing callers; will be removed in a
363
+ * future major version.
365
364
  */
366
- processPayment(userId: string, data: ProcessPaymentParams, options?: {
365
+ processPayment(_userId: string, data: ProcessPaymentParams, options?: {
367
366
  pollTimeoutMs?: number;
368
367
  }): Promise<Response>;
369
368
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _flopay_shared from '@flopay/shared';
2
- import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, BillingProvider, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
2
+ import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, CheckoutGateways, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
3
3
 
4
4
  /**
5
5
  * Manages the creation and lifecycle of payment elements.
@@ -106,8 +106,7 @@ declare class FloPay {
106
106
  *
107
107
  * Instances are cached per `publishableKey`, so calling `loadFloPay` twice
108
108
  * with the same key returns the same instance. Different keys produce
109
- * independent instances that can run side-by-side (used for the dedicated
110
- * PayPal Stripe account).
109
+ * independent instances that can run side-by-side.
111
110
  *
112
111
  * @example
113
112
  * ```ts
@@ -226,11 +225,10 @@ declare function clearSessionDisplayData(sessionId: string): void;
226
225
  interface BillingResponse<T> {
227
226
  data: T;
228
227
  }
229
- /** Raw checkout session from the billing API (includes gateway field). */
228
+ /** Raw checkout session from the billing API. */
230
229
  interface RawCheckoutSession {
231
230
  uuid: string;
232
231
  nonce: string;
233
- gateway?: BillingProvider;
234
232
  status: 'pending' | 'completed' | 'expired';
235
233
  successUrl: string;
236
234
  cancelUrl: string;
@@ -286,11 +284,7 @@ interface RawCheckoutSession {
286
284
  }>;
287
285
  coupons?: string[];
288
286
  checkoutMode?: 'full' | 'auto' | 'confirm';
289
- gatewayData: {
290
- publishableKey?: string | null;
291
- stripeClientSecret?: string | null;
292
- paypalPublishableKey?: string | null;
293
- };
287
+ gateways?: CheckoutGateways;
294
288
  accountData: {
295
289
  userId: string;
296
290
  firstName: string;
@@ -352,9 +346,9 @@ declare class PaymentAPI {
352
346
  /**
353
347
  * Fetch and normalize a checkout session.
354
348
  *
355
- * Reads the backend's `gateway` field to determine the provider,
356
- * then wraps the session in a `NormalizedCheckoutSession` for
357
- * provider-agnostic consumption.
349
+ * Reads the backend's `gateways` map to enumerate provider-specific data,
350
+ * then wraps the session in a `NormalizedCheckoutSession` for provider-
351
+ * agnostic consumption.
358
352
  */
359
353
  getUnifiedCheckoutSession(checkoutSessionId: string): Promise<NormalizedCheckoutSession>;
360
354
  /**
@@ -362,8 +356,13 @@ declare class PaymentAPI {
362
356
  *
363
357
  * The backend will either succeed, return `type: '3ds_required'`
364
358
  * (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
359
+ *
360
+ * @param userId Vestigial — backend's GatewayInterceptor routes via session,
361
+ * not headers, so this value is no longer sent on the wire. Kept in the
362
+ * signature for back-compat with existing callers; will be removed in a
363
+ * future major version.
365
364
  */
366
- processPayment(userId: string, data: ProcessPaymentParams, options?: {
365
+ processPayment(_userId: string, data: ProcessPaymentParams, options?: {
367
366
  pollTimeoutMs?: number;
368
367
  }): Promise<Response>;
369
368
  /**
package/dist/index.mjs CHANGED
@@ -603,9 +603,9 @@ var PaymentAPI = class {
603
603
  /**
604
604
  * Fetch and normalize a checkout session.
605
605
  *
606
- * Reads the backend's `gateway` field to determine the provider,
607
- * then wraps the session in a `NormalizedCheckoutSession` for
608
- * provider-agnostic consumption.
606
+ * Reads the backend's `gateways` map to enumerate provider-specific data,
607
+ * then wraps the session in a `NormalizedCheckoutSession` for provider-
608
+ * agnostic consumption.
609
609
  */
610
610
  async getUnifiedCheckoutSession(checkoutSessionId) {
611
611
  const res = await this.getCheckoutSession(checkoutSessionId);
@@ -616,16 +616,18 @@ var PaymentAPI = class {
616
616
  *
617
617
  * The backend will either succeed, return `type: '3ds_required'`
618
618
  * (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
619
+ *
620
+ * @param userId Vestigial — backend's GatewayInterceptor routes via session,
621
+ * not headers, so this value is no longer sent on the wire. Kept in the
622
+ * signature for back-compat with existing callers; will be removed in a
623
+ * future major version.
619
624
  */
620
- async processPayment(userId, data, options) {
625
+ async processPayment(_userId, data, options) {
621
626
  const response = await fetch(
622
627
  `${this.baseUrl}/v1/checkouts/sessions/process`,
623
628
  {
624
629
  method: "POST",
625
- headers: {
626
- "Content-Type": "application/json",
627
- "x-user-id": userId
628
- },
630
+ headers: { "Content-Type": "application/json" },
629
631
  body: JSON.stringify(data)
630
632
  }
631
633
  );
@@ -756,7 +758,7 @@ var PaymentAPI = class {
756
758
  throw await buildApiErrorFromResponse(response, "Failed to create checkout session");
757
759
  }
758
760
  const body = await response.json();
759
- if (body.data && "gateway" in body.data) {
761
+ if (body.data && "gateways" in body.data) {
760
762
  this.autoCacheDisplayData(body.data.uuid, params);
761
763
  const merged = this.mergeCachedDisplayData(body.data);
762
764
  return {
@@ -809,41 +811,38 @@ var PaymentAPI = class {
809
811
  }
810
812
  /** Normalize a raw session into a provider-agnostic shape. */
811
813
  normalizeRawSession(session) {
812
- const gateway = session.gateway;
813
- if (gateway === "chargebee") {
814
- return {
815
- provider: "chargebee",
816
- mode: "tokenize",
817
- data: { session: this.toCheckoutSession(session) },
818
- raw: { data: session }
819
- };
820
- }
821
- if (gateway === "stripe") {
814
+ const gateways = session.gateways ?? {};
815
+ const providers = [];
816
+ const data = {
817
+ session: this.toCheckoutSession(session)
818
+ };
819
+ const stripeGateway = gateways.stripe;
820
+ if (stripeGateway?.publishableKey) {
821
+ providers.push("stripe");
822
822
  const rawSession = session;
823
- const gatewayDataRecord = session.gatewayData ?? {};
824
823
  const stripeClientSecret = [
825
824
  rawSession["stripeClientSecret"],
826
- gatewayDataRecord["stripeClientSecret"],
827
- gatewayDataRecord["clientSecret"]
825
+ stripeGateway.stripeClientSecret
828
826
  ].find((value) => typeof value === "string" && value.length > 0);
829
- return {
830
- provider: "stripe",
831
- mode: "tokenize",
832
- data: {
833
- session: this.toCheckoutSession(session),
834
- stripe: {
835
- clientSecret: stripeClientSecret ?? "",
836
- publishableKey: session.gatewayData?.publishableKey ?? void 0,
837
- paypalPublishableKey: session.gatewayData?.paypalPublishableKey ?? void 0
838
- }
839
- },
840
- raw: { data: session }
827
+ data.stripe = {
828
+ clientSecret: stripeClientSecret ?? "",
829
+ publishableKey: stripeGateway.publishableKey ?? void 0,
830
+ paypalPublishableKey: stripeGateway.paypalPublishableKey ?? void 0,
831
+ environment: stripeGateway.environment
832
+ };
833
+ }
834
+ const paypalGateway = gateways.paypal;
835
+ if (paypalGateway?.publishableKey) {
836
+ providers.push("paypal");
837
+ data.paypal = {
838
+ publishableKey: paypalGateway.publishableKey,
839
+ environment: paypalGateway.environment
841
840
  };
842
841
  }
843
842
  return {
844
- provider: "recurly",
843
+ providers,
845
844
  mode: "tokenize",
846
- data: { session: this.toCheckoutSession(session) },
845
+ data,
847
846
  raw: { data: session }
848
847
  };
849
848
  }
@@ -885,8 +884,7 @@ var PaymentAPI = class {
885
884
  cancelUrl: raw.cancelUrl,
886
885
  coupons: raw.coupons,
887
886
  createdAt: raw.createdAt,
888
- gateway: raw.gateway,
889
- gatewayData: raw.gatewayData,
887
+ gateways: raw.gateways,
890
888
  accountData: raw.accountData,
891
889
  tagsData: raw.tagsData
892
890
  };