setup dpage account

This commit is contained in:
2026-03-14 09:54:00 +03:30
parent 584e4d7981
commit 6002774400
5 changed files with 65 additions and 6 deletions
@@ -39,6 +39,8 @@ import { IExternalInvoiceJob, InvoicePurpose } from "../interfaces/external-invo
import { InvoiceItemsRepository } from "../repositories/invoice-items.repository";
import { InvoicesRepository } from "../repositories/invoices.repository";
import { DkalaService } from "../../dkala/providers/dkala.service";
import { DPageService } from "../../dpage/dpage.service";
import { randomInt } from "crypto";
@Injectable()
export class InvoicesService {
private readonly logger = new Logger(InvoicesService.name);
@@ -57,6 +59,7 @@ export class InvoicesService {
private readonly accessLogService: AccessLogService,
private readonly restaurantService: RestaurantService,
private readonly dkalaService: DkalaService,
private readonly dpageService: DPageService,
) { }
///********************************** */
@@ -901,7 +904,23 @@ export class InvoicesService {
userSubscription.status = SubscriptionStatus.ACTIVE;
await this.scheduleNextRenewalJob(userSubscription);
this.logger.log(`Subscription ${userSubscription.id} activated `);
if (userSubscription.plan.service.slug?.toLowerCase().includes('dpage')) {
try {
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
await this.dpageService.setupDpageAccount({
danakSubscriptionId:userSubscription.id,
name: userSubscription.businessName,
slug: randomInt(100_000,1_000_000).toString(),
phone: userSubscription.user.phone,
firstName: userSubscription.user.firstName,
lastName: userSubscription.user.lastName
} );
this.logger.log(`External API call completed for dpage setup account: subscription ${userSubscription.id}`);
} catch (error) {
this.logger.error(`Failed to call external API for dpage setup account: ${error instanceof Error ? error.message : 'Unknown error'}`);
// Don't fail the transaction if external API call fails
}
}
}
// if serivce is dmenu for renew or upgrade it must call dmenu api
//