@omnibase/core-js 0.5.1 → 0.5.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/chunk-KGG7T6KJ.js +546 -0
- package/dist/index.cjs +4 -14
- package/dist/index.js +1 -1
- package/dist/payments/index.cjs +4 -14
- package/dist/payments/index.d.cts +4 -30
- package/dist/payments/index.d.ts +4 -30
- package/dist/payments/index.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,546 @@
|
|
|
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 session will be configured for either one-time payment or
|
|
19
|
+
* subscription based on the mode parameter.
|
|
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.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
24
|
+
* @param options.success_url - URL to redirect after successful payment
|
|
25
|
+
* @param options.cancel_url - URL to redirect if user cancels
|
|
26
|
+
*
|
|
27
|
+
* @returns Promise resolving to checkout session response with URL and session ID
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} When the API request fails due to network issues
|
|
30
|
+
* @throws {Error} When the server returns an error response (invalid price_id, etc.)
|
|
31
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* One-time payment checkout:
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const session = await checkoutManager.createSession({
|
|
37
|
+
* price_id: 'price_one_time_product',
|
|
38
|
+
* mode: 'payment',
|
|
39
|
+
* success_url: 'https://app.com/success',
|
|
40
|
+
* cancel_url: 'https://app.com/cancel'
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Redirect to Stripe checkout
|
|
44
|
+
* window.location.href = session.data.url;
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* Subscription checkout with existing customer:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const session = await checkoutManager.createSession({
|
|
51
|
+
* price_id: 'price_monthly_plan',
|
|
52
|
+
* mode: 'subscription',
|
|
53
|
+
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
54
|
+
* cancel_url: 'https://app.com/pricing',
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* console.log(`Session created: ${session.data.sessionId}`);
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @group Checkout
|
|
62
|
+
*/
|
|
63
|
+
async createSession(options) {
|
|
64
|
+
const response = await this.omnibaseClient.fetch(
|
|
65
|
+
"/api/v1/payments/checkout",
|
|
66
|
+
{
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/json"
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(options)
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const errorData = await response.text();
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Failed to create checkout session: ${response.status} - ${errorData}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const result = await response.json();
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/payments/config.ts
|
|
86
|
+
var ConfigManager = class {
|
|
87
|
+
constructor(omnibaseClient) {
|
|
88
|
+
this.omnibaseClient = omnibaseClient;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the current Stripe configuration from the database
|
|
92
|
+
*
|
|
93
|
+
* Retrieves the latest Stripe configuration including products, prices,
|
|
94
|
+
* and UI customization data. This configuration represents the current
|
|
95
|
+
* active pricing structure with all UI elements for pricing table rendering.
|
|
96
|
+
*
|
|
97
|
+
* @returns Promise resolving to the current Stripe configuration
|
|
98
|
+
*
|
|
99
|
+
* @throws {Error} When the API request fails due to network issues
|
|
100
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* Basic usage:
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const config = await getStripeConfig();
|
|
106
|
+
* console.log(`Found ${config.data.config.products.length} products`);
|
|
107
|
+
*
|
|
108
|
+
* // Access product UI configuration
|
|
109
|
+
* config.data.config.products.forEach(product => {
|
|
110
|
+
* console.log(`${product.name}: ${product.ui?.tagline || 'No tagline'}`);
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
async getStripeConfig() {
|
|
115
|
+
try {
|
|
116
|
+
const response = await this.omnibaseClient.fetch(
|
|
117
|
+
`/api/v1/stripe/config`,
|
|
118
|
+
{
|
|
119
|
+
method: "GET",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json"
|
|
122
|
+
},
|
|
123
|
+
credentials: "include"
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
const errorData = await response.text();
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Failed to get Stripe config: ${response.status} - ${errorData}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const data = await response.json();
|
|
133
|
+
return data;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error("Error getting Stripe config:", error);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get available products with UI-ready pricing data
|
|
141
|
+
*
|
|
142
|
+
* Transforms the raw Stripe configuration into UI-ready format for pricing
|
|
143
|
+
* table rendering. Includes formatted pricing, features, limits, and all
|
|
144
|
+
* display customizations needed for marketing pages.
|
|
145
|
+
*
|
|
146
|
+
* @returns Promise resolving to products ready for UI consumption
|
|
147
|
+
*
|
|
148
|
+
* @throws {Error} When the API request fails or configuration is invalid
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* Pricing table rendering:
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const products = await getAvailableProducts();
|
|
154
|
+
*
|
|
155
|
+
* products.forEach(product => {
|
|
156
|
+
* const display = product.pricing_display;
|
|
157
|
+
* console.log(`${display.name} - ${display.tagline}`);
|
|
158
|
+
*
|
|
159
|
+
* display.prices.forEach(price => {
|
|
160
|
+
* console.log(` ${price.display_name}: ${price.formatted_price}`);
|
|
161
|
+
* });
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
async getAvailableProducts() {
|
|
166
|
+
const configResponse = await this.getStripeConfig();
|
|
167
|
+
if (!configResponse.data?.config) {
|
|
168
|
+
throw new Error("No Stripe configuration found");
|
|
169
|
+
}
|
|
170
|
+
const products = configResponse.data.config.products;
|
|
171
|
+
return products.map(transformProductToUIReady).sort(
|
|
172
|
+
(a, b) => a.pricing_display.sort_order - b.pricing_display.sort_order
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get a specific product by ID
|
|
177
|
+
*
|
|
178
|
+
* Retrieves a single product configuration by its ID from the current
|
|
179
|
+
* Stripe configuration. Useful for product-specific operations.
|
|
180
|
+
*
|
|
181
|
+
* @param productId - The configuration product ID to retrieve
|
|
182
|
+
* @returns Promise resolving to the product or null if not found
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const product = await getProduct('starter_plan');
|
|
187
|
+
* if (product) {
|
|
188
|
+
* console.log(`Found product: ${product.name}`);
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
async getProduct(productId) {
|
|
193
|
+
const configResponse = await this.getStripeConfig();
|
|
194
|
+
if (!configResponse.data?.config) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const product = configResponse.data.config.products.find(
|
|
198
|
+
(p) => p.id === productId
|
|
199
|
+
);
|
|
200
|
+
return product || null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
function transformProductToUIReady(product) {
|
|
204
|
+
const ui = product.ui || {};
|
|
205
|
+
return {
|
|
206
|
+
...product,
|
|
207
|
+
pricing_display: {
|
|
208
|
+
name: ui.display_name || product.name,
|
|
209
|
+
tagline: ui.tagline,
|
|
210
|
+
features: ui.features || [],
|
|
211
|
+
badge: ui.badge,
|
|
212
|
+
cta_text: ui.cta_text || "Choose Plan",
|
|
213
|
+
highlighted: ui.highlighted || false,
|
|
214
|
+
sort_order: ui.sort_order || 0,
|
|
215
|
+
prices: product.prices.map((price) => {
|
|
216
|
+
const priceUI = price.ui || {};
|
|
217
|
+
return {
|
|
218
|
+
id: price.id,
|
|
219
|
+
display_name: priceUI.display_name || formatDefaultPriceName(price),
|
|
220
|
+
formatted_price: formatPrice(price, priceUI),
|
|
221
|
+
billing_period: priceUI.billing_period || formatDefaultBillingPeriod(price),
|
|
222
|
+
features: priceUI.features || [],
|
|
223
|
+
limits: priceUI.limits || []
|
|
224
|
+
};
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function formatPrice(price, priceUI) {
|
|
230
|
+
if (priceUI.price_display?.custom_text) {
|
|
231
|
+
return priceUI.price_display.custom_text;
|
|
232
|
+
}
|
|
233
|
+
if (!price.amount || price.amount === 0) {
|
|
234
|
+
return "Free";
|
|
235
|
+
}
|
|
236
|
+
const amount = price.amount / 100;
|
|
237
|
+
const currency = price.currency.toUpperCase();
|
|
238
|
+
let formattedPrice = "";
|
|
239
|
+
if (priceUI.price_display?.show_currency !== false) {
|
|
240
|
+
const currencySymbol = getCurrencySymbol(currency);
|
|
241
|
+
formattedPrice = `${currencySymbol}${amount.toFixed(2)}`;
|
|
242
|
+
} else {
|
|
243
|
+
formattedPrice = amount.toFixed(2);
|
|
244
|
+
}
|
|
245
|
+
if (priceUI.price_display?.suffix) {
|
|
246
|
+
formattedPrice += ` ${priceUI.price_display.suffix}`;
|
|
247
|
+
}
|
|
248
|
+
return formattedPrice;
|
|
249
|
+
}
|
|
250
|
+
function getCurrencySymbol(currency) {
|
|
251
|
+
const symbols = {
|
|
252
|
+
USD: "$",
|
|
253
|
+
EUR: "\u20AC",
|
|
254
|
+
GBP: "\xA3",
|
|
255
|
+
JPY: "\xA5",
|
|
256
|
+
CAD: "C$",
|
|
257
|
+
AUD: "A$"
|
|
258
|
+
};
|
|
259
|
+
return symbols[currency] || currency;
|
|
260
|
+
}
|
|
261
|
+
function formatDefaultPriceName(price) {
|
|
262
|
+
if (price.interval) {
|
|
263
|
+
return price.interval.charAt(0).toUpperCase() + price.interval.slice(1);
|
|
264
|
+
}
|
|
265
|
+
return "One-time";
|
|
266
|
+
}
|
|
267
|
+
function formatDefaultBillingPeriod(price) {
|
|
268
|
+
if (price.interval) {
|
|
269
|
+
const count = price.interval_count || 1;
|
|
270
|
+
const period = count === 1 ? price.interval : `${count} ${price.interval}s`;
|
|
271
|
+
return `per ${period}`;
|
|
272
|
+
}
|
|
273
|
+
return "one-time";
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/payments/portal.ts
|
|
277
|
+
var PortalManager = class {
|
|
278
|
+
/**
|
|
279
|
+
* Initialize the portal manager
|
|
280
|
+
*
|
|
281
|
+
* @param paymentHandler - Payment handler instance for API communication
|
|
282
|
+
*
|
|
283
|
+
* @group Portal
|
|
284
|
+
*/
|
|
285
|
+
constructor(omnibaseClient) {
|
|
286
|
+
this.omnibaseClient = omnibaseClient;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Create a new customer portal session
|
|
290
|
+
*
|
|
291
|
+
* Creates a portal session that allows the specified customer to
|
|
292
|
+
* manage their billing information, subscriptions, and payment methods.
|
|
293
|
+
* Returns a URL that the customer should be redirected to.
|
|
294
|
+
*
|
|
295
|
+
* The portal session is temporary and expires after a short period
|
|
296
|
+
* for security. Each access requires creating a new session.
|
|
297
|
+
*
|
|
298
|
+
* @param options - Configuration options for the portal session
|
|
299
|
+
* @param options.return_url - URL to redirect to when exiting the portal
|
|
300
|
+
*
|
|
301
|
+
* @returns Promise resolving to portal session response with access URL
|
|
302
|
+
*
|
|
303
|
+
* @throws {Error} When the API request fails due to network issues
|
|
304
|
+
* @throws {Error} When the server returns an error response
|
|
305
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* Basic portal creation:
|
|
309
|
+
* ```typescript
|
|
310
|
+
* const portal = await portalManager.create({
|
|
311
|
+
* return_url: 'https://myapp.com/account/billing'
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* // Redirect user to portal
|
|
315
|
+
* window.location.href = portal.data.url;
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* With error handling:
|
|
320
|
+
* ```typescript
|
|
321
|
+
* try {
|
|
322
|
+
* const portal = await portalManager.create({
|
|
323
|
+
* return_url: window.location.origin + '/billing'
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* window.location.href = portal.data.url;
|
|
327
|
+
* } catch (error) {
|
|
328
|
+
* console.error('Failed to create portal session:', error);
|
|
329
|
+
* showErrorMessage('Unable to access billing portal. Please try again.');
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @since 1.0.0
|
|
334
|
+
* @group Portal
|
|
335
|
+
*/
|
|
336
|
+
async create(options) {
|
|
337
|
+
const response = await this.omnibaseClient.fetch(
|
|
338
|
+
"/api/v1/payments/portal",
|
|
339
|
+
{
|
|
340
|
+
method: "POST",
|
|
341
|
+
headers: {
|
|
342
|
+
"Content-Type": "application/json"
|
|
343
|
+
},
|
|
344
|
+
body: JSON.stringify(options)
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
if (!response.ok) {
|
|
348
|
+
const errorData = await response.text();
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Failed to create customer portal: ${response.status} - ${errorData}`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
const result = await response.json();
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// src/payments/usage.ts
|
|
359
|
+
var UsageManager = class {
|
|
360
|
+
/**
|
|
361
|
+
* Initialize the usage manager
|
|
362
|
+
*
|
|
363
|
+
* @param paymentHandler - Payment handler instance for API communication
|
|
364
|
+
*
|
|
365
|
+
* @group Usage
|
|
366
|
+
*/
|
|
367
|
+
constructor(omnibaseClient) {
|
|
368
|
+
this.omnibaseClient = omnibaseClient;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Record a usage event for metered billing
|
|
372
|
+
*
|
|
373
|
+
* Records a usage event against a specific meter for billing calculation.
|
|
374
|
+
* The event will be aggregated with other usage events for the billing period
|
|
375
|
+
* to determine the customer's charges for metered products.
|
|
376
|
+
*
|
|
377
|
+
* Usage events should be recorded in real-time or as close to real-time as
|
|
378
|
+
* possible to ensure accurate billing and provide up-to-date usage visibility
|
|
379
|
+
* to customers.
|
|
380
|
+
*
|
|
381
|
+
* @param options - Usage recording options
|
|
382
|
+
* @param options.meter_event_name - Name of the meter to record against
|
|
383
|
+
* @param options.value - Usage quantity as string
|
|
384
|
+
*
|
|
385
|
+
* @returns Promise resolving to API response confirmation
|
|
386
|
+
*
|
|
387
|
+
* @throws {Error} When the API request fails due to network issues
|
|
388
|
+
* @throws {Error} When the server returns an error response (invalid meter name, customer, etc.)
|
|
389
|
+
* @throws {ValidationError} When required parameters are missing or invalid
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* API call tracking:
|
|
393
|
+
* ```typescript
|
|
394
|
+
* // Record each API call
|
|
395
|
+
* await usageManager.recordUsage({
|
|
396
|
+
* meter_event_name: 'api_requests',
|
|
397
|
+
* value: '1'
|
|
398
|
+
* });
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* Batch usage recording:
|
|
403
|
+
* ```typescript
|
|
404
|
+
* // Record multiple operations at once
|
|
405
|
+
* const usageEvents = [
|
|
406
|
+
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
407
|
+
* { meter_event_name: 'storage_gb', value: '10' },
|
|
408
|
+
* { meter_event_name: 'api_calls', value: '50' }
|
|
409
|
+
* ];
|
|
410
|
+
*
|
|
411
|
+
* for (const event of usageEvents) {
|
|
412
|
+
* await usageManager.recordUsage(event);
|
|
413
|
+
* }
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* With error handling:
|
|
418
|
+
* ```typescript
|
|
419
|
+
* try {
|
|
420
|
+
* await usageManager.recordUsage({
|
|
421
|
+
* meter_event_name: 'file_uploads',
|
|
422
|
+
* value: String(uploadedFiles.length)
|
|
423
|
+
* });
|
|
424
|
+
* } catch (error) {
|
|
425
|
+
* console.error('Failed to record usage:', error);
|
|
426
|
+
* // Usage recording failure shouldn't block user operations
|
|
427
|
+
* // but should be logged for billing accuracy
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*
|
|
431
|
+
* @since 1.0.0
|
|
432
|
+
* @group Usage
|
|
433
|
+
*/
|
|
434
|
+
async recordUsage(options) {
|
|
435
|
+
const response = await this.omnibaseClient.fetch("/api/v1/payments/usage", {
|
|
436
|
+
method: "POST",
|
|
437
|
+
headers: {
|
|
438
|
+
"Content-Type": "application/json"
|
|
439
|
+
},
|
|
440
|
+
body: JSON.stringify(options)
|
|
441
|
+
});
|
|
442
|
+
if (!response.ok) {
|
|
443
|
+
const errorData = await response.text();
|
|
444
|
+
throw new Error(
|
|
445
|
+
`Failed to record usage: ${response.status} - ${errorData}`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
const result = await response.json();
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// src/payments/handler.ts
|
|
454
|
+
var PaymentHandler = class {
|
|
455
|
+
/**
|
|
456
|
+
* Initialize the payment handler with API configuration
|
|
457
|
+
*
|
|
458
|
+
* Creates a new payment handler instance that will communicate with
|
|
459
|
+
* the specified API endpoint. The handler automatically handles
|
|
460
|
+
* request formatting and authentication headers.
|
|
461
|
+
*
|
|
462
|
+
* @param apiUrl - Base URL for the payment API endpoint
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* const paymentHandler = new PaymentHandler('https://api.myapp.com');
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @since 1.0.0
|
|
470
|
+
* @group Client
|
|
471
|
+
*/
|
|
472
|
+
constructor(omnibaseClient) {
|
|
473
|
+
this.omnibaseClient = omnibaseClient;
|
|
474
|
+
this.checkout = new CheckoutManager(this.omnibaseClient);
|
|
475
|
+
this.config = new ConfigManager(this.omnibaseClient);
|
|
476
|
+
this.portal = new PortalManager(this.omnibaseClient);
|
|
477
|
+
this.usage = new UsageManager(this.omnibaseClient);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Checkout session management
|
|
481
|
+
*
|
|
482
|
+
* Provides functionality for creating and managing Stripe checkout sessions
|
|
483
|
+
* for both one-time payments and subscription billing.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const session = await paymentHandler.checkout.createSession({
|
|
488
|
+
* price_id: 'price_monthly',
|
|
489
|
+
* mode: 'subscription',
|
|
490
|
+
* success_url: window.location.origin + '/success',
|
|
491
|
+
* cancel_url: window.location.origin + '/pricing'
|
|
492
|
+
* });
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
checkout;
|
|
496
|
+
/**
|
|
497
|
+
* Stripe configuration management
|
|
498
|
+
*
|
|
499
|
+
* Handles retrieval and processing of database-backed Stripe configurations,
|
|
500
|
+
* providing UI-ready product and pricing data for rendering pricing tables.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const products = await paymentHandler.config.getAvailableProducts();
|
|
505
|
+
* const config = await paymentHandler.config.getStripeConfig();
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
config;
|
|
509
|
+
/**
|
|
510
|
+
* Customer portal management
|
|
511
|
+
*
|
|
512
|
+
* Creates customer portal sessions for subscription management,
|
|
513
|
+
* billing history, and payment method updates.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* const portal = await paymentHandler.portal.create({
|
|
518
|
+
* return_url: 'https://app.com/billing'
|
|
519
|
+
* });
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
portal;
|
|
523
|
+
/**
|
|
524
|
+
* Usage tracking and metered billing
|
|
525
|
+
*
|
|
526
|
+
* Records usage events for metered billing products and manages
|
|
527
|
+
* usage-based pricing calculations.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* await paymentHandler.usage.recordUsage({
|
|
532
|
+
* meter_event_name: 'api_calls',
|
|
533
|
+
* value: '1'
|
|
534
|
+
* });
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
usage;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
export {
|
|
541
|
+
CheckoutManager,
|
|
542
|
+
ConfigManager,
|
|
543
|
+
PortalManager,
|
|
544
|
+
UsageManager,
|
|
545
|
+
PaymentHandler
|
|
546
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,6 @@ var CheckoutManager = class {
|
|
|
49
49
|
* @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
50
50
|
* @param options.success_url - URL to redirect after successful payment
|
|
51
51
|
* @param options.cancel_url - URL to redirect if user cancels
|
|
52
|
-
* @param options.customer_id - Optional existing Stripe customer ID
|
|
53
52
|
*
|
|
54
53
|
* @returns Promise resolving to checkout session response with URL and session ID
|
|
55
54
|
*
|
|
@@ -79,7 +78,6 @@ var CheckoutManager = class {
|
|
|
79
78
|
* mode: 'subscription',
|
|
80
79
|
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
81
80
|
* cancel_url: 'https://app.com/pricing',
|
|
82
|
-
* customer_id: 'cus_12345'
|
|
83
81
|
* });
|
|
84
82
|
*
|
|
85
83
|
* console.log(`Session created: ${session.data.sessionId}`);
|
|
@@ -324,20 +322,18 @@ var PortalManager = class {
|
|
|
324
322
|
* for security. Each access requires creating a new session.
|
|
325
323
|
*
|
|
326
324
|
* @param options - Configuration options for the portal session
|
|
327
|
-
* @param options.customer_id - Stripe customer ID for the user
|
|
328
325
|
* @param options.return_url - URL to redirect to when exiting the portal
|
|
329
326
|
*
|
|
330
327
|
* @returns Promise resolving to portal session response with access URL
|
|
331
328
|
*
|
|
332
329
|
* @throws {Error} When the API request fails due to network issues
|
|
333
|
-
* @throws {Error} When the server returns an error response
|
|
330
|
+
* @throws {Error} When the server returns an error response
|
|
334
331
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
335
332
|
*
|
|
336
333
|
* @example
|
|
337
334
|
* Basic portal creation:
|
|
338
335
|
* ```typescript
|
|
339
336
|
* const portal = await portalManager.create({
|
|
340
|
-
* customer_id: 'cus_abc123',
|
|
341
337
|
* return_url: 'https://myapp.com/account/billing'
|
|
342
338
|
* });
|
|
343
339
|
*
|
|
@@ -350,7 +346,6 @@ var PortalManager = class {
|
|
|
350
346
|
* ```typescript
|
|
351
347
|
* try {
|
|
352
348
|
* const portal = await portalManager.create({
|
|
353
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
354
349
|
* return_url: window.location.origin + '/billing'
|
|
355
350
|
* });
|
|
356
351
|
*
|
|
@@ -411,7 +406,6 @@ var UsageManager = class {
|
|
|
411
406
|
*
|
|
412
407
|
* @param options - Usage recording options
|
|
413
408
|
* @param options.meter_event_name - Name of the meter to record against
|
|
414
|
-
* @param options.customer_id - Stripe customer ID
|
|
415
409
|
* @param options.value - Usage quantity as string
|
|
416
410
|
*
|
|
417
411
|
* @returns Promise resolving to API response confirmation
|
|
@@ -426,7 +420,6 @@ var UsageManager = class {
|
|
|
426
420
|
* // Record each API call
|
|
427
421
|
* await usageManager.recordUsage({
|
|
428
422
|
* meter_event_name: 'api_requests',
|
|
429
|
-
* customer_id: user.stripeCustomerId,
|
|
430
423
|
* value: '1'
|
|
431
424
|
* });
|
|
432
425
|
* ```
|
|
@@ -436,9 +429,9 @@ var UsageManager = class {
|
|
|
436
429
|
* ```typescript
|
|
437
430
|
* // Record multiple operations at once
|
|
438
431
|
* const usageEvents = [
|
|
439
|
-
* { meter_event_name: 'compute_hours',
|
|
440
|
-
* { meter_event_name: 'storage_gb',
|
|
441
|
-
* { meter_event_name: 'api_calls',
|
|
432
|
+
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
433
|
+
* { meter_event_name: 'storage_gb', value: '10' },
|
|
434
|
+
* { meter_event_name: 'api_calls', value: '50' }
|
|
442
435
|
* ];
|
|
443
436
|
*
|
|
444
437
|
* for (const event of usageEvents) {
|
|
@@ -452,7 +445,6 @@ var UsageManager = class {
|
|
|
452
445
|
* try {
|
|
453
446
|
* await usageManager.recordUsage({
|
|
454
447
|
* meter_event_name: 'file_uploads',
|
|
455
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
456
448
|
* value: String(uploadedFiles.length)
|
|
457
449
|
* });
|
|
458
450
|
* } catch (error) {
|
|
@@ -549,7 +541,6 @@ var PaymentHandler = class {
|
|
|
549
541
|
* @example
|
|
550
542
|
* ```typescript
|
|
551
543
|
* const portal = await paymentHandler.portal.create({
|
|
552
|
-
* customer_id: 'cus_123',
|
|
553
544
|
* return_url: 'https://app.com/billing'
|
|
554
545
|
* });
|
|
555
546
|
* ```
|
|
@@ -565,7 +556,6 @@ var PaymentHandler = class {
|
|
|
565
556
|
* ```typescript
|
|
566
557
|
* await paymentHandler.usage.recordUsage({
|
|
567
558
|
* meter_event_name: 'api_calls',
|
|
568
|
-
* customer_id: 'cus_123',
|
|
569
559
|
* value: '1'
|
|
570
560
|
* });
|
|
571
561
|
* ```
|
package/dist/index.js
CHANGED
package/dist/payments/index.cjs
CHANGED
|
@@ -53,7 +53,6 @@ var CheckoutManager = class {
|
|
|
53
53
|
* @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
54
54
|
* @param options.success_url - URL to redirect after successful payment
|
|
55
55
|
* @param options.cancel_url - URL to redirect if user cancels
|
|
56
|
-
* @param options.customer_id - Optional existing Stripe customer ID
|
|
57
56
|
*
|
|
58
57
|
* @returns Promise resolving to checkout session response with URL and session ID
|
|
59
58
|
*
|
|
@@ -83,7 +82,6 @@ var CheckoutManager = class {
|
|
|
83
82
|
* mode: 'subscription',
|
|
84
83
|
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
85
84
|
* cancel_url: 'https://app.com/pricing',
|
|
86
|
-
* customer_id: 'cus_12345'
|
|
87
85
|
* });
|
|
88
86
|
*
|
|
89
87
|
* console.log(`Session created: ${session.data.sessionId}`);
|
|
@@ -328,20 +326,18 @@ var PortalManager = class {
|
|
|
328
326
|
* for security. Each access requires creating a new session.
|
|
329
327
|
*
|
|
330
328
|
* @param options - Configuration options for the portal session
|
|
331
|
-
* @param options.customer_id - Stripe customer ID for the user
|
|
332
329
|
* @param options.return_url - URL to redirect to when exiting the portal
|
|
333
330
|
*
|
|
334
331
|
* @returns Promise resolving to portal session response with access URL
|
|
335
332
|
*
|
|
336
333
|
* @throws {Error} When the API request fails due to network issues
|
|
337
|
-
* @throws {Error} When the server returns an error response
|
|
334
|
+
* @throws {Error} When the server returns an error response
|
|
338
335
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
339
336
|
*
|
|
340
337
|
* @example
|
|
341
338
|
* Basic portal creation:
|
|
342
339
|
* ```typescript
|
|
343
340
|
* const portal = await portalManager.create({
|
|
344
|
-
* customer_id: 'cus_abc123',
|
|
345
341
|
* return_url: 'https://myapp.com/account/billing'
|
|
346
342
|
* });
|
|
347
343
|
*
|
|
@@ -354,7 +350,6 @@ var PortalManager = class {
|
|
|
354
350
|
* ```typescript
|
|
355
351
|
* try {
|
|
356
352
|
* const portal = await portalManager.create({
|
|
357
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
358
353
|
* return_url: window.location.origin + '/billing'
|
|
359
354
|
* });
|
|
360
355
|
*
|
|
@@ -415,7 +410,6 @@ var UsageManager = class {
|
|
|
415
410
|
*
|
|
416
411
|
* @param options - Usage recording options
|
|
417
412
|
* @param options.meter_event_name - Name of the meter to record against
|
|
418
|
-
* @param options.customer_id - Stripe customer ID
|
|
419
413
|
* @param options.value - Usage quantity as string
|
|
420
414
|
*
|
|
421
415
|
* @returns Promise resolving to API response confirmation
|
|
@@ -430,7 +424,6 @@ var UsageManager = class {
|
|
|
430
424
|
* // Record each API call
|
|
431
425
|
* await usageManager.recordUsage({
|
|
432
426
|
* meter_event_name: 'api_requests',
|
|
433
|
-
* customer_id: user.stripeCustomerId,
|
|
434
427
|
* value: '1'
|
|
435
428
|
* });
|
|
436
429
|
* ```
|
|
@@ -440,9 +433,9 @@ var UsageManager = class {
|
|
|
440
433
|
* ```typescript
|
|
441
434
|
* // Record multiple operations at once
|
|
442
435
|
* const usageEvents = [
|
|
443
|
-
* { meter_event_name: 'compute_hours',
|
|
444
|
-
* { meter_event_name: 'storage_gb',
|
|
445
|
-
* { meter_event_name: 'api_calls',
|
|
436
|
+
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
437
|
+
* { meter_event_name: 'storage_gb', value: '10' },
|
|
438
|
+
* { meter_event_name: 'api_calls', value: '50' }
|
|
446
439
|
* ];
|
|
447
440
|
*
|
|
448
441
|
* for (const event of usageEvents) {
|
|
@@ -456,7 +449,6 @@ var UsageManager = class {
|
|
|
456
449
|
* try {
|
|
457
450
|
* await usageManager.recordUsage({
|
|
458
451
|
* meter_event_name: 'file_uploads',
|
|
459
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
460
452
|
* value: String(uploadedFiles.length)
|
|
461
453
|
* });
|
|
462
454
|
* } catch (error) {
|
|
@@ -553,7 +545,6 @@ var PaymentHandler = class {
|
|
|
553
545
|
* @example
|
|
554
546
|
* ```typescript
|
|
555
547
|
* const portal = await paymentHandler.portal.create({
|
|
556
|
-
* customer_id: 'cus_123',
|
|
557
548
|
* return_url: 'https://app.com/billing'
|
|
558
549
|
* });
|
|
559
550
|
* ```
|
|
@@ -569,7 +560,6 @@ var PaymentHandler = class {
|
|
|
569
560
|
* ```typescript
|
|
570
561
|
* await paymentHandler.usage.recordUsage({
|
|
571
562
|
* meter_event_name: 'api_calls',
|
|
572
|
-
* customer_id: 'cus_123',
|
|
573
563
|
* value: '1'
|
|
574
564
|
* });
|
|
575
565
|
* ```
|
|
@@ -63,7 +63,6 @@ type ApiResponse<T> = {
|
|
|
63
63
|
* mode: 'subscription',
|
|
64
64
|
* success_url: 'https://app.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
65
65
|
* cancel_url: 'https://app.com/pricing',
|
|
66
|
-
* customer_id: 'cus_1234567890'
|
|
67
66
|
* };
|
|
68
67
|
* ```
|
|
69
68
|
*
|
|
@@ -87,11 +86,6 @@ type CheckoutOptions = {
|
|
|
87
86
|
success_url: string;
|
|
88
87
|
/** URL to redirect to if the user cancels the checkout */
|
|
89
88
|
cancel_url: string;
|
|
90
|
-
/**
|
|
91
|
-
* Optional Stripe customer ID to associate with this checkout
|
|
92
|
-
* If not provided, a new customer will be created
|
|
93
|
-
*/
|
|
94
|
-
customer_id?: string;
|
|
95
89
|
};
|
|
96
90
|
/**
|
|
97
91
|
* Response from creating a checkout session
|
|
@@ -130,7 +124,6 @@ type CreateCheckoutResponse = ApiResponse<{
|
|
|
130
124
|
* mode: 'subscription',
|
|
131
125
|
* success_url: 'https://app.com/welcome?session_id={CHECKOUT_SESSION_ID}',
|
|
132
126
|
* cancel_url: 'https://app.com/pricing',
|
|
133
|
-
* customer_id: 'cus_existing_customer'
|
|
134
127
|
* });
|
|
135
128
|
*
|
|
136
129
|
* // Redirect user to checkout
|
|
@@ -164,7 +157,6 @@ declare class CheckoutManager {
|
|
|
164
157
|
* @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
165
158
|
* @param options.success_url - URL to redirect after successful payment
|
|
166
159
|
* @param options.cancel_url - URL to redirect if user cancels
|
|
167
|
-
* @param options.customer_id - Optional existing Stripe customer ID
|
|
168
160
|
*
|
|
169
161
|
* @returns Promise resolving to checkout session response with URL and session ID
|
|
170
162
|
*
|
|
@@ -194,7 +186,6 @@ declare class CheckoutManager {
|
|
|
194
186
|
* mode: 'subscription',
|
|
195
187
|
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
196
188
|
* cancel_url: 'https://app.com/pricing',
|
|
197
|
-
* customer_id: 'cus_12345'
|
|
198
189
|
* });
|
|
199
190
|
*
|
|
200
191
|
* console.log(`Session created: ${session.data.sessionId}`);
|
|
@@ -721,7 +712,6 @@ declare class ConfigManager {
|
|
|
721
712
|
* @example
|
|
722
713
|
* ```typescript
|
|
723
714
|
* const options: PortalOptions = {
|
|
724
|
-
* customer_id: 'cus_1234567890',
|
|
725
715
|
* return_url: 'https://app.com/billing'
|
|
726
716
|
* };
|
|
727
717
|
* ```
|
|
@@ -731,8 +721,6 @@ declare class ConfigManager {
|
|
|
731
721
|
* @group Portal
|
|
732
722
|
*/
|
|
733
723
|
type PortalOptions = {
|
|
734
|
-
/** Stripe customer ID for the user accessing the portal */
|
|
735
|
-
customer_id: string;
|
|
736
724
|
/** URL to redirect the customer to when they exit the portal */
|
|
737
725
|
return_url: string;
|
|
738
726
|
};
|
|
@@ -768,7 +756,6 @@ type CreateCustomerPortalResponse = ApiResponse<{
|
|
|
768
756
|
* const portalManager = new PortalManager(paymentHandler);
|
|
769
757
|
*
|
|
770
758
|
* const portal = await portalManager.create({
|
|
771
|
-
* customer_id: 'cus_customer123',
|
|
772
759
|
* return_url: 'https://app.com/billing'
|
|
773
760
|
* });
|
|
774
761
|
*
|
|
@@ -801,20 +788,18 @@ declare class PortalManager {
|
|
|
801
788
|
* for security. Each access requires creating a new session.
|
|
802
789
|
*
|
|
803
790
|
* @param options - Configuration options for the portal session
|
|
804
|
-
* @param options.customer_id - Stripe customer ID for the user
|
|
805
791
|
* @param options.return_url - URL to redirect to when exiting the portal
|
|
806
792
|
*
|
|
807
793
|
* @returns Promise resolving to portal session response with access URL
|
|
808
794
|
*
|
|
809
795
|
* @throws {Error} When the API request fails due to network issues
|
|
810
|
-
* @throws {Error} When the server returns an error response
|
|
796
|
+
* @throws {Error} When the server returns an error response
|
|
811
797
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
812
798
|
*
|
|
813
799
|
* @example
|
|
814
800
|
* Basic portal creation:
|
|
815
801
|
* ```typescript
|
|
816
802
|
* const portal = await portalManager.create({
|
|
817
|
-
* customer_id: 'cus_abc123',
|
|
818
803
|
* return_url: 'https://myapp.com/account/billing'
|
|
819
804
|
* });
|
|
820
805
|
*
|
|
@@ -827,7 +812,6 @@ declare class PortalManager {
|
|
|
827
812
|
* ```typescript
|
|
828
813
|
* try {
|
|
829
814
|
* const portal = await portalManager.create({
|
|
830
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
831
815
|
* return_url: window.location.origin + '/billing'
|
|
832
816
|
* });
|
|
833
817
|
*
|
|
@@ -855,7 +839,6 @@ declare class PortalManager {
|
|
|
855
839
|
* ```typescript
|
|
856
840
|
* const options: UsageOptions = {
|
|
857
841
|
* meter_event_name: 'api_calls',
|
|
858
|
-
* customer_id: 'cus_1234567890',
|
|
859
842
|
* value: '1'
|
|
860
843
|
* };
|
|
861
844
|
* ```
|
|
@@ -870,8 +853,6 @@ type UsageOptions = {
|
|
|
870
853
|
* Must match a meter configured in your Stripe billing configuration
|
|
871
854
|
*/
|
|
872
855
|
meter_event_name: string;
|
|
873
|
-
/** Stripe customer ID to record usage for */
|
|
874
|
-
customer_id: string;
|
|
875
856
|
/**
|
|
876
857
|
* Usage value to record as a string
|
|
877
858
|
* Typically represents quantity consumed (e.g., "1" for single API call, "250" for MB of storage)
|
|
@@ -896,14 +877,12 @@ type UsageOptions = {
|
|
|
896
877
|
* // Record a single API call
|
|
897
878
|
* await usageManager.recordUsage({
|
|
898
879
|
* meter_event_name: 'api_calls',
|
|
899
|
-
* customer_id: 'cus_customer123',
|
|
900
880
|
* value: '1'
|
|
901
881
|
* });
|
|
902
882
|
*
|
|
903
883
|
* // Record bulk data transfer
|
|
904
884
|
* await usageManager.recordUsage({
|
|
905
885
|
* meter_event_name: 'data_transfer_gb',
|
|
906
|
-
* customer_id: 'cus_customer123',
|
|
907
886
|
* value: '2.5'
|
|
908
887
|
* });
|
|
909
888
|
* ```
|
|
@@ -935,7 +914,6 @@ declare class UsageManager {
|
|
|
935
914
|
*
|
|
936
915
|
* @param options - Usage recording options
|
|
937
916
|
* @param options.meter_event_name - Name of the meter to record against
|
|
938
|
-
* @param options.customer_id - Stripe customer ID
|
|
939
917
|
* @param options.value - Usage quantity as string
|
|
940
918
|
*
|
|
941
919
|
* @returns Promise resolving to API response confirmation
|
|
@@ -950,7 +928,6 @@ declare class UsageManager {
|
|
|
950
928
|
* // Record each API call
|
|
951
929
|
* await usageManager.recordUsage({
|
|
952
930
|
* meter_event_name: 'api_requests',
|
|
953
|
-
* customer_id: user.stripeCustomerId,
|
|
954
931
|
* value: '1'
|
|
955
932
|
* });
|
|
956
933
|
* ```
|
|
@@ -960,9 +937,9 @@ declare class UsageManager {
|
|
|
960
937
|
* ```typescript
|
|
961
938
|
* // Record multiple operations at once
|
|
962
939
|
* const usageEvents = [
|
|
963
|
-
* { meter_event_name: 'compute_hours',
|
|
964
|
-
* { meter_event_name: 'storage_gb',
|
|
965
|
-
* { meter_event_name: 'api_calls',
|
|
940
|
+
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
941
|
+
* { meter_event_name: 'storage_gb', value: '10' },
|
|
942
|
+
* { meter_event_name: 'api_calls', value: '50' }
|
|
966
943
|
* ];
|
|
967
944
|
*
|
|
968
945
|
* for (const event of usageEvents) {
|
|
@@ -976,7 +953,6 @@ declare class UsageManager {
|
|
|
976
953
|
* try {
|
|
977
954
|
* await usageManager.recordUsage({
|
|
978
955
|
* meter_event_name: 'file_uploads',
|
|
979
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
980
956
|
* value: String(uploadedFiles.length)
|
|
981
957
|
* });
|
|
982
958
|
* } catch (error) {
|
|
@@ -1082,7 +1058,6 @@ declare class PaymentHandler {
|
|
|
1082
1058
|
* @example
|
|
1083
1059
|
* ```typescript
|
|
1084
1060
|
* const portal = await paymentHandler.portal.create({
|
|
1085
|
-
* customer_id: 'cus_123',
|
|
1086
1061
|
* return_url: 'https://app.com/billing'
|
|
1087
1062
|
* });
|
|
1088
1063
|
* ```
|
|
@@ -1098,7 +1073,6 @@ declare class PaymentHandler {
|
|
|
1098
1073
|
* ```typescript
|
|
1099
1074
|
* await paymentHandler.usage.recordUsage({
|
|
1100
1075
|
* meter_event_name: 'api_calls',
|
|
1101
|
-
* customer_id: 'cus_123',
|
|
1102
1076
|
* value: '1'
|
|
1103
1077
|
* });
|
|
1104
1078
|
* ```
|
package/dist/payments/index.d.ts
CHANGED
|
@@ -63,7 +63,6 @@ type ApiResponse<T> = {
|
|
|
63
63
|
* mode: 'subscription',
|
|
64
64
|
* success_url: 'https://app.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
65
65
|
* cancel_url: 'https://app.com/pricing',
|
|
66
|
-
* customer_id: 'cus_1234567890'
|
|
67
66
|
* };
|
|
68
67
|
* ```
|
|
69
68
|
*
|
|
@@ -87,11 +86,6 @@ type CheckoutOptions = {
|
|
|
87
86
|
success_url: string;
|
|
88
87
|
/** URL to redirect to if the user cancels the checkout */
|
|
89
88
|
cancel_url: string;
|
|
90
|
-
/**
|
|
91
|
-
* Optional Stripe customer ID to associate with this checkout
|
|
92
|
-
* If not provided, a new customer will be created
|
|
93
|
-
*/
|
|
94
|
-
customer_id?: string;
|
|
95
89
|
};
|
|
96
90
|
/**
|
|
97
91
|
* Response from creating a checkout session
|
|
@@ -130,7 +124,6 @@ type CreateCheckoutResponse = ApiResponse<{
|
|
|
130
124
|
* mode: 'subscription',
|
|
131
125
|
* success_url: 'https://app.com/welcome?session_id={CHECKOUT_SESSION_ID}',
|
|
132
126
|
* cancel_url: 'https://app.com/pricing',
|
|
133
|
-
* customer_id: 'cus_existing_customer'
|
|
134
127
|
* });
|
|
135
128
|
*
|
|
136
129
|
* // Redirect user to checkout
|
|
@@ -164,7 +157,6 @@ declare class CheckoutManager {
|
|
|
164
157
|
* @param options.mode - Payment mode ('payment' for one-time, 'subscription' for recurring)
|
|
165
158
|
* @param options.success_url - URL to redirect after successful payment
|
|
166
159
|
* @param options.cancel_url - URL to redirect if user cancels
|
|
167
|
-
* @param options.customer_id - Optional existing Stripe customer ID
|
|
168
160
|
*
|
|
169
161
|
* @returns Promise resolving to checkout session response with URL and session ID
|
|
170
162
|
*
|
|
@@ -194,7 +186,6 @@ declare class CheckoutManager {
|
|
|
194
186
|
* mode: 'subscription',
|
|
195
187
|
* success_url: 'https://app.com/dashboard?welcome=true',
|
|
196
188
|
* cancel_url: 'https://app.com/pricing',
|
|
197
|
-
* customer_id: 'cus_12345'
|
|
198
189
|
* });
|
|
199
190
|
*
|
|
200
191
|
* console.log(`Session created: ${session.data.sessionId}`);
|
|
@@ -721,7 +712,6 @@ declare class ConfigManager {
|
|
|
721
712
|
* @example
|
|
722
713
|
* ```typescript
|
|
723
714
|
* const options: PortalOptions = {
|
|
724
|
-
* customer_id: 'cus_1234567890',
|
|
725
715
|
* return_url: 'https://app.com/billing'
|
|
726
716
|
* };
|
|
727
717
|
* ```
|
|
@@ -731,8 +721,6 @@ declare class ConfigManager {
|
|
|
731
721
|
* @group Portal
|
|
732
722
|
*/
|
|
733
723
|
type PortalOptions = {
|
|
734
|
-
/** Stripe customer ID for the user accessing the portal */
|
|
735
|
-
customer_id: string;
|
|
736
724
|
/** URL to redirect the customer to when they exit the portal */
|
|
737
725
|
return_url: string;
|
|
738
726
|
};
|
|
@@ -768,7 +756,6 @@ type CreateCustomerPortalResponse = ApiResponse<{
|
|
|
768
756
|
* const portalManager = new PortalManager(paymentHandler);
|
|
769
757
|
*
|
|
770
758
|
* const portal = await portalManager.create({
|
|
771
|
-
* customer_id: 'cus_customer123',
|
|
772
759
|
* return_url: 'https://app.com/billing'
|
|
773
760
|
* });
|
|
774
761
|
*
|
|
@@ -801,20 +788,18 @@ declare class PortalManager {
|
|
|
801
788
|
* for security. Each access requires creating a new session.
|
|
802
789
|
*
|
|
803
790
|
* @param options - Configuration options for the portal session
|
|
804
|
-
* @param options.customer_id - Stripe customer ID for the user
|
|
805
791
|
* @param options.return_url - URL to redirect to when exiting the portal
|
|
806
792
|
*
|
|
807
793
|
* @returns Promise resolving to portal session response with access URL
|
|
808
794
|
*
|
|
809
795
|
* @throws {Error} When the API request fails due to network issues
|
|
810
|
-
* @throws {Error} When the server returns an error response
|
|
796
|
+
* @throws {Error} When the server returns an error response
|
|
811
797
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
812
798
|
*
|
|
813
799
|
* @example
|
|
814
800
|
* Basic portal creation:
|
|
815
801
|
* ```typescript
|
|
816
802
|
* const portal = await portalManager.create({
|
|
817
|
-
* customer_id: 'cus_abc123',
|
|
818
803
|
* return_url: 'https://myapp.com/account/billing'
|
|
819
804
|
* });
|
|
820
805
|
*
|
|
@@ -827,7 +812,6 @@ declare class PortalManager {
|
|
|
827
812
|
* ```typescript
|
|
828
813
|
* try {
|
|
829
814
|
* const portal = await portalManager.create({
|
|
830
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
831
815
|
* return_url: window.location.origin + '/billing'
|
|
832
816
|
* });
|
|
833
817
|
*
|
|
@@ -855,7 +839,6 @@ declare class PortalManager {
|
|
|
855
839
|
* ```typescript
|
|
856
840
|
* const options: UsageOptions = {
|
|
857
841
|
* meter_event_name: 'api_calls',
|
|
858
|
-
* customer_id: 'cus_1234567890',
|
|
859
842
|
* value: '1'
|
|
860
843
|
* };
|
|
861
844
|
* ```
|
|
@@ -870,8 +853,6 @@ type UsageOptions = {
|
|
|
870
853
|
* Must match a meter configured in your Stripe billing configuration
|
|
871
854
|
*/
|
|
872
855
|
meter_event_name: string;
|
|
873
|
-
/** Stripe customer ID to record usage for */
|
|
874
|
-
customer_id: string;
|
|
875
856
|
/**
|
|
876
857
|
* Usage value to record as a string
|
|
877
858
|
* Typically represents quantity consumed (e.g., "1" for single API call, "250" for MB of storage)
|
|
@@ -896,14 +877,12 @@ type UsageOptions = {
|
|
|
896
877
|
* // Record a single API call
|
|
897
878
|
* await usageManager.recordUsage({
|
|
898
879
|
* meter_event_name: 'api_calls',
|
|
899
|
-
* customer_id: 'cus_customer123',
|
|
900
880
|
* value: '1'
|
|
901
881
|
* });
|
|
902
882
|
*
|
|
903
883
|
* // Record bulk data transfer
|
|
904
884
|
* await usageManager.recordUsage({
|
|
905
885
|
* meter_event_name: 'data_transfer_gb',
|
|
906
|
-
* customer_id: 'cus_customer123',
|
|
907
886
|
* value: '2.5'
|
|
908
887
|
* });
|
|
909
888
|
* ```
|
|
@@ -935,7 +914,6 @@ declare class UsageManager {
|
|
|
935
914
|
*
|
|
936
915
|
* @param options - Usage recording options
|
|
937
916
|
* @param options.meter_event_name - Name of the meter to record against
|
|
938
|
-
* @param options.customer_id - Stripe customer ID
|
|
939
917
|
* @param options.value - Usage quantity as string
|
|
940
918
|
*
|
|
941
919
|
* @returns Promise resolving to API response confirmation
|
|
@@ -950,7 +928,6 @@ declare class UsageManager {
|
|
|
950
928
|
* // Record each API call
|
|
951
929
|
* await usageManager.recordUsage({
|
|
952
930
|
* meter_event_name: 'api_requests',
|
|
953
|
-
* customer_id: user.stripeCustomerId,
|
|
954
931
|
* value: '1'
|
|
955
932
|
* });
|
|
956
933
|
* ```
|
|
@@ -960,9 +937,9 @@ declare class UsageManager {
|
|
|
960
937
|
* ```typescript
|
|
961
938
|
* // Record multiple operations at once
|
|
962
939
|
* const usageEvents = [
|
|
963
|
-
* { meter_event_name: 'compute_hours',
|
|
964
|
-
* { meter_event_name: 'storage_gb',
|
|
965
|
-
* { meter_event_name: 'api_calls',
|
|
940
|
+
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
941
|
+
* { meter_event_name: 'storage_gb', value: '10' },
|
|
942
|
+
* { meter_event_name: 'api_calls', value: '50' }
|
|
966
943
|
* ];
|
|
967
944
|
*
|
|
968
945
|
* for (const event of usageEvents) {
|
|
@@ -976,7 +953,6 @@ declare class UsageManager {
|
|
|
976
953
|
* try {
|
|
977
954
|
* await usageManager.recordUsage({
|
|
978
955
|
* meter_event_name: 'file_uploads',
|
|
979
|
-
* customer_id: currentUser.stripeCustomerId,
|
|
980
956
|
* value: String(uploadedFiles.length)
|
|
981
957
|
* });
|
|
982
958
|
* } catch (error) {
|
|
@@ -1082,7 +1058,6 @@ declare class PaymentHandler {
|
|
|
1082
1058
|
* @example
|
|
1083
1059
|
* ```typescript
|
|
1084
1060
|
* const portal = await paymentHandler.portal.create({
|
|
1085
|
-
* customer_id: 'cus_123',
|
|
1086
1061
|
* return_url: 'https://app.com/billing'
|
|
1087
1062
|
* });
|
|
1088
1063
|
* ```
|
|
@@ -1098,7 +1073,6 @@ declare class PaymentHandler {
|
|
|
1098
1073
|
* ```typescript
|
|
1099
1074
|
* await paymentHandler.usage.recordUsage({
|
|
1100
1075
|
* meter_event_name: 'api_calls',
|
|
1101
|
-
* customer_id: 'cus_123',
|
|
1102
1076
|
* value: '1'
|
|
1103
1077
|
* });
|
|
1104
1078
|
* ```
|
package/dist/payments/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnibase/core-js",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "OmniBase core Javascript SDK - framework agnostic",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"import": "./dist/index.
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
16
|
"require": "./dist/index.cjs",
|
|
17
17
|
"types": "./dist/index.d.ts"
|
|
18
18
|
},
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"types": "./dist/auth/index.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"./permissions": {
|
|
23
|
-
"import": "./dist/permissions/index.
|
|
23
|
+
"import": "./dist/permissions/index.js",
|
|
24
24
|
"require": "./dist/permissions/index.cjs",
|
|
25
25
|
"types": "./dist/permissions/index.d.ts"
|
|
26
26
|
},
|