@flopay/js 1.0.0 → 1.0.3

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
@@ -155,6 +155,73 @@ declare class StripeAdapter implements PaymentProviderAdapter {
155
155
  destroy(): void;
156
156
  }
157
157
 
158
+ /**
159
+ * Client-side cache for display-only checkout fields the backend no longer
160
+ * persists (`overrideAmount`, `totalAmount`, `providerItemName`,
161
+ * `providerPlanName`, per-line `currency`).
162
+ *
163
+ * The cache lives in `sessionStorage` so it survives the navigation from the
164
+ * page that creates the session to the checkout page that fetches it, but
165
+ * dies on tab close. An in-memory fallback keeps the SDK working in Node /
166
+ * SSR contexts where `sessionStorage` is unavailable.
167
+ *
168
+ * Values from the server response always win — cached values fill in only
169
+ * where the server returned `null` or `undefined`.
170
+ */
171
+ /** Display-only fields per item that can be cached and merged back later. */
172
+ interface SessionDisplayItem {
173
+ /** Catalog code (preferred match key). */
174
+ code?: string;
175
+ /** @deprecated Match key fallback when `code` is not provided. */
176
+ providerItemId?: string;
177
+ /** Display-only name for the item. Takes priority over `providerItemName`. */
178
+ itemName?: string | null;
179
+ /** @deprecated Use `itemName`. */
180
+ providerItemName?: string | null;
181
+ totalAmount?: number;
182
+ overrideAmount?: number | null;
183
+ currency?: string;
184
+ }
185
+ /** Display-only fields per subscription that can be cached and merged back later. */
186
+ interface SessionDisplaySubscription {
187
+ /** Catalog code (preferred match key). */
188
+ code?: string;
189
+ /** @deprecated Match key fallback when `code` is not provided. */
190
+ providerPlanId?: string;
191
+ /** Display-only name for the subscription plan. Takes priority over `providerPlanName`. */
192
+ subscriptionName?: string | null;
193
+ /** @deprecated Use `subscriptionName`. */
194
+ providerPlanName?: string | null;
195
+ totalAmount?: number;
196
+ overrideAmount?: number | null;
197
+ currency?: string;
198
+ }
199
+ /** Display-only payload that can be stashed for later merge into a session response. */
200
+ interface SessionDisplayCacheData {
201
+ /** Session-level currency (falls into the response only when the server omits it). */
202
+ currency?: string;
203
+ items?: SessionDisplayItem[];
204
+ subscriptions?: SessionDisplaySubscription[];
205
+ }
206
+ /**
207
+ * Stash display-only data for a session. Called client-side right after the
208
+ * server returns a session ID, so the values survive the redirect to the
209
+ * checkout page.
210
+ */
211
+ declare function cacheSessionDisplayData(sessionId: string, data: SessionDisplayCacheData, options?: {
212
+ ttlMs?: number;
213
+ }): void;
214
+ /**
215
+ * Read previously-cached display data for a session, or `null` if nothing
216
+ * is cached (or the TTL has elapsed).
217
+ */
218
+ declare function getSessionDisplayData(sessionId: string): SessionDisplayCacheData | null;
219
+ /**
220
+ * Drop any cached display data for a session. Call from the success page
221
+ * after the payment completes; otherwise the TTL handles cleanup.
222
+ */
223
+ declare function clearSessionDisplayData(sessionId: string): void;
224
+
158
225
  /** Raw billing API response wrapper. */
