@forklaunch/implementation-billing-stripe 1.0.0 → 1.1.0

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.
@@ -1,9 +1,126 @@
1
- export { B as BillingProviderEnum, C as CurrencyEnum, P as PaymentMethodEnum, a as PlanCadenceEnum } from '../../planCadence.enum-BKHaW1xa.mjs';
1
+ declare const BillingProviderEnum: {
2
+ readonly STRIPE: "stripe";
3
+ };
4
+ type BillingProviderEnum = (typeof BillingProviderEnum)[keyof typeof BillingProviderEnum];
5
+
6
+ declare const CurrencyEnum: {
7
+ readonly USD: "USD";
8
+ readonly EUR: "EUR";
9
+ readonly JPY: "JPY";
10
+ readonly GBP: "GBP";
11
+ readonly AUD: "AUD";
12
+ readonly CAD: "CAD";
13
+ readonly CHF: "CHF";
14
+ readonly CNY: "CNY";
15
+ readonly AED: "AED";
16
+ readonly ARS: "ARS";
17
+ readonly BAM: "BAM";
18
+ readonly BDT: "BDT";
19
+ readonly BGN: "BGN";
20
+ readonly BOB: "BOB";
21
+ readonly BRL: "BRL";
22
+ readonly CLP: "CLP";
23
+ readonly COP: "COP";
24
+ readonly CRC: "CRC";
25
+ readonly CZK: "CZK";
26
+ readonly DKK: "DKK";
27
+ readonly DZD: "DZD";
28
+ readonly EGP: "EGP";
29
+ readonly ETB: "ETB";
30
+ readonly GEL: "GEL";
31
+ readonly GTQ: "GTQ";
32
+ readonly HKD: "HKD";
33
+ readonly HUF: "HUF";
34
+ readonly IDR: "IDR";
35
+ readonly ILS: "ILS";
36
+ readonly INR: "INR";
37
+ readonly ISK: "ISK";
38
+ readonly JMD: "JMD";
39
+ readonly KES: "KES";
40
+ readonly KHR: "KHR";
41
+ readonly KRW: "KRW";
42
+ readonly KZT: "KZT";
43
+ readonly LAK: "LAK";
44
+ readonly LKR: "LKR";
45
+ readonly MAD: "MAD";
46
+ readonly MMK: "MMK";
47
+ readonly MXN: "MXN";
48
+ readonly MYR: "MYR";
49
+ readonly NGN: "NGN";
50
+ readonly NOK: "NOK";
51
+ readonly NPR: "NPR";
52
+ readonly NZD: "NZD";
53
+ readonly PEN: "PEN";
54
+ readonly PHP: "PHP";
55
+ readonly PKR: "PKR";
56
+ readonly PLN: "PLN";
57
+ readonly PYG: "PYG";
58
+ readonly QAR: "QAR";
59
+ readonly RON: "RON";
60
+ readonly RSD: "RSD";
61
+ readonly RUB: "RUB";
62
+ readonly SAR: "SAR";
63
+ readonly SEK: "SEK";
64
+ readonly SGD: "SGD";
65
+ readonly THB: "THB";
66
+ readonly TRY: "TRY";
67
+ readonly TWD: "TWD";
68
+ readonly TZS: "TZS";
69
+ readonly UAH: "UAH";
70
+ readonly UGX: "UGX";
71
+ readonly UYU: "UYU";
72
+ readonly VND: "VND";
73
+ readonly ZAR: "ZAR";
74
+ readonly ZMW: "ZMW";
75
+ };
76
+ type CurrencyEnum = (typeof CurrencyEnum)[keyof typeof CurrencyEnum];
77
+
78
+ declare const PaymentMethodEnum: {
79
+ readonly AFFIRM: "affirm";
80
+ readonly AFTERPAY_CLEARPAY: "afterpay_clearpay";
81
+ readonly ALIPAY: "alipay";
82
+ readonly ALMA: "alma";
83
+ readonly AU_BECS_DEBIT: "au_becs_debit";
84
+ readonly BACS_DEBIT: "bacs_debit";
85
+ readonly BANCONTACT: "bancontact";
86
+ readonly BILLIE: "billie";
87
+ readonly BLIK: "blik";
88
+ readonly BOLETO: "boleto";
89
+ readonly CARD: "card";
90
+ readonly CASHAPP: "cashapp";
91
+ readonly EPS: "eps";
92
+ readonly FPX: "fpx";
93
+ readonly GIROPAY: "giropay";
94
+ readonly GRABPAY: "grabpay";
95
+ readonly IDEAL: "ideal";
96
+ readonly KLARNA: "klarna";
97
+ readonly KONBINI: "konbini";
98
+ readonly LINK: "link";
99
+ readonly MOBILEPAY: "mobilepay";
100
+ readonly MULTIBANCO: "multibanco";
101
+ readonly OXXO: "oxxo";
102
+ readonly P24: "p24";
103
+ readonly PAY_BY_BANK: "pay_by_bank";
104
+ readonly PAYNOW: "paynow";
105
+ readonly PAYPAL: "paypal";
106
+ readonly PIX: "pix";
107
+ readonly PROMPTPAY: "promptpay";
108
+ readonly SATISPAY: "satispay";
109
+ readonly SEPA_DEBIT: "sepa_debit";
110
+ readonly SOFORT: "sofort";
111
+ readonly SWISH: "swish";
112
+ readonly TWINT: "twint";
113
+ readonly US_BANK_ACCOUNT: "us_bank_account";
114
+ readonly WECHAT_PAY: "wechat_pay";
115
+ readonly ZIP: "zip";
116
+ };
117
+ type PaymentMethodEnum = (typeof PaymentMethodEnum)[keyof typeof PaymentMethodEnum];
2
118
 
