@flopay/shared 0.5.19 → 1.0.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
@@ -164,26 +164,56 @@ type CheckoutMode = 'full' | 'auto' | 'confirm';
164
164
  interface CheckoutSessionItem {
165
165
  uuid: string;
166
166
  checkoutSessionId: string;
167
- providerItemId: string;
168
- providerItemName: string;
167
+ /** Preferred catalog code for the item. */
168
+ code?: string;
169
+ /** @deprecated Use {@link CheckoutSessionItem.code}. Backend may stop returning this in a future major. */
170
+ providerItemId?: string;
171
+ /**
172
+ * Display-only name for the item. Preferred over `providerItemName`.
173
+ * The backend no longer persists names; the SDK populates this from the
174
+ * client-side display cache when the server response omits it.
175
+ */
176
+ itemName?: string | null;
177
+ /** @deprecated Use {@link CheckoutSessionItem.itemName}. Mirrored from `itemName` for backward compatibility. */
178
+ providerItemName?: string | null;
179
+ /** Display-only. Resolved from the catalog server-side; not part of the persisted session. */
169
180
  providerItemDescription?: string | null;
170
181
  quantity: number;
171
- totalAmount: number;
172
- overrideAmount: number | null;
173
- currency: string;
182
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
183
+ totalAmount?: number;
184
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
185
+ overrideAmount?: number | null;
186
+ /** @deprecated Prefer the session-level `currency` on {@link CheckoutSession}. Kept for backward compatibility and populated from cache when the server omits it. */
187
+ currency?: string;
174
188
  metadata?: Record<string, unknown> | null;
175
189
  }
176
190
  /** A subscription plan from a checkout session response. */
177
191
  interface CheckoutSessionSubscription {
178
192
  uuid: string;
179
193
  checkoutSessionId: string;
180
- providerPlanId: string;
181
- providerPlanName: string;
194
+ /** Preferred catalog code for the subscription plan. */
195
+ code?: string;
196
+ /** @deprecated Use {@link CheckoutSessionSubscription.code}. Backend may stop returning this in a future major. */
197
+ providerPlanId?: string;
198
+ /**
199
+ * Display-only name for the subscription plan. Preferred over
200
+ * `providerPlanName`. The backend no longer persists names; the SDK
201
+ * populates this from the client-side display cache when the server
202
+ * response omits it.
203
+ */
204
+ subscriptionName?: string | null;
205
+ /** @deprecated Use {@link CheckoutSessionSubscription.subscriptionName}. Mirrored from `subscriptionName` for backward compatibility. */
206
+ providerPlanName?: string | null;
207
+ /** Display-only. Resolved from the catalog server-side; not part of the persisted session. */
182
208
  providerPlanDescription?: string | null;
183
209
  quantity: number;
184
- totalAmount: number;
185
- overrideAmount: number | null;
186
- currency: string;
210
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
211
+ totalAmount?: number;
212
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
213
+ overrideAmount?: number | null;
214
+ /** @deprecated Prefer the session-level `currency` on {@link CheckoutSession}. Kept for backward compatibility and populated from cache when the server omits it. */
215
+ currency?: string;
216
+ /** @deprecated Removed from backend. Checkouts only create new subscriptions. */
187
217
  isUpdate?: boolean;
188
218
  metadata?: Record<string, unknown> | null;
189
219
  }
@@ -473,33 +503,65 @@ interface NormalizedCheckoutSession {
473
503
  }
474
504
  /** A one-time purchase item for checkout session creation. */