159
226
  interface BillingResponse<T> {
160
227
  data: T;
@@ -167,30 +234,53 @@ interface RawCheckoutSession {
167
234
  status: 'pending' | 'completed' | 'expired';
168
235
  successUrl: string;
169
236
  cancelUrl: string;
237
+ /** Session-level currency. Takes precedence over per-item/per-subscription currency. */
238
+ currency?: string;
170
239
  createdAt?: string;
171
240
  checkoutUrl?: string;
172
241
  items: Array<{
173
242
  uuid: string;
174
243
  checkoutSessionId: string;
175
- providerItemId: string;
176
- providerItemName: string;
244
+ /** Preferred catalog code. Falls back to the deprecated `providerItemId`. */
245
+ code?: string;
246
+ /** @deprecated Use `code`. */
247
+ providerItemId?: string;
248
+ /** Display-only name. Preferred over `providerItemName`. */
249
+ itemName?: string | null;
250
+ /** @deprecated Use `itemName`. Mirrored for backward compatibility. */
251
+ providerItemName?: string | null;
252
+ /** Display-only description from the catalog. */
177
253
  providerItemDescription?: string | null;
178
254
  quantity: number;
179
- totalAmount: number;
180
- overrideAmount: number | null;
181
- currency: string;
255
+ /** @deprecated Removed from the backend — resolved from the catalog. */
256
+ totalAmount?: number;
257
+ /** @deprecated Removed from the backend entirely. */
258
+ overrideAmount?: number | null;
259
+ /** @deprecated Use the session-level `currency`. */
260
+ currency?: string;
182
261
  metadata?: Record<string, unknown> | null;
183
262
  }>;
184
263
  subscriptions: Array<{
185
264
  uuid: string;
186
265
  checkoutSessionId: string;
187
- providerPlanId: string;
188
- providerPlanName: string;
266
+ /** Preferred catalog code. Falls back to the deprecated `providerPlanId`. */
267
+ code?: string;
268
+ /** @deprecated Use `code`. */
269
+ providerPlanId?: string;
270
+ /** Display-only name. Preferred over `providerPlanName`. */
271
+ subscriptionName?: string | null;
272
+ /** @deprecated Use `subscriptionName`. Mirrored for backward compatibility. */
273
+ providerPlanName?: string | null;
274
+ /** Display-only description from the catalog. */
189
275
  providerPlanDescription?: string | null;
190
276
  quantity: number;
191
- totalAmount: number;
192
- overrideAmount: number | null;
193
- currency: string;
277
+ /** @deprecated Removed from the backend — resolved from the catalog. */
278
+ totalAmount?: number;
279
+ /** @deprecated Removed from the backend entirely. */
280
+ overrideAmount?: number | null;
281
+ /** @deprecated Use the session-level `currency`. */
282
+ currency?: string;
283
+ /** @deprecated Removed from the backend. Checkouts only create new subscriptions. */
194
284
  isUpdate?: boolean;
195
285
  metadata?: Record<string, unknown> | null;
196
286
  }>;
@@ -232,6 +322,33 @@ declare class PaymentAPI {
232
322
  constructor(billingApiUrl: string);
233
323
  /** Fetch a raw checkout session by ID. */
234
324
  getCheckoutSession(checkoutSessionId: string): Promise<BillingResponse<RawCheckoutSession>>;
325
+ /**
326
+ * Stash display-only data for a session so subsequent fetches can fill in
327
+ * fields the backend no longer persists (`overrideAmount`, `totalAmount`,
328
+ * `providerItemName`, `providerPlanName`).
329
+ *
330
+ * Backed by `sessionStorage` in the browser, with an in-memory fallback in
331
+ * Node/SSR contexts. Default TTL: 1 hour.
332
+ *
333
+ * Server-returned values always win — cached values fill in only where the
334
+ * server returned `null` / `undefined`.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * paymentAPI.cacheSessionDisplayData(sessionId, {
339
+ * currency: 'USD',
340
+ * items: [{ code: 'pro_plan', overrideAmount: 24.99, providerItemName: 'Pro' }],
341
+ * });
342
+ * ```
343
+ */
344
+ cacheSessionDisplayData(sessionId: string, data: SessionDisplayCacheData, options?: {
345
+ ttlMs?: number;
346
+ }): void;
347
+ /**
348
+ * Drop any cached display data for a session. Call after the payment
349
+ * completes; otherwise the TTL handles cleanup.
350
+ */
351
+ clearSessionDisplayData(sessionId: string): void;
235
352
  /**
236
353
  * Fetch and normalize a checkout session.
237
354
  *
@@ -301,6 +418,24 @@ declare class PaymentAPI {
301
418
  private resolveProcessResponse;
302
419
  private toCheckoutProcessingPending;
303
420
  private clampRetryAfterMs;
421
+ /**
422
+ * Stash the display-only fields the consumer passed into a create-session
423
+ * call. Runs after the backend assigns a UUID so a later GET on the same
424
+ * session (typically after a redirect) can fill in fields the backend no
425
+ * longer persists — `overrideAmount`, `totalAmount`, `itemName`, etc.
426
+ *
427
+ * No-op when no UUID is available.
428
+ */
429
+ private autoCacheDisplayData;
430
+ /**
431
+ * Merge cached display-only fields (set by {@link cacheSessionDisplayData})
432
+ * into a raw session response and mirror the new/legacy name aliases so
433
+ * readers using either field always get a value when one exists.
434
+ *
435
+ * Server values always win — cache fills in only where the server returned
436
+ * `null` / `undefined`.
437
+ */
438
+ private mergeCachedDisplayData;
304
439
  }
305
440
 
306
441
  /**
@@ -321,11 +456,11 @@ declare class PaymentAPI {
321
456
  * billingApiUrl: 'https://billing.example.com',
322
457
  * checkoutBaseUrl: 'https://checkout.example.com',
323
458
  * clientId: 'client_123',
459
+ * currency: 'USD',
324
460
  * items: [{
325
- * providerItemId: 'prod_abc',
326
- * providerItemName: 'Pro Plan',
327
- * totalAmount: 49.99,
328
- * overrideAmount: 24.99,
461
+ * code: 'initial_charge',
462
+ * quantity: 1,
463
+ * metadata: { source: 'web' },
329
464
  * }],
330
465
  * account: { userId: 'user_1', email: 'user@example.com' },
331
466
  * successUrl: '/success',
@@ -344,4 +479,4 @@ declare function createCheckoutSessionWithRetries(options: CreateSessionParams &
344
479
  maxRetries?: number;
345
480
  }): Promise<CheckoutSessionResult>;
346
481
 
347
- export { FloPay, FloPayElements, PaymentAPI, StripeAdapter, createCheckoutSession, createCheckoutSessionWithRetries, loadFloPay };
482
+ export { FloPay, FloPayElements, PaymentAPI, type SessionDisplayCacheData, type SessionDisplayItem, type SessionDisplaySubscription, StripeAdapter, cacheSessionDisplayData, clearSessionDisplayData, createCheckoutSession, createCheckoutSessionWithRetries, getSessionDisplayData, loadFloPay };
package/dist/index.d.ts CHANGED
@@ -155,6 +155,73 @@ declare class StripeAdapter implements PaymentProviderAdapter {
155
155
  destroy(): void;
156
156
  }
157
157
 
158
+ /**
159
+ * Client-side cache for display-only checkout fields the backend no longer
160
+ * persists (`overrideAmount`, `totalAmount`, `providerItemName`,
161
+ * `providerPlanName`, per-line `currency`).
162
+ *
163
+ * The cache lives in `sessionStorage` so it survives the navigation from the
164
+ * page that creates the session to the checkout page that fetches it, but
165
+ * dies on tab close. An in-memory fallback keeps the SDK working in Node /
166
+ * SSR contexts where `sessionStorage` is unavailable.
167
+ *
168
+ * Values from the server response always win — cached values fill in only
169
+ * where the server returned `null` or `undefined`.
170
+ */
171
+ /** Display-only fields per item that can be cached and merged back later. */
172
+ interface SessionDisplayItem {
173
+ /** Catalog code (preferred match key). */
174
+ code?: string;
175
+ /** @deprecated Match key fallback when `code` is not provided. */
176
+ providerItemId?: string;
177
+ /** Display-only name for the item. Takes priority over `providerItemName`. */
178
+ itemName?: string | null;
179
+ /** @deprecated Use `itemName`. */
180
+ providerItemName?: string | null;
181
+ totalAmount?: number;
182
+ overrideAmount?: number | null;
183
+ currency?: string;
184
+ }
185
+ /** Display-only fields per subscription that can be cached and merged back later. */
186
+ interface SessionDisplaySubscription {
187
+ /** Catalog code (preferred match key). */
188
+ code?: string;
189
+ /** @deprecated Match key fallback when `code` is not provided. */
190
+ providerPlanId?: string;
191
+ /** Display-only name for the subscription plan. Takes priority over `providerPlanName`. */
192
+ subscriptionName?: string | null;
193
+ /** @deprecated Use `subscriptionName`. */
194
+ providerPlanName?: string | null;
195
+ totalAmount?: number;
196
+ overrideAmount?: number | null;
197
+ currency?: string;
198
+ }
199
+ /** Display-only payload that can be stashed for later merge into a session response. */
200
+ interface SessionDisplayCacheData {
201
+ /** Session-level currency (falls into the response only when the server omits it). */
202
+ currency?: string;
203
+ items?: SessionDisplayItem[];
204
+ subscriptions?: SessionDisplaySubscription[];
205
+ }
206
+ /**
207
+ * Stash display-only data for a session. Called client-side right after the
208
+ * server returns a session ID, so the values survive the redirect to the
209
+ * checkout page.
210
+ */
211
+ declare function cacheSessionDisplayData(sessionId: string, data: SessionDisplayCacheData, options?: {
212
+ ttlMs?: number;
213
+ }): void;
214
+ /**
215
+ * Read previously-cached display data for a session, or `null` if nothing
216
+ * is cached (or the TTL has elapsed).
217
+ */
218
+ declare function getSessionDisplayData(sessionId: string): SessionDisplayCacheData | null;
219
+ /**
220
+ * Drop any cached display data for a session. Call from the success page
221
+ * after the payment completes; otherwise the TTL handles cleanup.
222
+ */
223
+ declare function clearSessionDisplayData(sessionId: string): void;
224
+
158
225
  /** Raw billing API response wrapper. */
159
226
  interface BillingResponse<T> {
160
227
  data: T;
@@ -167,30 +234,53 @@ interface RawCheckoutSession {
167
234
  status: 'pending' | 'completed' | 'expired';
168
235
  successUrl: string;
169
236
  cancelUrl: string;
237
+ /** Session-level currency. Takes precedence over per-item/per-subscription currency. */
238
+ currency?: string;
170
239
  createdAt?: string;
171
240
  checkoutUrl?: string;
172
241
  items: Array<{
173
242
  uuid: string;
174
243
  checkoutSessionId: string;
175
- providerItemId: string;
176
- providerItemName: string;
244
+ /** Preferred catalog code. Falls back to the deprecated `providerItemId`. */
245
+ code?: string;
246
+ /** @deprecated Use `code`. */
247
+ providerItemId?: string;
248
+ /** Display-only name. Preferred over `providerItemName`. */
249
+ itemName?: string | null;
250
+ /** @deprecated Use `itemName`. Mirrored for backward compatibility. */
251
+ providerItemName?: string | null;
252
+ /** Display-only description from the catalog. */
177
253
  providerItemDescription?: string | null;
178
254
  quantity: number;
179
- totalAmount: number;
180
- overrideAmount: number | null;
181
- currency: string;
255
+ /** @deprecated Removed from the backend — resolved from the catalog. */
256
+ totalAmount?: number;
257
+ /** @deprecated Removed from the backend entirely. */
258
+ overrideAmount?: number | null;
259
+ /** @deprecated Use the session-level `currency`. */
260
+ currency?: string;
182
261
  metadata?: Record<string, unknown> | null;
183
262
  }>;
184
263
  subscriptions: Array<{
185
264
  uuid: string;
186
265
  checkoutSessionId: string;
187
- providerPlanId: string;
188
- providerPlanName: string;
266
+ /** Preferred catalog code. Falls back to the deprecated `providerPlanId`. */
267
+ code?: string;
268
+ /** @deprecated Use `code`. */
269
+ providerPlanId?: string;
270
+ /** Display-only name. Preferred over `providerPlanName`. */
271
+ subscriptionName?: string | null;
272
+ /** @deprecated Use `subscriptionName`. Mirrored for backward compatibility. */
273
+ providerPlanName?: string | null;
274
+ /** Display-only description from the catalog. */
189
275
  providerPlanDescription?: string | null;
190
276
  quantity: number;
191
- totalAmount: number;
192
- overrideAmount: number | null;
193
- currency: string;
277
+ /** @deprecated Removed from the backend — resolved from the catalog. */
278
+ totalAmount?: number;
279
+ /** @deprecated Removed from the backend entirely. */
280
+ overrideAmount?: number | null;
281
+ /** @deprecated Use the session-level `currency`. */
282
+ currency?: string;
283
+ /** @deprecated Removed from the backend. Checkouts only create new subscriptions. */
194
284
  isUpdate?: boolean;
195
285
  metadata?: Record<string, unknown> | null;
196
286
  }>;
@@ -232,6 +322,33 @@ declare class PaymentAPI {
232
322
  constructor(billingApiUrl: string);
233
323
  /** Fetch a raw checkout session by ID. */
234
324
  getCheckoutSession(checkoutSessionId: string): Promise<BillingResponse<RawCheckoutSession>>;
325
+ /**
326
+ * Stash display-only data for a session so subsequent fetches can fill in
327
+ * fields the backend no longer persists (`overrideAmount`, `totalAmount`,
328
+ * `providerItemName`, `providerPlanName`).
329
+ *
330
+ * Backed by `sessionStorage` in the browser, with an in-memory fallback in
331
+ * Node/SSR contexts. Default TTL: 1 hour.
332
+ *
333
+ * Server-returned values always win — cached values fill in only where the
334
+ * server returned `null` / `undefined`.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * paymentAPI.cacheSessionDisplayData(sessionId, {
339
+ * currency: 'USD',
340
+ * items: [{ code: 'pro_plan', overrideAmount: 24.99, providerItemName: 'Pro' }],
341
+ * });
342
+ * ```
343
+ */
344
+ cacheSessionDisplayData(sessionId: string, data: SessionDisplayCacheData, options?: {
345
+ ttlMs?: number;
346
+ }): void;
347
+ /**
348
+ * Drop any cached display data for a session. Call after the payment
349
+ * completes; otherwise the TTL handles cleanup.
350
+ */
351
+ clearSessionDisplayData(sessionId: string): void;
235
352
  /**
236
353
  * Fetch and normalize a checkout session.
237
354
  *
@@ -301,6 +418,24 @@ declare class PaymentAPI {
301
418
  private resolveProcessResponse;
302
419
  private toCheckoutProcessingPending;
303
420
  private clampRetryAfterMs;
421
+ /**
422
+ * Stash the display-only fields the consumer passed into a create-session
423
+ * call. Runs after the backend assigns a UUID so a later GET on the same
424
+ * session (typically after a redirect) can fill in fields the backend no
425
+ * longer persists — `overrideAmount`, `totalAmount`, `itemName`, etc.
426
+ *
427
+ * No-op when no UUID is available.
428
+ */
429
+ private autoCacheDisplayData;
430
+ /**
431
+ * Merge cached display-only fields (set by {@link cacheSessionDisplayData})
432
+ * into a raw session response and mirror the new/legacy name aliases so
433
+ * readers using either field always get a value when one exists.
434
+ *
435
+ * Server values always win — cache fills in only where the server returned
436
+ * `null` / `undefined`.
437
+ */
438
+ private mergeCachedDisplayData;
304
439
  }
305
440
 
306
441
  /**
@@ -321,11 +456,11 @@ declare class PaymentAPI {
321
456
  * billingApiUrl: 'https://billing.example.com',
322
457
  * checkoutBaseUrl: 'https://checkout.example.com',
323
458
  * clientId: 'client_123',
459
+ * currency: 'USD',
324
460
  * items: [{
325
- * providerItemId: 'prod_abc',
326
- * providerItemName: 'Pro Plan',
327
- * totalAmount: 49.99,
328
- * overrideAmount: 24.99,
461
+ * code: 'initial_charge',
462
+ * quantity: 1,
463
+ * metadata: { source: 'web' },
329
464
  * }],
330
465
  * account: { userId: 'user_1', email: 'user@example.com' },
331
466
  * successUrl: '/success',
@@ -344,4 +479,4 @@ declare function createCheckoutSessionWithRetries(options: CreateSessionParams &
344
479
  maxRetries?: number;
345
480
  }): Promise<CheckoutSessionResult>;
346
481
 
347
- export { FloPay, FloPayElements, PaymentAPI, StripeAdapter, createCheckoutSession, createCheckoutSessionWithRetries, loadFloPay };
482
+ export { FloPay, FloPayElements, PaymentAPI, type SessionDisplayCacheData, type SessionDisplayItem, type SessionDisplaySubscription, StripeAdapter, cacheSessionDisplayData, clearSessionDisplayData, createCheckoutSession, createCheckoutSessionWithRetries, getSessionDisplayData, loadFloPay };