Bump deps (#24)

* Bump deps

* refactoring

* fix test

Co-authored-by: Inal Arsanukaev <aiz@empayre.com>
This commit is contained in:
Inal Arsanukaev 2022-08-23 14:03:13 +03:00 committed by GitHub
parent cd9d2b0b65
commit cc9a3d69a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 37 deletions

View File

@ -13,7 +13,7 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>1.0.11</version>
<version>1.0.18</version>
</parent>
<properties>

View File

@ -3,6 +3,7 @@ package dev.vality.hooker.service;
import dev.vality.damsel.payment_processing.Customer;
import dev.vality.damsel.payment_processing.CustomerManagementSrv;
import dev.vality.damsel.payment_processing.CustomerNotFound;
import dev.vality.damsel.payment_processing.EventRange;
import dev.vality.hooker.configuration.meta.UserIdentityIdExtensionKit;
import dev.vality.hooker.configuration.meta.UserIdentityRealmExtensionKit;
import dev.vality.hooker.converter.CustomerBindingConverter;
@ -10,7 +11,6 @@ import dev.vality.hooker.converter.CustomerConverter;
import dev.vality.hooker.exception.NotFoundException;
import dev.vality.hooker.exception.RemoteHostException;
import dev.vality.hooker.model.CustomerMessage;
import dev.vality.hooker.utils.HellgateUtils;
import dev.vality.hooker.utils.TimeUtils;
import dev.vality.swag_webhook_events.model.*;
import dev.vality.woody.api.flow.WFlow;
@ -32,8 +32,7 @@ public class CustomerEventService implements EventService<CustomerMessage> {
try {
Customer customer = woodyFlow.createServiceFork(() -> {
addWoodyContext();
return customerClient.get(message.getSourceId(),
HellgateUtils.getEventRange(message.getSequenceId().intValue()));
return customerClient.get(message.getSourceId(), getEventRange(message));
}
).call();
@ -48,6 +47,10 @@ public class CustomerEventService implements EventService<CustomerMessage> {
}
}
private EventRange getEventRange(CustomerMessage message) {
return new EventRange().setLimit(message.getSequenceId().intValue());
}
private void addWoodyContext() {
ContextUtils.setCustomMetadataValue(UserIdentityIdExtensionKit.KEY, "hooker");
ContextUtils.setCustomMetadataValue(UserIdentityRealmExtensionKit.KEY, "service");

View File

@ -1,5 +1,6 @@
package dev.vality.hooker.service;
import dev.vality.damsel.payment_processing.EventRange;
import dev.vality.damsel.payment_processing.InvoiceNotFound;
import dev.vality.damsel.payment_processing.InvoicePayment;
import dev.vality.damsel.payment_processing.InvoicingSrv;
@ -9,7 +10,6 @@ import dev.vality.hooker.converter.RefundConverter;
import dev.vality.hooker.exception.NotFoundException;
import dev.vality.hooker.exception.RemoteHostException;
import dev.vality.hooker.model.InvoicingMessage;
import dev.vality.hooker.utils.HellgateUtils;
import dev.vality.hooker.utils.TimeUtils;
import dev.vality.swag_webhook_events.model.*;
import lombok.RequiredArgsConstructor;
@ -42,11 +42,7 @@ public class InvoicingEventService
@Override
public dev.vality.damsel.payment_processing.Invoice getInvoiceByMessage(InvoicingMessage message) {
try {
return invoicingClient.get(
HellgateUtils.USER_INFO,
message.getSourceId(),
HellgateUtils.getEventRange(message.getSequenceId().intValue())
);
return invoicingClient.get(message.getSourceId(), getEventRange(message));
} catch (InvoiceNotFound e) {
throw new NotFoundException("Invoice not found, invoiceId=" + message.getSourceId());
} catch (TException e) {
@ -54,6 +50,10 @@ public class InvoicingEventService
}
}
private EventRange getEventRange(InvoicingMessage message) {
return new EventRange().setLimit(message.getSequenceId().intValue());
}
private Event resolveEvent(InvoicingMessage m, dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
return switch (m.getEventType()) {
case INVOICE_CREATED -> new InvoiceCreated()

View File

@ -1,19 +0,0 @@
package dev.vality.hooker.utils;
import dev.vality.damsel.payment_processing.EventRange;
import dev.vality.damsel.payment_processing.ServiceUser;
import dev.vality.damsel.payment_processing.UserInfo;
import dev.vality.damsel.payment_processing.UserType;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class HellgateUtils {
public static final UserInfo USER_INFO = new UserInfo("hooker", UserType.service_user(new ServiceUser()));
public static EventRange getEventRange(Integer limit) {
return new EventRange().setLimit(limit);
}
}

View File

@ -84,7 +84,7 @@ public class PaymentToolUtils {
.detailsType(PaymentToolDetails.DetailsTypeEnum.PAYMENTTOOLDETAILSMOBILECOMMERCE);
} else {
throw new UnsupportedOperationException(
"Unknown payment tool type. Must be bank card, terminal or digital wallet");
"Unknown payment tool type " + paymentTool);
}
}
@ -123,7 +123,7 @@ public class PaymentToolUtils {
rootNode.put("mobile_commerce", mobilePhone.getCc() + mobilePhone.getCtn());
} else {
throw new UnsupportedOperationException(
"Unknown payment tool type. Must be bank card, terminal or digital wallet");
"Unknown payment tool type " + paymentTool);
}
return Base64.getUrlEncoder().encodeToString(rootNode.toString().getBytes(StandardCharsets.UTF_8));
}

View File

@ -13,6 +13,7 @@ import dev.vality.hooker.utils.BuildUtils;
import dev.vality.swag_webhook_events.model.Event;
import dev.vality.swag_webhook_events.model.RefundSucceeded;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,13 +38,13 @@ public class InvoicingEventServiceTest {
@BeforeEach
public void setUp() throws Exception {
Mockito.when(invoicingClient.get(any(), any(), any()))
Mockito.when(invoicingClient.get(any(), any()))
.thenReturn(BuildUtils.buildInvoice("partyId", "invoiceId", "1", "1",
InvoiceStatus.paid(new InvoicePaid()),
InvoicePaymentStatus.pending(new InvoicePaymentPending())));
}
@Test
@RepeatedTest(7)
public void testRefundSucceeded() {
InvoicingMessage message = random(InvoicingMessage.class);
message.setPaymentId("1");
@ -62,7 +63,7 @@ public class InvoicingEventServiceTest {
assertEquals("chicken-teriyaki", refundSucceded.getRefund().getRrn());
}
@Test
@RepeatedTest(7)
public void testJson() throws JsonProcessingException {
InvoicingMessage message = random(InvoicingMessage.class);
message.setPaymentId("1");

View File

@ -80,12 +80,18 @@ public class BuildUtils {
dev.vality.damsel.payment_processing.Invoice invoice = new dev.vality.damsel.payment_processing.Invoice()
.setInvoice(buildInvoice(partyId, invoiceId, invoiceStatus, thriftBaseProcessor))
.setPayments(buildPayments(partyId, paymentId, refundId, paymentStatus, thriftBaseProcessor));
if (invoice.getPayments().get(0).getPayment().getPayer().isSetPaymentResource()) {
Payer payer = invoice.getPayments().get(0).getPayment().getPayer();
if (payer.isSetPaymentResource()) {
PaymentTool paymentTool = PaymentTool.bank_card(
thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))
);
invoice.getPayments().get(0).getPayment().getPayer().getPaymentResource().getResource()
payer.getPaymentResource().getResource()
.setPaymentTool(paymentTool);
} else if (payer.isSetCustomer()) {
PaymentTool paymentTool = PaymentTool.bank_card(
thriftBaseProcessor.process(new BankCard(), new TBaseHandler<>(BankCard.class))
);
payer.getCustomer().setPaymentTool(paymentTool);
}
return invoice;
}

View File

@ -34,7 +34,6 @@ public class PaymentToolUtilsTest {
public void testDigitalWalletJson() throws JsonProcessingException {
PaymentTool paymentTool =
PaymentTool.digital_wallet(new DigitalWallet("kke"));
paymentTool.getDigitalWallet().setProviderDeprecated(LegacyDigitalWalletProvider.qiwi);
paymentTool.getDigitalWallet().setPaymentService(new PaymentServiceRef("qiwi"));
PaymentToolDetails paymentToolDetails = PaymentToolUtils.getPaymentToolDetails(paymentTool);
String json = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)