mirror of
https://github.com/valitydev/fraudbusters-mg-connector.git
synced 2024-11-06 01:15:17 +00:00
Fix pending (#34)
This commit is contained in:
parent
f8694312a5
commit
e88cfb16c9
@ -12,6 +12,10 @@ public enum InvoiceEventType implements EventType {
|
||||
INVOICE_PAYMENT_STATUS_CHANGED(
|
||||
"invoice_payment_change.payload.invoice_payment_status_changed",
|
||||
new IsNullCondition().not()),
|
||||
|
||||
INVOICE_PAYMENT_STARTED(
|
||||
"invoice_payment_change.payload.invoice_payment_started",
|
||||
new IsNullCondition().not()),
|
||||
INVOICE_PAYMENT_REFUND_STATUS_CHANGED(
|
||||
"invoice_payment_change.payload.invoice_payment_refund_change.payload.invoice_payment_refund_status_changed",
|
||||
new IsNullCondition().not()),
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.vality.fraudbusters.mg.connector.mapper.impl;
|
||||
|
||||
import dev.vality.damsel.domain.InvoicePaymentStatus;
|
||||
import dev.vality.damsel.domain.Payer;
|
||||
import dev.vality.damsel.domain.PaymentTool;
|
||||
import dev.vality.damsel.fraudbusters.PayerType;
|
||||
@ -30,46 +31,52 @@ public class PaymentMapper implements Mapper<InvoiceChange, MachineEvent, Paymen
|
||||
|
||||
@Override
|
||||
public boolean accept(InvoiceChange change) {
|
||||
return getChangeType().getFilter().match(change)
|
||||
return InvoiceEventType.INVOICE_PAYMENT_STATUS_CHANGED.getFilter().match(change)
|
||||
&& (change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus()
|
||||
.isSetFailed()
|
||||
|| change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus()
|
||||
.isSetProcessed()
|
||||
|| change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus()
|
||||
.isSetPending()
|
||||
|| change.getInvoicePaymentChange().getPayload().getInvoicePaymentStatusChanged().getStatus()
|
||||
.isSetCaptured());
|
||||
.isSetCaptured())
|
||||
|| InvoiceEventType.INVOICE_PAYMENT_STARTED.getFilter().match(change)
|
||||
&& change.getInvoicePaymentChange().getPayload().getInvoicePaymentStarted().getPayment().getStatus()
|
||||
.isSetPending();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Payment map(InvoiceChange change, MachineEvent event) {
|
||||
Payment payment = null;
|
||||
String paymentId = change.getInvoicePaymentChange().getId();
|
||||
InvoicePaymentChange invoicePaymentChange = change.getInvoicePaymentChange();
|
||||
InvoicePaymentChangePayload payload = invoicePaymentChange.getPayload();
|
||||
InvoicePaymentStatusChanged invoicePaymentStatusChanged = payload.getInvoicePaymentStatusChanged();
|
||||
|
||||
InvoicePaymentWrapper invoicePaymentWrapper = invokeHgGetInvoiceInfo(change, event, paymentId);
|
||||
|
||||
var invoice = invoicePaymentWrapper.getInvoice();
|
||||
var invoicePayment = invoicePaymentWrapper.getInvoicePayment();
|
||||
|
||||
Payer payer = invoicePayment.getPayment().getPayer();
|
||||
PaymentTool paymentTool = generalInfoInitiator.initPaymentTool(payer);
|
||||
Payment payment = initPayment(event, invoicePaymentStatusChanged, invoice, invoicePayment, payer, paymentTool);
|
||||
|
||||
if (InvoiceEventType.INVOICE_PAYMENT_STARTED.getFilter().match(change)) {
|
||||
InvoicePaymentStarted invoicePaymentStarted = payload.getInvoicePaymentStarted();
|
||||
payment = initPaymentByChangeStatusEvent(event, invoicePaymentStarted.getPayment().getStatus(), invoice,
|
||||
invoicePayment, payer, paymentTool);
|
||||
} else {
|
||||
InvoicePaymentStatusChanged invoicePaymentStatusChanged = payload.getInvoicePaymentStatusChanged();
|
||||
payment = initPaymentByChangeStatusEvent(event, invoicePaymentStatusChanged.getStatus(), invoice,
|
||||
invoicePayment, payer, paymentTool)
|
||||
.setError(generalInfoInitiator.initError(invoicePaymentStatusChanged));
|
||||
}
|
||||
log.debug("Map payment: {}", payment);
|
||||
return payment;
|
||||
}
|
||||
|
||||
private Payment initPayment(MachineEvent event,
|
||||
InvoicePaymentStatusChanged invoicePaymentStatusChanged,
|
||||
dev.vality.damsel.domain.Invoice invoice,
|
||||
InvoicePayment invoicePayment,
|
||||
Payer payer,
|
||||
PaymentTool paymentTool) {
|
||||
private Payment initPaymentByChangeStatusEvent(MachineEvent event,
|
||||
InvoicePaymentStatus status,
|
||||
dev.vality.damsel.domain.Invoice invoice,
|
||||
InvoicePayment invoicePayment,
|
||||
Payer payer,
|
||||
PaymentTool paymentTool) {
|
||||
var payment = invoicePayment.getPayment();
|
||||
return new Payment()
|
||||
.setStatus(TBaseUtil.unionFieldToEnum(invoicePaymentStatusChanged.getStatus(), PaymentStatus.class))
|
||||
.setStatus(TBaseUtil.unionFieldToEnum(status, PaymentStatus.class))
|
||||
.setCost(payment.getCost())
|
||||
.setReferenceInfo(generalInfoInitiator.initReferenceInfo(invoice))
|
||||
.setPaymentTool(paymentTool)
|
||||
@ -79,8 +86,7 @@ public class PaymentMapper implements Mapper<InvoiceChange, MachineEvent, Paymen
|
||||
.setProviderInfo(generalInfoInitiator.initProviderInfo(invoicePayment))
|
||||
.setPayerType(TBaseUtil.unionFieldToEnum(payer, PayerType.class))
|
||||
.setMobile(isMobile(paymentTool))
|
||||
.setRecurrent(isRecurrent(payer))
|
||||
.setError(generalInfoInitiator.initError(invoicePaymentStatusChanged));
|
||||
.setRecurrent(isRecurrent(payer));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,7 +70,7 @@ public class FraudbustersMgConnectorApplicationTest extends KafkaAbstractTest {
|
||||
List<SinkEvent> sinkEvents = MgEventSinkFlowGenerator.generateSuccessFlow(SOURCE_ID);
|
||||
mockPayment(SOURCE_ID);
|
||||
sinkEvents.forEach(sinkEvent -> produceMessageToEventSink(MG_EVENT, sinkEvent));
|
||||
checkMessageInTopic(PAYMENT, PaymentDeserializer.class, 2);
|
||||
checkMessageInTopic(PAYMENT, PaymentDeserializer.class, 5);
|
||||
|
||||
String sourceIdRefund2 = "sourceIdRefund2";
|
||||
mockPayment(sourceIdRefund2);
|
||||
@ -99,7 +99,7 @@ public class FraudbustersMgConnectorApplicationTest extends KafkaAbstractTest {
|
||||
sinkEvents = MgEventSinkFlowGenerator.generateSuccessFlow(SOURCE_ID);
|
||||
mockPaymentWithException(SOURCE_ID);
|
||||
sinkEvents.forEach(sinkEvent -> produceMessageToEventSink(MG_EVENT, sinkEvent));
|
||||
checkMessageInTopic(PAYMENT, PaymentDeserializer.class, 10);
|
||||
checkMessageInTopic(PAYMENT, PaymentDeserializer.class, 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -132,6 +132,9 @@ public class FraudbustersMgConnectorApplicationTest extends KafkaAbstractTest {
|
||||
}
|
||||
|
||||
private void mockPayment(String sourceId) throws TException, IOException {
|
||||
mockPayment(sourceId, 1);
|
||||
mockPayment(sourceId, 2);
|
||||
mockPayment(sourceId, 3);
|
||||
mockPayment(sourceId, 4);
|
||||
mockPayment(sourceId, 5);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user