working on payment

This commit is contained in:
Tria
2026-06-04 16:18:14 +03:00
parent 6b82b11757
commit 93020b3153
10 changed files with 664 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { DataSource, Repository } from "typeorm";
import { PaymentEntity } from "./entities/payment.entity";
import { PaymentStrategy } from "./strategies/payment.strategy";
import { PaymentTelebirrStrategy } from "./strategies/payment.telebirr.strategy";
type PaymentMethod = PaymentEntity["method"]
@Injectable()
export class PaymentService {
private strategies: Map<PaymentMethod, PaymentStrategy>;
private readonly paymentRepo: Repository<PaymentEntity>;
constructor(
private readonly dataSource: DataSource,
private readonly telebirrPaymentStategy: PaymentTelebirrStrategy) {
this.strategies = new Map([
["telebirr", this.telebirrPaymentStategy as PaymentStrategy]
])
this.paymentRepo = this.dataSource.getRepository(PaymentEntity)
}
async create(data: Pick<PaymentEntity, "amount" | "method" | "currency" | "type" | "tableId">): Promise<any> {
const strategy = this.strategies.get(data.method)
if (!strategy) throw new NotFoundException("strategy not found")
return strategy.pay(data.amount, data.currency, "")
// const payment = this.paymentRepo.create({
// amount: data.amount,
// method: data.method,
// type: data.type,
// currency: data.currency,
// tableId: data.tableId,
// })
// await this.paymentRepo.save(payment)
// return link;
}
getPaymentByReferenceIdAndMethod(data: Pick<PaymentEntity, "method" | "refId">): Promise<PaymentEntity | null> {
return this.paymentRepo.findOneBy(data)
}
}