diff --git a/src/main/java/dev/vality/hooker/converter/PaymentConverter.java b/src/main/java/dev/vality/hooker/converter/PaymentConverter.java index 6641fc2..b498079 100644 --- a/src/main/java/dev/vality/hooker/converter/PaymentConverter.java +++ b/src/main/java/dev/vality/hooker/converter/PaymentConverter.java @@ -4,6 +4,7 @@ import dev.vality.damsel.domain.AdditionalTransactionInfo; import dev.vality.damsel.domain.DisposablePaymentResource; import dev.vality.damsel.domain.InvoicePaymentCaptured; import dev.vality.damsel.domain.PaymentTool; +import dev.vality.damsel.payment_processing.Invoice; import dev.vality.damsel.payment_processing.InvoicePayment; import dev.vality.hooker.model.ExpandedPayment; import dev.vality.hooker.model.FeeType; @@ -13,27 +14,27 @@ import dev.vality.hooker.utils.PaymentToolUtils; import dev.vality.hooker.utils.TimeUtils; import dev.vality.swag_webhook_events.model.*; import lombok.RequiredArgsConstructor; -import org.springframework.core.convert.converter.Converter; import org.springframework.stereotype.Component; import java.util.Map; @Component @RequiredArgsConstructor -public class PaymentConverter implements Converter { +public class PaymentConverter { private final MetadataDeserializer deserializer; - @Override - public ExpandedPayment convert(InvoicePayment sourceWrapper) { + public ExpandedPayment convert(InvoicePayment sourceWrapper, Invoice invoice) { var source = sourceWrapper.getPayment(); ExpandedPayment target = new ExpandedPayment(); target.setId(source.getId()); target.setCreatedAt(TimeUtils.toOffsetDateTime(source.getCreatedAt())); target.setStatus(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName())); - target.setAmount(source.getCost().getAmount()); if (source.isSetChangedCost()) { target.setChangedAmount(source.getChangedCost().getAmount()); + target.setAmount(invoice.getInvoice().getCost().getAmount()); + } else { + target.setAmount(source.getCost().getAmount()); } target.setCurrency(source.getCost().getCurrency().getSymbolicCode()); target.setMetadata(getMetadata(source)); diff --git a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java index cd1f2cc..5874781 100644 --- a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java +++ b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java @@ -117,7 +117,7 @@ public class InvoicingEventService dev.vality.damsel.payment_processing.Invoice invoiceInfo) { var damselPayment = extractPayment(m, invoiceInfo); - return paymentConverter.convert(damselPayment); + return paymentConverter.convert(damselPayment, invoiceInfo); } private InvoicePayment extractPayment(InvoicingMessage message, diff --git a/src/test/java/dev/vality/hooker/converter/PaymentConverterTest.java b/src/test/java/dev/vality/hooker/converter/PaymentConverterTest.java index 891dd8f..751ed9f 100644 --- a/src/test/java/dev/vality/hooker/converter/PaymentConverterTest.java +++ b/src/test/java/dev/vality/hooker/converter/PaymentConverterTest.java @@ -10,7 +10,6 @@ import dev.vality.swag_webhook_events.model.Payment; import dev.vality.swag_webhook_events.model.PaymentResourcePayer; import dev.vality.swag_webhook_events.model.RecurrentPayer; import org.junit.jupiter.api.RepeatedTest; -import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; @@ -27,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; ObjectMapper.class }) @SpringBootTest -public class PaymentConverterTest { +public class PaymentConverterTest { @Autowired private PaymentConverter converter; @@ -49,7 +48,11 @@ public class PaymentConverterTest { source.setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending())); Payment target = converter .convert(new dev.vality.damsel.payment_processing.InvoicePayment(source, - List.of(), List.of(), List.of(), List.of())); + List.of(), List.of(), List.of(), List.of()), + createMockInvoice( + source.getStatus().isSetCaptured() + ? source.getStatus().getCaptured().getCost().getAmount() + : source.getCost().getAmount())); assertEquals(source.getId(), target.getId()); assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue()); if (source.getStatus().isSetCaptured() && source.getStatus().getCaptured().isSetCost()) { @@ -79,4 +82,14 @@ public class PaymentConverterTest { ((RecurrentPayer) target.getPayer()).getRecurrentParentPayment().getInvoiceID()); } } + + private static dev.vality.damsel.payment_processing.Invoice createMockInvoice(Long amount) { + return new dev.vality.damsel.payment_processing.Invoice().setInvoice( + new Invoice() + .setCost(new Cash() + .setAmount(amount) + .setCurrency(new CurrencyRef() + .setSymbolicCode("RUB")) + )); + } }