From 41479becc62f351cdd7724100b1e4916d35b850c Mon Sep 17 00:00:00 2001 From: echerniak Date: Mon, 13 Sep 2021 15:37:11 +0300 Subject: [PATCH] WIP.Inermediate commit --- .../anapi/v2/service/SearchService.java | 50 ++++-------------- .../rbkmoney/anapi/v2/util/OpenApiUtil.java | 51 +++++++++++++++++++ 2 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/rbkmoney/anapi/v2/util/OpenApiUtil.java diff --git a/src/main/java/com/rbkmoney/anapi/v2/service/SearchService.java b/src/main/java/com/rbkmoney/anapi/v2/service/SearchService.java index 537c0d5..5ff69f1 100644 --- a/src/main/java/com/rbkmoney/anapi/v2/service/SearchService.java +++ b/src/main/java/com/rbkmoney/anapi/v2/service/SearchService.java @@ -16,6 +16,8 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import static com.rbkmoney.anapi.v2.util.OpenApiUtil.mapToCategory; + @Service @RequiredArgsConstructor public class SearchService { @@ -92,25 +94,7 @@ public class SearchService { return null; } - private ChargebackCategory mapToCategory(InvoicePaymentChargebackCategory chargebackCategory) { - if (chargebackCategory.isSetAuthorisation()) { - return ChargebackCategory.AUTHORISATION; - } - if (chargebackCategory.isSetDispute()) { - return ChargebackCategory.DISPUTE; - } - - if (chargebackCategory.isSetFraud()) { - return ChargebackCategory.FRAUD; - } - - if (chargebackCategory.isSetProcessingError()) { - return ChargebackCategory.PROCESSING_ERROR; - } - - return null; - } public InlineResponse2009 findInvoices(InvoiceSearchQuery query) { try { @@ -147,26 +131,6 @@ public class SearchService { return null; } - private Invoice.StatusEnum mapToStatus(InvoiceStatus status) { - if (status.isSetFulfilled()) { - return Invoice.StatusEnum.FULFILLED; - } - - if (status.isSetPaid()) { - return Invoice.StatusEnum.PAID; - } - - if (status.isSetUnpaid()) { - return Invoice.StatusEnum.UNPAID; - } - - if (status.isSetCancelled()) { - return Invoice.StatusEnum.CANCELLED; - } - - throw new IllegalArgumentException(""); - } - public InlineResponse20011 findPayouts(PayoutSearchQuery query) { try { StatPayoutResponse magistaResponse = magistaClient.searchPayouts(query); @@ -288,8 +252,14 @@ public class SearchService { .shopID(refund.getShopId()) .status(mapToStatus(refund.getStatus())) .externalID(refund.getExternalId()) - .error(new RefundStatusError() - .code()); + .error(refund.getStatus().isSetFailed() ? + new RefundStatusError() + .code(refund.getStatus().getFailed().getFailure().getFailure().getCode()) + .message(refund.getStatus().getFailed().getFailure().getFailure().getReason()) + : null) + .invoiceID(refund.getInvoiceId()) + .paymentID(refund.getPaymentId()) + .reason(refund.getReason()); results.add(result); } return new InlineResponse20012() diff --git a/src/main/java/com/rbkmoney/anapi/v2/util/OpenApiUtil.java b/src/main/java/com/rbkmoney/anapi/v2/util/OpenApiUtil.java new file mode 100644 index 0000000..130fcc6 --- /dev/null +++ b/src/main/java/com/rbkmoney/anapi/v2/util/OpenApiUtil.java @@ -0,0 +1,51 @@ +package com.rbkmoney.anapi.v2.util; + +import com.rbkmoney.damsel.domain.InvoicePaymentChargebackCategory; +import com.rbkmoney.magista.InvoiceStatus; +import com.rbkmoney.openapi.anapi_v2.model.ChargebackCategory; +import com.rbkmoney.openapi.anapi_v2.model.Invoice; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class OpenApiUtil { + + public static ChargebackCategory mapToCategory(InvoicePaymentChargebackCategory chargebackCategory) { + if (chargebackCategory.isSetAuthorisation()) { + return ChargebackCategory.AUTHORISATION; + } + + if (chargebackCategory.isSetDispute()) { + return ChargebackCategory.DISPUTE; + } + + if (chargebackCategory.isSetFraud()) { + return ChargebackCategory.FRAUD; + } + + if (chargebackCategory.isSetProcessingError()) { + return ChargebackCategory.PROCESSING_ERROR; + } + + return null; + } + + public static Invoice.StatusEnum mapToStatus(InvoiceStatus status) { + if (status.isSetFulfilled()) { + return Invoice.StatusEnum.FULFILLED; + } + + if (status.isSetPaid()) { + return Invoice.StatusEnum.PAID; + } + + if (status.isSetUnpaid()) { + return Invoice.StatusEnum.UNPAID; + } + + if (status.isSetCancelled()) { + return Invoice.StatusEnum.CANCELLED; + } + + throw new IllegalArgumentException(""); + } +}