feat: Sync Stripe subscription period end and cancellation status with local records.
This commit is contained in:
@@ -18,13 +18,17 @@ export class StripeService {
|
||||
apiVersion: '2025-02-24.acacia' as any,
|
||||
});
|
||||
} else {
|
||||
this.logger.warn('Stripe secret key not configured. Stripe features will be unavailable.');
|
||||
this.logger.warn(
|
||||
'Stripe secret key not configured. Stripe features will be unavailable.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private getStripe(): Stripe {
|
||||
if (!this.stripe) {
|
||||
throw new BadRequestException('Stripe is not configured. Please set STRIPE_SECRET_KEY in environment.');
|
||||
throw new BadRequestException(
|
||||
'Stripe is not configured. Please set STRIPE_SECRET_KEY in environment.',
|
||||
);
|
||||
}
|
||||
return this.stripe;
|
||||
}
|
||||
@@ -90,7 +94,11 @@ export class StripeService {
|
||||
? `${user.agentProfile.firstName || ''} ${user.agentProfile.lastName || ''}`.trim()
|
||||
: undefined;
|
||||
|
||||
const customerId = await this.createCustomer(userId, user.email, customerName);
|
||||
const customerId = await this.createCustomer(
|
||||
userId,
|
||||
user.email,
|
||||
customerName,
|
||||
);
|
||||
|
||||
const session = await this.getStripe().checkout.sessions.create({
|
||||
customer: customerId,
|
||||
@@ -144,11 +152,19 @@ export class StripeService {
|
||||
return this.getStripe().subscriptions.cancel(stripeSubscriptionId);
|
||||
}
|
||||
|
||||
constructWebhookEvent(
|
||||
payload: Buffer,
|
||||
signature: string,
|
||||
): Stripe.Event {
|
||||
const webhookSecret = this.configService.get<string>('stripe.webhookSecret') || '';
|
||||
return this.getStripe().webhooks.constructEvent(payload, signature, webhookSecret);
|
||||
async getSubscription(
|
||||
stripeSubscriptionId: string,
|
||||
): Promise<Stripe.Subscription> {
|
||||
return this.getStripe().subscriptions.retrieve(stripeSubscriptionId);
|
||||
}
|
||||
|
||||
constructWebhookEvent(payload: Buffer, signature: string): Stripe.Event {
|
||||
const webhookSecret =
|
||||
this.configService.get<string>('stripe.webhookSecret') || '';
|
||||
return this.getStripe().webhooks.constructEvent(
|
||||
payload,
|
||||
signature,
|
||||
webhookSecret,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user