mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 00:05:17 +00:00
Change amount (#64)
Some checks failed
Deploy Docker Image / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Docker Image / build-and-deploy (push) Has been cancelled
This commit is contained in:
parent
572ff3bd71
commit
13610b6e21
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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"))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user