@bagou/payment-stripe 0.0.1

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.js ADDED
@@ -0,0 +1,716 @@
1
+ // @bun
2
+ var __legacyDecorateClassTS = function(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5
+ r = Reflect.decorate(decorators, target, key, desc);
6
+ else
7
+ for (var i = decorators.length - 1;i >= 0; i--)
8
+ if (d = decorators[i])
9
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
11
+ };
12
+ var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
13
+ var __legacyMetadataTS = (k, v) => {
14
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
15
+ return Reflect.metadata(k, v);
16
+ };
17
+
18
+ // src/StripeAnalytics.ts
19
+ import { inject, injectable as injectable2 } from "@ooneex/container";
20
+
21
+ // src/StripeClient.ts
22
+ import { injectable } from "@ooneex/container";
23
+ import Stripe from "stripe";
24
+ import { PaymentException } from "@ooneex/payment";
25
+ class StripeClient {
26
+ client;
27
+ constructor() {
28
+ const apiKey = Bun.env.STRIPE_SECRET_KEY;
29
+ if (!apiKey) {
30
+ throw new PaymentException("Stripe secret key is required. Please set the STRIPE_SECRET_KEY environment variable.", "TOKEN_REQUIRED");
31
+ }
32
+ this.client = new Stripe(apiKey, {
33
+ apiVersion: Bun.env.STRIPE_API_VERSION ?? "2025-06-30.basil"
34
+ });
35
+ }
36
+ get sdk() {
37
+ return this.client;
38
+ }
39
+ }
40
+ StripeClient = __legacyDecorateClassTS([
41
+ injectable(),
42
+ __legacyMetadataTS("design:paramtypes", [])
43
+ ], StripeClient);
44
+
45
+ // src/StripeAnalytics.ts
46
+ class StripeAnalytics {
47
+ client;
48
+ constructor(client) {
49
+ this.client = client;
50
+ }
51
+ async get(options) {
52
+ const startTimestamp = Math.floor(options.startDate.getTime() / 1000);
53
+ const endTimestamp = Math.floor(options.endDate.getTime() / 1000);
54
+ const [charges, subscriptions] = await Promise.all([
55
+ this.client.sdk.charges.list({
56
+ created: { gte: startTimestamp, lte: endTimestamp },
57
+ limit: options.limit ?? 100
58
+ }),
59
+ this.client.sdk.subscriptions.list({
60
+ created: { gte: startTimestamp, lte: endTimestamp },
61
+ limit: 100
62
+ })
63
+ ]);
64
+ let totalRevenue = 0;
65
+ let totalTransactions = 0;
66
+ const periodsMap = new Map;
67
+ for (const charge of charges.data) {
68
+ if (charge.status !== "succeeded")
69
+ continue;
70
+ if (options.currency && charge.currency !== options.currency)
71
+ continue;
72
+ totalRevenue += charge.amount;
73
+ totalTransactions++;
74
+ const date = new Date(charge.created * 1000).toISOString().split("T")[0];
75
+ const existing = periodsMap.get(date);
76
+ if (existing) {
77
+ existing.revenue += charge.amount;
78
+ existing.count++;
79
+ } else {
80
+ periodsMap.set(date, { revenue: charge.amount, count: 1, currency: charge.currency });
81
+ }
82
+ }
83
+ const periods = Array.from(periodsMap.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([date, data]) => ({
84
+ date,
85
+ revenue: data.revenue,
86
+ currency: data.currency,
87
+ transactionCount: data.count
88
+ }));
89
+ let activeSubscriptions = 0;
90
+ let newSubscriptions = 0;
91
+ let canceledSubscriptions = 0;
92
+ for (const sub of subscriptions.data) {
93
+ if (sub.status === "active")
94
+ activeSubscriptions++;
95
+ if (sub.status === "canceled")
96
+ canceledSubscriptions++;
97
+ if (sub.created >= startTimestamp && sub.created <= endTimestamp)
98
+ newSubscriptions++;
99
+ }
100
+ const currency = options.currency ?? charges.data[0]?.currency ?? "usd";
101
+ return {
102
+ totalRevenue,
103
+ totalTransactions,
104
+ currency,
105
+ periods,
106
+ activeSubscriptions,
107
+ newSubscriptions,
108
+ canceledSubscriptions
109
+ };
110
+ }
111
+ }
112
+ StripeAnalytics = __legacyDecorateClassTS([
113
+ injectable2(),
114
+ __legacyDecorateParamTS(0, inject(StripeClient)),
115
+ __legacyMetadataTS("design:paramtypes", [
116
+ typeof StripeClient === "undefined" ? Object : StripeClient
117
+ ])
118
+ ], StripeAnalytics);
119
+ // src/StripeCheckout.ts
120
+ import { inject as inject2, injectable as injectable3 } from "@ooneex/container";
121
+ class StripeCheckoutSession {
122
+ client;
123
+ constructor(client) {
124
+ this.client = client;
125
+ }
126
+ async create(data) {
127
+ const params = {
128
+ line_items: data.lineItems.map((item) => ({
129
+ price: item.price,
130
+ quantity: item.quantity ?? 1
131
+ })),
132
+ mode: data.mode,
133
+ success_url: data.successUrl
134
+ };
135
+ if (data.cancelUrl) {
136
+ params.cancel_url = data.cancelUrl;
137
+ }
138
+ if (data.customerId) {
139
+ params.customer = data.customerId;
140
+ } else if (data.customerEmail) {
141
+ params.customer_email = data.customerEmail;
142
+ }
143
+ if (data.metadata) {
144
+ params.metadata = data.metadata;
145
+ }
146
+ const session = await this.client.sdk.checkout.sessions.create(params);
147
+ return this.mapSession(session);
148
+ }
149
+ async get(id) {
150
+ const session = await this.client.sdk.checkout.sessions.retrieve(id);
151
+ return this.mapSession(session);
152
+ }
153
+ mapSession(session) {
154
+ return {
155
+ id: session.id,
156
+ url: session.url,
157
+ status: session.status ?? null,
158
+ paymentStatus: session.payment_status,
159
+ customerId: typeof session.customer === "string" ? session.customer : session.customer?.id ?? null,
160
+ customerEmail: session.customer_email ?? session.customer_details?.email ?? null,
161
+ amountTotal: session.amount_total,
162
+ currency: session.currency,
163
+ metadata: session.metadata ?? {}
164
+ };
165
+ }
166
+ }
167
+ StripeCheckoutSession = __legacyDecorateClassTS([
168
+ injectable3(),
169
+ __legacyDecorateParamTS(0, inject2(StripeClient)),
170
+ __legacyMetadataTS("design:paramtypes", [
171
+ typeof StripeClient === "undefined" ? Object : StripeClient
172
+ ])
173
+ ], StripeCheckoutSession);
174
+ // src/StripeCustomer.ts
175
+ import { inject as inject3, injectable as injectable4 } from "@ooneex/container";
176
+ class StripeCustomer {
177
+ client;
178
+ constructor(client) {
179
+ this.client = client;
180
+ }
181
+ async create(data) {
182
+ const params = {
183
+ email: data.email
184
+ };
185
+ if (data.name)
186
+ params.name = data.name;
187
+ if (data.phone)
188
+ params.phone = data.phone;
189
+ if (data.metadata)
190
+ params.metadata = data.metadata;
191
+ if (data.billingAddress)
192
+ params.address = this.toStripeAddress(data.billingAddress);
193
+ const customer = await this.client.sdk.customers.create(params);
194
+ return this.mapCustomer(customer);
195
+ }
196
+ async update(id, data) {
197
+ const params = {};
198
+ if (data.email)
199
+ params.email = data.email;
200
+ if (data.name !== undefined)
201
+ params.name = data.name ?? "";
202
+ if (data.phone !== undefined)
203
+ params.phone = data.phone;
204
+ if (data.metadata)
205
+ params.metadata = data.metadata;
206
+ if (data.billingAddress)
207
+ params.address = this.toStripeAddress(data.billingAddress);
208
+ const customer = await this.client.sdk.customers.update(id, params);
209
+ return this.mapCustomer(customer);
210
+ }
211
+ async remove(id) {
212
+ await this.client.sdk.customers.del(id);
213
+ }
214
+ async get(id) {
215
+ const customer = await this.client.sdk.customers.retrieve(id);
216
+ if (customer.deleted) {
217
+ throw new Error(`Customer ${id} has been deleted`);
218
+ }
219
+ return this.mapCustomer(customer);
220
+ }
221
+ async list(options) {
222
+ const params = {
223
+ limit: options?.limit ?? 10
224
+ };
225
+ if (options?.email)
226
+ params.email = options.email;
227
+ if (options?.startingAfter)
228
+ params.starting_after = options.startingAfter;
229
+ const response = await this.client.sdk.customers.list(params);
230
+ return {
231
+ items: response.data.map((c) => this.mapCustomer(c)),
232
+ hasMore: response.has_more
233
+ };
234
+ }
235
+ toStripeAddress(address) {
236
+ return {
237
+ line1: address.line1 ?? "",
238
+ line2: address.line2,
239
+ city: address.city,
240
+ state: address.state,
241
+ postal_code: address.postalCode,
242
+ country: address.country
243
+ };
244
+ }
245
+ mapCustomer(customer) {
246
+ const result = {
247
+ id: customer.id,
248
+ email: customer.email ?? ""
249
+ };
250
+ if (customer.name)
251
+ result.name = customer.name;
252
+ if (customer.phone)
253
+ result.phone = customer.phone;
254
+ if (customer.metadata)
255
+ result.metadata = customer.metadata;
256
+ if (customer.created)
257
+ result.createdAt = new Date(customer.created * 1000);
258
+ if (customer.address) {
259
+ const addr = {};
260
+ if (customer.address.line1)
261
+ addr.line1 = customer.address.line1;
262
+ if (customer.address.line2)
263
+ addr.line2 = customer.address.line2;
264
+ if (customer.address.city)
265
+ addr.city = customer.address.city;
266
+ if (customer.address.state)
267
+ addr.state = customer.address.state;
268
+ if (customer.address.postal_code)
269
+ addr.postalCode = customer.address.postal_code;
270
+ if (customer.address.country)
271
+ addr.country = customer.address.country;
272
+ result.billingAddress = addr;
273
+ }
274
+ return result;
275
+ }
276
+ }
277
+ StripeCustomer = __legacyDecorateClassTS([
278
+ injectable4(),
279
+ __legacyDecorateParamTS(0, inject3(StripeClient)),
280
+ __legacyMetadataTS("design:paramtypes", [
281
+ typeof StripeClient === "undefined" ? Object : StripeClient
282
+ ])
283
+ ], StripeCustomer);
284
+ // src/StripeCustomerPortal.ts
285
+ import { inject as inject4, injectable as injectable5 } from "@ooneex/container";
286
+ class StripeCustomerPortal {
287
+ client;
288
+ constructor(client) {
289
+ this.client = client;
290
+ }
291
+ async create(data) {
292
+ const session = await this.client.sdk.billingPortal.sessions.create({
293
+ customer: data.customerId,
294
+ return_url: data.returnUrl
295
+ });
296
+ return {
297
+ id: session.id,
298
+ url: session.url,
299
+ returnUrl: session.return_url ?? data.returnUrl,
300
+ createdAt: new Date(session.created * 1000)
301
+ };
302
+ }
303
+ }
304
+ StripeCustomerPortal = __legacyDecorateClassTS([
305
+ injectable5(),
306
+ __legacyDecorateParamTS(0, inject4(StripeClient)),
307
+ __legacyMetadataTS("design:paramtypes", [
308
+ typeof StripeClient === "undefined" ? Object : StripeClient
309
+ ])
310
+ ], StripeCustomerPortal);
311
+ // src/StripeDiscount.ts
312
+ import { inject as inject5, injectable as injectable6 } from "@ooneex/container";
313
+ class StripeDiscount {
314
+ client;
315
+ constructor(client) {
316
+ this.client = client;
317
+ }
318
+ async create(data) {
319
+ const params = {
320
+ name: data.name,
321
+ duration: data.duration
322
+ };
323
+ if (data.type === "percentage") {
324
+ params.percent_off = data.amount;
325
+ } else {
326
+ params.amount_off = data.amount;
327
+ params.currency = data.currency ?? "usd";
328
+ }
329
+ if (data.duration === "repeating") {
330
+ params.duration_in_months = data.durationInMonths;
331
+ }
332
+ if (data.maxRedemptions)
333
+ params.max_redemptions = data.maxRedemptions;
334
+ if (data.redeemBy)
335
+ params.redeem_by = Math.floor(data.redeemBy.getTime() / 1000);
336
+ if (data.metadata)
337
+ params.metadata = data.metadata;
338
+ if (data.appliesTo)
339
+ params.applies_to = { products: data.appliesTo };
340
+ const coupon = await this.client.sdk.coupons.create(params);
341
+ if (data.code) {
342
+ await this.client.sdk.promotionCodes.create({
343
+ coupon: coupon.id,
344
+ code: data.code,
345
+ max_redemptions: data.maxRedemptions,
346
+ expires_at: data.redeemBy ? Math.floor(data.redeemBy.getTime() / 1000) : undefined
347
+ });
348
+ }
349
+ return this.mapCoupon(coupon);
350
+ }
351
+ async update(id, data) {
352
+ const coupon = await this.client.sdk.coupons.update(id, {
353
+ name: data.name,
354
+ metadata: data.metadata
355
+ });
356
+ return this.mapCoupon(coupon);
357
+ }
358
+ async remove(id) {
359
+ await this.client.sdk.coupons.del(id);
360
+ }
361
+ async get(id) {
362
+ const coupon = await this.client.sdk.coupons.retrieve(id);
363
+ return this.mapCoupon(coupon);
364
+ }
365
+ async list(options) {
366
+ const response = await this.client.sdk.coupons.list({
367
+ limit: options?.limit ?? 10,
368
+ starting_after: options?.startingAfter
369
+ });
370
+ return {
371
+ items: response.data.map((c) => this.mapCoupon(c)),
372
+ hasMore: response.has_more
373
+ };
374
+ }
375
+ mapCoupon(coupon) {
376
+ const result = {
377
+ id: coupon.id,
378
+ name: coupon.name ?? "",
379
+ type: coupon.percent_off !== null ? "percentage" : "fixed",
380
+ amount: coupon.percent_off !== null ? coupon.percent_off ?? 0 : coupon.amount_off ?? 0,
381
+ duration: coupon.duration,
382
+ timesRedeemed: coupon.times_redeemed,
383
+ isValid: coupon.valid
384
+ };
385
+ if (coupon.currency)
386
+ result.currency = coupon.currency;
387
+ if (coupon.duration_in_months)
388
+ result.durationInMonths = coupon.duration_in_months;
389
+ if (coupon.max_redemptions)
390
+ result.maxRedemptions = coupon.max_redemptions;
391
+ if (coupon.redeem_by)
392
+ result.redeemBy = new Date(coupon.redeem_by * 1000);
393
+ if (coupon.metadata)
394
+ result.metadata = coupon.metadata;
395
+ if (coupon.created)
396
+ result.createdAt = new Date(coupon.created * 1000);
397
+ return result;
398
+ }
399
+ }
400
+ StripeDiscount = __legacyDecorateClassTS([
401
+ injectable6(),
402
+ __legacyDecorateParamTS(0, inject5(StripeClient)),
403
+ __legacyMetadataTS("design:paramtypes", [
404
+ typeof StripeClient === "undefined" ? Object : StripeClient
405
+ ])
406
+ ], StripeDiscount);
407
+ // src/StripeProducts.ts
408
+ import { inject as inject6, injectable as injectable7 } from "@ooneex/container";
409
+ class StripeProducts {
410
+ client;
411
+ constructor(client) {
412
+ this.client = client;
413
+ }
414
+ async create(data) {
415
+ const params = {
416
+ name: data.name
417
+ };
418
+ if (data.description)
419
+ params.description = data.description;
420
+ if (data.images)
421
+ params.images = data.images;
422
+ if (data.metadata)
423
+ params.metadata = data.metadata;
424
+ if (data.active !== undefined)
425
+ params.active = data.active;
426
+ const product = await this.client.sdk.products.create(params);
427
+ return this.mapProduct(product);
428
+ }
429
+ async update(id, data) {
430
+ const params = {};
431
+ if (data.name)
432
+ params.name = data.name;
433
+ if (data.description !== undefined)
434
+ params.description = data.description;
435
+ if (data.images)
436
+ params.images = data.images;
437
+ if (data.metadata)
438
+ params.metadata = data.metadata;
439
+ if (data.active !== undefined)
440
+ params.active = data.active;
441
+ const product = await this.client.sdk.products.update(id, params);
442
+ return this.mapProduct(product);
443
+ }
444
+ async remove(id) {
445
+ await this.client.sdk.products.del(id);
446
+ }
447
+ async get(id) {
448
+ const product = await this.client.sdk.products.retrieve(id);
449
+ return this.mapProduct(product);
450
+ }
451
+ async list(options) {
452
+ const params = {
453
+ limit: options?.limit ?? 10
454
+ };
455
+ if (options?.active !== undefined)
456
+ params.active = options.active;
457
+ if (options?.startingAfter)
458
+ params.starting_after = options.startingAfter;
459
+ const response = await this.client.sdk.products.list(params);
460
+ return {
461
+ items: response.data.map((p) => this.mapProduct(p)),
462
+ hasMore: response.has_more
463
+ };
464
+ }
465
+ async createPrice(data) {
466
+ const params = {
467
+ product: data.productId,
468
+ currency: data.currency,
469
+ unit_amount: data.unitAmount
470
+ };
471
+ if (data.type === "recurring" && data.interval) {
472
+ params.recurring = {
473
+ interval: data.interval,
474
+ interval_count: data.intervalCount ?? 1
475
+ };
476
+ }
477
+ if (data.metadata)
478
+ params.metadata = data.metadata;
479
+ const price = await this.client.sdk.prices.create(params);
480
+ return this.mapPrice(price);
481
+ }
482
+ async getPrice(id) {
483
+ const price = await this.client.sdk.prices.retrieve(id);
484
+ return this.mapPrice(price);
485
+ }
486
+ async listPrices(productId, options) {
487
+ const response = await this.client.sdk.prices.list({
488
+ product: productId,
489
+ limit: options?.limit ?? 10,
490
+ active: options?.active
491
+ });
492
+ return {
493
+ items: response.data.map((p) => this.mapPrice(p)),
494
+ hasMore: response.has_more
495
+ };
496
+ }
497
+ mapProduct(product) {
498
+ const result = {
499
+ id: product.id,
500
+ name: product.name,
501
+ active: product.active
502
+ };
503
+ if (product.description)
504
+ result.description = product.description;
505
+ if (product.images?.length)
506
+ result.images = product.images;
507
+ if (product.metadata)
508
+ result.metadata = product.metadata;
509
+ if (product.created)
510
+ result.createdAt = new Date(product.created * 1000);
511
+ if (product.updated)
512
+ result.updatedAt = new Date(product.updated * 1000);
513
+ return result;
514
+ }
515
+ mapPrice(price) {
516
+ const result = {
517
+ id: price.id,
518
+ productId: typeof price.product === "string" ? price.product : price.product.id,
519
+ currency: price.currency,
520
+ unitAmount: price.unit_amount,
521
+ type: price.type,
522
+ active: price.active
523
+ };
524
+ if (price.recurring) {
525
+ result.interval = price.recurring.interval;
526
+ result.intervalCount = price.recurring.interval_count;
527
+ }
528
+ if (price.metadata)
529
+ result.metadata = price.metadata;
530
+ if (price.created)
531
+ result.createdAt = new Date(price.created * 1000);
532
+ return result;
533
+ }
534
+ }
535
+ StripeProducts = __legacyDecorateClassTS([
536
+ injectable7(),
537
+ __legacyDecorateParamTS(0, inject6(StripeClient)),
538
+ __legacyMetadataTS("design:paramtypes", [
539
+ typeof StripeClient === "undefined" ? Object : StripeClient
540
+ ])
541
+ ], StripeProducts);
542
+ // src/StripeProvider.ts
543
+ import { inject as inject8, injectable as injectable9 } from "@ooneex/container";
544
+
545
+ // src/StripeWebhookEvent.ts
546
+ import { inject as inject7, injectable as injectable8 } from "@ooneex/container";
547
+ import { PaymentException as PaymentException2 } from "@ooneex/payment";
548
+
549
+ // src/types.ts
550
+ var EStripeEvent;
551
+ ((EStripeEvent2) => {
552
+ EStripeEvent2["CheckoutSessionCompleted"] = "checkout.session.completed";
553
+ EStripeEvent2["InvoicePaid"] = "invoice.paid";
554
+ EStripeEvent2["CustomerSubscriptionDeleted"] = "customer.subscription.deleted";
555
+ EStripeEvent2["CustomerSubscriptionUpdated"] = "customer.subscription.updated";
556
+ EStripeEvent2["PaymentIntentPaymentFailed"] = "payment_intent.payment_failed";
557
+ })(EStripeEvent ||= {});
558
+ var EStripeDiscountType;
559
+ ((EStripeDiscountType2) => {
560
+ EStripeDiscountType2["PERCENTAGE"] = "percentage";
561
+ EStripeDiscountType2["FIXED"] = "fixed";
562
+ })(EStripeDiscountType ||= {});
563
+ var EStripeDiscountDuration;
564
+ ((EStripeDiscountDuration2) => {
565
+ EStripeDiscountDuration2["ONCE"] = "once";
566
+ EStripeDiscountDuration2["REPEATING"] = "repeating";
567
+ EStripeDiscountDuration2["FOREVER"] = "forever";
568
+ })(EStripeDiscountDuration ||= {});
569
+ var EStripePriceType;
570
+ ((EStripePriceType2) => {
571
+ EStripePriceType2["ONE_TIME"] = "one_time";
572
+ EStripePriceType2["RECURRING"] = "recurring";
573
+ })(EStripePriceType ||= {});
574
+ var EStripePriceInterval;
575
+ ((EStripePriceInterval2) => {
576
+ EStripePriceInterval2["DAY"] = "day";
577
+ EStripePriceInterval2["WEEK"] = "week";
578
+ EStripePriceInterval2["MONTH"] = "month";
579
+ EStripePriceInterval2["YEAR"] = "year";
580
+ })(EStripePriceInterval ||= {});
581
+
582
+ // src/StripeWebhookEvent.ts
583
+ class StripeWebhookEvent {
584
+ client;
585
+ constructor(client) {
586
+ this.client = client;
587
+ }
588
+ async construct(payload, signature, secret) {
589
+ let raw;
590
+ try {
591
+ raw = await this.client.sdk.webhooks.constructEventAsync(payload, signature, secret);
592
+ } catch (err) {
593
+ throw new PaymentException2(`Webhook signature verification failed: ${err instanceof Error ? err.message : String(err)}`, "WEBHOOK_SIGNATURE_INVALID");
594
+ }
595
+ const created = new Date(raw.created * 1000);
596
+ switch (raw.type) {
597
+ case "checkout.session.completed" /* CheckoutSessionCompleted */: {
598
+ const obj = raw.data.object;
599
+ const data = {
600
+ id: obj.id,
601
+ customerId: typeof obj.customer === "string" ? obj.customer : obj.customer?.id ?? null,
602
+ customerEmail: obj.customer_email ?? obj.customer_details?.email ?? null,
603
+ amountTotal: obj.amount_total,
604
+ currency: obj.currency,
605
+ paymentStatus: obj.payment_status,
606
+ subscriptionId: typeof obj.subscription === "string" ? obj.subscription : obj.subscription?.id ?? null,
607
+ metadata: obj.metadata ?? {}
608
+ };
609
+ return { type: "checkout.session.completed" /* CheckoutSessionCompleted */, id: raw.id, created, data };
610
+ }
611
+ case "invoice.paid" /* InvoicePaid */: {
612
+ const obj = raw.data.object;
613
+ const data = {
614
+ id: obj.id ?? "",
615
+ customerId: typeof obj.customer === "string" ? obj.customer : obj.customer?.id ?? null,
616
+ subscriptionId: typeof obj.subscription === "string" ? obj.subscription : obj.subscription?.id ?? null,
617
+ amountPaid: obj.amount_paid,
618
+ currency: obj.currency,
619
+ status: obj.status ?? null,
620
+ hostedInvoiceUrl: obj.hosted_invoice_url ?? null
621
+ };
622
+ return { type: "invoice.paid" /* InvoicePaid */, id: raw.id, created, data };
623
+ }
624
+ case "customer.subscription.deleted" /* CustomerSubscriptionDeleted */: {
625
+ const obj = raw.data.object;
626
+ const data = {
627
+ id: obj.id,
628
+ customerId: typeof obj.customer === "string" ? obj.customer : obj.customer?.id ?? null,
629
+ status: obj.status,
630
+ currentPeriodEnd: new Date(obj.current_period_end * 1000),
631
+ canceledAt: obj.canceled_at ? new Date(obj.canceled_at * 1000) : null,
632
+ metadata: obj.metadata ?? {}
633
+ };
634
+ return { type: "customer.subscription.deleted" /* CustomerSubscriptionDeleted */, id: raw.id, created, data };
635
+ }
636
+ case "customer.subscription.updated" /* CustomerSubscriptionUpdated */: {
637
+ const obj = raw.data.object;
638
+ const data = {
639
+ id: obj.id,
640
+ customerId: typeof obj.customer === "string" ? obj.customer : obj.customer?.id ?? null,
641
+ status: obj.status,
642
+ currentPeriodEnd: new Date(obj.current_period_end * 1000),
643
+ cancelAtPeriodEnd: obj.cancel_at_period_end,
644
+ metadata: obj.metadata ?? {}
645
+ };
646
+ return { type: "customer.subscription.updated" /* CustomerSubscriptionUpdated */, id: raw.id, created, data };
647
+ }
648
+ case "payment_intent.payment_failed" /* PaymentIntentPaymentFailed */: {
649
+ const obj = raw.data.object;
650
+ const data = {
651
+ id: obj.id,
652
+ customerId: typeof obj.customer === "string" ? obj.customer : obj.customer?.id ?? null,
653
+ amount: obj.amount,
654
+ currency: obj.currency,
655
+ lastPaymentErrorMessage: obj.last_payment_error?.message ?? null
656
+ };
657
+ return { type: "payment_intent.payment_failed" /* PaymentIntentPaymentFailed */, id: raw.id, created, data };
658
+ }
659
+ default:
660
+ throw new PaymentException2(`Unsupported webhook event type: ${raw.type}`, "UNSUPPORTED_EVENT_TYPE");
661
+ }
662
+ }
663
+ }
664
+ StripeWebhookEvent = __legacyDecorateClassTS([
665
+ injectable8(),
666
+ __legacyDecorateParamTS(0, inject7(StripeClient)),
667
+ __legacyMetadataTS("design:paramtypes", [
668
+ typeof StripeClient === "undefined" ? Object : StripeClient
669
+ ])
670
+ ], StripeWebhookEvent);
671
+
672
+ // src/StripeProvider.ts
673
+ class StripeProvider {
674
+ checkoutSession;
675
+ webhookEvent;
676
+ constructor(checkoutSession, webhookEvent) {
677
+ this.checkoutSession = checkoutSession;
678
+ this.webhookEvent = webhookEvent;
679
+ }
680
+ createCheckoutSession(data) {
681
+ return this.checkoutSession.create(data);
682
+ }
683
+ retrieveSession(id) {
684
+ return this.checkoutSession.get(id);
685
+ }
686
+ constructWebhookEvent(payload, signature, secret) {
687
+ return this.webhookEvent.construct(payload, signature, secret);
688
+ }
689
+ }
690
+ StripeProvider = __legacyDecorateClassTS([
691
+ injectable9(),
692
+ __legacyDecorateParamTS(0, inject8(StripeCheckoutSession)),
693
+ __legacyDecorateParamTS(1, inject8(StripeWebhookEvent)),
694
+ __legacyMetadataTS("design:paramtypes", [
695
+ typeof StripeCheckoutSession === "undefined" ? Object : StripeCheckoutSession,
696
+ typeof StripeWebhookEvent === "undefined" ? Object : StripeWebhookEvent
697
+ ])
698
+ ], StripeProvider);
699
+ export {
700
+ StripeWebhookEvent,
701
+ StripeProvider,
702
+ StripeProducts,
703
+ StripeDiscount,
704
+ StripeCustomerPortal,
705
+ StripeCustomer,
706
+ StripeClient,
707
+ StripeCheckoutSession,
708
+ StripeAnalytics,
709
+ EStripePriceType,
710
+ EStripePriceInterval,
711
+ EStripeEvent,
712
+ EStripeDiscountType,
713
+ EStripeDiscountDuration
714
+ };
715
+
716
+ //# debugId=F73E4879FAD14F2B64756E2164756E21