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.DisposablePaymentResource;
|
||||||
import dev.vality.damsel.domain.InvoicePaymentCaptured;
|
import dev.vality.damsel.domain.InvoicePaymentCaptured;
|
||||||
import dev.vality.damsel.domain.PaymentTool;
|
import dev.vality.damsel.domain.PaymentTool;
|
||||||
|
import dev.vality.damsel.payment_processing.Invoice;
|
||||||
import dev.vality.damsel.payment_processing.InvoicePayment;
|
import dev.vality.damsel.payment_processing.InvoicePayment;
|
||||||
import dev.vality.hooker.model.ExpandedPayment;
|
import dev.vality.hooker.model.ExpandedPayment;
|
||||||
import dev.vality.hooker.model.FeeType;
|
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.hooker.utils.TimeUtils;
|
||||||
import dev.vality.swag_webhook_events.model.*;
|
import dev.vality.swag_webhook_events.model.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
public class PaymentConverter {
|
||||||
|
|
||||||
private final MetadataDeserializer deserializer;
|
private final MetadataDeserializer deserializer;
|
||||||
|
|
||||||
@Override
|
public ExpandedPayment convert(InvoicePayment sourceWrapper, Invoice invoice) {
|
||||||
public ExpandedPayment convert(InvoicePayment sourceWrapper) {
|
|
||||||
var source = sourceWrapper.getPayment();
|
var source = sourceWrapper.getPayment();
|
||||||
ExpandedPayment target = new ExpandedPayment();
|
ExpandedPayment target = new ExpandedPayment();
|
||||||
target.setId(source.getId());
|
target.setId(source.getId());
|
||||||
target.setCreatedAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()));
|
target.setCreatedAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()));
|
||||||
target.setStatus(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()));
|
target.setStatus(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()));
|
||||||
target.setAmount(source.getCost().getAmount());
|
|
||||||
if (source.isSetChangedCost()) {
|
if (source.isSetChangedCost()) {
|
||||||
target.setChangedAmount(source.getChangedCost().getAmount());
|
target.setChangedAmount(source.getChangedCost().getAmount());
|
||||||
|
target.setAmount(invoice.getInvoice().getCost().getAmount());
|
||||||
|
} else {
|
||||||
|
target.setAmount(source.getCost().getAmount());
|
||||||
}
|
}
|
||||||
target.setCurrency(source.getCost().getCurrency().getSymbolicCode());
|
target.setCurrency(source.getCost().getCurrency().getSymbolicCode());
|
||||||
target.setMetadata(getMetadata(source));
|
target.setMetadata(getMetadata(source));
|
||||||
|
@ -117,7 +117,7 @@ public class InvoicingEventService
|
|||||||
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
||||||
var damselPayment = extractPayment(m, invoiceInfo);
|
var damselPayment = extractPayment(m, invoiceInfo);
|
||||||
|
|
||||||
return paymentConverter.convert(damselPayment);
|
return paymentConverter.convert(damselPayment, invoiceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvoicePayment extractPayment(InvoicingMessage message,
|
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.PaymentResourcePayer;
|
||||||
import dev.vality.swag_webhook_events.model.RecurrentPayer;
|
import dev.vality.swag_webhook_events.model.RecurrentPayer;
|
||||||
import org.junit.jupiter.api.RepeatedTest;
|
import org.junit.jupiter.api.RepeatedTest;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -27,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
ObjectMapper.class
|
ObjectMapper.class
|
||||||
})
|
})
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class PaymentConverterTest {
|
public class PaymentConverterTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PaymentConverter converter;
|
private PaymentConverter converter;
|
||||||
@ -49,7 +48,11 @@ public class PaymentConverterTest {
|
|||||||
source.setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()));
|
source.setStatus(InvoicePaymentStatus.pending(new InvoicePaymentPending()));
|
||||||
Payment target = converter
|
Payment target = converter
|
||||||
.convert(new dev.vality.damsel.payment_processing.InvoicePayment(source,
|
.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.getId(), target.getId());
|
||||||
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
assertEquals(source.getStatus().getSetField().getFieldName(), target.getStatus().getValue());
|
||||||
if (source.getStatus().isSetCaptured() && source.getStatus().getCaptured().isSetCost()) {
|
if (source.getStatus().isSetCaptured() && source.getStatus().getCaptured().isSetCost()) {
|
||||||
@ -79,4 +82,14 @@ public class PaymentConverterTest {
|
|||||||
((RecurrentPayer) target.getPayer()).getRecurrentParentPayment().getInvoiceID());
|
((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