mirror of
https://github.com/valitydev/hooker.git
synced 2024-11-06 00:05:17 +00:00
APM-273: add extra params in webhook (#32)
This commit is contained in:
parent
caf725b6b1
commit
be75d6432c
2
.github/workflows/basic-linters.yml
vendored
2
.github/workflows/basic-linters.yml
vendored
@ -7,4 +7,4 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v1
|
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v2
|
||||||
|
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -7,4 +7,4 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v1
|
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v2
|
||||||
|
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v1
|
uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v2
|
||||||
secrets:
|
secrets:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
|
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
|
||||||
|
4
pom.xml
4
pom.xml
@ -13,7 +13,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
<artifactId>service-parent-pom</artifactId>
|
<artifactId>service-parent-pom</artifactId>
|
||||||
<version>1.0.18</version>
|
<version>2.0.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -85,6 +85,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality</groupId>
|
<groupId>dev.vality</groupId>
|
||||||
<artifactId>shared-resources</artifactId>
|
<artifactId>shared-resources</artifactId>
|
||||||
|
<version>${shared-resources.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality.geck</groupId>
|
<groupId>dev.vality.geck</groupId>
|
||||||
@ -97,6 +98,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality.woody</groupId>
|
<groupId>dev.vality.woody</groupId>
|
||||||
<artifactId>woody-thrift</artifactId>
|
<artifactId>woody-thrift</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.vality.geck</groupId>
|
<groupId>dev.vality.geck</groupId>
|
||||||
|
@ -5,6 +5,7 @@ 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.InvoicePayment;
|
import dev.vality.damsel.payment_processing.InvoicePayment;
|
||||||
|
import dev.vality.hooker.model.ExpandedPayment;
|
||||||
import dev.vality.hooker.model.FeeType;
|
import dev.vality.hooker.model.FeeType;
|
||||||
import dev.vality.hooker.utils.CashFlowUtils;
|
import dev.vality.hooker.utils.CashFlowUtils;
|
||||||
import dev.vality.hooker.utils.ErrorUtils;
|
import dev.vality.hooker.utils.ErrorUtils;
|
||||||
@ -15,6 +16,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
||||||
@ -22,18 +25,18 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
|||||||
private final MetadataDeserializer deserializer;
|
private final MetadataDeserializer deserializer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Payment convert(InvoicePayment sourceWrapper) {
|
public ExpandedPayment convert(InvoicePayment sourceWrapper) {
|
||||||
var source = sourceWrapper.getPayment();
|
var source = sourceWrapper.getPayment();
|
||||||
|
ExpandedPayment target = new ExpandedPayment();
|
||||||
Payment target = new Payment()
|
target.setId(source.getId());
|
||||||
.id(source.getId())
|
target.setCreatedAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()));
|
||||||
.createdAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()))
|
target.setStatus(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()));
|
||||||
.status(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()))
|
target.setAmount(source.getCost().getAmount());
|
||||||
.amount(source.getCost().getAmount())
|
target.setCurrency(source.getCost().getCurrency().getSymbolicCode());
|
||||||
.currency(source.getCost().getCurrency().getSymbolicCode())
|
target.setMetadata(getMetadata(source));
|
||||||
.metadata(getMetadata(source))
|
target.setFee(getFee(sourceWrapper));
|
||||||
.fee(getFee(sourceWrapper))
|
target.setRrn(getRrn(sourceWrapper));
|
||||||
.rrn(getRrn(sourceWrapper));
|
target.setExtraPaymentInfo(getExtraPaymentInfo(sourceWrapper));
|
||||||
|
|
||||||
if (source.getStatus().isSetFailed()) {
|
if (source.getStatus().isSetFailed()) {
|
||||||
setErrorDetails(source, target);
|
setErrorDetails(source, target);
|
||||||
@ -65,6 +68,10 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
|
|||||||
return isSetAdditionalInfo(sourceWrapper) ? getAdditionalInfo(sourceWrapper).getRrn() : null;
|
return isSetAdditionalInfo(sourceWrapper) ? getAdditionalInfo(sourceWrapper).getRrn() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getExtraPaymentInfo(InvoicePayment sourceWrapper) {
|
||||||
|
return isSetAdditionalInfo(sourceWrapper) ? getAdditionalInfo(sourceWrapper).getExtraPaymentInfo() : null;
|
||||||
|
}
|
||||||
|
|
||||||
private void setErrorDetails(dev.vality.damsel.domain.InvoicePayment source, Payment target) {
|
private void setErrorDetails(dev.vality.damsel.domain.InvoicePayment source, Payment target) {
|
||||||
target.setError(ErrorUtils.getPaymentError(source.getStatus().getFailed().getFailure()));
|
target.setError(ErrorUtils.getPaymentError(source.getStatus().getFailed().getFailure()));
|
||||||
}
|
}
|
||||||
|
16
src/main/java/dev/vality/hooker/model/ExpandedPayment.java
Normal file
16
src/main/java/dev/vality/hooker/model/ExpandedPayment.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package dev.vality.hooker.model;
|
||||||
|
|
||||||
|
import dev.vality.swag_webhook_events.model.Payment;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ExpandedPayment extends Payment {
|
||||||
|
|
||||||
|
private Map<String, String> extraPaymentInfo;
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ import dev.vality.hooker.converter.PaymentConverter;
|
|||||||
import dev.vality.hooker.converter.RefundConverter;
|
import dev.vality.hooker.converter.RefundConverter;
|
||||||
import dev.vality.hooker.exception.NotFoundException;
|
import dev.vality.hooker.exception.NotFoundException;
|
||||||
import dev.vality.hooker.exception.RemoteHostException;
|
import dev.vality.hooker.exception.RemoteHostException;
|
||||||
|
import dev.vality.hooker.model.ExpandedPayment;
|
||||||
import dev.vality.hooker.model.InvoicingMessage;
|
import dev.vality.hooker.model.InvoicingMessage;
|
||||||
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.*;
|
||||||
@ -98,7 +99,8 @@ public class InvoicingEventService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Payment getSwagPayment(InvoicingMessage m, dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
private ExpandedPayment getSwagPayment(InvoicingMessage m,
|
||||||
|
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);
|
||||||
@ -120,7 +122,7 @@ public class InvoicingEventService
|
|||||||
private Event resolvePaymentStatusChanged(InvoicingMessage message,
|
private Event resolvePaymentStatusChanged(InvoicingMessage message,
|
||||||
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
||||||
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
||||||
Payment swagPayment = getSwagPayment(message, invoiceInfo);
|
ExpandedPayment swagPayment = getSwagPayment(message, invoiceInfo);
|
||||||
return switch (message.getPaymentStatus()) {
|
return switch (message.getPaymentStatus()) {
|
||||||
case PENDING -> new PaymentStarted()
|
case PENDING -> new PaymentStarted()
|
||||||
.invoice(swagInvoice)
|
.invoice(swagInvoice)
|
||||||
@ -180,7 +182,7 @@ public class InvoicingEventService
|
|||||||
private Event resolveRefundStatusChanged(InvoicingMessage message,
|
private Event resolveRefundStatusChanged(InvoicingMessage message,
|
||||||
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
|
||||||
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
|
||||||
Payment swagPayment = getSwagPayment(message, invoiceInfo);
|
ExpandedPayment swagPayment = getSwagPayment(message, invoiceInfo);
|
||||||
Refund swagRefund = getSwagRefund(message, invoiceInfo);
|
Refund swagRefund = getSwagRefund(message, invoiceInfo);
|
||||||
return switch (message.getRefundStatus()) {
|
return switch (message.getRefundStatus()) {
|
||||||
case PENDING -> new RefundCreated().invoice(swagInvoice).payment(swagPayment).refund(swagRefund);
|
case PENDING -> new RefundCreated().invoice(swagInvoice).payment(swagPayment).refund(swagRefund);
|
||||||
|
@ -14,7 +14,6 @@ import dev.vality.swag_webhook_events.model.Event;
|
|||||||
import dev.vality.swag_webhook_events.model.RefundSucceeded;
|
import dev.vality.swag_webhook_events.model.RefundSucceeded;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.RepeatedTest;
|
import org.junit.jupiter.api.RepeatedTest;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
@ -74,5 +73,6 @@ public class InvoicingEventServiceTest {
|
|||||||
Event event = service.getEventByMessage(message);
|
Event event = service.getEventByMessage(message);
|
||||||
String json = objectMapper.writeValueAsString(event);
|
String json = objectMapper.writeValueAsString(event);
|
||||||
assertTrue(json.contains("\"payment_id\":271771960"));
|
assertTrue(json.contains("\"payment_id\":271771960"));
|
||||||
|
assertTrue(json.contains("\"extraPaymentInfo\":{\"c2c_commission\":\"100\"}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import dev.vality.damsel.base.Content;
|
|||||||
import dev.vality.damsel.domain.*;
|
import dev.vality.damsel.domain.*;
|
||||||
import dev.vality.damsel.json.Value;
|
import dev.vality.damsel.json.Value;
|
||||||
import dev.vality.damsel.payment_processing.InvoicePayment;
|
import dev.vality.damsel.payment_processing.InvoicePayment;
|
||||||
|
import dev.vality.damsel.payment_processing.InvoicePaymentSession;
|
||||||
import dev.vality.damsel.payment_processing.InvoiceRefundSession;
|
import dev.vality.damsel.payment_processing.InvoiceRefundSession;
|
||||||
import dev.vality.geck.serializer.kit.mock.MockMode;
|
import dev.vality.geck.serializer.kit.mock.MockMode;
|
||||||
import dev.vality.geck.serializer.kit.mock.MockTBaseProcessor;
|
import dev.vality.geck.serializer.kit.mock.MockTBaseProcessor;
|
||||||
@ -72,9 +73,9 @@ public class BuildUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static dev.vality.damsel.payment_processing.Invoice buildInvoice(String partyId, String invoiceId,
|
public static dev.vality.damsel.payment_processing.Invoice buildInvoice(String partyId, String invoiceId,
|
||||||
String paymentId, String refundId,
|
String paymentId, String refundId,
|
||||||
InvoiceStatus invoiceStatus,
|
InvoiceStatus invoiceStatus,
|
||||||
InvoicePaymentStatus paymentStatus)
|
InvoicePaymentStatus paymentStatus)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
MockTBaseProcessor thriftBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
MockTBaseProcessor thriftBaseProcessor = new MockTBaseProcessor(MockMode.RANDOM, 15, 1);
|
||||||
dev.vality.damsel.payment_processing.Invoice invoice = new dev.vality.damsel.payment_processing.Invoice()
|
dev.vality.damsel.payment_processing.Invoice invoice = new dev.vality.damsel.payment_processing.Invoice()
|
||||||
@ -99,9 +100,9 @@ public class BuildUtils {
|
|||||||
private static Invoice buildInvoice(String partyId, String invoiceId, InvoiceStatus invoiceStatus,
|
private static Invoice buildInvoice(String partyId, String invoiceId, InvoiceStatus invoiceStatus,
|
||||||
MockTBaseProcessor thriftBaseProcessor) throws IOException {
|
MockTBaseProcessor thriftBaseProcessor) throws IOException {
|
||||||
return thriftBaseProcessor.process(
|
return thriftBaseProcessor.process(
|
||||||
new Invoice(),
|
new Invoice(),
|
||||||
new TBaseHandler<>(Invoice.class)
|
new TBaseHandler<>(Invoice.class)
|
||||||
)
|
)
|
||||||
.setId(invoiceId)
|
.setId(invoiceId)
|
||||||
.setOwnerId(partyId)
|
.setOwnerId(partyId)
|
||||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||||
@ -118,18 +119,18 @@ public class BuildUtils {
|
|||||||
.setAdjustments(Collections.emptyList())
|
.setAdjustments(Collections.emptyList())
|
||||||
.setPayment(buildPayment(partyId, paymentId, paymentStatus, thriftBaseProcessor))
|
.setPayment(buildPayment(partyId, paymentId, paymentStatus, thriftBaseProcessor))
|
||||||
.setRefunds(buildRefunds(refundId, thriftBaseProcessor))
|
.setRefunds(buildRefunds(refundId, thriftBaseProcessor))
|
||||||
.setSessions(Collections.emptyList())
|
.setSessions(Collections.singletonList(
|
||||||
);
|
new InvoicePaymentSession().setTransactionInfo(getTransactionInfo()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static dev.vality.damsel.domain.InvoicePayment buildPayment(String partyId, String paymentId,
|
private static dev.vality.damsel.domain.InvoicePayment buildPayment(String partyId, String paymentId,
|
||||||
InvoicePaymentStatus paymentStatus,
|
InvoicePaymentStatus paymentStatus,
|
||||||
MockTBaseProcessor thriftBaseProcessor)
|
MockTBaseProcessor thriftBaseProcessor)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return thriftBaseProcessor.process(
|
return thriftBaseProcessor.process(
|
||||||
new dev.vality.damsel.domain.InvoicePayment(),
|
new dev.vality.damsel.domain.InvoicePayment(),
|
||||||
new TBaseHandler<>(dev.vality.damsel.domain.InvoicePayment.class)
|
new TBaseHandler<>(dev.vality.damsel.domain.InvoicePayment.class)
|
||||||
)
|
)
|
||||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||||
.setId(paymentId)
|
.setId(paymentId)
|
||||||
.setOwnerId(partyId)
|
.setOwnerId(partyId)
|
||||||
@ -153,9 +154,9 @@ public class BuildUtils {
|
|||||||
MockTBaseProcessor thriftBaseProcessor
|
MockTBaseProcessor thriftBaseProcessor
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
return thriftBaseProcessor.process(
|
return thriftBaseProcessor.process(
|
||||||
new InvoicePaymentRefund(),
|
new InvoicePaymentRefund(),
|
||||||
new TBaseHandler<>(InvoicePaymentRefund.class)
|
new TBaseHandler<>(InvoicePaymentRefund.class)
|
||||||
)
|
)
|
||||||
.setReason("keksik")
|
.setReason("keksik")
|
||||||
.setCreatedAt("2016-03-22T06:12:27Z")
|
.setCreatedAt("2016-03-22T06:12:27Z")
|
||||||
.setId(refundId);
|
.setId(refundId);
|
||||||
@ -170,7 +171,8 @@ public class BuildUtils {
|
|||||||
|
|
||||||
private static AdditionalTransactionInfo getAdditionalInfo() {
|
private static AdditionalTransactionInfo getAdditionalInfo() {
|
||||||
return new AdditionalTransactionInfo()
|
return new AdditionalTransactionInfo()
|
||||||
.setRrn("chicken-teriyaki");
|
.setRrn("chicken-teriyaki")
|
||||||
|
.setExtraPaymentInfo(Map.of("c2c_commission", "100"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CustomerMessage buildCustomerMessage(Long eventId, String partyId, EventType eventType,
|
public static CustomerMessage buildCustomerMessage(Long eventId, String partyId, EventType eventType,
|
||||||
|
Loading…
Reference in New Issue
Block a user