Refactor ProcessPaymentService to remove RetryPaymentService dependency and streamline payment processing logic
This commit is contained in:
parent
a961414e93
commit
ebf16c1c24
@ -7,7 +7,6 @@ import { ProcessorTypeEnum } from '../enumns/processor-type.enum';
|
|||||||
import { PaymentStatusEnum } from '../enumns/payment-status.enum';
|
import { PaymentStatusEnum } from '../enumns/payment-status.enum';
|
||||||
import { PaymentDefaultProcessor } from '../processor/payment-default.processor';
|
import { PaymentDefaultProcessor } from '../processor/payment-default.processor';
|
||||||
import { PaymentFallbackProcessor } from '../processor/payment-fallback.processor';
|
import { PaymentFallbackProcessor } from '../processor/payment-fallback.processor';
|
||||||
import { RetryPaymentService } from './retry-payment.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProcessPaymentService {
|
export class ProcessPaymentService {
|
||||||
@ -18,7 +17,6 @@ export class ProcessPaymentService {
|
|||||||
private healthService: HealthService,
|
private healthService: HealthService,
|
||||||
private paymentDefaultProcessor: PaymentDefaultProcessor,
|
private paymentDefaultProcessor: PaymentDefaultProcessor,
|
||||||
private paymentFallbackProcessor: PaymentFallbackProcessor,
|
private paymentFallbackProcessor: PaymentFallbackProcessor,
|
||||||
private retryPaymentService: RetryPaymentService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(paymentId: string): Promise<void> {
|
async execute(paymentId: string): Promise<void> {
|
||||||
@ -40,24 +38,11 @@ export class ProcessPaymentService {
|
|||||||
throw new Error('No payment processor available');
|
throw new Error('No payment processor available');
|
||||||
}
|
}
|
||||||
|
|
||||||
let result;
|
|
||||||
|
|
||||||
let processorUsed: ProcessorTypeEnum =
|
|
||||||
preferredProcessor === ProcessorTypeEnum.DEFAULT
|
|
||||||
? ProcessorTypeEnum.DEFAULT
|
|
||||||
: ProcessorTypeEnum.FALLBACK;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (preferredProcessor === ProcessorTypeEnum.DEFAULT) {
|
if (preferredProcessor === ProcessorTypeEnum.DEFAULT) {
|
||||||
result = await this.paymentDefaultProcessor.execute(payment);
|
await this.paymentDefaultProcessor.execute(payment);
|
||||||
processorUsed = ProcessorTypeEnum.DEFAULT;
|
|
||||||
} else {
|
} else {
|
||||||
result = await this.paymentFallbackProcessor.execute(payment);
|
await this.paymentFallbackProcessor.execute(payment);
|
||||||
processorUsed = ProcessorTypeEnum.FALLBACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
await this.retryPaymentService.execute(payment.id, processorUsed);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
@ -67,7 +52,6 @@ export class ProcessPaymentService {
|
|||||||
await this.repository.update(payment.id, {
|
await this.repository.update(payment.id, {
|
||||||
status: PaymentStatusEnum.RETRY,
|
status: PaymentStatusEnum.RETRY,
|
||||||
});
|
});
|
||||||
await this.retryPaymentService.execute(payment.id, processorUsed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user