@omnibase/core-js 0.5.8 → 0.5.9

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.
@@ -0,0 +1,542 @@
1
+ // src/payments/checkout.ts
2
+ var CheckoutManager = class {
3
+ /**
4
+ * Initialize the checkout manager
5
+ *
6
+ * @param paymentHandler - Payment handler instance for API communication
7
+ *
8
+ * @group Checkout
9
+ */
10
+ constructor(omnibaseClient) {
11
+ this.omnibaseClient = omnibaseClient;
12
+ }
13
+ /**
14
+ * Create a new Stripe checkout session
15
+ *
16
+ * Creates a checkout session with the specified options and returns
17
+ * the session URL for redirecting the user to complete payment.
18
+ * The checkout mode (one-time payment or subscription) is automatically
19
+ * determined from the price's configuration - no need to specify it manually.
20
+ *
21
+ * @param options - Configuration options for the checkout session
22
+ * @param options.price_id - Stripe price ID for the product/service
23
+ * @param options.success_url - URL to redirect after successful payment
24
+ * @param options.cancel_url - URL to redirect if user cancels
25
+ *
26
+ * @returns Promise resolving to checkout session response with URL and session ID
27
+ *
28
+ * @throws {Error} When the API request fails due to network issues
29
+ * @throws {Error} When the server returns an error response (invalid price_id, etc.)
30
+ * @throws {ValidationError} When required parameters are missing or invalid
31
+ *
32
+ * @example
33
+ * Creating a checkout session (mode is auto-detected):
34
+ * ```typescript
35
+ * const session = await checkoutManager.createSession({
36
+ * price_id: 'price_one_time_product',
37
+ * success_url: 'https://app.com/success',
38
+ * cancel_url: 'https://app.com/cancel'
39
+ * });
40
+ *
41
+ * // Redirect to Stripe checkout
42
+ * window.location.href = session.data.url;
43
+ * ```
44
+ *
45
+ * @example
46
+ * Checkout with session tracking:
47
+ * ```typescript
48
+ * const session = await checkoutManager.createSession({
49
+ * price_id: 'price_monthly_plan',
50
+ * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
51
+ * cancel_url: 'https://app.com/pricing',
52
+ * });
53
+ *
54
+ * console.log(`Session created: ${session.data.sessionId}`);
55
+ * ```
56
+ *
57
+ * @since 1.0.0
58
+ * @group Checkout
59
+ */
60
+ async createSession(options) {
61
+ const response = await this.omnibaseClient.fetch(
62
+ "/api/v1/payments/checkout",
63
+ {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json"
67
+ },
68
+ body: JSON.stringify(options)
69
+ }
70
+ );
71
+ if (!response.ok) {
72
+ const errorData = await response.text();
73
+ throw new Error(
74
+ `Failed to create checkout session: ${response.status} - ${errorData}`
75
+ );
76
+ }
77
+ const result = await response.json();
78
+ return result;
79
+ }
80
+ };
81
+
82
+ // src/payments/config.ts
83
+ var ConfigManager = class {
84
+ constructor(omnibaseClient) {
85
+ this.omnibaseClient = omnibaseClient;
86
+ }
87
+ /**
88
+ * Get the current Stripe configuration from the database
89
+ *
90
+ * Retrieves the latest Stripe configuration including products, prices,
91
+ * and UI customization data. This configuration represents the current
92
+ * active pricing structure with all UI elements for pricing table rendering.
93
+ *
94
+ * @returns Promise resolving to the current Stripe configuration
95
+ *
96
+ * @throws {Error} When the API request fails due to network issues
97
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
98
+ *
99
+ * @example
100
+ * Basic usage:
101
+ * ```typescript
102
+ * const config = await getStripeConfig();
103
+ * console.log(`Found ${config.data.config.products.length} products`);
104
+ *
105
+ * // Access product UI configuration
106
+ * config.data.config.products.forEach(product => {
107
+ * console.log(`${product.name}: ${product.ui?.tagline || 'No tagline'}`);
108
+ * });
109
+ * ```
110
+ */
111
+ async getStripeConfig() {
112
+ try {
113
+ const response = await this.omnibaseClient.fetch(
114
+ `/api/v1/stripe/config`,
115
+ {
116
+ method: "GET",
117
+ headers: {
118
+ "Content-Type": "application/json"
119
+ },
120
+ credentials: "include"
121
+ }
122
+ );
123
+ if (!response.ok) {
124
+ const errorData = await response.text();
125
+ throw new Error(
126
+ `Failed to get Stripe config: ${response.status} - ${errorData}`
127
+ );
128
+ }
129
+ const data = await response.json();
130
+ return data;
131
+ } catch (error) {
132
+ console.error("Error getting Stripe config:", error);
133
+ throw error;
134
+ }
135
+ }
136
+ /**
137
+ * Get available products with UI-ready pricing data
138
+ *
139
+ * Transforms the raw Stripe configuration into UI-ready format for pricing
140
+ * table rendering. Includes formatted pricing, features, limits, and all
141
+ * display customizations needed for marketing pages.
142
+ *
143
+ * @returns Promise resolving to products ready for UI consumption
144
+ *
145
+ * @throws {Error} When the API request fails or configuration is invalid
146
+ *
147
+ * @example
148
+ * Pricing table rendering:
149
+ * ```typescript
150
+ * const products = await getAvailableProducts();
151
+ *
152
+ * products.forEach(product => {
153
+ * const display = product.pricing_display;
154
+ * console.log(`${display.name} - ${display.tagline}`);
155
+ *
156
+ * display.prices.forEach(price => {
157
+ * console.log(` ${price.display_name}: ${price.formatted_price}`);
158
+ * });
159
+ * });
160
+ * ```
161
+ */
162
+ async getAvailableProducts() {
163
+ const configResponse = await this.getStripeConfig();
164
+ if (!configResponse.data?.config) {
165
+ throw new Error("No Stripe configuration found");
166
+ }
167
+ const products = configResponse.data.config.products;
168
+ return products.map(transformProductToUIReady).sort(
169
+ (a, b) => a.pricing_display.sort_order - b.pricing_display.sort_order
170
+ );
171
+ }
172
+ /**
173
+ * Get a specific product by ID
174
+ *
175
+ * Retrieves a single product configuration by its ID from the current
176
+ * Stripe configuration. Useful for product-specific operations.
177
+ *
178
+ * @param productId - The configuration product ID to retrieve
179
+ * @returns Promise resolving to the product or null if not found
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const product = await getProduct('starter_plan');
184
+ * if (product) {
185
+ * console.log(`Found product: ${product.name}`);
186
+ * }
187
+ * ```
188
+ */
189
+ async getProduct(productId) {
190
+ const configResponse = await this.getStripeConfig();
191
+ if (!configResponse.data?.config) {
192
+ return null;
193
+ }
194
+ const product = configResponse.data.config.products.find(
195
+ (p) => p.id === productId
196
+ );
197
+ return product || null;
198
+ }
199
+ };
200
+ function transformProductToUIReady(product) {
201
+ const ui = product.ui || {};
202
+ return {
203
+ ...product,
204
+ pricing_display: {
205
+ name: ui.display_name || product.name,
206
+ tagline: ui.tagline,
207
+ features: ui.features || [],
208
+ badge: ui.badge,
209
+ cta_text: ui.cta_text || "Choose Plan",
210
+ highlighted: ui.highlighted || false,
211
+ sort_order: ui.sort_order || 0,
212
+ prices: product.prices.map((price) => {
213
+ const priceUI = price.ui || {};
214
+ return {
215
+ id: price.id,
216
+ display_name: priceUI.display_name || formatDefaultPriceName(price),
217
+ formatted_price: formatPrice(price, priceUI),
218
+ billing_period: priceUI.billing_period || formatDefaultBillingPeriod(price),
219
+ features: priceUI.features || [],
220
+ limits: priceUI.limits || []
221
+ };
222
+ })
223
+ }
224
+ };
225
+ }
226
+ function formatPrice(price, priceUI) {
227
+ if (priceUI.price_display?.custom_text) {
228
+ return priceUI.price_display.custom_text;
229
+ }
230
+ if (!price.amount || price.amount === 0) {
231
+ return "Free";
232
+ }
233
+ const amount = price.amount / 100;
234
+ const currency = price.currency.toUpperCase();
235
+ let formattedPrice = "";
236
+ if (priceUI.price_display?.show_currency !== false) {
237
+ const currencySymbol = getCurrencySymbol(currency);
238
+ formattedPrice = `${currencySymbol}${amount.toFixed(2)}`;
239
+ } else {
240
+ formattedPrice = amount.toFixed(2);
241
+ }
242
+ if (priceUI.price_display?.suffix) {
243
+ formattedPrice += ` ${priceUI.price_display.suffix}`;
244
+ }
245
+ return formattedPrice;
246
+ }
247
+ function getCurrencySymbol(currency) {
248
+ const symbols = {
249
+ USD: "$",
250
+ EUR: "\u20AC",
251
+ GBP: "\xA3",
252
+ JPY: "\xA5",
253
+ CAD: "C$",
254
+ AUD: "A$"
255
+ };
256
+ return symbols[currency] || currency;
257
+ }
258
+ function formatDefaultPriceName(price) {
259
+ if (price.interval) {
260
+ return price.interval.charAt(0).toUpperCase() + price.interval.slice(1);
261
+ }
262
+ return "One-time";
263
+ }
264
+ function formatDefaultBillingPeriod(price) {
265
+ if (price.interval) {
266
+ const count = price.interval_count || 1;
267
+ const period = count === 1 ? price.interval : `${count} ${price.interval}s`;
268
+ return `per ${period}`;
269
+ }
270
+ return "one-time";
271
+ }
272
+
273
+ // src/payments/portal.ts
274
+ var PortalManager = class {
275
+ /**
276
+ * Initialize the portal manager
277
+ *
278
+ * @param paymentHandler - Payment handler instance for API communication
279
+ *
280
+ * @group Portal
281
+ */
282
+ constructor(omnibaseClient) {
283
+ this.omnibaseClient = omnibaseClient;
284
+ }
285
+ /**
286
+ * Create a new customer portal session
287
+ *
288
+ * Creates a portal session that allows the specified customer to
289
+ * manage their billing information, subscriptions, and payment methods.
290
+ * Returns a URL that the customer should be redirected to.
291
+ *
292
+ * The portal session is temporary and expires after a short period
293
+ * for security. Each access requires creating a new session.
294
+ *
295
+ * @param options - Configuration options for the portal session
296
+ * @param options.return_url - URL to redirect to when exiting the portal
297
+ *
298
+ * @returns Promise resolving to portal session response with access URL
299
+ *
300
+ * @throws {Error} When the API request fails due to network issues
301
+ * @throws {Error} When the server returns an error response
302
+ * @throws {ValidationError} When required parameters are missing or invalid
303
+ *
304
+ * @example
305
+ * Basic portal creation:
306
+ * ```typescript
307
+ * const portal = await portalManager.create({
308
+ * return_url: 'https://myapp.com/account/billing'
309
+ * });
310
+ *
311
+ * // Redirect user to portal
312
+ * window.location.href = portal.data.url;
313
+ * ```
314
+ *
315
+ * @example
316
+ * With error handling:
317
+ * ```typescript
318
+ * try {
319
+ * const portal = await portalManager.create({
320
+ * return_url: window.location.origin + '/billing'
321
+ * });
322
+ *
323
+ * window.location.href = portal.data.url;
324
+ * } catch (error) {
325
+ * console.error('Failed to create portal session:', error);
326
+ * showErrorMessage('Unable to access billing portal. Please try again.');
327
+ * }
328
+ * ```
329
+ *
330
+ * @since 1.0.0
331
+ * @group Portal
332
+ */
333
+ async create(options) {
334
+ const response = await this.omnibaseClient.fetch(
335
+ "/api/v1/payments/portal",
336
+ {
337
+ method: "POST",
338
+ headers: {
339
+ "Content-Type": "application/json"
340
+ },
341
+ body: JSON.stringify(options)
342
+ }
343
+ );
344
+ if (!response.ok) {
345
+ const errorData = await response.text();
346
+ throw new Error(
347
+ `Failed to create customer portal: ${response.status} - ${errorData}`
348
+ );
349
+ }
350
+ const result = await response.json();
351
+ return result;
352
+ }
353
+ };
354
+
355
+ // src/payments/usage.ts
356
+ var UsageManager = class {
357
+ /**
358
+ * Initialize the usage manager
359
+ *
360
+ * @param paymentHandler - Payment handler instance for API communication
361
+ *
362
+ * @group Usage
363
+ */
364
+ constructor(omnibaseClient) {
365
+ this.omnibaseClient = omnibaseClient;
366
+ }
367
+ /**
368
+ * Record a usage event for metered billing
369
+ *
370
+ * Records a usage event against a specific meter for billing calculation.
371
+ * The event will be aggregated with other usage events for the billing period
372
+ * to determine the customer's charges for metered products.
373
+ *
374
+ * Usage events should be recorded in real-time or as close to real-time as
375
+ * possible to ensure accurate billing and provide up-to-date usage visibility
376
+ * to customers.
377
+ *
378
+ * @param options - Usage recording options
379
+ * @param options.meter_event_name - Name of the meter to record against
380
+ * @param options.value - Usage quantity as string
381
+ *
382
+ * @returns Promise resolving to API response confirmation
383
+ *
384
+ * @throws {Error} When the API request fails due to network issues
385
+ * @throws {Error} When the server returns an error response (invalid meter name, customer, etc.)
386
+ * @throws {ValidationError} When required parameters are missing or invalid
387
+ *
388
+ * @example
389
+ * API call tracking:
390
+ * ```typescript
391
+ * // Record each API call
392
+ * await usageManager.recordUsage({
393
+ * meter_event_name: 'api_requests',
394
+ * value: '1'
395
+ * });
396
+ * ```
397
+ *
398
+ * @example
399
+ * Batch usage recording:
400
+ * ```typescript
401
+ * // Record multiple operations at once
402
+ * const usageEvents = [
403
+ * { meter_event_name: 'compute_hours', value: '0.5' },
404
+ * { meter_event_name: 'storage_gb', value: '10' },
405
+ * { meter_event_name: 'api_calls', value: '50' }
406
+ * ];
407
+ *
408
+ * for (const event of usageEvents) {
409
+ * await usageManager.recordUsage(event);
410
+ * }
411
+ * ```
412
+ *
413
+ * @example
414
+ * With error handling:
415
+ * ```typescript
416
+ * try {
417
+ * await usageManager.recordUsage({
418
+ * meter_event_name: 'file_uploads',
419
+ * value: String(uploadedFiles.length)
420
+ * });
421
+ * } catch (error) {
422
+ * console.error('Failed to record usage:', error);
423
+ * // Usage recording failure shouldn't block user operations
424
+ * // but should be logged for billing accuracy
425
+ * }
426
+ * ```
427
+ *
428
+ * @since 1.0.0
429
+ * @group Usage
430
+ */
431
+ async recordUsage(options) {
432
+ const response = await this.omnibaseClient.fetch("/api/v1/payments/usage", {
433
+ method: "POST",
434
+ headers: {
435
+ "Content-Type": "application/json"
436
+ },
437
+ body: JSON.stringify(options)
438
+ });
439
+ if (!response.ok) {
440
+ const errorData = await response.text();
441
+ throw new Error(
442
+ `Failed to record usage: ${response.status} - ${errorData}`
443
+ );
444
+ }
445
+ const result = await response.json();
446
+ return result;
447
+ }
448
+ };
449
+
450
+ // src/payments/handler.ts
451
+ var PaymentHandler = class {
452
+ /**
453
+ * Initialize the payment handler with API configuration
454
+ *
455
+ * Creates a new payment handler instance that will communicate with
456
+ * the specified API endpoint. The handler automatically handles
457
+ * request formatting and authentication headers.
458
+ *
459
+ * @param apiUrl - Base URL for the payment API endpoint
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * const paymentHandler = new PaymentHandler('https://api.myapp.com');
464
+ * ```
465
+ *
466
+ * @since 1.0.0
467
+ * @group Client
468
+ */
469
+ constructor(omnibaseClient) {
470
+ this.omnibaseClient = omnibaseClient;
471
+ this.checkout = new CheckoutManager(this.omnibaseClient);
472
+ this.config = new ConfigManager(this.omnibaseClient);
473
+ this.portal = new PortalManager(this.omnibaseClient);
474
+ this.usage = new UsageManager(this.omnibaseClient);
475
+ }
476
+ /**
477
+ * Checkout session management
478
+ *
479
+ * Provides functionality for creating and managing Stripe checkout sessions
480
+ * for both one-time payments and subscription billing.
481
+ *
482
+ * @example
483
+ * ```typescript
484
+ * const session = await paymentHandler.checkout.createSession({
485
+ * price_id: 'price_monthly',
486
+ * success_url: window.location.origin + '/success',
487
+ * cancel_url: window.location.origin + '/pricing'
488
+ * });
489
+ * ```
490
+ */
491
+ checkout;
492
+ /**
493
+ * Stripe configuration management
494
+ *
495
+ * Handles retrieval and processing of database-backed Stripe configurations,
496
+ * providing UI-ready product and pricing data for rendering pricing tables.
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * const products = await paymentHandler.config.getAvailableProducts();
501
+ * const config = await paymentHandler.config.getStripeConfig();
502
+ * ```
503
+ */
504
+ config;
505
+ /**
506
+ * Customer portal management
507
+ *
508
+ * Creates customer portal sessions for subscription management,
509
+ * billing history, and payment method updates.
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const portal = await paymentHandler.portal.create({
514
+ * return_url: 'https://app.com/billing'
515
+ * });
516
+ * ```
517
+ */
518
+ portal;
519
+ /**
520
+ * Usage tracking and metered billing
521
+ *
522
+ * Records usage events for metered billing products and manages
523
+ * usage-based pricing calculations.
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * await paymentHandler.usage.recordUsage({
528
+ * meter_event_name: 'api_calls',
529
+ * value: '1'
530
+ * });
531
+ * ```
532
+ */
533
+ usage;
534
+ };
535
+
536
+ export {
537
+ CheckoutManager,
538
+ ConfigManager,
539
+ PortalManager,
540
+ UsageManager,
541
+ PaymentHandler
542
+ };
package/dist/index.cjs CHANGED
@@ -41,12 +41,11 @@ var CheckoutManager = class {
41
41
  *
42
42
  * Creates a checkout session with the specified options and returns
43
43
  * the session URL for redirecting the user to complete payment.
44
- * The session will be configured for either one-time payment or
45
- * subscription based on the mode parameter.
44
+ * The checkout mode (one-time payment or subscription) is automatically
45
+ * determined from the price's configuration - no need to specify it manually.
46
46
  *
47
47
  * @param options - Configuration options for the checkout session
48
48
  * @param options.price_id - Stripe price ID for the product/service
49
- * @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
50
49
  * @param options.success_url - URL to redirect after successful payment
51
50
  * @param options.cancel_url - URL to redirect if user cancels
52
51
  *
@@ -57,11 +56,10 @@ var CheckoutManager = class {
57
56
  * @throws {ValidationError} When required parameters are missing or invalid
58
57
  *
59
58
  * @example
60
- * One-time payment checkout:
59
+ * Creating a checkout session (mode is auto-detected):
61
60
  * ```typescript
62
61
  * const session = await checkoutManager.createSession({
63
62
  * price_id: 'price_one_time_product',
64
- * mode: 'payment',
65
63
  * success_url: 'https://app.com/success',
66
64
  * cancel_url: 'https://app.com/cancel'
67
65
  * });
@@ -71,12 +69,11 @@ var CheckoutManager = class {
71
69
  * ```
72
70
  *
73
71
  * @example
74
- * Subscription checkout with existing customer:
72
+ * Checkout with session tracking:
75
73
  * ```typescript
76
74
  * const session = await checkoutManager.createSession({
77
75
  * price_id: 'price_monthly_plan',
78
- * mode: 'subscription',
79
- * success_url: 'https://app.com/dashboard?welcome=true',
76
+ * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
80
77
  * cancel_url: 'https://app.com/pricing',
81
78
  * });
82
79
  *
@@ -512,7 +509,6 @@ var PaymentHandler = class {
512
509
  * ```typescript
513
510
  * const session = await paymentHandler.checkout.createSession({
514
511
  * price_id: 'price_monthly',
515
- * mode: 'subscription',
516
512
  * success_url: window.location.origin + '/success',
517
513
  * cancel_url: window.location.origin + '/pricing'
518
514
  * });
@@ -1242,10 +1238,9 @@ var OmnibaseClient = class {
1242
1238
  *
1243
1239
  * @example
1244
1240
  * ```typescript
1245
- * // Create a checkout session
1241
+ * // Create a checkout session (mode auto-detected from price)
1246
1242
  * const checkout = await omnibase.payments.checkout.createSession({
1247
1243
  * price_id: 'price_123',
1248
- * mode: 'subscription',
1249
1244
  * success_url: 'https://app.com/success',
1250
1245
  * cancel_url: 'https://app.com/cancel'
1251
1246
  * });
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  PermissionsClient
3
3
  } from "./chunk-DDFBRGMG.js";
4
+ import {
5
+ PaymentHandler
6
+ } from "./chunk-PNP3T7XU.js";
4
7
  import {
5
8
  TenantHandler
6
9
  } from "./chunk-L7EZC6WP.js";
7
- import {
8
- PaymentHandler
9
- } from "./chunk-KGG7T6KJ.js";
10
10
 
11
11
  // src/client.ts
12
12
  var OmnibaseClient = class {
@@ -27,10 +27,9 @@ var OmnibaseClient = class {
27
27
  *
28
28
  * @example
29
29
  * ```typescript
30
- * // Create a checkout session
30
+ * // Create a checkout session (mode auto-detected from price)
31
31
  * const checkout = await omnibase.payments.checkout.createSession({
32
32
  * price_id: 'price_123',
33
- * mode: 'subscription',
34
33
  * success_url: 'https://app.com/success',
35
34
  * cancel_url: 'https://app.com/cancel'
36
35
  * });
@@ -45,12 +45,11 @@ var CheckoutManager = class {
45
45
  *
46
46
  * Creates a checkout session with the specified options and returns
47
47
  * the session URL for redirecting the user to complete payment.
48
- * The session will be configured for either one-time payment or
49
- * subscription based on the mode parameter.
48
+ * The checkout mode (one-time payment or subscription) is automatically
49
+ * determined from the price's configuration - no need to specify it manually.
50
50
  *
51
51
  * @param options - Configuration options for the checkout session
52
52
  * @param options.price_id - Stripe price ID for the product/service
53
- * @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
54
53
  * @param options.success_url - URL to redirect after successful payment
55
54
  * @param options.cancel_url - URL to redirect if user cancels
56
55
  *
@@ -61,11 +60,10 @@ var CheckoutManager = class {
61
60
  * @throws {ValidationError} When required parameters are missing or invalid
62
61
  *
63
62
  * @example
64
- * One-time payment checkout:
63
+ * Creating a checkout session (mode is auto-detected):
65
64
  * ```typescript
66
65
  * const session = await checkoutManager.createSession({
67
66
  * price_id: 'price_one_time_product',
68
- * mode: 'payment',
69
67
  * success_url: 'https://app.com/success',
70
68
  * cancel_url: 'https://app.com/cancel'
71
69
  * });
@@ -75,12 +73,11 @@ var CheckoutManager = class {
75
73
  * ```
76
74
  *
77
75
  * @example
78
- * Subscription checkout with existing customer:
76
+ * Checkout with session tracking:
79
77
  * ```typescript
80
78
  * const session = await checkoutManager.createSession({
81
79
  * price_id: 'price_monthly_plan',
82
- * mode: 'subscription',
83
- * success_url: 'https://app.com/dashboard?welcome=true',
80
+ * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
84
81
  * cancel_url: 'https://app.com/pricing',
85
82
  * });
86
83
  *
@@ -516,7 +513,6 @@ var PaymentHandler = class {
516
513
  * ```typescript
517
514
  * const session = await paymentHandler.checkout.createSession({
518
515
  * price_id: 'price_monthly',
519
- * mode: 'subscription',
520
516
  * success_url: window.location.origin + '/success',
521
517
  * cancel_url: window.location.origin + '/pricing'
522
518
  * });
@@ -73,12 +73,6 @@ type ApiResponse<T> = {
73
73
  type CheckoutOptions = {
74
74
  /** Stripe price ID for the product/service being purchased */
75
75
  price_id: string;
76
- /**
77
- * Checkout mode determining the type of transaction
78
- * - 'payment': One-time payment
79
- * - 'subscription': Recurring subscription
80
- */
81
- mode: "payment" | "subscription";
82
76
  /**
83
77
  * URL to redirect to after successful payment
84
78
  * Can include {CHECKOUT_SESSION_ID} placeholder for session tracking
@@ -115,13 +109,12 @@ type CreateCheckoutResponse = ApiResponse<{
115
109
  * sensitive payment data to touch your servers.
116
110
  *
117
111
  * @example
118
- * Creating a subscription checkout:
112
+ * Creating a checkout session (mode auto-detected from price):
119
113
  * ```typescript
120
114
  * const checkoutManager = new CheckoutManager(paymentHandler);
121
115
  *
122
116
  * const session = await checkoutManager.createSession({
123
117
  * price_id: 'price_monthly_pro',
124
- * mode: 'subscription',
125
118
  * success_url: 'https://app.com/welcome?session_id={CHECKOUT_SESSION_ID}',
126
119
  * cancel_url: 'https://app.com/pricing',
127
120
  * });
@@ -149,12 +142,11 @@ declare class CheckoutManager {
149
142
  *
150
143
  * Creates a checkout session with the specified options and returns
151
144
  * the session URL for redirecting the user to complete payment.
152
- * The session will be configured for either one-time payment or
153
- * subscription based on the mode parameter.
145
+ * The checkout mode (one-time payment or subscription) is automatically
146
+ * determined from the price's configuration - no need to specify it manually.
154
147
  *
155
148
  * @param options - Configuration options for the checkout session
156
149
  * @param options.price_id - Stripe price ID for the product/service
157
- * @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
158
150
  * @param options.success_url - URL to redirect after successful payment
159
151
  * @param options.cancel_url - URL to redirect if user cancels
160
152
  *
@@ -165,11 +157,10 @@ declare class CheckoutManager {
165
157
  * @throws {ValidationError} When required parameters are missing or invalid
166
158
  *
167
159
  * @example
168
- * One-time payment checkout:
160
+ * Creating a checkout session (mode is auto-detected):
169
161
  * ```typescript
170
162
  * const session = await checkoutManager.createSession({
171
163
  * price_id: 'price_one_time_product',
172
- * mode: 'payment',
173
164
  * success_url: 'https://app.com/success',
174
165
  * cancel_url: 'https://app.com/cancel'
175
166
  * });
@@ -179,12 +170,11 @@ declare class CheckoutManager {
179
170
  * ```
180
171
  *
181
172
  * @example
182
- * Subscription checkout with existing customer:
173
+ * Checkout with session tracking:
183
174
  * ```typescript
184
175
  * const session = await checkoutManager.createSession({
185
176
  * price_id: 'price_monthly_plan',
186
- * mode: 'subscription',
187
- * success_url: 'https://app.com/dashboard?welcome=true',
177
+ * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
188
178
  * cancel_url: 'https://app.com/pricing',
189
179
  * });
190
180
  *
@@ -983,10 +973,9 @@ declare class UsageManager {
983
973
  * ```typescript
984
974
  * const paymentHandler = new PaymentHandler('https://api.example.com');
985
975
  *
986
- * // Create a checkout session
976
+ * // Create a checkout session (mode auto-detected from price)
987
977
  * const checkout = await paymentHandler.checkout.createSession({
988
978
  * price_id: 'price_123',
989
- * mode: 'subscription',
990
979
  * success_url: 'https://app.com/success',
991
980
  * cancel_url: 'https://app.com/cancel'
992
981
  * });
@@ -1029,7 +1018,6 @@ declare class PaymentHandler {
1029
1018
  * ```typescript
1030
1019
  * const session = await paymentHandler.checkout.createSession({
1031
1020
  * price_id: 'price_monthly',
1032
- * mode: 'subscription',
1033
1021
  * success_url: window.location.origin + '/success',
1034
1022
  * cancel_url: window.location.origin + '/pricing'
1035
1023
  * });
@@ -1941,10 +1929,9 @@ declare class OmnibaseClient {
1941
1929
  *
1942
1930
  * @example
1943
1931
  * ```typescript
1944
- * // Create a checkout session
1932
+ * // Create a checkout session (mode auto-detected from price)
1945
1933
  * const checkout = await omnibase.payments.checkout.createSession({
1946
1934
  * price_id: 'price_123',
1947
- * mode: 'subscription',
1948
1935
  * success_url: 'https://app.com/success',
1949
1936
  * cancel_url: 'https://app.com/cancel'
1950
1937
  * });
@@ -73,12 +73,6 @@ type ApiResponse<T> = {
73
73
  type CheckoutOptions = {
74
74
  /** Stripe price ID for the product/service being purchased */
75
75
  price_id: string;
76
- /**
77
- * Checkout mode determining the type of transaction
78
- * - 'payment': One-time payment
79
- * - 'subscription': Recurring subscription
80
- */
81
- mode: "payment" | "subscription";
82
76
  /**
83
77
  * URL to redirect to after successful payment
84
78
  * Can include {CHECKOUT_SESSION_ID} placeholder for session tracking
@@ -115,13 +109,12 @@ type CreateCheckoutResponse = ApiResponse<{
115
109
  * sensitive payment data to touch your servers.
116
110
  *
117
111
  * @example
118
- * Creating a subscription checkout:
112
+ * Creating a checkout session (mode auto-detected from price):
119
113
  * ```typescript
120
114
  * const checkoutManager = new CheckoutManager(paymentHandler);
121
115
  *
122
116
  * const session = await checkoutManager.createSession({
123
117
  * price_id: 'price_monthly_pro',
124
- * mode: 'subscription',
125
118
  * success_url: 'https://app.com/welcome?session_id={CHECKOUT_SESSION_ID}',
126
119
  * cancel_url: 'https://app.com/pricing',
127
120
  * });
@@ -149,12 +142,11 @@ declare class CheckoutManager {
149
142
  *
150
143
  * Creates a checkout session with the specified options and returns
151
144
  * the session URL for redirecting the user to complete payment.
152
- * The session will be configured for either one-time payment or
153
- * subscription based on the mode parameter.
145
+ * The checkout mode (one-time payment or subscription) is automatically
146
+ * determined from the price's configuration - no need to specify it manually.
154
147
  *
155
148
  * @param options - Configuration options for the checkout session
156
149
  * @param options.price_id - Stripe price ID for the product/service
157
- * @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
158
150
  * @param options.success_url - URL to redirect after successful payment
159
151
  * @param options.cancel_url - URL to redirect if user cancels
160
152
  *
@@ -165,11 +157,10 @@ declare class CheckoutManager {
165
157
  * @throws {ValidationError} When required parameters are missing or invalid
166
158
  *
167
159
  * @example
168
- * One-time payment checkout:
160
+ * Creating a checkout session (mode is auto-detected):
169
161
  * ```typescript
170
162
  * const session = await checkoutManager.createSession({
171
163
  * price_id: 'price_one_time_product',
172
- * mode: 'payment',
173
164
  * success_url: 'https://app.com/success',
174
165
  * cancel_url: 'https://app.com/cancel'
175
166
  * });
@@ -179,12 +170,11 @@ declare class CheckoutManager {
179
170
  * ```
180
171
  *
181
172
  * @example
182
- * Subscription checkout with existing customer:
173
+ * Checkout with session tracking:
183
174
  * ```typescript
184
175
  * const session = await checkoutManager.createSession({
185
176
  * price_id: 'price_monthly_plan',
186
- * mode: 'subscription',
187
- * success_url: 'https://app.com/dashboard?welcome=true',
177
+ * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
188
178
  * cancel_url: 'https://app.com/pricing',
189
179
  * });
190
180
  *
@@ -983,10 +973,9 @@ declare class UsageManager {
983
973
  * ```typescript
984
974
  * const paymentHandler = new PaymentHandler('https://api.example.com');
985
975
  *
986
- * // Create a checkout session
976
+ * // Create a checkout session (mode auto-detected from price)
987
977
  * const checkout = await paymentHandler.checkout.createSession({
988
978
  * price_id: 'price_123',
989
- * mode: 'subscription',
990
979
  * success_url: 'https://app.com/success',
991
980
  * cancel_url: 'https://app.com/cancel'
992
981
  * });
@@ -1029,7 +1018,6 @@ declare class PaymentHandler {
1029
1018
  * ```typescript
1030
1019
  * const session = await paymentHandler.checkout.createSession({
1031
1020
  * price_id: 'price_monthly',
1032
- * mode: 'subscription',
1033
1021
  * success_url: window.location.origin + '/success',
1034
1022
  * cancel_url: window.location.origin + '/pricing'
1035
1023
  * });
@@ -1941,10 +1929,9 @@ declare class OmnibaseClient {
1941
1929
  *
1942
1930
  * @example
1943
1931
  * ```typescript
1944
- * // Create a checkout session
1932
+ * // Create a checkout session (mode auto-detected from price)
1945
1933
  * const checkout = await omnibase.payments.checkout.createSession({
1946
1934
  * price_id: 'price_123',
1947
- * mode: 'subscription',
1948
1935
  * success_url: 'https://app.com/success',
1949
1936
  * cancel_url: 'https://app.com/cancel'
1950
1937
  * });
@@ -4,7 +4,7 @@ import {
4
4
  PaymentHandler,
5
5
  PortalManager,
6
6
  UsageManager
7
- } from "../chunk-KGG7T6KJ.js";
7
+ } from "../chunk-PNP3T7XU.js";
8
8
  export {
9
9
  CheckoutManager,
10
10
  ConfigManager,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "OmniBase core Javascript SDK - framework agnostic",
5
5
  "files": [
6
6
  "dist/**/*"