mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 00:05:17 +00:00
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 <ggmaleva@yandex.ru>
This commit is contained in:
parent
9fe3d01970
commit
948d257462
2
pom.xml
2
pom.xml
@ -127,7 +127,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
<artifactId>swag-webhook-events</artifactId>
|
<artifactId>swag-webhook-events</artifactId>
|
||||||
<version>1.122-9daaca8-client</version>
|
<version>1.126-46e732a-client</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
|
@ -75,9 +75,9 @@ public class InvoicingEventService
|
|||||||
.eventType(Event.EventTypeEnum.REFUNDCREATED);
|
.eventType(Event.EventTypeEnum.REFUNDCREATED);
|
||||||
case INVOICE_PAYMENT_REFUND_STATUS_CHANGED -> resolveRefundStatusChanged(m, invoiceInfo);
|
case INVOICE_PAYMENT_REFUND_STATUS_CHANGED -> resolveRefundStatusChanged(m, invoiceInfo);
|
||||||
case INVOICE_PAYMENT_CASH_CHANGED -> resolvePaymentCashChange(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);
|
.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);
|
.eventType(Event.EventTypeEnum.PAYMENTINTERACTIONCOMPLETED);
|
||||||
default -> throw new UnsupportedOperationException("Unknown event type " + m.getEventType());
|
default -> throw new UnsupportedOperationException("Unknown event type " + m.getEventType());
|
||||||
};
|
};
|
||||||
@ -222,8 +222,19 @@ public class InvoicingEventService
|
|||||||
.eventType(Event.EventTypeEnum.PAYMENTCASHCHANGED);
|
.eventType(Event.EventTypeEnum.PAYMENTCASHCHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Event resolvePaymentUserInteraction(InvoicingMessage message) {
|
private Event resolvePaymentInteractionRequested(InvoicingMessage message,
|
||||||
|
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
||||||
return new PaymentInteractionRequested()
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import dev.vality.hooker.model.*;
|
|||||||
import dev.vality.hooker.model.interaction.*;
|
import dev.vality.hooker.model.interaction.*;
|
||||||
import dev.vality.hooker.utils.BuildUtils;
|
import dev.vality.hooker.utils.BuildUtils;
|
||||||
import dev.vality.swag_webhook_events.model.Event;
|
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 dev.vality.swag_webhook_events.model.RefundSucceeded;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@ -28,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
@PostgresqlSpringBootITest
|
@PostgresqlSpringBootITest
|
||||||
public class InvoicingEventServiceTest {
|
class InvoicingEventServiceTest {
|
||||||
|
|
||||||
@MockBean
|
@MockBean
|
||||||
private InvoicingSrv.Iface invoicingClient;
|
private InvoicingSrv.Iface invoicingClient;
|
||||||
@ -48,7 +50,7 @@ public class InvoicingEventServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RepeatedTest(7)
|
@RepeatedTest(7)
|
||||||
public void testRefundSucceeded() {
|
void testRefundSucceeded() {
|
||||||
InvoicingMessage message = random(InvoicingMessage.class, "userInteraction");
|
InvoicingMessage message = random(InvoicingMessage.class, "userInteraction");
|
||||||
message.setPaymentId("1");
|
message.setPaymentId("1");
|
||||||
message.setRefundId("1");
|
message.setRefundId("1");
|
||||||
@ -67,7 +69,7 @@ public class InvoicingEventServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RepeatedTest(7)
|
@RepeatedTest(7)
|
||||||
public void testJson() throws JsonProcessingException {
|
void testJson() throws JsonProcessingException {
|
||||||
InvoicingMessage message = random(InvoicingMessage.class, "userInteraction");
|
InvoicingMessage message = random(InvoicingMessage.class, "userInteraction");
|
||||||
message.setPaymentId("1");
|
message.setPaymentId("1");
|
||||||
message.setType(InvoicingMessageEnum.PAYMENT);
|
message.setType(InvoicingMessageEnum.PAYMENT);
|
||||||
@ -83,7 +85,7 @@ public class InvoicingEventServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserInteractions() throws JsonProcessingException {
|
void testUserInteractionRequested() throws JsonProcessingException {
|
||||||
InvoicingMessage message = createDefaultInvoicingMessage();
|
InvoicingMessage message = createDefaultInvoicingMessage();
|
||||||
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_REQUESTED);
|
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_REQUESTED);
|
||||||
message.setUserInteraction(new BrowserHttpInteraction("get", "http://test", null));
|
message.setUserInteraction(new BrowserHttpInteraction("get", "http://test", null));
|
||||||
@ -92,10 +94,13 @@ public class InvoicingEventServiceTest {
|
|||||||
assertTrue(json.contains("\"eventType\":\"PaymentInteractionRequested\""));
|
assertTrue(json.contains("\"eventType\":\"PaymentInteractionRequested\""));
|
||||||
assertTrue(json.contains("\"requestType\":\"get\""));
|
assertTrue(json.contains("\"requestType\":\"get\""));
|
||||||
assertTrue(json.contains("\"userInteractionType\":\"BrowserHTTPRequest\""));
|
assertTrue(json.contains("\"userInteractionType\":\"BrowserHTTPRequest\""));
|
||||||
|
assertTrue(json.contains("\"invoiceId\":\"invoiceId\""));
|
||||||
|
assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId())));
|
||||||
|
assertTrue(event instanceof PaymentInteractionRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserInteractionsCompleted() throws JsonProcessingException {
|
void testUserInteractionsCompleted() throws JsonProcessingException {
|
||||||
InvoicingMessage message = createDefaultInvoicingMessage();
|
InvoicingMessage message = createDefaultInvoicingMessage();
|
||||||
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
||||||
message.setUserInteraction(new QrCodeDisplay("wefvqewvrq32fveqrw".getBytes()));
|
message.setUserInteraction(new QrCodeDisplay("wefvqewvrq32fveqrw".getBytes()));
|
||||||
@ -103,10 +108,13 @@ public class InvoicingEventServiceTest {
|
|||||||
String json = objectMapper.writeValueAsString(event);
|
String json = objectMapper.writeValueAsString(event);
|
||||||
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
||||||
assertTrue(json.contains("\"userInteractionType\":\"QrCodeDisplayRequest\""));
|
assertTrue(json.contains("\"userInteractionType\":\"QrCodeDisplayRequest\""));
|
||||||
|
assertTrue(json.contains("\"invoiceId\":\"invoiceId\""));
|
||||||
|
assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId())));
|
||||||
|
assertTrue(event instanceof PaymentInteractionCompleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserInteractionsCompletedApiExtension() throws JsonProcessingException {
|
void testUserInteractionsCompletedApiExtension() throws JsonProcessingException {
|
||||||
InvoicingMessage message = createDefaultInvoicingMessage();
|
InvoicingMessage message = createDefaultInvoicingMessage();
|
||||||
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
||||||
message.setUserInteraction(new ApiExtension("p2p"));
|
message.setUserInteraction(new ApiExtension("p2p"));
|
||||||
@ -114,10 +122,13 @@ public class InvoicingEventServiceTest {
|
|||||||
String json = objectMapper.writeValueAsString(event);
|
String json = objectMapper.writeValueAsString(event);
|
||||||
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
||||||
assertTrue(json.contains("\"userInteractionType\":\"ApiExtensionRequest\""));
|
assertTrue(json.contains("\"userInteractionType\":\"ApiExtensionRequest\""));
|
||||||
|
assertTrue(json.contains("\"invoiceId\":\"invoiceId\""));
|
||||||
|
assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId())));
|
||||||
|
assertTrue(event instanceof PaymentInteractionCompleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserInteractionsCompletedPaymentTerminal() throws JsonProcessingException {
|
void testUserInteractionsCompletedPaymentTerminal() throws JsonProcessingException {
|
||||||
InvoicingMessage message = createDefaultInvoicingMessage();
|
InvoicingMessage message = createDefaultInvoicingMessage();
|
||||||
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
||||||
message.setUserInteraction(new PaymentTerminalReceipt("p2p", "2016-03-22T06:12:27Z"));
|
message.setUserInteraction(new PaymentTerminalReceipt("p2p", "2016-03-22T06:12:27Z"));
|
||||||
@ -125,10 +136,13 @@ public class InvoicingEventServiceTest {
|
|||||||
String json = objectMapper.writeValueAsString(event);
|
String json = objectMapper.writeValueAsString(event);
|
||||||
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
assertTrue(json.contains("\"eventType\":\"PaymentInteractionCompleted\""));
|
||||||
assertTrue(json.contains("\"userInteractionType\":\"PaymentTerminalReceipt\""));
|
assertTrue(json.contains("\"userInteractionType\":\"PaymentTerminalReceipt\""));
|
||||||
|
assertTrue(json.contains("\"invoiceId\":\"invoiceId\""));
|
||||||
|
assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId())));
|
||||||
|
assertTrue(event instanceof PaymentInteractionCompleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserInteractionsCompletedCrypto() throws JsonProcessingException {
|
void testUserInteractionsCompletedCrypto() throws JsonProcessingException {
|
||||||
InvoicingMessage message = createDefaultInvoicingMessage();
|
InvoicingMessage message = createDefaultInvoicingMessage();
|
||||||
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
message.setEventType(EventType.INVOICE_PAYMENT_USER_INTERACTION_CHANGE_COMPLETED);
|
||||||
message.setUserInteraction(new CryptoCurrencyTransfer("address", new Rational(1L, 10L), "bitcoin"));
|
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("\"cryptoAddress\":\"address\""));
|
||||||
assertTrue(json.contains("\"cryptoCurrency\":\"bitcoin\""));
|
assertTrue(json.contains("\"cryptoCurrency\":\"bitcoin\""));
|
||||||
assertTrue(json.contains("\"denominator\":1"));
|
assertTrue(json.contains("\"denominator\":1"));
|
||||||
|
assertTrue(json.contains("\"invoiceId\":\"invoiceId\""));
|
||||||
|
assertTrue(json.contains("\"paymentId\":\"%s\"".formatted(message.getPaymentId())));
|
||||||
|
assertTrue(event instanceof PaymentInteractionCompleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
Loading…
Reference in New Issue
Block a user