475
505
  interface CheckoutItem {
476
- /** The provider's item/product ID (e.g. Stripe price ID, Recurly plan code). */
477
- providerItemId: string;
478
- /** Display name for the item. */
506
+ /**
507
+ * Catalog code for the item — the preferred identifier. When omitted, the
508
+ * deprecated `providerItemId` is used as a fallback.
509
+ */
510
+ code?: string;
511
+ /**
512
+ * @deprecated Use {@link CheckoutItem.code}. Still accepted as a fallback
513
+ * when `code` is not provided.
514
+ */
515
+ providerItemId?: string;
516
+ /**
517
+ * Display-only name for the item. Takes priority over the deprecated
518
+ * `providerItemName`. Backend resolves names from the catalog; pass this
519
+ * to seed the client-side display cache for the post-redirect fetch.
520
+ */
521
+ itemName?: string | null;
522
+ /** @deprecated Use {@link CheckoutItem.itemName}. Still accepted as a fallback when `itemName` is not provided. */
479
523
  providerItemName?: string | null;
480
524
  /** Defaults to 1. */
481
525
  quantity?: number;
482
- /** The regular (full) price in the given currency. */
483
- totalAmount: number;
484
- /** A discounted price to charge instead of totalAmount. */
526
+ /** Display-only. Backend resolves prices from the catalog; pass this to seed the client-side display cache so the UI can render the regular price after redirect. */
527
+ totalAmount?: number;
528
+ /** Display-only. Backend ignores this entirely; pass this to seed the client-side display cache so the UI can render the discounted price after redirect. */
485
529
  overrideAmount?: number | null;
486
- /** ISO 4217 currency code. Defaults to 'USD'. */
530
+ /** @deprecated Prefer the session-level `currency` on {@link CreateSessionParams}/{@link InlineSessionParams}. */
487
531
  currency?: string;
532
+ /** Arbitrary key/value metadata forwarded to the backend. */
533
+ metadata?: Record<string, unknown> | null;
488
534
  }
489
535
  /** A recurring subscription plan for checkout session creation. */
490
536
  interface CheckoutSubscription {
491
- /** The provider's plan ID. */
492
- providerPlanId: string;
493
- /** Display name for the plan. */
537
+ /**
538
+ * Catalog code for the plan — the preferred identifier. When omitted, the
539
+ * deprecated `providerPlanId` is used as a fallback.
540
+ */
541
+ code?: string;
542
+ /**
543
+ * @deprecated Use {@link CheckoutSubscription.code}. Still accepted as a
544
+ * fallback when `code` is not provided.
545
+ */
546
+ providerPlanId?: string;
547
+ /**
548
+ * Display-only name for the subscription plan. Takes priority over the
549
+ * deprecated `providerPlanName`. Backend resolves names from the catalog;
550
+ * pass this to seed the client-side display cache for the post-redirect fetch.
551
+ */
552
+ subscriptionName?: string | null;
553
+ /** @deprecated Use {@link CheckoutSubscription.subscriptionName}. Still accepted as a fallback when `subscriptionName` is not provided. */
494
554
  providerPlanName?: string | null;
495
555
  /** Defaults to 1. */
496
556
  quantity?: number;
497
- /** The regular (full) price in the given currency. */
498
- totalAmount: number;
499
- /** A discounted price to charge instead of totalAmount. */
557
+ /** Display-only. Backend resolves prices from the catalog; pass this to seed the client-side display cache so the UI can render the regular price after redirect. */
558
+ totalAmount?: number;
559
+ /** Display-only. Backend ignores this entirely; pass this to seed the client-side display cache so the UI can render the discounted price after redirect. */
500
560
  overrideAmount?: number | null;
501
- /** ISO 4217 currency code. Defaults to 'USD'. */
561
+ /** @deprecated Prefer the session-level `currency` on {@link CreateSessionParams}/{@link InlineSessionParams}. */
502
562
  currency?: string;
563
+ /** Arbitrary key/value metadata forwarded to the backend. */
564
+ metadata?: Record<string, unknown> | null;
503
565
  }
504
566
  /** Buyer's account information for session creation. */
