import { BadGatewayException, Injectable } from "@nestjs/common"; import { PaymentMessage } from "../../../common/enums/message.enum"; import { GatewayEnum } from "../enums/gateway.enum"; // import { ParsianGateway } from "../gateways/parsian.gateway"; import { ZarinpalGateway } from "../gateways/zarinpal.gateway"; import { IPaymentGateway, IPaymentGatewayFactory } from "../interfaces/IPayment"; import { GatewayType } from "../types/gateway.type"; @Injectable() export class PaymentGatewayFactory implements IPaymentGatewayFactory { private readonly gateways: Map; constructor( private readonly zarinpalGateway: ZarinpalGateway, // private readonly parsianGateway: ParsianGateway, ) { this.gateways = new Map(); this.initializeGateways(); } private initializeGateways(): void { this.gateways.set(GatewayEnum.ZARINPAL, this.zarinpalGateway); // this.gateways.set(GatewayEnum.PARSIAN, this.parsianGateway); } getPaymentGateway(provider: GatewayType): IPaymentGateway { const gateway = this.gateways.get(provider); if (!gateway) { throw new BadGatewayException(PaymentMessage.PAYMENT_GATEWAY_NOT_FOUND); } return gateway; } getAvailablePaymentGateways() { const gateways = Array.from(this.gateways.keys()).map((name) => ({ name: name as GatewayEnum })); return { gateways }; } }