renew dkala subscription
This commit is contained in:
@@ -38,6 +38,7 @@ import { InvoiceStatus } from "../enums/invoice-status.enum";
|
||||
import { IExternalInvoiceJob, InvoicePurpose } from "../interfaces/external-invoice.interface";
|
||||
import { InvoiceItemsRepository } from "../repositories/invoice-items.repository";
|
||||
import { InvoicesRepository } from "../repositories/invoices.repository";
|
||||
import { DkalaService } from "../../dkala/providers/dkala.service";
|
||||
@Injectable()
|
||||
export class InvoicesService {
|
||||
private readonly logger = new Logger(InvoicesService.name);
|
||||
@@ -55,6 +56,7 @@ export class InvoicesService {
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly accessLogService: AccessLogService,
|
||||
private readonly restaurantService: RestaurantService,
|
||||
private readonly dkalaService: DkalaService,
|
||||
) { }
|
||||
|
||||
///********************************** */
|
||||
@@ -833,6 +835,19 @@ export class InvoicesService {
|
||||
// Don't fail the transaction if external API call fails
|
||||
}
|
||||
}
|
||||
else if (upgradePlan.service.slug?.toLowerCase().includes('dkala')) {
|
||||
try {
|
||||
this.logger.log(`Calling external API for dkala upgrade: subscription ${userSubscription.id}`);
|
||||
await this.dkalaService.upgradeSubscription(
|
||||
userSubscription.id,
|
||||
userSubscription.endDate
|
||||
);
|
||||
this.logger.log(`External API call completed for dkala upgrade: subscription ${userSubscription.id}`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to call external API for dkala upgrade: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
// Don't fail the transaction if external API call fails
|
||||
}
|
||||
}
|
||||
} else if (purpose == InvoicePurpose.RENEW) {
|
||||
|
||||
if (userSubscription.status == SubscriptionStatus.ACTIVE) {
|
||||
@@ -866,6 +881,20 @@ export class InvoicesService {
|
||||
}
|
||||
}
|
||||
|
||||
else if (userSubscription.plan.service.slug?.toLowerCase().includes('dkala')) {
|
||||
try {
|
||||
this.logger.log(`Calling external API for dkala renew: subscription ${userSubscription.id}`);
|
||||
await this.dkalaService.upgradeSubscription(
|
||||
userSubscription.id,
|
||||
userSubscription.endDate
|
||||
);
|
||||
this.logger.log(`External API call completed for dkala renew: subscription ${userSubscription.id}`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to call external API for dkala renew: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
// Don't fail the transaction if external API call fails
|
||||
}
|
||||
}
|
||||
|
||||
} else if (purpose == InvoicePurpose.NEW) {
|
||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||
await this.scheduleNextRenewalJob(userSubscription);
|
||||
|
||||
Reference in New Issue
Block a user