505
567
  interface CheckoutAccount {
@@ -534,6 +596,12 @@ interface CreateSessionParams {
534
596
  checkoutBaseUrl: string;
535
597
  /** The client ID for the checkout session. */
536
598
  clientId: string;
599
+ /**
600
+ * Session-level ISO 4217 currency code. Takes precedence over any
601
+ * per-item/per-subscription `currency` field. When omitted, the SDK
602
+ * falls back to `items[0].currency ?? subscriptions[0].currency`.
603
+ */
604
+ currency?: string;
537
605
  /** One-time purchase items. */
538
606
  items?: CheckoutItem[];
539
607
  /** Recurring subscription plans. */
@@ -572,6 +640,12 @@ interface CreateSessionParams {
572
640
  interface InlineSessionParams {
573
641
  /** The client ID for the checkout session. */
574
642
  clientId: string;
643
+ /**
644
+ * Session-level ISO 4217 currency code. Takes precedence over any
645
+ * per-item/per-subscription `currency` field. When omitted, the SDK
646
+ * falls back to `items[0].currency ?? subscriptions[0].currency`.
647
+ */
648
+ currency?: string;
575
649
  /** One-time purchase items. */
576
650
  items?: CheckoutItem[];
577
651
  /** Recurring subscription plans. */
@@ -743,7 +817,7 @@ declare function getConfiguredBillingApiUrl(): string;
743
817
  declare function getFloPayEnvironment(): FloPayEnvironment;
744
818
 
745
819
  /** Current SDK version. */
746
- declare const SDK_VERSION = "0.5.19";
820
+ declare const SDK_VERSION = "1.0.2";
747
821
  /** Billing API URL for staging environment. */
748
822
  declare const BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
749
823
  /** Billing API URL for production environment. */
@@ -878,12 +952,21 @@ interface CheckoutDisplayData {
878
952
  /** Discount percentage (0–100). */
879
953
  discountPercent: number;
880
954
  }
955
+ /** Options for {@link buildCheckoutDisplayData}. */
956
+ interface BuildCheckoutDisplayDataOptions {
957
+ /**
958
+ * When `true`, items are hidden from the order summary if the session also
959
+ * contains subscriptions (matches the legacy checkout/CheckoutModal
960
+ * behavior). Defaults to `false` — items are always shown.
961
+ */
962
+ hideBundledItems?: boolean;
963
+ }
881
964
  /**
882
965
  * Builds display data from a `CheckoutSession` for rendering an order summary.
883
966
  *
884
- * Matches the display logic in checkout/CheckoutModal exactly:
885
967
  * - Subscriptions are always shown
886
- * - Items are hidden when the session has both subscriptions AND items
968
+ * - Items are shown by default; pass `{ hideBundledItems: true }` to suppress
969
+ * them when the session also contains subscriptions (legacy behavior)
887
970
  * - `overrideAmount` (when not null/undefined) is the discounted price
888
971
  * - Plan name "4-WEEK PLAN" with price <= 1 is renamed to "7-DAY TRIAL: FULL ACCESS"
889
972
  * - Discount percentage and savings are computed from the difference
@@ -900,7 +983,37 @@ interface CheckoutDisplayData {
900
983
  * // display.currency → 'EUR'
901
984
  * ```
902
985
  */
903
- declare function buildCheckoutDisplayData(session: CheckoutSession): CheckoutDisplayData;
986
+ declare function buildCheckoutDisplayData(session: CheckoutSession, options?: BuildCheckoutDisplayDataOptions): CheckoutDisplayData;
987
+
988
+ /**
989
+ * Resolve the session-level currency, honoring the documented fallback:
990
+ * `session.currency ?? items[*].currency ?? subscriptions[*].currency`.
991
+ *
992
+ * Returns the first non-blank currency found, or 'USD' when nothing is set.
993
+ * Empty and whitespace-only strings are treated as unset so they do not
994
+ * bypass the fallback chain.
995
+ */
996
+ declare function resolveSessionCurrency(sessionCurrency: string | undefined, items: ReadonlyArray<{
997
+ currency?: string;
998
+ }> | undefined, subscriptions: ReadonlyArray<{
999
+ currency?: string;
1000
+ }> | undefined): string;
1001
+ /**
1002
+ * Build the request payload for a single item.
1003
+ *
1004
+ * Sends the new `code` field alongside the deprecated `providerItemId`,
1005
+ * `providerItemName`, `totalAmount`, and `overrideAmount` fields so that
1006
+ * both new and old backend versions accept the same request body.
1007
+ */
1008
+ declare function buildItemPayload(item: CheckoutItem, sessionCurrency: string): Record<string, unknown>;
1009
+ /**
1010
+ * Build the request payload for a single subscription.
1011
+ *
1012
+ * Sends the new `code` field alongside the deprecated `providerPlanId`,
1013
+ * `providerPlanName`, `totalAmount`, and `overrideAmount` fields for
1014
+ * backward compatibility.
1015
+ */
1016
+ declare function buildSubscriptionPayload(subscription: CheckoutSubscription, sessionCurrency: string): Record<string, unknown>;
904
1017
 
905
1018
  /**
906
1019
  * Look up currency information by ISO 3166-1 alpha-2 country code.
@@ -912,4 +1025,4 @@ declare function isValidPublishableKey(key: string): boolean;
912
1025
  /** Returns `true` if the string looks like a Stripe secret key. */
913
1026
  declare function isValidSecretKey(key: string): boolean;
914
1027
 
915
- export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutSession, type CheckoutSessionItem, type CheckoutSessionResult, type CheckoutSessionSubscription, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, SUPPORTED_CARD_BRANDS, type StateOption, type TagsData, type TokenizedBody, US_STATES, type UpdateCustomerParams, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, configureFlopay, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, isAVSEnabled, isAVSFieldVisible, isValidPublishableKey, isValidSecretKey, networkError, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, validationError };
1028
+ export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutSession, type CheckoutSessionItem, type CheckoutSessionResult, type CheckoutSessionSubscription, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, SUPPORTED_CARD_BRANDS, type StateOption, type TagsData, type TokenizedBody, US_STATES, type UpdateCustomerParams, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildSubscriptionPayload, configureFlopay, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, isAVSEnabled, isAVSFieldVisible, isValidPublishableKey, isValidSecretKey, networkError, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveSessionCurrency, validationError };
package/dist/index.d.ts CHANGED
@@ -164,26 +164,56 @@ type CheckoutMode = 'full' | 'auto' | 'confirm';
164
164
  interface CheckoutSessionItem {
165
165
  uuid: string;
166
166
  checkoutSessionId: string;
167
- providerItemId: string;
168
- providerItemName: string;
167
+ /** Preferred catalog code for the item. */
168
+ code?: string;
169
+ /** @deprecated Use {@link CheckoutSessionItem.code}. Backend may stop returning this in a future major. */
170
+ providerItemId?: string;
171
+ /**
172
+ * Display-only name for the item. Preferred over `providerItemName`.
173
+ * The backend no longer persists names; the SDK populates this from the
174
+ * client-side display cache when the server response omits it.
175
+ */
176
+ itemName?: string | null;
177
+ /** @deprecated Use {@link CheckoutSessionItem.itemName}. Mirrored from `itemName` for backward compatibility. */
178
+ providerItemName?: string | null;
179
+ /** Display-only. Resolved from the catalog server-side; not part of the persisted session. */
169
180
  providerItemDescription?: string | null;
170
181
  quantity: number;
171
- totalAmount: number;
172
- overrideAmount: number | null;
173
- currency: string;
182
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
183
+ totalAmount?: number;
184
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
185
+ overrideAmount?: number | null;
186
+ /** @deprecated Prefer the session-level `currency` on {@link CheckoutSession}. Kept for backward compatibility and populated from cache when the server omits it. */
187
+ currency?: string;
174
188
  metadata?: Record<string, unknown> | null;
175
189
  }
176
190
  /** A subscription plan from a checkout session response. */
177
191
  interface CheckoutSessionSubscription {
178
192
  uuid: string;
179
193
  checkoutSessionId: string;
180
- providerPlanId: string;
181
- providerPlanName: string;
194
+ /** Preferred catalog code for the subscription plan. */
195
+ code?: string;
196
+ /** @deprecated Use {@link CheckoutSessionSubscription.code}. Backend may stop returning this in a future major. */
197
+ providerPlanId?: string;
198
+ /**
199
+ * Display-only name for the subscription plan. Preferred over
200
+ * `providerPlanName`. The backend no longer persists names; the SDK
201
+ * populates this from the client-side display cache when the server
202
+ * response omits it.
203
+ */
204
+ subscriptionName?: string | null;
205
+ /** @deprecated Use {@link CheckoutSessionSubscription.subscriptionName}. Mirrored from `subscriptionName` for backward compatibility. */
206
+ providerPlanName?: string | null;
207
+ /** Display-only. Resolved from the catalog server-side; not part of the persisted session. */
182
208
  providerPlanDescription?: string | null;
183
209
  quantity: number;
184
- totalAmount: number;
185
- overrideAmount: number | null;
186
- currency: string;
210
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
211
+ totalAmount?: number;
212
+ /** Display-only. Backend no longer persists this; the SDK populates it from the client-side cache (set via `paymentAPI.cacheSessionDisplayData`) when missing from the server response. */
213
+ overrideAmount?: number | null;
214
+ /** @deprecated Prefer the session-level `currency` on {@link CheckoutSession}. Kept for backward compatibility and populated from cache when the server omits it. */
215
+ currency?: string;
216
+ /** @deprecated Removed from backend. Checkouts only create new subscriptions. */
187
217
  isUpdate?: boolean;
188
218
  metadata?: Record<string, unknown> | null;
189
219
  }
@@ -473,33 +503,65 @@ interface NormalizedCheckoutSession {
473
503
  }
474
504
  /** A one-time purchase item for checkout session creation. */
475
505
  interface CheckoutItem {
476
- /** The provider's item/product ID (e.g. Stripe price ID, Recurly plan code). */
477
- providerItemId: string;
478
- /** Display name for the item. */
506
+ /**
507
+ * Catalog code for the item — the preferred identifier. When omitted, the
508
+ * deprecated `providerItemId` is used as a fallback.
509
+ */
510
+ code?: string;
511
+ /**
512
+ * @deprecated Use {@link CheckoutItem.code}. Still accepted as a fallback
513
+ * when `code` is not provided.
514
+ */
515
+ providerItemId?: string;
516
+ /**
517
+ * Display-only name for the item. Takes priority over the deprecated
518
+ * `providerItemName`. Backend resolves names from the catalog; pass this
519
+ * to seed the client-side display cache for the post-redirect fetch.
520
+ */
521
+ itemName?: string | null;
522
+ /** @deprecated Use {@link CheckoutItem.itemName}. Still accepted as a fallback when `itemName` is not provided. */
479
523
  providerItemName?: string | null;
480
524
  /** Defaults to 1. */
481
525
  quantity?: number;
482
- /** The regular (full) price in the given currency. */
483
- totalAmount: number;
484
- /** A discounted price to charge instead of totalAmount. */
526
+ /** Display-only. Backend resolves prices from the catalog; pass this to seed the client-side display cache so the UI can render the regular price after redirect. */
527
+ totalAmount?: number;
528
+ /** Display-only. Backend ignores this entirely; pass this to seed the client-side display cache so the UI can render the discounted price after redirect. */
485
529
  overrideAmount?: number | null;
486
- /** ISO 4217 currency code. Defaults to 'USD'. */
530
+ /** @deprecated Prefer the session-level `currency` on {@link CreateSessionParams}/{@link InlineSessionParams}. */
487
531
  currency?: string;
532
+ /** Arbitrary key/value metadata forwarded to the backend. */
533
+ metadata?: Record<string, unknown> | null;
488
534
  }
489
535
  /** A recurring subscription plan for checkout session creation. */
490
536
  interface CheckoutSubscription {
491
- /** The provider's plan ID. */
492
- providerPlanId: string;
493
- /** Display name for the plan. */
537
+ /**
538
+ * Catalog code for the plan — the preferred identifier. When omitted, the
539
+ * deprecated `providerPlanId` is used as a fallback.
540
+ */
541
+ code?: string;
542
+ /**
543
+ * @deprecated Use {@link CheckoutSubscription.code}. Still accepted as a
544
+ * fallback when `code` is not provided.
545
+ */
546
+ providerPlanId?: string;
547
+ /**
548
+ * Display-only name for the subscription plan. Takes priority over the
549
+ * deprecated `providerPlanName`. Backend resolves names from the catalog;
550
+ * pass this to seed the client-side display cache for the post-redirect fetch.
551
+ */
552
+ subscriptionName?: string | null;
553
+ /** @deprecated Use {@link CheckoutSubscription.subscriptionName}. Still accepted as a fallback when `subscriptionName` is not provided. */
494
554
  providerPlanName?: string | null;
495
555
  /** Defaults to 1. */
496
556
  quantity?: number;
497
- /** The regular (full) price in the given currency. */
498
- totalAmount: number;
499
- /** A discounted price to charge instead of totalAmount. */
557
+ /** Display-only. Backend resolves prices from the catalog; pass this to seed the client-side display cache so the UI can render the regular price after redirect. */
558
+ totalAmount?: number;
559
+ /** Display-only. Backend ignores this entirely; pass this to seed the client-side display cache so the UI can render the discounted price after redirect. */
500
560
  overrideAmount?: number | null;
501
- /** ISO 4217 currency code. Defaults to 'USD'. */
561
+ /** @deprecated Prefer the session-level `currency` on {@link CreateSessionParams}/{@link InlineSessionParams}. */
502
562
  currency?: string;
563
+ /** Arbitrary key/value metadata forwarded to the backend. */
564
+ metadata?: Record<string, unknown> | null;
503
565
  }
504
566
  /** Buyer's account information for session creation. */
505
567
  interface CheckoutAccount {
@@ -534,6 +596,12 @@ interface CreateSessionParams {
534
596
  checkoutBaseUrl: string;
535
597
  /** The client ID for the checkout session. */
536
598
  clientId: string;
599
+ /**
600
+ * Session-level ISO 4217 currency code. Takes precedence over any
601
+ * per-item/per-subscription `currency` field. When omitted, the SDK
602
+ * falls back to `items[0].currency ?? subscriptions[0].currency`.
603
+ */
604
+ currency?: string;
537
605
  /** One-time purchase items. */
538
606
  items?: CheckoutItem[];
539
607
  /** Recurring subscription plans. */
@@ -572,6 +640,12 @@ interface CreateSessionParams {
572
640
  interface InlineSessionParams {
573
641
  /** The client ID for the checkout session. */
574
642
  clientId: string;
643
+ /**
644
+ * Session-level ISO 4217 currency code. Takes precedence over any
645
+ * per-item/per-subscription `currency` field. When omitted, the SDK
646
+ * falls back to `items[0].currency ?? subscriptions[0].currency`.
647
+ */
648
+ currency?: string;
575
649
  /** One-time purchase items. */
576
650
  items?: CheckoutItem[];
577
651
  /** Recurring subscription plans. */
@@ -743,7 +817,7 @@ declare function getConfiguredBillingApiUrl(): string;
743
817
  declare function getFloPayEnvironment(): FloPayEnvironment;
744
818
 
745
819
  /** Current SDK version. */
746
- declare const SDK_VERSION = "0.5.19";
820
+ declare const SDK_VERSION = "1.0.2";
747
821
  /** Billing API URL for staging environment. */
748
822
  declare const BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
749
823
  /** Billing API URL for production environment. */
@@ -878,12 +952,21 @@ interface CheckoutDisplayData {
878
952
  /** Discount percentage (0–100). */
879
953
  discountPercent: number;
880
954
  }
955
+ /** Options for {@link buildCheckoutDisplayData}. */
956
+ interface BuildCheckoutDisplayDataOptions {
957
+ /**
958
+ * When `true`, items are hidden from the order summary if the session also
959
+ * contains subscriptions (matches the legacy checkout/CheckoutModal
960
+ * behavior). Defaults to `false` — items are always shown.
961
+ */
962
+ hideBundledItems?: boolean;
963
+ }
881
964
  /**
882
965
  * Builds display data from a `CheckoutSession` for rendering an order summary.
883
966
  *
884
- * Matches the display logic in checkout/CheckoutModal exactly:
885
967
  * - Subscriptions are always shown
886
- * - Items are hidden when the session has both subscriptions AND items
968
+ * - Items are shown by default; pass `{ hideBundledItems: true }` to suppress
969
+ * them when the session also contains subscriptions (legacy behavior)
887
970
  * - `overrideAmount` (when not null/undefined) is the discounted price
888
971
  * - Plan name "4-WEEK PLAN" with price <= 1 is renamed to "7-DAY TRIAL: FULL ACCESS"
889
972
  * - Discount percentage and savings are computed from the difference
@@ -900,7 +983,37 @@ interface CheckoutDisplayData {
900
983
  * // display.currency → 'EUR'
901
984
  * ```
902
985
  */
903
- declare function buildCheckoutDisplayData(session: CheckoutSession): CheckoutDisplayData;
986
+ declare function buildCheckoutDisplayData(session: CheckoutSession, options?: BuildCheckoutDisplayDataOptions): CheckoutDisplayData;
987
+
988
+ /**
989
+ * Resolve the session-level currency, honoring the documented fallback:
990
+ * `session.currency ?? items[*].currency ?? subscriptions[*].currency`.
991
+ *
992
+ * Returns the first non-blank currency found, or 'USD' when nothing is set.
993
+ * Empty and whitespace-only strings are treated as unset so they do not
994
+ * bypass the fallback chain.
995
+ */
996
+ declare function resolveSessionCurrency(sessionCurrency: string | undefined, items: ReadonlyArray<{
997
+ currency?: string;
998
+ }> | undefined, subscriptions: ReadonlyArray<{
999
+ currency?: string;
1000
+ }> | undefined): string;
1001
+ /**
1002
+ * Build the request payload for a single item.
1003
+ *
1004
+ * Sends the new `code` field alongside the deprecated `providerItemId`,
1005
+ * `providerItemName`, `totalAmount`, and `overrideAmount` fields so that
1006
+ * both new and old backend versions accept the same request body.
1007
+ */
1008
+ declare function buildItemPayload(item: CheckoutItem, sessionCurrency: string): Record<string, unknown>;
1009
+ /**
1010
+ * Build the request payload for a single subscription.
1011
+ *
1012
+ * Sends the new `code` field alongside the deprecated `providerPlanId`,
1013
+ * `providerPlanName`, `totalAmount`, and `overrideAmount` fields for
1014
+ * backward compatibility.
1015
+ */
1016
+ declare function buildSubscriptionPayload(subscription: CheckoutSubscription, sessionCurrency: string): Record<string, unknown>;
904
1017
 
905
1018
  /**
906
1019
  * Look up currency information by ISO 3166-1 alpha-2 country code.
@@ -912,4 +1025,4 @@ declare function isValidPublishableKey(key: string): boolean;
912
1025
  /** Returns `true` if the string looks like a Stripe secret key. */
913
1026
  declare function isValidSecretKey(key: string): boolean;
914
1027
 
915
- export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutSession, type CheckoutSessionItem, type CheckoutSessionResult, type CheckoutSessionSubscription, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, SUPPORTED_CARD_BRANDS, type StateOption, type TagsData, type TokenizedBody, US_STATES, type UpdateCustomerParams, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, configureFlopay, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, isAVSEnabled, isAVSFieldVisible, isValidPublishableKey, isValidSecretKey, networkError, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, validationError };
1028
+ export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutSession, type CheckoutSessionItem, type CheckoutSessionResult, type CheckoutSessionSubscription, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, SUPPORTED_CARD_BRANDS, type StateOption, type TagsData, type TokenizedBody, US_STATES, type UpdateCustomerParams, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildSubscriptionPayload, configureFlopay, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, isAVSEnabled, isAVSFieldVisible, isValidPublishableKey, isValidSecretKey, networkError, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveSessionCurrency, validationError };
package/dist/index.mjs CHANGED
@@ -45,7 +45,7 @@ function getFloPayEnvironment() {
45
45
  }
46
46
 
47
47
  // src/constants.ts
48
- var SDK_VERSION = "0.5.19";
48
+ var SDK_VERSION = "1.0.2";
49
49
  var BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
50
50
  var BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
51
51
  var DEFAULT_API_BASE_URL = BILLING_API_URL_STAGING;
@@ -698,16 +698,80 @@ function getStateFromPostalCode(country, postalCode) {
698
698
  }
699
699
  }
700
700
 
701
+ // src/checkout-payload.ts
702
+ function nonBlank(value) {
703
+ if (typeof value !== "string") return void 0;
704
+ const trimmed = value.trim();
705
+ return trimmed.length > 0 ? trimmed : void 0;
706
+ }
707
+ function resolveSessionCurrency(sessionCurrency, items, subscriptions) {
708
+ const session = nonBlank(sessionCurrency);
709
+ if (session) return session;
710
+ for (const item of items ?? []) {
711
+ const c = nonBlank(item.currency);
712
+ if (c) return c;
713
+ }
714
+ for (const sub of subscriptions ?? []) {
715
+ const c = nonBlank(sub.currency);
716
+ if (c) return c;
717
+ }
718
+ return "USD";
719
+ }
720
+ function buildItemPayload(item, sessionCurrency) {
721
+ const code = nonBlank(item.code) ?? nonBlank(item.providerItemId);
722
+ if (!code) {
723
+ throw new Error("CheckoutItem requires either `code` or the deprecated `providerItemId`.");
724
+ }
725
+ const itemName = nonBlank(item.itemName) ?? nonBlank(item.providerItemName) ?? null;
726
+ const payload = {
727
+ code,
728
+ providerItemId: nonBlank(item.providerItemId) ?? code,
729
+ itemName,
730
+ providerItemName: nonBlank(item.providerItemName) ?? itemName,
731
+ quantity: item.quantity ?? 1,
732
+ totalAmount: item.totalAmount,
733
+ overrideAmount: item.overrideAmount ?? null,
734
+ currency: nonBlank(item.currency) ?? sessionCurrency
735
+ };
736
+ if (item.metadata) {
737
+ payload["metadata"] = item.metadata;
738
+ }
739
+ return payload;
740
+ }
741
+ function buildSubscriptionPayload(subscription, sessionCurrency) {
742
+ const code = nonBlank(subscription.code) ?? nonBlank(subscription.providerPlanId);
743
+ if (!code) {
744
+ throw new Error(
745
+ "CheckoutSubscription requires either `code` or the deprecated `providerPlanId`."
746
+ );
747
+ }
748
+ const subscriptionName = nonBlank(subscription.subscriptionName) ?? nonBlank(subscription.providerPlanName) ?? null;
749
+ const payload = {
750
+ code,
751
+ providerPlanId: nonBlank(subscription.providerPlanId) ?? code,
752
+ subscriptionName,
753
+ providerPlanName: nonBlank(subscription.providerPlanName) ?? subscriptionName,
754
+ quantity: subscription.quantity ?? 1,
755
+ totalAmount: subscription.totalAmount,
756
+ overrideAmount: subscription.overrideAmount ?? null,
757
+ currency: nonBlank(subscription.currency) ?? sessionCurrency
758
+ };
759
+ if (subscription.metadata) {
760
+ payload["metadata"] = subscription.metadata;
761
+ }
762
+ return payload;
763
+ }
764
+
701
765
  // src/display.ts
702
- function buildCheckoutDisplayData(session) {
766
+ function buildCheckoutDisplayData(session, options = {}) {
703
767
  const itemsList = [];
704
- let currency = "USD";
705
768
  const subscriptions = session.subscriptions ?? [];
706
769
  const items = session.items ?? [];
770
+ const currency = resolveSessionCurrency(session.currency, items, subscriptions).toUpperCase();
707
771
  for (const sub of subscriptions) {
708
- const originalPrice = sub.totalAmount;
772
+ const originalPrice = sub.totalAmount ?? 0;
709
773
  const discountedPrice = sub.overrideAmount ?? originalPrice;
710
- let name = sub.providerPlanName || "Subscription";
774
+ let name = sub.subscriptionName || sub.providerPlanName || sub.code || "Subscription";
711
775
  if (name === "4-WEEK PLAN" && discountedPrice <= 1) {
712
776
  name = "7-DAY TRIAL: FULL ACCESS";
713
777
  }
@@ -717,20 +781,18 @@ function buildCheckoutDisplayData(session) {
717
781
  price: discountedPrice,
718
782
  originalPrice
719
783
  });
720
- if (sub.currency) currency = sub.currency.toUpperCase();
721
784
  }
722
- const hideItems = subscriptions.length > 0 && items.length > 0;
785
+ const hideItems = options.hideBundledItems === true && subscriptions.length > 0 && items.length > 0;
723
786
  if (!hideItems) {
724
787
  for (const item of items) {
725
- const originalPrice = item.totalAmount;
788
+ const originalPrice = item.totalAmount ?? 0;
726
789
  const discountedPrice = item.overrideAmount ?? originalPrice;
727
790
  itemsList.push({
728
- name: item.providerItemName || "Item",
791
+ name: item.itemName || item.providerItemName || item.code || "Item",
729
792
  quantity: item.quantity,
730
793
  price: discountedPrice,
731
794
  originalPrice
732
795
  });
733
- if (item.currency) currency = item.currency.toUpperCase();
734
796
  }
735
797
  }
736
798
  if (itemsList.length === 0) {
@@ -740,7 +802,6 @@ function buildCheckoutDisplayData(session) {
740
802
  price: session.amount / 100,
741
803
  originalPrice: session.amount / 100
742
804
  });
743
- currency = session.currency?.toUpperCase() ?? "USD";
744
805
  }
745
806
  const originalTotal = itemsList.reduce((sum, i) => sum + i.originalPrice * i.quantity, 0);
746
807
  const total = itemsList.reduce((sum, i) => sum + i.price * i.quantity, 0);
@@ -791,6 +852,8 @@ export {
791
852
  apiError,
792
853
  authenticationError,
793
854
  buildCheckoutDisplayData,
855
+ buildItemPayload,
856
+ buildSubscriptionPayload,
794
857
  configureFlopay,
795
858
  getConfiguredBillingApiUrl,
796
859
  getCountryByCode,
@@ -809,6 +872,7 @@ export {
809
872
  resolveAVSConfig,
810
873
  resolveBillingApiUrl,
811
874
  resolveButtonsLayoutTheme,
875
+ resolveSessionCurrency,
812
876
  validationError
813
877
  };
814
878
  //# sourceMappingURL=index.mjs.map