3
- declare const PartyEnum: {
4
- readonly USER: "user";
5
- readonly ORGANIZATION: "organization";
119
+ declare const PlanCadenceEnum: {
120
+ readonly WEEKLY: "week";
121
+ readonly MONTHLY: "month";
122
+ readonly ANNUALLY: "year";
6
123
  };
7
- type PartyEnum = (typeof PartyEnum)[keyof typeof PartyEnum];
124
+ type PlanCadenceEnum = (typeof PlanCadenceEnum)[keyof typeof PlanCadenceEnum];
8
125
 
9
- export { PartyEnum };
126
+ export { BillingProviderEnum, CurrencyEnum, PaymentMethodEnum, PlanCadenceEnum };
@@ -1,9 +1,126 @@
1
- export { B as BillingProviderEnum, C as CurrencyEnum, P as PaymentMethodEnum, a as PlanCadenceEnum } from '../../planCadence.enum-BKHaW1xa.js';
1
+ declare const BillingProviderEnum: {
2
+ readonly STRIPE: "stripe";
3
+ };
4
+ type BillingProviderEnum = (typeof BillingProviderEnum)[keyof typeof BillingProviderEnum];
5
+
6
+ declare const CurrencyEnum: {
7
+ readonly USD: "USD";
8
+ readonly EUR: "EUR";
9
+ readonly JPY: "JPY";
10
+ readonly GBP: "GBP";
11
+ readonly AUD: "AUD";
12
+ readonly CAD: "CAD";
13
+ readonly CHF: "CHF";
14
+ readonly CNY: "CNY";
15
+ readonly AED: "AED";
16
+ readonly ARS: "ARS";
17
+ readonly BAM: "BAM";
18
+ readonly BDT: "BDT";
19
+ readonly BGN: "BGN";
20
+ readonly BOB: "BOB";
21
+ readonly BRL: "BRL";
22
+ readonly CLP: "CLP";
23
+ readonly COP: "COP";
24
+ readonly CRC: "CRC";
25
+ readonly CZK: "CZK";
26
+ readonly DKK: "DKK";
27
+ readonly DZD: "DZD";
28
+ readonly EGP: "EGP";
29
+ readonly ETB: "ETB";
30
+ readonly GEL: "GEL";
31
+ readonly GTQ: "GTQ";
32
+ readonly HKD: "HKD";
33
+ readonly HUF: "HUF";
34
+ readonly IDR: "IDR";
35
+ readonly ILS: "ILS";
36
+ readonly INR: "INR";
37
+ readonly ISK: "ISK";
38
+ readonly JMD: "JMD";
39
+ readonly KES: "KES";
40
+ readonly KHR: "KHR";
41
+ readonly KRW: "KRW";
42
+ readonly KZT: "KZT";
43
+ readonly LAK: "LAK";
44
+ readonly LKR: "LKR";
45
+ readonly MAD: "MAD";
46
+ readonly MMK: "MMK";
47
+ readonly MXN: "MXN";
48
+ readonly MYR: "MYR";
49
+ readonly NGN: "NGN";
50
+ readonly NOK: "NOK";
51
+ readonly NPR: "NPR";
52
+ readonly NZD: "NZD";
53
+ readonly PEN: "PEN";
54
+ readonly PHP: "PHP";
55
+ readonly PKR: "PKR";
56
+ readonly PLN: "PLN";
57
+ readonly PYG: "PYG";
58
+ readonly QAR: "QAR";
59
+ readonly RON: "RON";
60
+ readonly RSD: "RSD";
61
+ readonly RUB: "RUB";
62
+ readonly SAR: "SAR";
63
+ readonly SEK: "SEK";
64
+ readonly SGD: "SGD";
65
+ readonly THB: "THB";
66
+ readonly TRY: "TRY";
67
+ readonly TWD: "TWD";
68
+ readonly TZS: "TZS";
69
+ readonly UAH: "UAH";
70
+ readonly UGX: "UGX";
71
+ readonly UYU: "UYU";
72
+ readonly VND: "VND";
73
+ readonly ZAR: "ZAR";
74
+ readonly ZMW: "ZMW";
75
+ };
76
+ type CurrencyEnum = (typeof CurrencyEnum)[keyof typeof CurrencyEnum];
77
+
78
+ declare const PaymentMethodEnum: {
79
+ readonly AFFIRM: "affirm";
80
+ readonly AFTERPAY_CLEARPAY: "afterpay_clearpay";
81
+ readonly ALIPAY: "alipay";
82
+ readonly ALMA: "alma";
83
+ readonly AU_BECS_DEBIT: "au_becs_debit";
84
+ readonly BACS_DEBIT: "bacs_debit";
85
+ readonly BANCONTACT: "bancontact";
86
+ readonly BILLIE: "billie";
87
+ readonly BLIK: "blik";
88
+ readonly BOLETO: "boleto";
89
+ readonly CARD: "card";
90
+ readonly CASHAPP: "cashapp";
91
+ readonly EPS: "eps";
92
+ readonly FPX: "fpx";
93
+ readonly GIROPAY: "giropay";
94
+ readonly GRABPAY: "grabpay";
95
+ readonly IDEAL: "ideal";
96
+ readonly KLARNA: "klarna";
97
+ readonly KONBINI: "konbini";
98
+ readonly LINK: "link";
99
+ readonly MOBILEPAY: "mobilepay";
100
+ readonly MULTIBANCO: "multibanco";
101
+ readonly OXXO: "oxxo";
102
+ readonly P24: "p24";
103
+ readonly PAY_BY_BANK: "pay_by_bank";
104
+ readonly PAYNOW: "paynow";
105
+ readonly PAYPAL: "paypal";
106
+ readonly PIX: "pix";
107
+ readonly PROMPTPAY: "promptpay";
108
+ readonly SATISPAY: "satispay";
109
+ readonly SEPA_DEBIT: "sepa_debit";
110
+ readonly SOFORT: "sofort";
111
+ readonly SWISH: "swish";
112
+ readonly TWINT: "twint";
113
+ readonly US_BANK_ACCOUNT: "us_bank_account";
114
+ readonly WECHAT_PAY: "wechat_pay";
115
+ readonly ZIP: "zip";
116
+ };
117
+ type PaymentMethodEnum = (typeof PaymentMethodEnum)[keyof typeof PaymentMethodEnum];
2
118
 
3
- declare const PartyEnum: {
4
- readonly USER: "user";
5
- readonly ORGANIZATION: "organization";
119
+ declare const PlanCadenceEnum: {
120
+ readonly WEEKLY: "week";
121
+ readonly MONTHLY: "month";
122
+ readonly ANNUALLY: "year";
6
123
  };
7
- type PartyEnum = (typeof PartyEnum)[keyof typeof PartyEnum];
124
+ type PlanCadenceEnum = (typeof PlanCadenceEnum)[keyof typeof PlanCadenceEnum];
8
125
 
9
- export { PartyEnum };
126
+ export { BillingProviderEnum, CurrencyEnum, PaymentMethodEnum, PlanCadenceEnum };
@@ -22,7 +22,6 @@ var enum_exports = {};
22
22
  __export(enum_exports, {
23
23
  BillingProviderEnum: () => BillingProviderEnum,
24
24
  CurrencyEnum: () => CurrencyEnum,
25
- PartyEnum: () => PartyEnum,
26
25
  PaymentMethodEnum: () => PaymentMethodEnum,
27
26
  PlanCadenceEnum: () => PlanCadenceEnum
28
27
  });
@@ -105,12 +104,6 @@ var CurrencyEnum = {
105
104
  ZMW: "ZMW"
106
105
  };
107
106
 
108
- // domain/enum/party.enum.ts
109
- var PartyEnum = {
110
- USER: "user",
111
- ORGANIZATION: "organization"
112
- };
113
-
114
107
  // domain/enum/paymentMethod.enum.ts
115
108
  var PaymentMethodEnum = {
116
109
  AFFIRM: "affirm",
@@ -162,7 +155,6 @@ var PlanCadenceEnum = {
162
155
  0 && (module.exports = {
163
156
  BillingProviderEnum,
164
157
  CurrencyEnum,
165
- PartyEnum,
166
158
  PaymentMethodEnum,
167
159
  PlanCadenceEnum
168
160
  });
@@ -75,12 +75,6 @@ var CurrencyEnum = {
75
75
  ZMW: "ZMW"
76
76
  };
77
77
 
78
- // domain/enum/party.enum.ts
79
- var PartyEnum = {
80
- USER: "user",
81
- ORGANIZATION: "organization"
82
- };
83
-
84
78
  // domain/enum/paymentMethod.enum.ts
85
79
  var PaymentMethodEnum = {
86
80
  AFFIRM: "affirm",
@@ -131,7 +125,6 @@ var PlanCadenceEnum = {
131
125
  export {
132
126
  BillingProviderEnum,
133
127
  CurrencyEnum,
134
- PartyEnum,
135
128
  PaymentMethodEnum,
136
129
  PlanCadenceEnum
137
130
  };
@@ -2,7 +2,7 @@ import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { InferEntity, EntityManager } from '@mikro-orm/core';
3
3
  import Stripe__default from 'stripe';
4
4
  import { BillingPortalDto, CreateBillingPortalDto, UpdateBillingPortalDto, CheckoutSessionDto, CreateCheckoutSessionDto, UpdateCheckoutSessionDto, PaymentLinkDto, CreatePaymentLinkDto, UpdatePaymentLinkDto, PlanDto, CreatePlanDto, UpdatePlanDto, SubscriptionDto, CreateSubscriptionDto, UpdateSubscriptionDto } from '@forklaunch/interfaces-billing/types';
5
- import { P as PaymentMethodEnum, C as CurrencyEnum, a as PlanCadenceEnum, B as BillingProviderEnum } from '../../planCadence.enum-BKHaW1xa.mjs';
5
+ import { PaymentMethodEnum, CurrencyEnum, PlanCadenceEnum, BillingProviderEnum } from '../enum/index.mjs';
6
6
  import * as _forklaunch_core_persistence from '@forklaunch/core/persistence';
7
7
 
8
8
  type BillingPortalOmissions = 'customer';
@@ -2,7 +2,7 @@ import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { InferEntity, EntityManager } from '@mikro-orm/core';
3
3
  import Stripe__default from 'stripe';
4
4
  import { BillingPortalDto, CreateBillingPortalDto, UpdateBillingPortalDto, CheckoutSessionDto, CreateCheckoutSessionDto, UpdateCheckoutSessionDto, PaymentLinkDto, CreatePaymentLinkDto, UpdatePaymentLinkDto, PlanDto, CreatePlanDto, UpdatePlanDto, SubscriptionDto, CreateSubscriptionDto, UpdateSubscriptionDto } from '@forklaunch/interfaces-billing/types';
5
- import { P as PaymentMethodEnum, C as CurrencyEnum, a as PlanCadenceEnum, B as BillingProviderEnum } from '../../planCadence.enum-BKHaW1xa.js';
5
+ import { PaymentMethodEnum, CurrencyEnum, PlanCadenceEnum, BillingProviderEnum } from '../enum/index.js';
6
6
  import * as _forklaunch_core_persistence from '@forklaunch/core/persistence';
7
7
 
8
8
  type BillingPortalOmissions = 'customer';
@@ -1,5 +1,4 @@
1
1
  export * from './billingProvider.enum';
2
2
  export * from './currency.enum';
3
- export * from './party.enum';
4
3
  export * from './paymentMethod.enum';
5
4
  export * from './planCadence.enum';
@@ -5,7 +5,6 @@ import {
5
5
  import { AnySchemaValidator } from '@forklaunch/validator';
6
6
  import { EntityManager } from '@mikro-orm/core';
7
7
  import Stripe from 'stripe';
8
- import { PartyEnum } from '../domain/enum/party.enum';
9
8
  import { StripeWebhookEvent } from '../persistence/entities';
10
9
  import { BillingProviderEnum } from '../domain/enum/billingProvider.enum';
11
10
  import { CurrencyEnum } from '../domain/enum/currency.enum';
@@ -38,6 +37,7 @@ export class StripeWebhookService<
38
37
  SubscriptionEntities extends
39
38
  StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>
40
39
  > {
40
+ protected readonly partyEnum: PartyEnum;
41
41
  protected readonly stripeClient: Stripe;
42
42
  protected readonly em: EntityManager;
43
43
  protected readonly schemaValidator: SchemaValidator;
@@ -90,8 +90,10 @@ export class StripeWebhookService<
90
90
  SchemaValidator,
91
91
  PartyEnum,
92
92
  SubscriptionEntities
93
- >
93
+ >,
94
+ partyEnum: PartyEnum
94
95
  ) {
96
+ this.partyEnum = partyEnum;
95
97
  this.stripeClient = stripeClient;
96
98
  this.em = em;
97
99
  this.schemaValidator = schemaValidator;
@@ -103,6 +105,25 @@ export class StripeWebhookService<
103
105
  this.subscriptionService = subscriptionService;
104
106
  }
105
107
 
108
+ /**
109
+ * Resolve the party type for a subscription event.
110
+ * Stripe subscriptions are customer-scoped — customers map to users
111
+ * by default. Override this method to implement organization-level
112
+ * subscriptions or other party resolution logic.
113
+ */
114
+ protected resolvePartyType(
115
+ _event: Stripe.Event
116
+ ): PartyEnum[keyof PartyEnum] {
117
+ // Default: first value in the enum container.
118
+ // Subclasses can override to inspect event metadata for party type.
119
+ const keys = Object.keys(
120
+ this.partyEnum as Record<string, unknown>
121
+ );
122
+ return (this.partyEnum as Record<string, PartyEnum[keyof PartyEnum]>)[
123
+ keys[0]
124
+ ];
125
+ }
126
+
106
127
  /**
107
128
  * Extract features from Stripe product metadata.
108
129
  * Features can be stored as:
@@ -377,7 +398,7 @@ export class StripeWebhookService<
377
398
  typeof event.data.object.customer === 'string'
378
399
  ? event.data.object.customer
379
400
  : event.data.object.customer.id,
380
- partyType: PartyEnum.USER as PartyEnum[keyof PartyEnum],
401
+ partyType: this.resolvePartyType(event),
381
402
  description: event.data.object.description ?? undefined,
382
403
  active: true,
383
404
  productId: event.data.object.items.data[0].plan.id,
@@ -410,7 +431,7 @@ export class StripeWebhookService<
410
431
  typeof event.data.object.customer === 'string'
411
432
  ? event.data.object.customer
412
433
  : event.data.object.customer.id,
413
- partyType: PartyEnum.USER as PartyEnum[keyof PartyEnum],
434
+ partyType: this.resolvePartyType(event),
414
435
  description: event.data.object.description ?? undefined,
415
436
  active: true,
416
437
  externalId: event.data.object.id,
@@ -8,7 +8,7 @@ import { AnySchemaValidator } from '@forklaunch/validator';
8
8
  import { EntityManager } from '@mikro-orm/core';
9
9
  import Stripe__default from 'stripe';
10
10
  import { StripeBillingPortalEntities, StripeBillingPortalDtos, StripeBillingPortalMappers, StripeCreateBillingPortalDto, StripeUpdateBillingPortalDto, StripeCheckoutSessionEntities, StripeCheckoutSessionDtos, StripeCheckoutSessionMappers, StripeCreateCheckoutSessionDto, StripePaymentLinkEntities, StripePaymentLinkDtos, StripeCreatePaymentLinkDto, StripeUpdatePaymentLinkDto, StripePaymentLinkDto, StripePaymentLinkMappers, StripePlanEntities, StripePlanDtos, StripeCreatePlanDto, StripeUpdatePlanDto, StripePlanDto, StripePlanMappers, StripeSubscriptionEntities, StripeSubscriptionDtos, StripeCreateSubscriptionDto, StripeUpdateSubscriptionDto, StripeSubscriptionDto, StripeSubscriptionMappers } from '../domain/types/index.mjs';
11
- import { P as PaymentMethodEnum, C as CurrencyEnum, a as PlanCadenceEnum, B as BillingProviderEnum } from '../planCadence.enum-BKHaW1xa.mjs';
11
+ import { PaymentMethodEnum, CurrencyEnum, PlanCadenceEnum, BillingProviderEnum } from '../domain/enum/index.mjs';
12
12
  export * from '@forklaunch/interfaces-billing/types';
13
13
  import '@forklaunch/core/persistence';
14
14
 
@@ -159,6 +159,7 @@ declare class StripeSubscriptionService<SchemaValidator extends AnySchemaValidat
159
159
  }
160
160
 
161
161
  declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, StatusEnum, PartyEnum, BillingPortalEntities extends StripeBillingPortalEntities = StripeBillingPortalEntities, CheckoutSessionEntities extends StripeCheckoutSessionEntities<StatusEnum> = StripeCheckoutSessionEntities<StatusEnum>, PaymentLinkEntities extends StripePaymentLinkEntities<StatusEnum> = StripePaymentLinkEntities<StatusEnum>, PlanEntities extends StripePlanEntities = StripePlanEntities, SubscriptionEntities extends StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>> {
162
+ protected readonly partyEnum: PartyEnum;
162
163
  protected readonly stripeClient: Stripe__default;
163
164
  protected readonly em: EntityManager;
164
165
  protected readonly schemaValidator: SchemaValidator;
@@ -168,7 +169,14 @@ declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, S
168
169
  protected readonly paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>;
169
170
  protected readonly planService: StripePlanService<SchemaValidator, PlanEntities>;
170
171
  protected readonly subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>;
171
- constructor(stripeClient: Stripe__default, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>);
172
+ constructor(stripeClient: Stripe__default, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>, partyEnum: PartyEnum);
173
+ /**
174
+ * Resolve the party type for a subscription event.
175
+ * Stripe subscriptions are customer-scoped — customers map to users
176
+ * by default. Override this method to implement organization-level
177
+ * subscriptions or other party resolution logic.
178
+ */
179
+ protected resolvePartyType(_event: Stripe__default.Event): PartyEnum[keyof PartyEnum];
172
180
  /**
173
181
  * Extract features from Stripe product metadata.
174
182
  * Features can be stored as:
@@ -8,7 +8,7 @@ import { AnySchemaValidator } from '@forklaunch/validator';
8
8
  import { EntityManager } from '@mikro-orm/core';
9
9
  import Stripe__default from 'stripe';
10
10
  import { StripeBillingPortalEntities, StripeBillingPortalDtos, StripeBillingPortalMappers, StripeCreateBillingPortalDto, StripeUpdateBillingPortalDto, StripeCheckoutSessionEntities, StripeCheckoutSessionDtos, StripeCheckoutSessionMappers, StripeCreateCheckoutSessionDto, StripePaymentLinkEntities, StripePaymentLinkDtos, StripeCreatePaymentLinkDto, StripeUpdatePaymentLinkDto, StripePaymentLinkDto, StripePaymentLinkMappers, StripePlanEntities, StripePlanDtos, StripeCreatePlanDto, StripeUpdatePlanDto, StripePlanDto, StripePlanMappers, StripeSubscriptionEntities, StripeSubscriptionDtos, StripeCreateSubscriptionDto, StripeUpdateSubscriptionDto, StripeSubscriptionDto, StripeSubscriptionMappers } from '../domain/types/index.js';
11
- import { P as PaymentMethodEnum, C as CurrencyEnum, a as PlanCadenceEnum, B as BillingProviderEnum } from '../planCadence.enum-BKHaW1xa.js';
11
+ import { PaymentMethodEnum, CurrencyEnum, PlanCadenceEnum, BillingProviderEnum } from '../domain/enum/index.js';
12
12
  export * from '@forklaunch/interfaces-billing/types';
13
13
  import '@forklaunch/core/persistence';
14
14
 
@@ -159,6 +159,7 @@ declare class StripeSubscriptionService<SchemaValidator extends AnySchemaValidat
159
159
  }
160
160
 
161
161
  declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, StatusEnum, PartyEnum, BillingPortalEntities extends StripeBillingPortalEntities = StripeBillingPortalEntities, CheckoutSessionEntities extends StripeCheckoutSessionEntities<StatusEnum> = StripeCheckoutSessionEntities<StatusEnum>, PaymentLinkEntities extends StripePaymentLinkEntities<StatusEnum> = StripePaymentLinkEntities<StatusEnum>, PlanEntities extends StripePlanEntities = StripePlanEntities, SubscriptionEntities extends StripeSubscriptionEntities<PartyEnum> = StripeSubscriptionEntities<PartyEnum>> {
162
+ protected readonly partyEnum: PartyEnum;
162
163
  protected readonly stripeClient: Stripe__default;
163
164
  protected readonly em: EntityManager;
164
165
  protected readonly schemaValidator: SchemaValidator;
@@ -168,7 +169,14 @@ declare class StripeWebhookService<SchemaValidator extends AnySchemaValidator, S
168
169
  protected readonly paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>;
169
170
  protected readonly planService: StripePlanService<SchemaValidator, PlanEntities>;
170
171
  protected readonly subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>;
171
- constructor(stripeClient: Stripe__default, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>);
172
+ constructor(stripeClient: Stripe__default, em: EntityManager, schemaValidator: SchemaValidator, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, billingPortalService: StripeBillingPortalService<SchemaValidator, BillingPortalEntities>, checkoutSessionService: StripeCheckoutSessionService<SchemaValidator, StatusEnum, CheckoutSessionEntities>, paymentLinkService: StripePaymentLinkService<SchemaValidator, StatusEnum, PaymentLinkEntities>, planService: StripePlanService<SchemaValidator, PlanEntities>, subscriptionService: StripeSubscriptionService<SchemaValidator, PartyEnum, SubscriptionEntities>, partyEnum: PartyEnum);
173
+ /**
174
+ * Resolve the party type for a subscription event.
175
+ * Stripe subscriptions are customer-scoped — customers map to users
176
+ * by default. Override this method to implement organization-level
177
+ * subscriptions or other party resolution logic.
178
+ */
179
+ protected resolvePartyType(_event: Stripe__default.Event): PartyEnum[keyof PartyEnum];
172
180
  /**
173
181
  * Extract features from Stripe product metadata.
174
182
  * Features can be stored as:
@@ -615,12 +615,6 @@ var StripeSubscriptionService = class {
615
615
  }
616
616
  };
617
617
 
618
- // domain/enum/party.enum.ts
619
- var PartyEnum = {
620
- USER: "user",
621
- ORGANIZATION: "organization"
622
- };
623
-
624
618
  // persistence/entities/index.ts
625
619
  var import_persistence = require("@forklaunch/core/persistence");
626
620
  var BillingPortal = (0, import_persistence.defineComplianceEntity)({
@@ -698,6 +692,7 @@ var BillingProviderEnum = {
698
692
 
699
693
  // services/webhook.service.ts
700
694
  var StripeWebhookService = class {
695
+ partyEnum;
701
696
  stripeClient;
702
697
  em;
703
698
  schemaValidator;
@@ -707,7 +702,8 @@ var StripeWebhookService = class {
707
702
  paymentLinkService;
708
703
  planService;
709
704
  subscriptionService;
710
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService) {
705
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
706
+ this.partyEnum = partyEnum;
711
707
  this.stripeClient = stripeClient;
712
708
  this.em = em;
713
709
  this.schemaValidator = schemaValidator;
@@ -718,6 +714,18 @@ var StripeWebhookService = class {
718
714
  this.planService = planService;
719
715
  this.subscriptionService = subscriptionService;
720
716
  }
717
+ /**
718
+ * Resolve the party type for a subscription event.
719
+ * Stripe subscriptions are customer-scoped — customers map to users
720
+ * by default. Override this method to implement organization-level
721
+ * subscriptions or other party resolution logic.
722
+ */
723
+ resolvePartyType(_event) {
724
+ const keys = Object.keys(
725
+ this.partyEnum
726
+ );
727
+ return this.partyEnum[keys[0]];
728
+ }
721
729
  /**
722
730
  * Extract features from Stripe product metadata.
723
731
  * Features can be stored as:
@@ -926,7 +934,7 @@ var StripeWebhookService = class {
926
934
  {
927
935
  id: event.data.object.id,
928
936
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
929
- partyType: PartyEnum.USER,
937
+ partyType: this.resolvePartyType(event),
930
938
  description: event.data.object.description ?? void 0,
931
939
  active: true,
932
940
  productId: event.data.object.items.data[0].plan.id,
@@ -949,7 +957,7 @@ var StripeWebhookService = class {
949
957
  {
950
958
  id: event.data.object.id,
951
959
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
952
- partyType: PartyEnum.USER,
960
+ partyType: this.resolvePartyType(event),
953
961
  description: event.data.object.description ?? void 0,
954
962
  active: true,
955
963
  externalId: event.data.object.id,
@@ -583,12 +583,6 @@ var StripeSubscriptionService = class {
583
583
  }
584
584
  };
585
585
 
586
- // domain/enum/party.enum.ts
587
- var PartyEnum = {
588
- USER: "user",
589
- ORGANIZATION: "organization"
590
- };
591
-
592
586
  // persistence/entities/index.ts
593
587
  import { defineComplianceEntity, fp } from "@forklaunch/core/persistence";
594
588
  var BillingPortal = defineComplianceEntity({
@@ -666,6 +660,7 @@ var BillingProviderEnum = {
666
660
 
667
661
  // services/webhook.service.ts
668
662
  var StripeWebhookService = class {
663
+ partyEnum;
669
664
  stripeClient;
670
665
  em;
671
666
  schemaValidator;
@@ -675,7 +670,8 @@ var StripeWebhookService = class {
675
670
  paymentLinkService;
676
671
  planService;
677
672
  subscriptionService;
678
- constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService) {
673
+ constructor(stripeClient, em, schemaValidator, openTelemetryCollector, billingPortalService, checkoutSessionService, paymentLinkService, planService, subscriptionService, partyEnum) {
674
+ this.partyEnum = partyEnum;
679
675
  this.stripeClient = stripeClient;
680
676
  this.em = em;
681
677
  this.schemaValidator = schemaValidator;
@@ -686,6 +682,18 @@ var StripeWebhookService = class {
686
682
  this.planService = planService;
687
683
  this.subscriptionService = subscriptionService;
688
684
  }
685
+ /**
686
+ * Resolve the party type for a subscription event.
687
+ * Stripe subscriptions are customer-scoped — customers map to users
688
+ * by default. Override this method to implement organization-level
689
+ * subscriptions or other party resolution logic.
690
+ */
691
+ resolvePartyType(_event) {
692
+ const keys = Object.keys(
693
+ this.partyEnum
694
+ );
695
+ return this.partyEnum[keys[0]];
696
+ }
689
697
  /**
690
698
  * Extract features from Stripe product metadata.
691
699
  * Features can be stored as:
@@ -894,7 +902,7 @@ var StripeWebhookService = class {
894
902
  {
895
903
  id: event.data.object.id,
896
904
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
897
- partyType: PartyEnum.USER,
905
+ partyType: this.resolvePartyType(event),
898
906
  description: event.data.object.description ?? void 0,
899
907
  active: true,
900
908
  productId: event.data.object.items.data[0].plan.id,
@@ -917,7 +925,7 @@ var StripeWebhookService = class {
917
925
  {
918
926
  id: event.data.object.id,
919
927
  partyId: typeof event.data.object.customer === "string" ? event.data.object.customer : event.data.object.customer.id,
920
- partyType: PartyEnum.USER,
928
+ partyType: this.resolvePartyType(event),
921
929
  description: event.data.object.description ?? void 0,
922
930
  active: true,
923
931
  externalId: event.data.object.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-billing-stripe",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Stripe implementation for forklaunch billing",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -55,7 +55,7 @@
55
55
  "@forklaunch/interfaces-billing": "1.0.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@typescript/native-preview": "7.0.0-dev.20260301.1",
58
+ "@typescript/native-preview": "7.0.0-dev.20260320.1",
59
59
  "depcheck": "^1.4.7",
60
60
  "prettier": "^3.8.1",
61
61
  "typedoc": "^0.28.18"
@@ -1,5 +0,0 @@
1
- export const PartyEnum = {
2
- USER: 'user',
3
- ORGANIZATION: 'organization'
4
- } as const;
5
- export type PartyEnum = (typeof PartyEnum)[keyof typeof PartyEnum];
@@ -1,126 +0,0 @@
1
- declare const BillingProviderEnum: {
2
- readonly STRIPE: "stripe";
3
- };
4
- type BillingProviderEnum = (typeof BillingProviderEnum)[keyof typeof BillingProviderEnum];
5
-
6
- declare const CurrencyEnum: {
7
- readonly USD: "USD";
8
- readonly EUR: "EUR";
9
- readonly JPY: "JPY";
10
- readonly GBP: "GBP";
11
- readonly AUD: "AUD";
12
- readonly CAD: "CAD";
13
- readonly CHF: "CHF";
14
- readonly CNY: "CNY";
15
- readonly AED: "AED";
16
- readonly ARS: "ARS";
17
- readonly BAM: "BAM";
18
- readonly BDT: "BDT";
19
- readonly BGN: "BGN";
20
- readonly BOB: "BOB";
21
- readonly BRL: "BRL";
22
- readonly CLP: "CLP";
23
- readonly COP: "COP";
24
- readonly CRC: "CRC";
25
- readonly CZK: "CZK";
26
- readonly DKK: "DKK";
27
- readonly DZD: "DZD";
28
- readonly EGP: "EGP";
29
- readonly ETB: "ETB";
30
- readonly GEL: "GEL";
31
- readonly GTQ: "GTQ";
32
- readonly HKD: "HKD";
33
- readonly HUF: "HUF";
34
- readonly IDR: "IDR";
35
- readonly ILS: "ILS";
36
- readonly INR: "INR";
37
- readonly ISK: "ISK";
38
- readonly JMD: "JMD";
39
- readonly KES: "KES";
40
- readonly KHR: "KHR";
41
- readonly KRW: "KRW";
42
- readonly KZT: "KZT";
43
- readonly LAK: "LAK";
44
- readonly LKR: "LKR";
45
- readonly MAD: "MAD";
46
- readonly MMK: "MMK";
47
- readonly MXN: "MXN";
48
- readonly MYR: "MYR";
49
- readonly NGN: "NGN";
50
- readonly NOK: "NOK";
51
- readonly NPR: "NPR";
52
- readonly NZD: "NZD";
53
- readonly PEN: "PEN";
54
- readonly PHP: "PHP";
55
- readonly PKR: "PKR";
56
- readonly PLN: "PLN";
57
- readonly PYG: "PYG";
58
- readonly QAR: "QAR";
59
- readonly RON: "RON";
60
- readonly RSD: "RSD";
61
- readonly RUB: "RUB";
62
- readonly SAR: "SAR";
63
- readonly SEK: "SEK";
64
- readonly SGD: "SGD";
65
- readonly THB: "THB";
66
- readonly TRY: "TRY";
67
- readonly TWD: "TWD";
68
- readonly TZS: "TZS";
69
- readonly UAH: "UAH";
70
- readonly UGX: "UGX";
71
- readonly UYU: "UYU";
72
- readonly VND: "VND";
73
- readonly ZAR: "ZAR";
74
- readonly ZMW: "ZMW";
75
- };
76
- type CurrencyEnum = (typeof CurrencyEnum)[keyof typeof CurrencyEnum];
77
-
78
- declare const PaymentMethodEnum: {
79
- readonly AFFIRM: "affirm";
80
- readonly AFTERPAY_CLEARPAY: "afterpay_clearpay";
81
- readonly ALIPAY: "alipay";
82
- readonly ALMA: "alma";
83
- readonly AU_BECS_DEBIT: "au_becs_debit";
84
- readonly BACS_DEBIT: "bacs_debit";
85
- readonly BANCONTACT: "bancontact";
86
- readonly BILLIE: "billie";
87
- readonly BLIK: "blik";
88
- readonly BOLETO: "boleto";
89
- readonly CARD: "card";
90
- readonly CASHAPP: "cashapp";
91
- readonly EPS: "eps";
92
- readonly FPX: "fpx";
93
- readonly GIROPAY: "giropay";
94
- readonly GRABPAY: "grabpay";
95
- readonly IDEAL: "ideal";
96
- readonly KLARNA: "klarna";
97
- readonly KONBINI: "konbini";
98
- readonly LINK: "link";
99
- readonly MOBILEPAY: "mobilepay";
100
- readonly MULTIBANCO: "multibanco";
101
- readonly OXXO: "oxxo";
102
- readonly P24: "p24";
103
- readonly PAY_BY_BANK: "pay_by_bank";
104
- readonly PAYNOW: "paynow";
105
- readonly PAYPAL: "paypal";
106
- readonly PIX: "pix";
107
- readonly PROMPTPAY: "promptpay";
108
- readonly SATISPAY: "satispay";
109
- readonly SEPA_DEBIT: "sepa_debit";
110
- readonly SOFORT: "sofort";
111
- readonly SWISH: "swish";
112
- readonly TWINT: "twint";
113
- readonly US_BANK_ACCOUNT: "us_bank_account";
114
- readonly WECHAT_PAY: "wechat_pay";
115
- readonly ZIP: "zip";
116
- };
117
- type PaymentMethodEnum = (typeof PaymentMethodEnum)[keyof typeof PaymentMethodEnum];
118
-
119
- declare const PlanCadenceEnum: {
120
- readonly WEEKLY: "week";
121
- readonly MONTHLY: "month";
122
- readonly ANNUALLY: "year";
123
- };
124
- type PlanCadenceEnum = (typeof PlanCadenceEnum)[keyof typeof PlanCadenceEnum];
125
-
126
- export { BillingProviderEnum as B, CurrencyEnum as C, PaymentMethodEnum as P, PlanCadenceEnum as a };
@@ -1,126 +0,0 @@
1
- declare const BillingProviderEnum: {
2
- readonly STRIPE: "stripe";
3
- };
4
- type BillingProviderEnum = (typeof BillingProviderEnum)[keyof typeof BillingProviderEnum];
5
-
6
- declare const CurrencyEnum: {
7
- readonly USD: "USD";
8
- readonly EUR: "EUR";
9
- readonly JPY: "JPY";
10
- readonly GBP: "GBP";
11
- readonly AUD: "AUD";
12
- readonly CAD: "CAD";
13
- readonly CHF: "CHF";
14
- readonly CNY: "CNY";
15
- readonly AED: "AED";
16
- readonly ARS: "ARS";
17
- readonly BAM: "BAM";
18
- readonly BDT: "BDT";
19
- readonly BGN: "BGN";
20
- readonly BOB: "BOB";
21
- readonly BRL: "BRL";
22
- readonly CLP: "CLP";
23
- readonly COP: "COP";
24
- readonly CRC: "CRC";
25
- readonly CZK: "CZK";
26
- readonly DKK: "DKK";
27
- readonly DZD: "DZD";
28
- readonly EGP: "EGP";
29
- readonly ETB: "ETB";
30
- readonly GEL: "GEL";
31
- readonly GTQ: "GTQ";
32
- readonly HKD: "HKD";
33
- readonly HUF: "HUF";
34
- readonly IDR: "IDR";
35
- readonly ILS: "ILS";
36
- readonly INR: "INR";
37
- readonly ISK: "ISK";
38
- readonly JMD: "JMD";
39
- readonly KES: "KES";
40
- readonly KHR: "KHR";
41
- readonly KRW: "KRW";
42
- readonly KZT: "KZT";
43
- readonly LAK: "LAK";
44
- readonly LKR: "LKR";
45
- readonly MAD: "MAD";
46
- readonly MMK: "MMK";
47
- readonly MXN: "MXN";
48
- readonly MYR: "MYR";
49
- readonly NGN: "NGN";
50
- readonly NOK: "NOK";
51
- readonly NPR: "NPR";
52
- readonly NZD: "NZD";
53
- readonly PEN: "PEN";
54
- readonly PHP: "PHP";
55
- readonly PKR: "PKR";
56
- readonly PLN: "PLN";
57
- readonly PYG: "PYG";
58
- readonly QAR: "QAR";
59
- readonly RON: "RON";
60
- readonly RSD: "RSD";
61
- readonly RUB: "RUB";
62
- readonly SAR: "SAR";
63
- readonly SEK: "SEK";
64
- readonly SGD: "SGD";
65
- readonly THB: "THB";
66
- readonly TRY: "TRY";
67
- readonly TWD: "TWD";
68
- readonly TZS: "TZS";
69
- readonly UAH: "UAH";
70
- readonly UGX: "UGX";
71
- readonly UYU: "UYU";
72
- readonly VND: "VND";
73
- readonly ZAR: "ZAR";
74
- readonly ZMW: "ZMW";
75
- };
76
- type CurrencyEnum = (typeof CurrencyEnum)[keyof typeof CurrencyEnum];
77
-
78
- declare const PaymentMethodEnum: {
79
- readonly AFFIRM: "affirm";
80
- readonly AFTERPAY_CLEARPAY: "afterpay_clearpay";
81
- readonly ALIPAY: "alipay";
82
- readonly ALMA: "alma";
83
- readonly AU_BECS_DEBIT: "au_becs_debit";
84
- readonly BACS_DEBIT: "bacs_debit";
85
- readonly BANCONTACT: "bancontact";
86
- readonly BILLIE: "billie";
87
- readonly BLIK: "blik";
88
- readonly BOLETO: "boleto";
89
- readonly CARD: "card";
90
- readonly CASHAPP: "cashapp";
91
- readonly EPS: "eps";
92
- readonly FPX: "fpx";
93
- readonly GIROPAY: "giropay";
94
- readonly GRABPAY: "grabpay";
95
- readonly IDEAL: "ideal";
96
- readonly KLARNA: "klarna";
97
- readonly KONBINI: "konbini";
98
- readonly LINK: "link";
99
- readonly MOBILEPAY: "mobilepay";
100
- readonly MULTIBANCO: "multibanco";
101
- readonly OXXO: "oxxo";
102
- readonly P24: "p24";
103
- readonly PAY_BY_BANK: "pay_by_bank";
104
- readonly PAYNOW: "paynow";
105
- readonly PAYPAL: "paypal";
106
- readonly PIX: "pix";
107
- readonly PROMPTPAY: "promptpay";
108
- readonly SATISPAY: "satispay";
109
- readonly SEPA_DEBIT: "sepa_debit";
110
- readonly SOFORT: "sofort";
111
- readonly SWISH: "swish";
112
- readonly TWINT: "twint";
113
- readonly US_BANK_ACCOUNT: "us_bank_account";
114
- readonly WECHAT_PAY: "wechat_pay";
115
- readonly ZIP: "zip";
116
- };
117
- type PaymentMethodEnum = (typeof PaymentMethodEnum)[keyof typeof PaymentMethodEnum];
118
-
119
- declare const PlanCadenceEnum: {
120
- readonly WEEKLY: "week";
121
- readonly MONTHLY: "month";
122
- readonly ANNUALLY: "year";
123
- };
124
- type PlanCadenceEnum = (typeof PlanCadenceEnum)[keyof typeof PlanCadenceEnum];
125
-
126
- export { BillingProviderEnum as B, CurrencyEnum as C, PaymentMethodEnum as P, PlanCadenceEnum as a };