From 948d257462978d80008457a30c1972c554027395 Mon Sep 17 00:00:00 2001 From: Gregory <32060161+ggmaleva@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:48:46 +0300 Subject: [PATCH] add paymentId and invoiceId for userInteraction event (#59) * add paymentId and invoiceId for userInteraction event * fix event * add checking type for test --------- Co-authored-by: ggmaleva --- pom.xml | 2 +- .../hooker/service/InvoicingEventService.java | 19 ++++++++--- .../service/InvoicingEventServiceTest.java | 33 ++++++++++++++----- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 250b0a8..3f06c47 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ dev.vality swag-webhook-events - 1.122-9daaca8-client + 1.126-46e732a-client dev.vality diff --git a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java index dcc8788..26045db 100644 --- a/src/main/java/dev/vality/hooker/service/InvoicingEventService.java +++ b/src/main/java/dev/vality/hooker/service/InvoicingEventService.java @@ -75,9 +75,9 @@ public class InvoicingEventService .eventType(Event.EventTypeEnum.REFUNDCREATED); case INVOICE_PAYMENT_REFUND_STATUS_CHANGED -> resolveRefundStatusChanged(m, invoiceInfo); case INVOICE_PAYMENT_CASH_CHANGED -> resolvePaymentCashChange(m, invoiceInfo); - case INVOICE_PAYMENT_USER_INTERACTION_CHANGE_REQUESTED -> resolvePaymentUserInteraction(m) + case INVOICE_PAYMENT_USER_INTERACTION_CHANGE_REQUESTED -> resolvePaymentInteractionRequested(m, invoiceInfo) .eventType(Event.EventTypeEnum.PAYMENTINTERACTIONREQUESTED); - case INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED -> resolvePaymentUserInteraction(m) + case INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED -> resolvePaymentInteractionCompleted(m, invoiceInfo) .eventType(Event.EventTypeEnum.PAYMENTINTERACTIONCOMPLETED); default -> throw new UnsupportedOperationException("Unknown event type " + m.getEventType()); }; @@ -222,8 +222,19 @@ public class InvoicingEventService .eventType(Event.EventTypeEnum.PAYMENTCASHCHANGED); } - private Event resolvePaymentUserInteraction(InvoicingMessage message) { + private Event resolvePaymentInteractionRequested(InvoicingMessage message, + dev.vality.damsel.payment_processing.Invoice invoiceInfo) { return new PaymentInteractionRequested() - .userInteractionDetails(userInteractionConverter.convert(message)); + .userInteractionDetails(userInteractionConverter.convert(message)) + .invoiceId(invoiceInfo.getInvoice().getId()) + .paymentId(message.getPaymentId()); + } + + private Event resolvePaymentInteractionCompleted(InvoicingMessage message, + dev.vality.damsel.payment_processing.Invoice invoiceInfo) { + return new PaymentInteractionCompleted() + .userInteractionDetails(userInteractionConverter.convert(message)) + .invoiceId(invoiceInfo.getInvoice().getId()) + .paymentId(message.getPaymentId()); } } diff --git a/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java b/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java index 2a123c5..c25b683 100644 --- a/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java +++ b/src/test/java/dev/vality/hooker/service/InvoicingEventServiceTest.java @@ -13,6 +13,8 @@ import dev.vality.hooker.model.*; import dev.vality.hooker.model.interaction.*; import dev.vality.hooker.utils.BuildUtils; import dev.vality.swag_webhook_events.model.Event; +import dev.vality.swag_webhook_events.model.PaymentInteractionCompleted; +import dev.vality.swag_webhook_events.model.PaymentInteractionRequested; import dev.vality.swag_webhook_events.model.RefundSucceeded; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeEach; @@ -28,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @PostgresqlSpringBootITest -public class InvoicingEventServiceTest { +class InvoicingEventServiceTest { @MockBean private InvoicingSrv.Iface invoicingClient; @@ -48,7 +50,7 @@ public class InvoicingEventServiceTest { } @RepeatedTest(7) - public void testRefundSucceeded() { + void testRefundSucceeded() { InvoicingMessage message = random(InvoicingMessage.class, "userInteraction"); message.setPaymentId("1"); message.setRefundId("1"); @@ -67,7 +69,7 @@ public class InvoicingEventServiceTest { } @RepeatedTest(7) - public void testJson() throws JsonProcessingException { + void testJson() throws JsonProcessingException { InvoicingMessage message = random(InvoicingMessage.class, "userInteraction"); message.setPaymentId("1"); message.setType(InvoicingMessageEnum.PAYMENT); @@ -83,7 +85,7 @@ public class InvoicingEventServiceTest { } @Test - public void testUserInteractions() throws JsonProcessingException { + void testUserInteractionRequested() throws JsonProcessingException { InvoicingMessage message = createDefaultInvoicingMessage(); message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_REQUESTED); message.setUserInteraction(new BrowserHttpInteraction("get", "http://test", null)); @@ -92,10 +94,13 @@ public class InvoicingEventServiceTest { assertTrue(json.contains("\"eventType\":\"PaymentInteractionRequested\"")); assertTrue(json.contains("\"requestType\":\"get\"")); assertTrue(json.contains("\"userInteractionType\":\"BrowserHTTPRequest\"")); + assertTrue(json.contains("\"invoiceId\":\"invoiceId\"")); + assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId()))); + assertTrue(event instanceof PaymentInteractionRequested); } @Test - public void testUserInteractionsCompleted() throws JsonProcessingException { + void testUserInteractionsCompleted() throws JsonProcessingException { InvoicingMessage message = createDefaultInvoicingMessage(); message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED); message.setUserInteraction(new QrCodeDisplay("wefvqewvrq32fveqrw".getBytes())); @@ -103,10 +108,13 @@ public class InvoicingEventServiceTest { String json = objectMapper.writeValueAsString(event); assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\"")); assertTrue(json.contains("\"userInteractionType\":\"QrCodeDisplayRequest\"")); + assertTrue(json.contains("\"invoiceId\":\"invoiceId\"")); + assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId()))); + assertTrue(event instanceof PaymentInteractionCompleted); } @Test - public void testUserInteractionsCompletedApiExtension() throws JsonProcessingException { + void testUserInteractionsCompletedApiExtension() throws JsonProcessingException { InvoicingMessage message = createDefaultInvoicingMessage(); message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED); message.setUserInteraction(new ApiExtension("p2p")); @@ -114,10 +122,13 @@ public class InvoicingEventServiceTest { String json = objectMapper.writeValueAsString(event); assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\"")); assertTrue(json.contains("\"userInteractionType\":\"ApiExtensionRequest\"")); + assertTrue(json.contains("\"invoiceId\":\"invoiceId\"")); + assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId()))); + assertTrue(event instanceof PaymentInteractionCompleted); } @Test - public void testUserInteractionsCompletedPaymentTerminal() throws JsonProcessingException { + void testUserInteractionsCompletedPaymentTerminal() throws JsonProcessingException { InvoicingMessage message = createDefaultInvoicingMessage(); message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED); message.setUserInteraction(new PaymentTerminalReceipt("p2p", "2016-03-22T06:12:27Z")); @@ -125,10 +136,13 @@ public class InvoicingEventServiceTest { String json = objectMapper.writeValueAsString(event); assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\"")); assertTrue(json.contains("\"userInteractionType\":\"PaymentTerminalReceipt\"")); + assertTrue(json.contains("\"invoiceId\":\"invoiceId\"")); + assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId()))); + assertTrue(event instanceof PaymentInteractionCompleted); } @Test - public void testUserInteractionsCompletedCrypto() throws JsonProcessingException { + void testUserInteractionsCompletedCrypto() throws JsonProcessingException { InvoicingMessage message = createDefaultInvoicingMessage(); message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED); message.setUserInteraction(new CryptoCurrencyTransfer("address", new Rational(1L, 10L), "bitcoin")); @@ -139,6 +153,9 @@ public class InvoicingEventServiceTest { assertTrue(json.contains("\"cryptoAddress\":\"address\"")); assertTrue(json.contains("\"cryptoCurrency\":\"bitcoin\"")); assertTrue(json.contains("\"denominator\":1")); + assertTrue(json.contains("\"invoiceId\":\"invoiceId\"")); + assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId()))); + assertTrue(event instanceof PaymentInteractionCompleted); } @NotNull