mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 05:58:18 +00:00
feat: ( payment ) create payment microservice
This commit is contained in:
@@ -1,24 +1,12 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import {
|
||||
WaafiProvider,
|
||||
WaafiWebhookPayload,
|
||||
ProviderPaymentStatus,
|
||||
} from '@edr/payment-providers';
|
||||
import { PaymentIntentStatus, PaymentMethodType } from '@prisma/client';
|
||||
import { PrismaService } from '../../../common/prisma.service';
|
||||
import { PaymentsService } from '../payments.service';
|
||||
import { WaafiProvider } from '../providers/waafi.provider';
|
||||
import { PaymentIntentStatus, PaymentMethodType } from '@prisma/client';
|
||||
|
||||
interface WaafiWebhookPayload {
|
||||
schemaVersion: string;
|
||||
requestId: string;
|
||||
timestamp: string;
|
||||
eventType: string;
|
||||
params: {
|
||||
state: string;
|
||||
referenceId: string;
|
||||
transactionId: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
description?: string;
|
||||
};
|
||||
signature?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class WaafiWebhookService {
|
||||
@@ -76,13 +64,13 @@ export class WaafiWebhookService {
|
||||
|
||||
const mappedStatus = this.waafiProvider.mapState(state);
|
||||
|
||||
if (mappedStatus === PaymentIntentStatus.SUCCEEDED) {
|
||||
if (mappedStatus === ProviderPaymentStatus.SUCCEEDED) {
|
||||
await this.paymentsService.finalizePaymentSuccess({
|
||||
intentId: intent.id,
|
||||
providerTxnId: transactionId,
|
||||
});
|
||||
this.logger.log(`Waafi payment succeeded: intent=${intent.id} txn=${transactionId}`);
|
||||
} else if (mappedStatus === PaymentIntentStatus.FAILED) {
|
||||
} else if (mappedStatus === ProviderPaymentStatus.FAILED) {
|
||||
await this.paymentsService.markPaymentFailed({
|
||||
intentId: intent.id,
|
||||
failureCode: state,
|
||||
@@ -93,7 +81,7 @@ export class WaafiWebhookService {
|
||||
await this.prisma.paymentIntent.update({
|
||||
where: { id: intent.id },
|
||||
data: {
|
||||
status: mappedStatus,
|
||||
status: mappedStatus as unknown as PaymentIntentStatus,
|
||||
providerTxnId: transactionId,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user