APM-273: add extra params in webhook (#32)

This commit is contained in:
malkoas 2023-01-13 11:31:36 +03:00 committed by GitHub
parent caf725b6b1
commit be75d6432c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 36 deletions

View File

@ -7,4 +7,4 @@ on:
jobs:
lint:
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v1
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v2

View File

@ -7,4 +7,4 @@ on:
jobs:
build:
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v1
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v2

View File

@ -7,7 +7,7 @@ on:
jobs:
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:
github-token: ${{ secrets.GITHUB_TOKEN }}
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}

View File

@ -13,7 +13,7 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>1.0.18</version>
<version>2.0.2</version>
</parent>
<properties>
@ -85,6 +85,7 @@
<dependency>
<groupId>dev.vality</groupId>
<artifactId>shared-resources</artifactId>
<version>${shared-resources.version}</version>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>
@ -97,6 +98,7 @@
<dependency>
<groupId>dev.vality.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>

View File

@ -5,6 +5,7 @@ import dev.vality.damsel.domain.DisposablePaymentResource;
import dev.vality.damsel.domain.InvoicePaymentCaptured;
import dev.vality.damsel.domain.PaymentTool;
import dev.vality.damsel.payment_processing.InvoicePayment;
import dev.vality.hooker.model.ExpandedPayment;
import dev.vality.hooker.model.FeeType;
import dev.vality.hooker.utils.CashFlowUtils;
import dev.vality.hooker.utils.ErrorUtils;
@ -15,6 +16,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
@RequiredArgsConstructor
public class PaymentConverter implements Converter<InvoicePayment, Payment> {
@ -22,18 +25,18 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
private final MetadataDeserializer deserializer;
@Override
public Payment convert(InvoicePayment sourceWrapper) {
public ExpandedPayment convert(InvoicePayment sourceWrapper) {
var source = sourceWrapper.getPayment();
Payment target = new Payment()
.id(source.getId())
.createdAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()))
.status(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()))
.amount(source.getCost().getAmount())
.currency(source.getCost().getCurrency().getSymbolicCode())
.metadata(getMetadata(source))
.fee(getFee(sourceWrapper))
.rrn(getRrn(sourceWrapper));
ExpandedPayment target = new ExpandedPayment();
target.setId(source.getId());
target.setCreatedAt(TimeUtils.toOffsetDateTime(source.getCreatedAt()));
target.setStatus(Payment.StatusEnum.fromValue(source.getStatus().getSetField().getFieldName()));
target.setAmount(source.getCost().getAmount());
target.setCurrency(source.getCost().getCurrency().getSymbolicCode());
target.setMetadata(getMetadata(source));
target.setFee(getFee(sourceWrapper));
target.setRrn(getRrn(sourceWrapper));
target.setExtraPaymentInfo(getExtraPaymentInfo(sourceWrapper));
if (source.getStatus().isSetFailed()) {
setErrorDetails(source, target);
@ -65,6 +68,10 @@ public class PaymentConverter implements Converter<InvoicePayment, Payment> {
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) {
target.setError(ErrorUtils.getPaymentError(source.getStatus().getFailed().getFailure()));
}

View 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;
}

View File

@ -9,6 +9,7 @@ import dev.vality.hooker.converter.PaymentConverter;
import dev.vality.hooker.converter.RefundConverter;
import dev.vality.hooker.exception.NotFoundException;
import dev.vality.hooker.exception.RemoteHostException;
import dev.vality.hooker.model.ExpandedPayment;
import dev.vality.hooker.model.InvoicingMessage;
import dev.vality.hooker.utils.TimeUtils;
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);
return paymentConverter.convert(damselPayment);
@ -120,7 +122,7 @@ public class InvoicingEventService
private Event resolvePaymentStatusChanged(InvoicingMessage message,
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
Payment swagPayment = getSwagPayment(message, invoiceInfo);
ExpandedPayment swagPayment = getSwagPayment(message, invoiceInfo);
return switch (message.getPaymentStatus()) {
case PENDING -> new PaymentStarted()
.invoice(swagInvoice)
@ -180,7 +182,7 @@ public class InvoicingEventService
private Event resolveRefundStatusChanged(InvoicingMessage message,
dev.vality.damsel.payment_processing.Invoice invoiceInfo) {
Invoice swagInvoice = getSwagInvoice(invoiceInfo);
Payment swagPayment = getSwagPayment(message, invoiceInfo);
ExpandedPayment swagPayment = getSwagPayment(message, invoiceInfo);
Refund swagRefund = getSwagRefund(message, invoiceInfo);
return switch (message.getRefundStatus()) {
case PENDING -> new RefundCreated().invoice(swagInvoice).payment(swagPayment).refund(swagRefund);

View File

@ -14,7 +14,6 @@ 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;
import org.springframework.boot.test.mock.mockito.MockBean;
@ -74,5 +73,6 @@ public class InvoicingEventServiceTest {
Event event = service.getEventByMessage(message);
String json = objectMapper.writeValueAsString(event);
assertTrue(json.contains("\"payment_id\":271771960"));
assertTrue(json.contains("\"extraPaymentInfo\":{\"c2c_commission\":\"100\"}"));
}
}

View File

@ -4,6 +4,7 @@ import dev.vality.damsel.base.Content;
import dev.vality.damsel.domain.*;
import dev.vality.damsel.json.Value;
import dev.vality.damsel.payment_processing.InvoicePayment;
import dev.vality.damsel.payment_processing.InvoicePaymentSession;
import dev.vality.damsel.payment_processing.InvoiceRefundSession;
import dev.vality.geck.serializer.kit.mock.MockMode;
import dev.vality.geck.serializer.kit.mock.MockTBaseProcessor;
@ -118,8 +119,8 @@ public class BuildUtils {
.setAdjustments(Collections.emptyList())
.setPayment(buildPayment(partyId, paymentId, paymentStatus, 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,
@ -170,7 +171,8 @@ public class BuildUtils {
private static AdditionalTransactionInfo getAdditionalInfo() {
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,