feat: ( payment ) create payment microservice

This commit is contained in:
Abubeker Yasin
2026-06-11 15:25:24 +03:00
parent 3235567b41
commit 2b430f8e76
54 changed files with 2809 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryFailedError, Repository } from "typeorm";
import { BaseRepository } from "@edr/api-common";
import { PaymentWebhookEvent } from "./entities/payment-webhook-event.entity";
const PG_UNIQUE_VIOLATION = "23505";
@Injectable()
export class WebhookEventsRepository extends BaseRepository<PaymentWebhookEvent> {
constructor(
@InjectRepository(PaymentWebhookEvent)
repository: Repository<PaymentWebhookEvent>,
) {
super(repository);
}
/**
* Insert the event, relying on the unique (provider, external_event_id) index for dedupe.
* Returns null when the event was already recorded (duplicate delivery / provider replay).
*/
async createDeduped(
data: Partial<PaymentWebhookEvent>,
): Promise<PaymentWebhookEvent | null> {
try {
return await this.create(data);
} catch (err) {
if (
err instanceof QueryFailedError &&
(err.driverError as { code?: string })?.code === PG_UNIQUE_VIOLATION
) {
return null;
}
throw err;
}
}
async markProcessed(id: string, processingError?: string): Promise<void> {
await this.update(id, {
processedAt: new Date(),
processingError: processingError ?? null,
});
}
}