inapp-purchase for dpage
This commit is contained in:
@@ -12,20 +12,17 @@ export class ApiKeyGuard implements CanActivate {
|
|||||||
const request = context.switchToHttp().getRequest<FastifyRequest>();
|
const request = context.switchToHttp().getRequest<FastifyRequest>();
|
||||||
const apiKey = request.headers["x-api-key"] as string;
|
const apiKey = request.headers["x-api-key"] as string;
|
||||||
|
|
||||||
console.log("apiKey", apiKey);
|
|
||||||
if (!apiKey) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
if (!apiKey) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
||||||
|
|
||||||
// Get allowed API keys from environment (comma-separated)
|
// Get allowed API keys from environment (comma-separated)
|
||||||
const allowedApiKeys = this.configService.getOrThrow<string>("EXTERNAL_API_KEYS");
|
const allowedApiKeys = this.configService.getOrThrow<string>("EXTERNAL_API_KEYS");
|
||||||
const validApiKeys = allowedApiKeys.split(",").filter((key) => key.trim().length > 0);
|
const validApiKeys = allowedApiKeys.split(",").filter((key) => key.trim().length > 0);
|
||||||
|
|
||||||
console.log("validApiKeys", validApiKeys);
|
|
||||||
|
|
||||||
if (validApiKeys.length === 0) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
if (validApiKeys.length === 0) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
||||||
|
|
||||||
const isValidApiKey = validApiKeys.includes(apiKey);
|
const isValidApiKey = validApiKeys.includes(apiKey);
|
||||||
|
|
||||||
console.log("isValidApiKey", isValidApiKey);
|
|
||||||
|
|
||||||
if (!isValidApiKey) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
if (!isValidApiKey) throw new UnauthorizedException(AuthMessage.UNAUTHORIZED_ACCESS);
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,38 @@ export class DPageService {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async finishPurchaseCatalogue(businessId: string, count: number) {
|
||||||
|
try {
|
||||||
|
const { data } = await firstValueFrom(
|
||||||
|
this.httpService
|
||||||
|
.post(`${this.config.baseUrl}/super-admin/catalogue/purchase/finish`, {
|
||||||
|
businessId,
|
||||||
|
count
|
||||||
|
}, {
|
||||||
|
headers: this.getHeaders(),
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
catchError((err: AxiosError) => {
|
||||||
|
this.logger.error(`Failed to perform finish purchase catalogue: ${err.message}`, err.stack);
|
||||||
|
return throwError(() => err);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof AxiosError && error.response) {
|
||||||
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
|
}
|
||||||
|
this.logger.error(`Error performing to finish purchase catalogue: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -946,6 +946,16 @@ export class InvoicesService {
|
|||||||
await this.walletsService.createSupportPlanTransaction(invoice.totalPrice, userWallet.id, queryRunner);
|
await this.walletsService.createSupportPlanTransaction(invoice.totalPrice, userWallet.id, queryRunner);
|
||||||
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.SUPPORT_PLAN_WALLET_TRANSFER);
|
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.SUPPORT_PLAN_WALLET_TRANSFER);
|
||||||
//
|
//
|
||||||
|
} else if (invoice.isExternal) {
|
||||||
|
if (invoice.items[0]?.name == 'purchase_new_catalogue') {
|
||||||
|
// call dpage api
|
||||||
|
const businessId = invoice.externalBusinessId
|
||||||
|
if (!businessId) {
|
||||||
|
throw new BadRequestException("business id not found")
|
||||||
|
}
|
||||||
|
const count = invoice.items[0].count
|
||||||
|
this.dpageService.finishPurchaseCatalogue(businessId, count)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.walletsService.createInvoiceTransaction(invoice.totalPrice, userWallet.id, queryRunner);
|
await this.walletsService.createInvoiceTransaction(invoice.totalPrice, userWallet.id, queryRunner);
|
||||||
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.INVOICE_WALLET_TRANSFER);
|
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.INVOICE_WALLET_TRANSFER);
|
||||||
|
|||||||
Reference in New Issue
Block a user