feat: add annual billing, free trial, upgrade/downgrade, and ACH invoice support
- Add monthly/annual billing toggle with 25% annual discount on pricing page - Implement 14-day no-card free trial (server-side Stripe subscription creation) - Enable upgrade/downgrade via Stripe Customer Portal - Add admin-initiated ACH/invoice billing for enterprise customers - Add billing card to Settings page with plan info and Manage Billing button - Handle past_due status with read-only grace period access - Add trial ending and trial expired email templates - Add DB migration for billing_interval and collection_method columns - Update ONBOARDING-AND-AUTH.md documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,12 +14,15 @@ const PLAN_FEATURES: Record<string, { name: string; unitLimit: number }> = {
|
||||
enterprise: { name: 'Enterprise', unitLimit: 999999 },
|
||||
};
|
||||
|
||||
type BillingInterval = 'month' | 'year';
|
||||
|
||||
@Injectable()
|
||||
export class BillingService {
|
||||
private readonly logger = new Logger(BillingService.name);
|
||||
private stripe: Stripe | null = null;
|
||||
private webhookSecret: string;
|
||||
private priceMap: Record<string, string>;
|
||||
private priceMap: Record<string, { monthly: string; annual: string }>;
|
||||
private requirePaymentForTrial: boolean;
|
||||
|
||||
constructor(
|
||||
private configService: ConfigService,
|
||||
@@ -37,27 +40,118 @@ export class BillingService {
|
||||
}
|
||||
|
||||
this.webhookSecret = this.configService.get<string>('STRIPE_WEBHOOK_SECRET') || '';
|
||||
this.requirePaymentForTrial =
|
||||
this.configService.get<string>('REQUIRE_PAYMENT_METHOD_FOR_TRIAL') === 'true';
|
||||
|
||||
// Build price map with backward-compat: new monthly vars fall back to old single vars
|
||||
this.priceMap = {
|
||||
starter: this.configService.get<string>('STRIPE_STARTER_PRICE_ID') || '',
|
||||
professional: this.configService.get<string>('STRIPE_PROFESSIONAL_PRICE_ID') || '',
|
||||
enterprise: this.configService.get<string>('STRIPE_ENTERPRISE_PRICE_ID') || '',
|
||||
starter: {
|
||||
monthly: this.configService.get<string>('STRIPE_STARTER_MONTHLY_PRICE_ID')
|
||||
|| this.configService.get<string>('STRIPE_STARTER_PRICE_ID') || '',
|
||||
annual: this.configService.get<string>('STRIPE_STARTER_ANNUAL_PRICE_ID') || '',
|
||||
},
|
||||
professional: {
|
||||
monthly: this.configService.get<string>('STRIPE_PROFESSIONAL_MONTHLY_PRICE_ID')
|
||||
|| this.configService.get<string>('STRIPE_PROFESSIONAL_PRICE_ID') || '',
|
||||
annual: this.configService.get<string>('STRIPE_PROFESSIONAL_ANNUAL_PRICE_ID') || '',
|
||||
},
|
||||
enterprise: {
|
||||
monthly: this.configService.get<string>('STRIPE_ENTERPRISE_MONTHLY_PRICE_ID')
|
||||
|| this.configService.get<string>('STRIPE_ENTERPRISE_PRICE_ID') || '',
|
||||
annual: this.configService.get<string>('STRIPE_ENTERPRISE_ANNUAL_PRICE_ID') || '',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Price Resolution ────────────────────────────────────────
|
||||
|
||||
private getPriceId(planId: string, interval: BillingInterval): string {
|
||||
const plan = this.priceMap[planId];
|
||||
if (!plan) throw new BadRequestException(`Invalid plan: ${planId}`);
|
||||
const priceId = interval === 'year' ? plan.annual : plan.monthly;
|
||||
if (!priceId || priceId.includes('placeholder')) {
|
||||
throw new BadRequestException(`Price not configured for ${planId} (${interval})`);
|
||||
}
|
||||
return priceId;
|
||||
}
|
||||
|
||||
// ─── Trial Signup (No Card Required) ────────────────────────
|
||||
|
||||
/**
|
||||
* Start a free trial without collecting payment.
|
||||
* Creates a Stripe customer + subscription with trial_period_days,
|
||||
* then provisions the organization immediately.
|
||||
*/
|
||||
async startTrial(
|
||||
planId: string,
|
||||
billingInterval: BillingInterval,
|
||||
email: string,
|
||||
businessName: string,
|
||||
): Promise<{ success: boolean; subscriptionId: string }> {
|
||||
if (!this.stripe) throw new BadRequestException('Stripe not configured');
|
||||
if (!email) throw new BadRequestException('Email is required');
|
||||
if (!businessName) throw new BadRequestException('Business name is required');
|
||||
|
||||
const priceId = this.getPriceId(planId, billingInterval);
|
||||
|
||||
// 1. Create Stripe customer
|
||||
const customer = await this.stripe.customers.create({
|
||||
email,
|
||||
metadata: { plan_id: planId, business_name: businessName, billing_interval: billingInterval },
|
||||
});
|
||||
|
||||
// 2. Create subscription with 14-day trial (no payment method)
|
||||
const subscription = await this.stripe.subscriptions.create({
|
||||
customer: customer.id,
|
||||
items: [{ price: priceId }],
|
||||
trial_period_days: 14,
|
||||
payment_settings: {
|
||||
save_default_payment_method: 'on_subscription',
|
||||
},
|
||||
trial_settings: {
|
||||
end_behavior: { missing_payment_method: 'cancel' },
|
||||
},
|
||||
metadata: { plan_id: planId, business_name: businessName, billing_interval: billingInterval },
|
||||
});
|
||||
|
||||
const trialEnd = subscription.trial_end
|
||||
? new Date(subscription.trial_end * 1000)
|
||||
: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// 3. Provision organization immediately with trial status
|
||||
await this.provisionOrganization(
|
||||
customer.id,
|
||||
subscription.id,
|
||||
email,
|
||||
planId,
|
||||
businessName,
|
||||
'trial',
|
||||
billingInterval,
|
||||
trialEnd,
|
||||
);
|
||||
|
||||
this.logger.log(`Trial started for ${email}, plan=${planId}, interval=${billingInterval}`);
|
||||
return { success: true, subscriptionId: subscription.id };
|
||||
}
|
||||
|
||||
// ─── Checkout Session (Card-required flow / post-trial) ─────
|
||||
|
||||
/**
|
||||
* Create a Stripe Checkout Session for a new subscription.
|
||||
* Used when REQUIRE_PAYMENT_METHOD_FOR_TRIAL=true, or for
|
||||
* post-trial conversion where the user adds a payment method.
|
||||
*/
|
||||
async createCheckoutSession(planId: string, email?: string, businessName?: string): Promise<{ url: string }> {
|
||||
if (!this.stripe) {
|
||||
throw new BadRequestException('Stripe not configured');
|
||||
}
|
||||
async createCheckoutSession(
|
||||
planId: string,
|
||||
billingInterval: BillingInterval = 'month',
|
||||
email?: string,
|
||||
businessName?: string,
|
||||
): Promise<{ url: string }> {
|
||||
if (!this.stripe) throw new BadRequestException('Stripe not configured');
|
||||
|
||||
const priceId = this.priceMap[planId];
|
||||
if (!priceId || priceId.includes('placeholder')) {
|
||||
throw new BadRequestException(`Invalid plan: ${planId}`);
|
||||
}
|
||||
const priceId = this.getPriceId(planId, billingInterval);
|
||||
|
||||
const session = await this.stripe.checkout.sessions.create({
|
||||
const sessionConfig: Stripe.Checkout.SessionCreateParams = {
|
||||
mode: 'subscription',
|
||||
payment_method_types: ['card'],
|
||||
line_items: [{ price: priceId, quantity: 1 }],
|
||||
@@ -67,12 +161,28 @@ export class BillingService {
|
||||
metadata: {
|
||||
plan_id: planId,
|
||||
business_name: businessName || '',
|
||||
billing_interval: billingInterval,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// If trial is card-required, add trial period to checkout
|
||||
if (this.requirePaymentForTrial) {
|
||||
sessionConfig.subscription_data = {
|
||||
trial_period_days: 14,
|
||||
metadata: {
|
||||
plan_id: planId,
|
||||
business_name: businessName || '',
|
||||
billing_interval: billingInterval,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const session = await this.stripe.checkout.sessions.create(sessionConfig);
|
||||
return { url: session.url! };
|
||||
}
|
||||
|
||||
// ─── Webhook Handling ───────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Handle a Stripe webhook event.
|
||||
*/
|
||||
@@ -117,19 +227,39 @@ export class BillingService {
|
||||
case 'customer.subscription.deleted':
|
||||
await this.handleSubscriptionDeleted(event.data.object as Stripe.Subscription);
|
||||
break;
|
||||
case 'customer.subscription.trial_will_end':
|
||||
await this.handleTrialWillEnd(event.data.object as Stripe.Subscription);
|
||||
break;
|
||||
case 'customer.subscription.updated':
|
||||
await this.handleSubscriptionUpdated(event.data.object as Stripe.Subscription);
|
||||
break;
|
||||
default:
|
||||
this.logger.log(`Unhandled Stripe event: ${event.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Provisioning Status ────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Get provisioning status for a checkout session.
|
||||
* Get provisioning status for a checkout session OR subscription ID.
|
||||
*/
|
||||
async getProvisioningStatus(sessionId: string): Promise<{ status: string; activationUrl?: string }> {
|
||||
if (!this.stripe) return { status: 'not_configured' };
|
||||
|
||||
const session = await this.stripe.checkout.sessions.retrieve(sessionId);
|
||||
const customerId = session.customer as string;
|
||||
// Try as checkout session first
|
||||
let customerId: string | null = null;
|
||||
try {
|
||||
const session = await this.stripe.checkout.sessions.retrieve(sessionId);
|
||||
customerId = session.customer as string;
|
||||
} catch {
|
||||
// Not a checkout session — try looking up by subscription ID
|
||||
try {
|
||||
const subscription = await this.stripe.subscriptions.retrieve(sessionId);
|
||||
customerId = subscription.customer as string;
|
||||
} catch {
|
||||
return { status: 'pending' };
|
||||
}
|
||||
}
|
||||
|
||||
if (!customerId) return { status: 'pending' };
|
||||
|
||||
@@ -139,25 +269,131 @@ export class BillingService {
|
||||
);
|
||||
|
||||
if (rows.length === 0) return { status: 'provisioning' };
|
||||
if (rows[0].status === 'active') return { status: 'active' };
|
||||
if (['active', 'trial'].includes(rows[0].status)) return { status: 'active' };
|
||||
return { status: 'provisioning' };
|
||||
}
|
||||
|
||||
// ─── Stripe Customer Portal ─────────────────────────────────
|
||||
|
||||
/**
|
||||
* Create a Stripe Customer Portal session.
|
||||
* Create a Stripe Customer Portal session for managing subscription.
|
||||
*/
|
||||
async createPortalSession(customerId: string): Promise<{ url: string }> {
|
||||
async createPortalSession(orgId: string): Promise<{ url: string }> {
|
||||
if (!this.stripe) throw new BadRequestException('Stripe not configured');
|
||||
|
||||
const rows = await this.dataSource.query(
|
||||
`SELECT stripe_customer_id FROM shared.organizations WHERE id = $1`,
|
||||
[orgId],
|
||||
);
|
||||
if (rows.length === 0 || !rows[0].stripe_customer_id) {
|
||||
throw new BadRequestException('No Stripe customer found for this organization');
|
||||
}
|
||||
|
||||
const session = await this.stripe.billingPortal.sessions.create({
|
||||
customer: customerId,
|
||||
customer: rows[0].stripe_customer_id,
|
||||
return_url: `${this.getAppUrl()}/settings`,
|
||||
});
|
||||
|
||||
return { url: session.url };
|
||||
}
|
||||
|
||||
// ─── Provisioning (inline, no BullMQ for now — add queue later) ─────
|
||||
// ─── Subscription Info ──────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Get current subscription details for the Settings billing tab.
|
||||
*/
|
||||
async getSubscriptionInfo(orgId: string): Promise<{
|
||||
plan: string;
|
||||
planName: string;
|
||||
billingInterval: string;
|
||||
status: string;
|
||||
collectionMethod: string;
|
||||
trialEndsAt: string | null;
|
||||
currentPeriodEnd: string | null;
|
||||
cancelAtPeriodEnd: boolean;
|
||||
}> {
|
||||
const rows = await this.dataSource.query(
|
||||
`SELECT plan_level, billing_interval, status, collection_method,
|
||||
trial_ends_at, stripe_subscription_id
|
||||
FROM shared.organizations WHERE id = $1`,
|
||||
[orgId],
|
||||
);
|
||||
|
||||
if (rows.length === 0) throw new BadRequestException('Organization not found');
|
||||
|
||||
const org = rows[0];
|
||||
let currentPeriodEnd: string | null = null;
|
||||
let cancelAtPeriodEnd = false;
|
||||
|
||||
// Fetch live data from Stripe if available
|
||||
if (this.stripe && org.stripe_subscription_id) {
|
||||
try {
|
||||
const sub = await this.stripe.subscriptions.retrieve(org.stripe_subscription_id, {
|
||||
expand: ['items.data'],
|
||||
}) as Stripe.Subscription;
|
||||
// current_period_end is on the subscription item in newer Stripe API versions
|
||||
const firstItem = sub.items?.data?.[0];
|
||||
if (firstItem?.current_period_end) {
|
||||
currentPeriodEnd = new Date(firstItem.current_period_end * 1000).toISOString();
|
||||
}
|
||||
cancelAtPeriodEnd = sub.cancel_at_period_end;
|
||||
} catch {
|
||||
// Non-critical — use DB data only
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
plan: org.plan_level || 'starter',
|
||||
planName: PLAN_FEATURES[org.plan_level]?.name || org.plan_level || 'Starter',
|
||||
billingInterval: org.billing_interval || 'month',
|
||||
status: org.status || 'active',
|
||||
collectionMethod: org.collection_method || 'charge_automatically',
|
||||
trialEndsAt: org.trial_ends_at ? new Date(org.trial_ends_at).toISOString() : null,
|
||||
currentPeriodEnd,
|
||||
cancelAtPeriodEnd,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Invoice / ACH Billing (Admin) ──────────────────────────
|
||||
|
||||
/**
|
||||
* Switch a customer's subscription to invoice collection (ACH/wire).
|
||||
* Admin-only operation for enterprise customers.
|
||||
*/
|
||||
async switchToInvoiceBilling(
|
||||
orgId: string,
|
||||
collectionMethod: 'charge_automatically' | 'send_invoice',
|
||||
daysUntilDue: number = 30,
|
||||
): Promise<void> {
|
||||
if (!this.stripe) throw new BadRequestException('Stripe not configured');
|
||||
|
||||
const rows = await this.dataSource.query(
|
||||
`SELECT stripe_subscription_id, stripe_customer_id FROM shared.organizations WHERE id = $1`,
|
||||
[orgId],
|
||||
);
|
||||
if (rows.length === 0 || !rows[0].stripe_subscription_id) {
|
||||
throw new BadRequestException('No Stripe subscription found for this organization');
|
||||
}
|
||||
|
||||
const updateParams: Stripe.SubscriptionUpdateParams = {
|
||||
collection_method: collectionMethod,
|
||||
};
|
||||
if (collectionMethod === 'send_invoice') {
|
||||
updateParams.days_until_due = daysUntilDue;
|
||||
}
|
||||
|
||||
await this.stripe.subscriptions.update(rows[0].stripe_subscription_id, updateParams);
|
||||
|
||||
// Update DB
|
||||
await this.dataSource.query(
|
||||
`UPDATE shared.organizations SET collection_method = $1, updated_at = NOW() WHERE id = $2`,
|
||||
[collectionMethod, orgId],
|
||||
);
|
||||
|
||||
this.logger.log(`Billing method updated for org ${orgId}: ${collectionMethod}`);
|
||||
}
|
||||
|
||||
// ─── Webhook Handlers ──────────────────────────────────────
|
||||
|
||||
private async handleCheckoutCompleted(session: Stripe.Checkout.Session): Promise<void> {
|
||||
const customerId = session.customer as string;
|
||||
@@ -165,11 +401,27 @@ export class BillingService {
|
||||
const email = session.customer_email || session.customer_details?.email || '';
|
||||
const planId = session.metadata?.plan_id || 'starter';
|
||||
const businessName = session.metadata?.business_name || 'My HOA';
|
||||
const billingInterval = (session.metadata?.billing_interval || 'month') as BillingInterval;
|
||||
|
||||
this.logger.log(`Provisioning org for ${email}, plan=${planId}, customer=${customerId}`);
|
||||
|
||||
try {
|
||||
await this.provisionOrganization(customerId, subscriptionId, email, planId, businessName);
|
||||
// Determine if this is a trial checkout (card required for trial)
|
||||
let status: 'active' | 'trial' = 'active';
|
||||
let trialEnd: Date | undefined;
|
||||
|
||||
if (this.stripe && subscriptionId) {
|
||||
const sub = await this.stripe.subscriptions.retrieve(subscriptionId);
|
||||
if (sub.status === 'trialing' && sub.trial_end) {
|
||||
status = 'trial';
|
||||
trialEnd = new Date(sub.trial_end * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
await this.provisionOrganization(
|
||||
customerId, subscriptionId, email, planId, businessName,
|
||||
status, billingInterval, trialEnd,
|
||||
);
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Provisioning failed: ${err.message}`, err.stack);
|
||||
}
|
||||
@@ -177,10 +429,10 @@ export class BillingService {
|
||||
|
||||
private async handlePaymentSucceeded(invoice: Stripe.Invoice): Promise<void> {
|
||||
const customerId = invoice.customer as string;
|
||||
// Activate tenant if it was pending
|
||||
// Activate tenant if it was pending/trial
|
||||
await this.dataSource.query(
|
||||
`UPDATE shared.organizations SET status = 'active', updated_at = NOW()
|
||||
WHERE stripe_customer_id = $1 AND status != 'active'`,
|
||||
WHERE stripe_customer_id = $1 AND status IN ('trial', 'past_due')`,
|
||||
[customerId],
|
||||
);
|
||||
}
|
||||
@@ -188,9 +440,17 @@ export class BillingService {
|
||||
private async handlePaymentFailed(invoice: Stripe.Invoice): Promise<void> {
|
||||
const customerId = invoice.customer as string;
|
||||
const rows = await this.dataSource.query(
|
||||
`SELECT email FROM shared.organizations WHERE stripe_customer_id = $1`,
|
||||
`SELECT email, name FROM shared.organizations WHERE stripe_customer_id = $1`,
|
||||
[customerId],
|
||||
);
|
||||
|
||||
// Set org to past_due for grace period (read-only access)
|
||||
await this.dataSource.query(
|
||||
`UPDATE shared.organizations SET status = 'past_due', updated_at = NOW()
|
||||
WHERE stripe_customer_id = $1 AND status = 'active'`,
|
||||
[customerId],
|
||||
);
|
||||
|
||||
if (rows.length > 0 && rows[0].email) {
|
||||
await this.emailService.sendPaymentFailedEmail(rows[0].email, rows[0].name || 'Your organization');
|
||||
}
|
||||
@@ -207,6 +467,91 @@ export class BillingService {
|
||||
this.logger.log(`Subscription cancelled for customer ${customerId}`);
|
||||
}
|
||||
|
||||
private async handleTrialWillEnd(subscription: Stripe.Subscription): Promise<void> {
|
||||
const customerId = subscription.customer as string;
|
||||
const rows = await this.dataSource.query(
|
||||
`SELECT id, email, name FROM shared.organizations WHERE stripe_customer_id = $1`,
|
||||
[customerId],
|
||||
);
|
||||
|
||||
if (rows.length === 0) return;
|
||||
|
||||
const org = rows[0];
|
||||
const daysRemaining = 3; // This webhook fires 3 days before trial end
|
||||
const settingsUrl = `${this.getAppUrl()}/settings`;
|
||||
|
||||
if (org.email) {
|
||||
await this.emailService.sendTrialEndingEmail(
|
||||
org.email,
|
||||
org.name || 'Your organization',
|
||||
daysRemaining,
|
||||
settingsUrl,
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(`Trial ending soon for customer ${customerId}, org ${org.id}`);
|
||||
}
|
||||
|
||||
private async handleSubscriptionUpdated(subscription: Stripe.Subscription): Promise<void> {
|
||||
const customerId = subscription.customer as string;
|
||||
|
||||
// Determine new status
|
||||
let newStatus: string;
|
||||
switch (subscription.status) {
|
||||
case 'trialing':
|
||||
newStatus = 'trial';
|
||||
break;
|
||||
case 'active':
|
||||
newStatus = 'active';
|
||||
break;
|
||||
case 'past_due':
|
||||
newStatus = 'past_due';
|
||||
break;
|
||||
case 'canceled':
|
||||
case 'unpaid':
|
||||
newStatus = 'archived';
|
||||
break;
|
||||
default:
|
||||
return; // Don't update for other statuses
|
||||
}
|
||||
|
||||
// Determine billing interval from the subscription items
|
||||
let billingInterval: BillingInterval = 'month';
|
||||
if (subscription.items?.data?.[0]?.price?.recurring?.interval === 'year') {
|
||||
billingInterval = 'year';
|
||||
}
|
||||
|
||||
// Determine plan from price metadata or existing mapping
|
||||
let planId: string | null = null;
|
||||
const activePriceId = subscription.items?.data?.[0]?.price?.id;
|
||||
if (activePriceId) {
|
||||
for (const [plan, prices] of Object.entries(this.priceMap)) {
|
||||
if (prices.monthly === activePriceId || prices.annual === activePriceId) {
|
||||
planId = plan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build update query dynamically
|
||||
const updates: string[] = [`status = '${newStatus}'`, `billing_interval = '${billingInterval}'`, `updated_at = NOW()`];
|
||||
if (planId) {
|
||||
updates.push(`plan_level = '${planId}'`);
|
||||
}
|
||||
if (subscription.collection_method) {
|
||||
updates.push(`collection_method = '${subscription.collection_method}'`);
|
||||
}
|
||||
|
||||
await this.dataSource.query(
|
||||
`UPDATE shared.organizations SET ${updates.join(', ')} WHERE stripe_customer_id = $1`,
|
||||
[customerId],
|
||||
);
|
||||
|
||||
this.logger.log(`Subscription updated for customer ${customerId}: status=${newStatus}, interval=${billingInterval}`);
|
||||
}
|
||||
|
||||
// ─── Provisioning ──────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Full provisioning flow: create org, schema, user, invite token, email.
|
||||
*/
|
||||
@@ -216,20 +561,26 @@ export class BillingService {
|
||||
email: string,
|
||||
planId: string,
|
||||
businessName: string,
|
||||
status: 'active' | 'trial' = 'active',
|
||||
billingInterval: BillingInterval = 'month',
|
||||
trialEndsAt?: Date,
|
||||
): Promise<void> {
|
||||
// 1. Create or upsert organization
|
||||
const schemaName = `tenant_${uuid().replace(/-/g, '').substring(0, 12)}`;
|
||||
|
||||
const orgRows = await this.dataSource.query(
|
||||
`INSERT INTO shared.organizations (name, schema_name, status, plan_level, stripe_customer_id, stripe_subscription_id, email)
|
||||
VALUES ($1, $2, 'active', $3, $4, $5, $6)
|
||||
`INSERT INTO shared.organizations
|
||||
(name, schema_name, status, plan_level, stripe_customer_id, stripe_subscription_id, email, billing_interval, trial_ends_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
ON CONFLICT (stripe_customer_id) DO UPDATE SET
|
||||
stripe_subscription_id = EXCLUDED.stripe_subscription_id,
|
||||
plan_level = EXCLUDED.plan_level,
|
||||
status = 'active',
|
||||
status = EXCLUDED.status,
|
||||
billing_interval = EXCLUDED.billing_interval,
|
||||
trial_ends_at = EXCLUDED.trial_ends_at,
|
||||
updated_at = NOW()
|
||||
RETURNING id, schema_name`,
|
||||
[businessName, schemaName, planId, customerId, subscriptionId, email],
|
||||
[businessName, schemaName, status, planId, customerId, subscriptionId, email, billingInterval, trialEndsAt || null],
|
||||
);
|
||||
|
||||
const orgId = orgRows[0].id;
|
||||
@@ -285,7 +636,7 @@ export class BillingService {
|
||||
[orgId],
|
||||
);
|
||||
|
||||
this.logger.log(`✅ Provisioning complete for org=${orgId}, user=${userId}`);
|
||||
this.logger.log(`Provisioning complete for org=${orgId}, user=${userId}, status=${status}`);
|
||||
}
|
||||
|
||||
private getAppUrl(): string {
|
||||
|
||||
Reference in New Issue
Block a user