@mostajs/subscriptions-plan 0.1.0 → 0.3.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.
- package/dist/lib/stripe-billing.d.ts +10 -8
- package/dist/lib/stripe-billing.d.ts.map +1 -1
- package/dist/lib/stripe-billing.js +36 -72
- package/dist/lib/stripe-billing.js.map +1 -1
- package/dist/lib/subscribe.d.ts +33 -0
- package/dist/lib/subscribe.d.ts.map +1 -0
- package/dist/lib/subscribe.js +105 -0
- package/dist/lib/subscribe.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/package.json +20 -5
|
@@ -2,6 +2,7 @@ import type Stripe from 'stripe';
|
|
|
2
2
|
import type { BillingConfig } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Create a Stripe Checkout session for subscription billing.
|
|
5
|
+
* Delegates to @mostajs/payment.createBillingSession
|
|
5
6
|
*/
|
|
6
7
|
export declare function createBillingSession(stripe: Stripe, config: BillingConfig, params: {
|
|
7
8
|
customerId: string;
|
|
@@ -15,11 +16,17 @@ export declare function createBillingSession(stripe: Stripe, config: BillingConf
|
|
|
15
16
|
sessionId: string;
|
|
16
17
|
}>;
|
|
17
18
|
/**
|
|
18
|
-
* Create a Stripe Customer Portal session
|
|
19
|
+
* Create a Stripe Customer Portal session.
|
|
20
|
+
* Delegates to @mostajs/payment.createPortalSession
|
|
19
21
|
*/
|
|
20
22
|
export declare function createPortalSession(stripe: Stripe, config: BillingConfig, customerId: string): Promise<{
|
|
21
23
|
url: string;
|
|
22
24
|
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Verify a Stripe webhook event.
|
|
27
|
+
* Delegates to @mostajs/payment.handleWebhook
|
|
28
|
+
*/
|
|
29
|
+
export declare function verifyWebhookEvent(stripe: Stripe, body: string | Buffer, signature: string, secret: string): Promise<Stripe.Event>;
|
|
23
30
|
/**
|
|
24
31
|
* Create a Stripe customer for a new account.
|
|
25
32
|
*/
|
|
@@ -29,7 +36,7 @@ export declare function createStripeCustomer(stripe: Stripe, params: {
|
|
|
29
36
|
metadata?: Record<string, string>;
|
|
30
37
|
}): Promise<string>;
|
|
31
38
|
/**
|
|
32
|
-
* Cancel a Stripe subscription
|
|
39
|
+
* Cancel a Stripe subscription.
|
|
33
40
|
*/
|
|
34
41
|
export declare function cancelSubscription(stripe: Stripe, stripeSubId: string, immediate?: boolean): Promise<void>;
|
|
35
42
|
/**
|
|
@@ -37,12 +44,7 @@ export declare function cancelSubscription(stripe: Stripe, stripeSubId: string,
|
|
|
37
44
|
*/
|
|
38
45
|
export declare function changeSubscriptionPlan(stripe: Stripe, stripeSubId: string, newPriceId: string): Promise<void>;
|
|
39
46
|
/**
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
export declare function verifyWebhookEvent(stripe: Stripe, body: string | Buffer, signature: string, secret: string): Stripe.Event;
|
|
43
|
-
/**
|
|
44
|
-
* Handle billing webhook events.
|
|
45
|
-
* Returns the action taken for logging/auditing.
|
|
47
|
+
* Parse billing webhook events into structured actions.
|
|
46
48
|
*/
|
|
47
49
|
export declare function parseBillingEvent(event: Stripe.Event): {
|
|
48
50
|
type: 'subscription_created' | 'subscription_updated' | 'subscription_deleted' | 'invoice_paid' | 'invoice_failed' | 'checkout_completed' | 'unknown';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-billing.d.ts","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stripe-billing.d.ts","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAItD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,M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MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG;IACtD,IAAI,EAAE,sBAAsB,GAAG,sBAAsB,GAAG,sBAAsB,GACxE,cAAc,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,SAAS,CAAA;IAC1E,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CAyCA"}
|
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
// @mostajs/subscriptions-plan — Stripe Billing integration
|
|
2
2
|
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
// v0.2.0: delegates to @mostajs/payment for core Stripe operations
|
|
4
|
+
// ─── Delegate to @mostajs/payment ───────────────────────────
|
|
3
5
|
/**
|
|
4
6
|
* Create a Stripe Checkout session for subscription billing.
|
|
7
|
+
* Delegates to @mostajs/payment.createBillingSession
|
|
5
8
|
*/
|
|
6
9
|
export async function createBillingSession(stripe, config, params) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
trial_period_days: params.trialDays,
|
|
15
|
-
metadata: params.metadata,
|
|
16
|
-
},
|
|
10
|
+
const { createBillingSession: pmBilling } = await import('@mostajs/payment/server');
|
|
11
|
+
return pmBilling(stripe, {
|
|
12
|
+
customerId: params.customerId,
|
|
13
|
+
priceId: params.priceId,
|
|
14
|
+
successUrl: params.successUrl ?? config.successUrl,
|
|
15
|
+
cancelUrl: params.cancelUrl ?? config.cancelUrl,
|
|
16
|
+
trialDays: params.trialDays,
|
|
17
17
|
metadata: params.metadata,
|
|
18
18
|
});
|
|
19
|
-
return { url: session.url, sessionId: session.id };
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
|
-
* Create a Stripe Customer Portal session
|
|
21
|
+
* Create a Stripe Customer Portal session.
|
|
22
|
+
* Delegates to @mostajs/payment.createPortalSession
|
|
23
23
|
*/
|
|
24
24
|
export async function createPortalSession(stripe, config, customerId) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
return_url: config.portalReturnUrl,
|
|
28
|
-
});
|
|
29
|
-
return { url: session.url };
|
|
25
|
+
const { createPortalSession: pmPortal } = await import('@mostajs/payment/server');
|
|
26
|
+
return pmPortal(stripe, customerId, config.portalReturnUrl);
|
|
30
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Verify a Stripe webhook event.
|
|
30
|
+
* Delegates to @mostajs/payment.handleWebhook
|
|
31
|
+
*/
|
|
32
|
+
export async function verifyWebhookEvent(stripe, body, signature, secret) {
|
|
33
|
+
const { handleWebhook } = await import('@mostajs/payment/server');
|
|
34
|
+
return handleWebhook(stripe, body, signature, secret);
|
|
35
|
+
}
|
|
36
|
+
// ─── Subscriptions-plan specific ────────────────────────────
|
|
31
37
|
/**
|
|
32
38
|
* Create a Stripe customer for a new account.
|
|
33
39
|
*/
|
|
@@ -40,16 +46,14 @@ export async function createStripeCustomer(stripe, params) {
|
|
|
40
46
|
return customer.id;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
|
-
* Cancel a Stripe subscription
|
|
49
|
+
* Cancel a Stripe subscription.
|
|
44
50
|
*/
|
|
45
51
|
export async function cancelSubscription(stripe, stripeSubId, immediate = false) {
|
|
46
52
|
if (immediate) {
|
|
47
53
|
await stripe.subscriptions.cancel(stripeSubId);
|
|
48
54
|
}
|
|
49
55
|
else {
|
|
50
|
-
await stripe.subscriptions.update(stripeSubId, {
|
|
51
|
-
cancel_at_period_end: true,
|
|
52
|
-
});
|
|
56
|
+
await stripe.subscriptions.update(stripeSubId, { cancel_at_period_end: true });
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
@@ -58,35 +62,18 @@ export async function cancelSubscription(stripe, stripeSubId, immediate = false)
|
|
|
58
62
|
export async function changeSubscriptionPlan(stripe, stripeSubId, newPriceId) {
|
|
59
63
|
const sub = await stripe.subscriptions.retrieve(stripeSubId);
|
|
60
64
|
await stripe.subscriptions.update(stripeSubId, {
|
|
61
|
-
items: [{
|
|
62
|
-
id: sub.items.data[0].id,
|
|
63
|
-
price: newPriceId,
|
|
64
|
-
}],
|
|
65
|
+
items: [{ id: sub.items.data[0].id, price: newPriceId }],
|
|
65
66
|
proration_behavior: 'always_invoice',
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
export function verifyWebhookEvent(stripe, body, signature, secret) {
|
|
72
|
-
return stripe.webhooks.constructEvent(body, signature, secret);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Handle billing webhook events.
|
|
76
|
-
* Returns the action taken for logging/auditing.
|
|
70
|
+
* Parse billing webhook events into structured actions.
|
|
77
71
|
*/
|
|
78
72
|
export function parseBillingEvent(event) {
|
|
79
73
|
switch (event.type) {
|
|
80
74
|
case 'checkout.session.completed': {
|
|
81
|
-
const
|
|
82
|
-
return {
|
|
83
|
-
type: 'checkout_completed',
|
|
84
|
-
data: {
|
|
85
|
-
customerId: session.customer,
|
|
86
|
-
subscriptionId: session.subscription,
|
|
87
|
-
metadata: session.metadata,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
75
|
+
const s = event.data.object;
|
|
76
|
+
return { type: 'checkout_completed', data: { customerId: s.customer, subscriptionId: s.subscription, metadata: s.metadata } };
|
|
90
77
|
}
|
|
91
78
|
case 'customer.subscription.created':
|
|
92
79
|
case 'customer.subscription.updated': {
|
|
@@ -94,9 +81,7 @@ export function parseBillingEvent(event) {
|
|
|
94
81
|
return {
|
|
95
82
|
type: event.type === 'customer.subscription.created' ? 'subscription_created' : 'subscription_updated',
|
|
96
83
|
data: {
|
|
97
|
-
stripeSubId: sub.id,
|
|
98
|
-
customerId: sub.customer,
|
|
99
|
-
status: sub.status,
|
|
84
|
+
stripeSubId: sub.id, customerId: sub.customer, status: sub.status,
|
|
100
85
|
priceId: sub.items.data[0]?.price?.id,
|
|
101
86
|
currentPeriodStart: new Date(sub.current_period_start * 1000).toISOString(),
|
|
102
87
|
currentPeriodEnd: new Date(sub.current_period_end * 1000).toISOString(),
|
|
@@ -106,42 +91,21 @@ export function parseBillingEvent(event) {
|
|
|
106
91
|
}
|
|
107
92
|
case 'customer.subscription.deleted': {
|
|
108
93
|
const sub = event.data.object;
|
|
109
|
-
return {
|
|
110
|
-
type: 'subscription_deleted',
|
|
111
|
-
data: {
|
|
112
|
-
stripeSubId: sub.id,
|
|
113
|
-
customerId: sub.customer,
|
|
114
|
-
},
|
|
115
|
-
};
|
|
94
|
+
return { type: 'subscription_deleted', data: { stripeSubId: sub.id, customerId: sub.customer } };
|
|
116
95
|
}
|
|
117
96
|
case 'invoice.paid': {
|
|
118
|
-
const
|
|
97
|
+
const inv = event.data.object;
|
|
119
98
|
return {
|
|
120
99
|
type: 'invoice_paid',
|
|
121
100
|
data: {
|
|
122
|
-
stripeInvoiceId:
|
|
123
|
-
|
|
124
|
-
subscriptionId: invoice.subscription,
|
|
125
|
-
amount: invoice.amount_paid,
|
|
126
|
-
currency: invoice.currency,
|
|
127
|
-
pdfUrl: invoice.invoice_pdf,
|
|
128
|
-
hostedUrl: invoice.hosted_invoice_url,
|
|
129
|
-
periodStart: invoice.period_start ? new Date(invoice.period_start * 1000).toISOString() : null,
|
|
130
|
-
periodEnd: invoice.period_end ? new Date(invoice.period_end * 1000).toISOString() : null,
|
|
101
|
+
stripeInvoiceId: inv.id, customerId: inv.customer, subscriptionId: inv.subscription,
|
|
102
|
+
amount: inv.amount_paid, currency: inv.currency, pdfUrl: inv.invoice_pdf,
|
|
131
103
|
},
|
|
132
104
|
};
|
|
133
105
|
}
|
|
134
106
|
case 'invoice.payment_failed': {
|
|
135
|
-
const
|
|
136
|
-
return {
|
|
137
|
-
type: 'invoice_failed',
|
|
138
|
-
data: {
|
|
139
|
-
stripeInvoiceId: invoice.id,
|
|
140
|
-
customerId: invoice.customer,
|
|
141
|
-
subscriptionId: invoice.subscription,
|
|
142
|
-
amount: invoice.amount_due,
|
|
143
|
-
},
|
|
144
|
-
};
|
|
107
|
+
const inv = event.data.object;
|
|
108
|
+
return { type: 'invoice_failed', data: { stripeInvoiceId: inv.id, customerId: inv.customer, amount: inv.amount_due } };
|
|
145
109
|
}
|
|
146
110
|
default:
|
|
147
111
|
return { type: 'unknown', data: { eventType: event.type } };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-billing.js","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,wCAAwC;
|
|
1
|
+
{"version":3,"file":"stripe-billing.js","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,wCAAwC;AACxC,mEAAmE;AAKnE,+DAA+D;AAE/D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,MAAqB,EACrB,MAOC;IAED,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;IACnF,OAAO,SAAS,CAAC,MAAM,EAAE;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU;QAClD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS;QAC/C,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,MAAqB,EACrB,UAAkB;IAElB,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,yB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AE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,CAAA;IAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IDialect } from '@mostajs/orm';
|
|
2
|
+
export interface SubscribeParams {
|
|
3
|
+
accountId: string;
|
|
4
|
+
planId: string;
|
|
5
|
+
/** Payment provider: 'direct' (free/manual), 'stripe', 'chargily', 'paypal', 'satim' */
|
|
6
|
+
provider?: string;
|
|
7
|
+
/** URLs for payment redirect */
|
|
8
|
+
successUrl?: string;
|
|
9
|
+
cancelUrl?: string;
|
|
10
|
+
/** Customer info (for provider checkout) */
|
|
11
|
+
customerEmail?: string;
|
|
12
|
+
customerName?: string;
|
|
13
|
+
/** Stripe customer ID (if already exists) */
|
|
14
|
+
stripeCustomerId?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SubscribeResult {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
/** If payment required, redirect URL */
|
|
19
|
+
url?: string | null;
|
|
20
|
+
/** If direct subscription (free plan), the subscription object */
|
|
21
|
+
subscription?: any;
|
|
22
|
+
/** Error message */
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to a plan — handles free (direct) and paid (via payment provider).
|
|
27
|
+
*
|
|
28
|
+
* - Free plan (price=0): creates subscription directly in DB
|
|
29
|
+
* - Paid plan: delegates to @mostajs/payment provider for checkout redirect
|
|
30
|
+
* - Falls back to direct subscription if no provider available
|
|
31
|
+
*/
|
|
32
|
+
export declare function subscribeToPlan(dialect: IDialect, params: SubscribeParams): Promise<SubscribeResult>;
|
|
33
|
+
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../src/lib/subscribe.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAG5C,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gCAAgC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAA;IACX,wCAAwC;IACxC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,kEAAkE;IAClE,YAAY,CAAC,EAAE,GAAG,CAAA;IAClB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,eAAe,CAAC,CAuC1B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Subscribe to plan (multi-provider)
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
// Delegates payment to @mostajs/payment providers
|
|
4
|
+
import { getPlanRepo, getSubscriptionRepo } from './plan-factory.js';
|
|
5
|
+
/**
|
|
6
|
+
* Subscribe to a plan — handles free (direct) and paid (via payment provider).
|
|
7
|
+
*
|
|
8
|
+
* - Free plan (price=0): creates subscription directly in DB
|
|
9
|
+
* - Paid plan: delegates to @mostajs/payment provider for checkout redirect
|
|
10
|
+
* - Falls back to direct subscription if no provider available
|
|
11
|
+
*/
|
|
12
|
+
export async function subscribeToPlan(dialect, params) {
|
|
13
|
+
const planRepo = getPlanRepo(dialect);
|
|
14
|
+
const subRepo = getSubscriptionRepo(dialect);
|
|
15
|
+
// Verify plan exists
|
|
16
|
+
const plan = await planRepo.findById(params.planId);
|
|
17
|
+
if (!plan)
|
|
18
|
+
return { ok: false, error: 'Plan non trouve' };
|
|
19
|
+
// Free plan or no provider → direct subscription
|
|
20
|
+
if (!plan.price || plan.price === 0 || !params.provider || params.provider === 'direct') {
|
|
21
|
+
return directSubscribe(subRepo, params.accountId, params.planId);
|
|
22
|
+
}
|
|
23
|
+
// Paid plan → try payment provider
|
|
24
|
+
try {
|
|
25
|
+
const { getProvider, registerProvider } = await import('@mostajs/payment/server');
|
|
26
|
+
// Auto-register provider if not done yet
|
|
27
|
+
await ensureProvider(params.provider);
|
|
28
|
+
const provider = getProvider(params.provider);
|
|
29
|
+
const result = await provider.createCheckout({
|
|
30
|
+
orderId: `sub_${params.accountId}_${params.planId}`,
|
|
31
|
+
amount: plan.price / 100, // cents → units
|
|
32
|
+
currency: plan.currency ?? 'usd',
|
|
33
|
+
description: `Abonnement ${plan.name}`,
|
|
34
|
+
successUrl: params.successUrl ?? '/dashboard/billing?success=1',
|
|
35
|
+
cancelUrl: params.cancelUrl ?? '/dashboard/billing?canceled=1',
|
|
36
|
+
customerId: params.stripeCustomerId,
|
|
37
|
+
priceId: plan.stripePriceId,
|
|
38
|
+
metadata: { accountId: params.accountId, planId: params.planId },
|
|
39
|
+
});
|
|
40
|
+
return { ok: true, url: result.url };
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.warn(`[subscribe] Provider ${params.provider} failed:`, e.message);
|
|
44
|
+
// Fallback to direct subscription
|
|
45
|
+
return directSubscribe(subRepo, params.accountId, params.planId);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Direct subscription — no payment required (free plan or fallback).
|
|
50
|
+
*/
|
|
51
|
+
async function directSubscribe(subRepo, accountId, planId) {
|
|
52
|
+
// Cancel existing active subscriptions
|
|
53
|
+
const existing = await subRepo.findAll({ account: accountId, status: 'active' });
|
|
54
|
+
for (const sub of existing) {
|
|
55
|
+
await subRepo.update(sub.id, { status: 'canceled' });
|
|
56
|
+
}
|
|
57
|
+
// Create new subscription
|
|
58
|
+
const subscription = await subRepo.create({
|
|
59
|
+
account: accountId,
|
|
60
|
+
plan: planId,
|
|
61
|
+
status: 'active',
|
|
62
|
+
});
|
|
63
|
+
return { ok: true, subscription };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Auto-register a payment provider from environment variables.
|
|
67
|
+
*/
|
|
68
|
+
async function ensureProvider(name) {
|
|
69
|
+
const { listProviders } = await import('@mostajs/payment/server');
|
|
70
|
+
if (listProviders().includes(name))
|
|
71
|
+
return;
|
|
72
|
+
switch (name) {
|
|
73
|
+
case 'stripe': {
|
|
74
|
+
if (!process.env.STRIPE_SECRET_KEY)
|
|
75
|
+
throw new Error('STRIPE_SECRET_KEY not configured');
|
|
76
|
+
const { createStripeProvider, registerProvider } = await import('@mostajs/payment/server');
|
|
77
|
+
registerProvider(createStripeProvider());
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'chargily': {
|
|
81
|
+
if (!process.env.CHARGILY_API_KEY)
|
|
82
|
+
throw new Error('CHARGILY_API_KEY not configured');
|
|
83
|
+
const { createChargilyProvider, registerProvider } = await import('@mostajs/payment/server');
|
|
84
|
+
registerProvider(createChargilyProvider());
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'paypal': {
|
|
88
|
+
if (!process.env.PAYPAL_CLIENT_ID)
|
|
89
|
+
throw new Error('PAYPAL_CLIENT_ID not configured');
|
|
90
|
+
const { createPayPalProvider, registerProvider } = await import('@mostajs/payment/server');
|
|
91
|
+
registerProvider(createPayPalProvider());
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'satim': {
|
|
95
|
+
if (!process.env.SATIM_MERCHANT_ID)
|
|
96
|
+
throw new Error('SATIM_MERCHANT_ID not configured');
|
|
97
|
+
const { createSatimProvider, registerProvider } = await import('@mostajs/payment/server');
|
|
98
|
+
registerProvider(createSatimProvider());
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
throw new Error(`Unknown payment provider: ${name}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=subscribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../../src/lib/subscribe.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,wCAAwC;AACxC,kDAAkD;AAGlD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AA2BpE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAiB,EACjB,MAAuB;IAEvB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAA;IAE5C,qBAAqB;IACrB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAQ,CAAA;IAC1D,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAA;IAEzD,iDAAiD;IACjD,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACxF,OAAO,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAClE,CAAC;IAED,mCAAmC;IACnC,IAAI,CAAC;QACH,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;QAEj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AAE,CAAC,CAAA;YAC1C,MAAK;QACP,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB;gBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;YACrF,MAAM,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;YAC1F,gBAAgB,CAAC,oBAAoB,EAAE,CAAC,CAAA;YACxC,MAAK;QACP,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;YACvF,MAAM,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;YACzF,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,CAAA;YACvC,MAAK;QACP,CAAC;QACD;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC;AACH,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { getPlanRepo, getSubscriptionRepo, getInvoiceRepo, getUsageLogRepo, resetRepos, } from './lib/plan-factory.js';
|
|
2
2
|
export { checkQuota, isDialectAllowed, isTransportAllowed, getUsageSummary, incrementUsage, DEFAULT_PLANS, } from './lib/quota-check.js';
|
|
3
3
|
export { createBillingSession, createPortalSession, createStripeCustomer, cancelSubscription, changeSubscriptionPlan, verifyWebhookEvent, parseBillingEvent, } from './lib/stripe-billing.js';
|
|
4
|
+
export { subscribeToPlan } from './lib/subscribe.js';
|
|
5
|
+
export type { SubscribeParams, SubscribeResult } from './lib/subscribe.js';
|
|
4
6
|
export { createPlanHandlers } from './api/plans.route.js';
|
|
5
7
|
export { createSubscriptionHandlers } from './api/subscriptions.route.js';
|
|
6
8
|
export { createUsageHandlers } from './api/usage.route.js';
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAG7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAG1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAG7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/server.js
CHANGED
|
@@ -6,6 +6,8 @@ export { getPlanRepo, getSubscriptionRepo, getInvoiceRepo, getUsageLogRepo, rese
|
|
|
6
6
|
export { checkQuota, isDialectAllowed, isTransportAllowed, getUsageSummary, incrementUsage, DEFAULT_PLANS, } from './lib/quota-check.js';
|
|
7
7
|
// Stripe Billing
|
|
8
8
|
export { createBillingSession, createPortalSession, createStripeCustomer, cancelSubscription, changeSubscriptionPlan, verifyWebhookEvent, parseBillingEvent, } from './lib/stripe-billing.js';
|
|
9
|
+
// Subscribe (multi-provider via @mostajs/payment)
|
|
10
|
+
export { subscribeToPlan } from './lib/subscribe.js';
|
|
9
11
|
// API handlers
|
|
10
12
|
export { createPlanHandlers } from './api/plans.route.js';
|
|
11
13
|
export { createSubscriptionHandlers } from './api/subscriptions.route.js';
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wCAAwC;AAExC,eAAe;AACf,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAA;AAE9B,oBAAoB;AACpB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,GACd,M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AO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE7D,eAAe;AACf,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/subscriptions-plan",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Subscription plans, billing, invoices and usage tracking for @mostajs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,15 +29,30 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
31
31
|
"license": "MIT",
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"stripe": "^17.0.0"
|
|
34
|
-
},
|
|
35
32
|
"peerDependencies": {
|
|
36
33
|
"@mostajs/orm": "^1.8.0",
|
|
34
|
+
"@mostajs/payment": ">=0.2.0",
|
|
37
35
|
"next": ">=14.0.0",
|
|
38
|
-
"react": ">=18.0.0"
|
|
36
|
+
"react": ">=18.0.0",
|
|
37
|
+
"stripe": ">=17.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@mostajs/payment": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"stripe": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"next": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"react": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
39
52
|
},
|
|
40
53
|
"devDependencies": {
|
|
54
|
+
"@mostajs/orm": "file:../mosta-orm",
|
|
55
|
+
"@mostajs/payment": "file:../mosta-payment",
|
|
41
56
|
"@types/node": "^22.0.0",
|
|
42
57
|
"better-sqlite3": "^12.0.0",
|
|
43
58
|
"tsx": "^4.0.0",
|