Add MakePaymentToProcessorService for handling payment processing

This commit is contained in:
Jose Eduardo 2025-08-10 00:55:09 -04:00
parent 2bd2d6a5cc
commit 439ce1bff3

View File

@ -0,0 +1,31 @@
import { Injectable, Logger } from '@nestjs/common';
import { firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import { InjectRepository } from '@nestjs/typeorm';
import { Payment } from '../entities/payment.entity';
import { Repository } from 'typeorm';
@Injectable()
export class MakePaymentToProcessorService {
private readonly logger = new Logger(MakePaymentToProcessorService.name);
constructor(
private readonly httpService: HttpService,
@InjectRepository(Payment) private readonly repository: Repository<Payment>,
) {}
async execute(payment: Payment, url: string): Promise<boolean> {
const paymentData = {
amount: payment.amount,
correlationId: payment.correlationId,
};
const response = await firstValueFrom(
this.httpService.post(`${url}/payments`, paymentData, {
timeout: 2000, // 30 segundos
}),
);
return response.status === 200;
}
}