Change amount (#64)
Some checks failed
Deploy Docker Image / build-and-deploy (push) Has been cancelled

This commit is contained in:
struga 2024-10-03 11:26:58 +03:00 committed by GitHub
parent 572ff3bd71
commit 13610b6e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 9 deletions

View File

@ -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<InvoicePayment, Payment> {
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));

View File

@ -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,

View File

@ -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"))
));
}
}