From 4b047db9d24cf7df17d11eced4b873030894857b Mon Sep 17 00:00:00 2001 From: echerniak Date: Tue, 12 Oct 2021 08:02:33 +0300 Subject: [PATCH] Magista proto updated --- pom.xml | 2 +- ...PaymentToPaymentSearchResultConverter.java | 39 +++++++++++++------ ...entToPaymentSearchResultConverterTest.java | 35 ++++++++++++++--- .../anapi/v2/testutil/MagistaUtil.java | 7 ++-- 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 8227619..846a575 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ com.rbkmoney magista-proto - 1.18-e470bc7 + 1.19-50148e1 com.rbkmoney diff --git a/src/main/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverter.java b/src/main/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverter.java index 83dfa21..e4fbf0a 100644 --- a/src/main/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverter.java +++ b/src/main/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverter.java @@ -1,7 +1,7 @@ package com.rbkmoney.anapi.v2.converter.search.response; +import com.rbkmoney.damsel.domain.InvoicePaymentStatus; import com.rbkmoney.geck.common.util.TypeUtil; -import com.rbkmoney.magista.InvoicePaymentStatus; import com.rbkmoney.magista.StatPayment; import com.rbkmoney.openapi.anapi_v2.model.*; import org.springframework.stereotype.Component; @@ -28,6 +28,9 @@ public class StatPaymentToPaymentSearchResultConverter { .countryGeoID(payment.getLocationInfo().getCountryGeoId()) : null) .status(mapStatus(payment.getStatus())) + .error(payment.getStatus().isSetFailed() + ? new PaymentError().code(payment.getStatus().getFailed().getFailure().getFailure().getCode()) + : null) .statusChangedAt(payment.getStatusChangedAt() != null ? TypeUtil.stringToInstant(payment.getStatusChangedAt()).atOffset(ZoneOffset.UTC) : null) .id(payment.getId()) @@ -62,17 +65,29 @@ public class StatPaymentToPaymentSearchResultConverter { } protected PaymentSearchResult.StatusEnum mapStatus(InvoicePaymentStatus status) { - return switch (status) { - case pending -> PENDING; - case processed -> PROCESSED; - case captured -> CAPTURED; - case cancelled -> CANCELLED; - case refunded -> REFUNDED; - case failed -> FAILED; - case charged_back -> CHARGEDBACK; - default -> throw new IllegalArgumentException( - String.format("Payment status %s cannot be processed", status)); + if (status.isSetPending()) { + return PENDING; + } + if (status.isSetProcessed()) { + return PROCESSED; + } + if (status.isSetCaptured()) { + return CAPTURED; + } + if (status.isSetCancelled()) { + return CANCELLED; + } + if (status.isSetRefunded()) { + return REFUNDED; + } + if (status.isSetFailed()) { + return FAILED; + } + if (status.isSetChargedBack()) { + return CHARGEDBACK; + } + throw new IllegalArgumentException( + String.format("Payment status %s cannot be processed", status)); - }; } } diff --git a/src/test/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverterTest.java b/src/test/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverterTest.java index 2f85bca..846c22c 100644 --- a/src/test/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverterTest.java +++ b/src/test/java/com/rbkmoney/anapi/v2/converter/search/response/StatPaymentToPaymentSearchResultConverterTest.java @@ -1,9 +1,12 @@ package com.rbkmoney.anapi.v2.converter.search.response; -import com.rbkmoney.damsel.domain.AdditionalTransactionInfo; -import com.rbkmoney.damsel.domain.PaymentResourcePayer; -import com.rbkmoney.damsel.domain.RecurrentPayer; +import com.rbkmoney.damsel.domain.InvoicePaymentStatus; +import com.rbkmoney.damsel.domain.*; import com.rbkmoney.geck.common.util.TypeUtil; +import com.rbkmoney.magista.CustomerPayer; +import com.rbkmoney.magista.InvoicePaymentFlow; +import com.rbkmoney.magista.InvoicePaymentFlowHold; +import com.rbkmoney.magista.Payer; import com.rbkmoney.magista.*; import com.rbkmoney.openapi.anapi_v2.model.PaymentFlow; import com.rbkmoney.openapi.anapi_v2.model.PaymentSearchResult; @@ -14,6 +17,7 @@ import java.time.OffsetDateTime; import static com.rbkmoney.anapi.v2.testutil.MagistaUtil.createSearchPaymentAllResponse; import static com.rbkmoney.anapi.v2.testutil.RandomUtil.randomString; import static com.rbkmoney.openapi.anapi_v2.model.Payer.PayerTypeEnum.*; +import static com.rbkmoney.openapi.anapi_v2.model.PaymentSearchResult.StatusEnum.*; import static org.junit.jupiter.api.Assertions.*; class StatPaymentToPaymentSearchResultConverterTest { @@ -66,8 +70,27 @@ class StatPaymentToPaymentSearchResultConverterTest { @Test void mapStatus() { - for (InvoicePaymentStatus status : InvoicePaymentStatus.values()) { - assertNotNull(converter.mapStatus(status)); - } + var status = InvoicePaymentStatus.pending(new InvoicePaymentPending()); + assertEquals(PENDING, converter.mapStatus(status)); + + status = InvoicePaymentStatus.processed(new InvoicePaymentProcessed()); + assertEquals(PROCESSED, converter.mapStatus(status)); + + status = InvoicePaymentStatus.captured(new InvoicePaymentCaptured()); + assertEquals(CAPTURED, converter.mapStatus(status)); + + status = InvoicePaymentStatus.cancelled(new InvoicePaymentCancelled()); + assertEquals(CANCELLED, converter.mapStatus(status)); + + status = InvoicePaymentStatus.refunded(new InvoicePaymentRefunded()); + assertEquals(REFUNDED, converter.mapStatus(status)); + + status = InvoicePaymentStatus.failed(new InvoicePaymentFailed()); + assertEquals(FAILED, converter.mapStatus(status)); + + status = InvoicePaymentStatus.charged_back(new InvoicePaymentChargedBack()); + assertEquals(CHARGEDBACK, converter.mapStatus(status)); + + assertThrows(IllegalArgumentException.class, () -> converter.mapStatus(new InvoicePaymentStatus())); } } \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/anapi/v2/testutil/MagistaUtil.java b/src/test/java/com/rbkmoney/anapi/v2/testutil/MagistaUtil.java index fcc9481..00b0d14 100644 --- a/src/test/java/com/rbkmoney/anapi/v2/testutil/MagistaUtil.java +++ b/src/test/java/com/rbkmoney/anapi/v2/testutil/MagistaUtil.java @@ -5,6 +5,7 @@ import com.rbkmoney.bouncer.decisions.Judgement; import com.rbkmoney.bouncer.decisions.Resolution; import com.rbkmoney.bouncer.decisions.ResolutionAllowed; import com.rbkmoney.damsel.domain.InvoicePaymentRefundStatus; +import com.rbkmoney.damsel.domain.InvoicePaymentStatus; import com.rbkmoney.damsel.domain.InvoiceStatus; import com.rbkmoney.damsel.domain.*; import com.rbkmoney.damsel.geo_ip.LocationInfo; @@ -14,7 +15,6 @@ import com.rbkmoney.geck.serializer.kit.mock.MockTBaseProcessor; import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler; import com.rbkmoney.magista.InvoicePaymentFlow; import com.rbkmoney.magista.InvoicePaymentFlowInstant; -import com.rbkmoney.magista.InvoicePaymentStatus; import com.rbkmoney.magista.*; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; @@ -48,6 +48,8 @@ public class MagistaUtil { public static StatPaymentResponse createSearchPaymentAllResponse() { var payment = fillRequiredTBaseObject(new StatPayment(), StatPayment.class); + var status = new InvoicePaymentStatus(); + status.setPending(new InvoicePaymentPending()); var cart = fillRequiredTBaseObject(new InvoiceCart(), InvoiceCart.class); var line = fillRequiredTBaseObject(new InvoiceLine(), InvoiceLine.class); var instant = fillRequiredTBaseObject(new InvoicePaymentFlowInstant(), InvoicePaymentFlowInstant.class); @@ -56,8 +58,7 @@ public class MagistaUtil { return response.setPayments( List.of(payment - .setStatus(InvoicePaymentStatus - .pending) + .setStatus(status) .setCart(cart.setLines(List.of(line))) .setFlow(InvoicePaymentFlow .instant(instant))