WIP. Refactoring in progress

This commit is contained in:
echerniak 2021-09-16 14:59:35 +03:00
parent a0be312bd4
commit 05f2b62f35
No known key found for this signature in database
GPG Key ID: 7D79B3A9CB749B36
8 changed files with 351 additions and 116 deletions

View File

@ -0,0 +1,20 @@
package com.rbkmoney.anapi.v2.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
return new ThreadPoolTaskExecutor();
}
}

View File

@ -1,10 +1,9 @@
package com.rbkmoney.anapi.v2.controller;
import com.rbkmoney.anapi.v2.converter.search.request.ParamsToPaymentSearchQueryConverter;
import com.rbkmoney.anapi.v2.exception.BadRequestException;
import com.rbkmoney.anapi.v2.service.SearchService;
import com.rbkmoney.anapi.v2.util.DamselUtil;
import com.rbkmoney.damsel.domain.LegacyBankCardPaymentSystem;
import com.rbkmoney.damsel.domain.LegacyBankCardTokenProvider;
import com.rbkmoney.damsel.domain.LegacyTerminalPaymentProvider;
import com.rbkmoney.magista.*;
import com.rbkmoney.openapi.anapi_v2.api.*;
import com.rbkmoney.openapi.anapi_v2.model.*;
@ -25,8 +24,12 @@ import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import static com.rbkmoney.anapi.v2.util.CommonUtil.getRequestDeadlineMillis;
import static com.rbkmoney.anapi.v2.util.CommonUtil.merge;
import static com.rbkmoney.anapi.v2.util.DamselUtil.*;
@ -36,6 +39,7 @@ import static com.rbkmoney.anapi.v2.util.DamselUtil.*;
public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesApi, PayoutsApi, RefundsApi {
private final SearchService searchService;
private final ParamsToPaymentSearchQueryConverter paymentSearchConverter;
@Override
public Optional<NativeWebRequest> getRequest() {
@ -73,59 +77,57 @@ public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesAp
@Min(1L) @Valid Long paymentAmountTo,
@Valid List<String> excludedShops,
@Valid String continuationToken) {
//TODO: clarify mapping for paymentInstitutionRealm, xrequestID, xrequestDeadline
PaymentSearchQuery query;
try {
query = new PaymentSearchQuery()
.setCommonSearchQueryParams(
fillCommonParams(fromTime, toTime, limit, partyID, merge(shopID, shopIDs),
continuationToken))
.setExcludedShopIds(excludedShops)
.setExternalId(externalID)
.setInvoiceIds(merge(invoiceID, invoiceIDs));
//TODO: clarify mapping for paymentInstitutionRealm, xrequestID
PaymentParams paymentParams = new PaymentParams()
.setPaymentTool(paymentMethod != null ? mapToPaymentTool(paymentMethod) : null)
.setPaymentFlow(paymentFlow != null ? mapToInvoicePaymentFlow(paymentFlow) : null)
.setPaymentTerminalProvider(
paymentTerminalProvider != null
? LegacyTerminalPaymentProvider.valueOf(paymentTerminalProvider) :
null)
.setPaymentTokenProvider(
bankCardTokenProvider != null
?
LegacyBankCardTokenProvider
.valueOf(bankCardTokenProvider.getValue()) :
null)
.setPaymentEmail(payerEmail)
.setPaymentApprovalCode(approvalCode)
.setPaymentCustomerId(customerID)
.setPaymentFingerprint(payerFingerprint)
.setPaymentFirst6(first6)
.setPaymentLast4(last4)
.setPaymentId(paymentID)
.setPaymentIp(payerIP)
.setPaymentRrn(rrn)
.setPaymentStatus(paymentStatus != null ? getStatus(paymentStatus) : null)
.setPaymentSystem(bankCardPaymentSystem != null
? LegacyBankCardPaymentSystem.valueOf(bankCardPaymentSystem.getValue()) :
null);
if (paymentAmountFrom != null) {
paymentParams.setPaymentAmountFrom(paymentAmountFrom);
PaymentSearchQuery query = paymentSearchConverter.convert(partyID,
fromTime,
toTime,
limit,
shopID,
shopIDs,
paymentInstitutionRealm,
invoiceIDs,
paymentStatus, paymentFlow,
paymentMethod,
paymentTerminalProvider,
invoiceID,
paymentID,
externalID,
payerEmail,
payerIP,
payerFingerprint,
customerID,
first6,
last4,
rrn,
approvalCode,
bankCardTokenProvider,
bankCardPaymentSystem,
paymentAmountFrom,
paymentAmountTo,
excludedShops,
continuationToken);
try {
InlineResponse20010 response;
if (xrequestDeadline != null) {
response = searchService
.findPayments(query)
.get(getRequestDeadlineMillis(xrequestDeadline), TimeUnit.MILLISECONDS);
} else {
response = searchService.findPayments(query).get();
}
if (paymentAmountTo != null) {
paymentParams.setPaymentAmountTo(paymentAmountTo);
}
query.setPaymentParams(paymentParams);
} catch (IllegalArgumentException e) {
return ResponseEntity.ok(response);
} catch (InterruptedException e) {
log.error(e.getMessage());
return new ResponseEntity(
new DefaultLogicError()
.code(DefaultLogicError.CodeEnum.INVALIDREQUEST)
.message(e.getMessage()),
HttpStatus.BAD_REQUEST);
Thread.currentThread().interrupt();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (ExecutionException e) {
log.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (TimeoutException e) {
log.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.REQUEST_TIMEOUT);
}
return ResponseEntity.ok(searchService.findPayments(query));
}
@GetMapping(
@ -152,7 +154,11 @@ public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesAp
@Valid String continuationToken) {
//TODO: clarify mapping for paymentInstitutionRealm, xrequestID, xrequestDeadline, offset
ChargebackSearchQuery query;
Long timeoutMillis = null;
try {
if (xrequestDeadline != null) {
timeoutMillis = getRequestDeadlineMillis(xrequestDeadline);
}
query = new ChargebackSearchQuery()
.setCommonSearchQueryParams(
fillCommonParams(fromTime, toTime, limit, partyID, merge(shopID, shopIDs),
@ -185,7 +191,25 @@ public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesAp
.message(e.getMessage()),
HttpStatus.BAD_REQUEST);
}
return ResponseEntity.ok(searchService.findChargebacks(query));
try {
InlineResponse2008 response;
if (timeoutMillis != null) {
response = searchService.findChargebacks(query).get(timeoutMillis, TimeUnit.MILLISECONDS);
} else {
response = searchService.findChargebacks(query).get();
}
return ResponseEntity.ok(response);
} catch (InterruptedException e) {
log.error(e.getMessage());
Thread.currentThread().interrupt();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (ExecutionException e) {
log.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (TimeoutException e) {
log.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.REQUEST_TIMEOUT);
}
}
@GetMapping(
@ -210,6 +234,17 @@ public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesAp
@Min(1L) @Valid Long invoiceAmountTo,
@Valid List<String> excludedShops,
@Valid String continuationToken) {
try {
//gives 10 seconds to finish the methods execution
return futureResponse.get(10, TimeUnit.SECONDS);
} catch (TimeoutException te) {
//in case it takes longer we cancel the request and check if the method is not done
if (futureResponse.cancel(true) || !futureResponse.isDone()) {
throw new TestTimeoutException();
} else {
return futureResponse.get();
}
}
//TODO: clarify mapping for paymentInstitutionRealm, xrequestID, xrequestDeadline, excludedShops
InvoiceSearchQuery query;
try {
@ -322,16 +357,29 @@ public class SearchController implements PaymentsApi, ChargebacksApi, InvoicesAp
return ResponseEntity.ok(searchService.findRefunds(query));
}
@ExceptionHandler({ConstraintViolationException.class})
@ExceptionHandler({ConstraintViolationException.class, BadRequestException.class, IllegalArgumentException.class})
public ResponseEntity<DefaultLogicError> handleConstraintViolation(Exception ex) {
Set<ConstraintViolation<?>> constraintViolations =
((ConstraintViolationException) ex).getConstraintViolations();
String errorMessage =
constraintViolations.stream()
.map(violation -> violation.getPropertyPath() + ": " + violation.getMessage())
.collect(Collectors.joining(", "));
return new ResponseEntity<>(new DefaultLogicError()
.code(DefaultLogicError.CodeEnum.INVALIDREQUEST)
.message(errorMessage), HttpStatus.BAD_REQUEST);
DefaultLogicError error;
if (ex instanceof ConstraintViolationException) {
Set<ConstraintViolation<?>> constraintViolations =
((ConstraintViolationException) ex).getConstraintViolations();
String errorMessage =
constraintViolations.stream()
.map(violation -> violation.getPropertyPath() + ": " + violation.getMessage())
.collect(Collectors.joining(", "));
error = new DefaultLogicError()
.code(DefaultLogicError.CodeEnum.INVALIDREQUEST)
.message(errorMessage);
} else if (ex instanceof BadRequestException) {
error = new DefaultLogicError()
.code(((BadRequestException) ex).getErrorCode())
.message(ex.getMessage());
} else {
error = new DefaultLogicError()
.code(DefaultLogicError.CodeEnum.INVALIDREQUEST)
.message(ex.getMessage());
}
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
}

View File

@ -0,0 +1,93 @@
package com.rbkmoney.anapi.v2.converter.search.request;
import com.rbkmoney.damsel.domain.LegacyBankCardPaymentSystem;
import com.rbkmoney.damsel.domain.LegacyBankCardTokenProvider;
import com.rbkmoney.damsel.domain.LegacyTerminalPaymentProvider;
import com.rbkmoney.magista.PaymentParams;
import com.rbkmoney.magista.PaymentSearchQuery;
import com.rbkmoney.openapi.anapi_v2.model.BankCardPaymentSystem;
import com.rbkmoney.openapi.anapi_v2.model.BankCardTokenProvider;
import org.springframework.stereotype.Component;
import java.time.OffsetDateTime;
import java.util.List;
import static com.rbkmoney.anapi.v2.util.CommonUtil.merge;
import static com.rbkmoney.anapi.v2.util.DamselUtil.*;
@Component
public class ParamsToPaymentSearchQueryConverter {
public PaymentSearchQuery convert(String partyID,
OffsetDateTime fromTime,
OffsetDateTime toTime,
Integer limit,
String shopID,
List<String> shopIDs,
String paymentInstitutionRealm,
List<String> invoiceIDs,
String paymentStatus, String paymentFlow,
String paymentMethod,
String paymentTerminalProvider,
String invoiceID,
String paymentID,
String externalID,
String payerEmail,
String payerIP,
String payerFingerprint,
String customerID,
String first6,
String last4,
String rrn,
String approvalCode,
BankCardTokenProvider bankCardTokenProvider,
BankCardPaymentSystem bankCardPaymentSystem,
Long paymentAmountFrom,
Long paymentAmountTo,
List<String> excludedShops,
String continuationToken) {
PaymentSearchQuery query = new PaymentSearchQuery()
.setCommonSearchQueryParams(
fillCommonParams(fromTime, toTime, limit, partyID, merge(shopID, shopIDs),
continuationToken))
.setExcludedShopIds(excludedShops)
.setExternalId(externalID)
.setInvoiceIds(merge(invoiceID, invoiceIDs));
PaymentParams paymentParams = new PaymentParams()
.setPaymentTool(paymentMethod != null ? mapToPaymentTool(paymentMethod) : null)
.setPaymentFlow(paymentFlow != null ? mapToInvoicePaymentFlow(paymentFlow) : null)
.setPaymentTerminalProvider(
paymentTerminalProvider != null
? LegacyTerminalPaymentProvider.valueOf(paymentTerminalProvider) :
null)
.setPaymentTokenProvider(
bankCardTokenProvider != null
?
LegacyBankCardTokenProvider
.valueOf(bankCardTokenProvider.getValue()) :
null)
.setPaymentEmail(payerEmail)
.setPaymentApprovalCode(approvalCode)
.setPaymentCustomerId(customerID)
.setPaymentFingerprint(payerFingerprint)
.setPaymentFirst6(first6)
.setPaymentLast4(last4)
.setPaymentId(paymentID)
.setPaymentIp(payerIP)
.setPaymentRrn(rrn)
.setPaymentStatus(paymentStatus != null ? getStatus(paymentStatus) : null)
.setPaymentSystem(bankCardPaymentSystem != null
? LegacyBankCardPaymentSystem.valueOf(bankCardPaymentSystem.getValue()) :
null);
if (paymentAmountFrom != null) {
paymentParams.setPaymentAmountFrom(paymentAmountFrom);
}
if (paymentAmountTo != null) {
paymentParams.setPaymentAmountTo(paymentAmountTo);
}
query.setPaymentParams(paymentParams);
return query;
}
}

View File

@ -0,0 +1,47 @@
package com.rbkmoney.anapi.v2.converter.search.response;
import com.rbkmoney.geck.common.util.TypeUtil;
import com.rbkmoney.magista.StatPayment;
import com.rbkmoney.openapi.anapi_v2.model.GeoLocationInfo;
import com.rbkmoney.openapi.anapi_v2.model.PaymentFlow;
import com.rbkmoney.openapi.anapi_v2.model.PaymentSearchResult;
import com.rbkmoney.openapi.anapi_v2.model.TransactionInfo;
import org.springframework.stereotype.Component;
import java.time.ZoneOffset;
import static com.rbkmoney.anapi.v2.util.OpenApiUtil.fillPaymentStatusInfo;
import static com.rbkmoney.anapi.v2.util.OpenApiUtil.getPayer;
@Component
public class StatPaymentToPaymentSearchResultConverter {
public PaymentSearchResult convert(StatPayment payment) {
PaymentSearchResult result = new PaymentSearchResult()
.amount(payment.getAmount())
.createdAt(TypeUtil.stringToInstant(payment.getCreatedAt()).atOffset(ZoneOffset.UTC))
.currency(payment.getCurrencySymbolicCode())
.externalID(payment.getExternalId())
.fee(payment.getFee())
.flow(new PaymentFlow()
.type(payment.getFlow().isSetHold() ? PaymentFlow.TypeEnum.PAYMENTFLOWHOLD :
PaymentFlow.TypeEnum.PAYMENTFLOWINSTANT))
.geoLocationInfo(payment.getLocationInfo() != null ? new GeoLocationInfo()
.cityGeoID(payment.getLocationInfo().getCityGeoId())
.countryGeoID(payment.getLocationInfo().getCountryGeoId())
: null)
.id(payment.getId())
.invoiceID(payment.getInvoiceId())
.makeRecurrent(payment.isMakeRecurrent())
.payer(getPayer(payment))
.shopID(payment.getShopId())
.shortID(payment.getShortId())
.transactionInfo(payment.getAdditionalTransactionInfo() != null
? new TransactionInfo()
.approvalCode(payment.getAdditionalTransactionInfo().getApprovalCode())
.rrn(payment.getAdditionalTransactionInfo().getRrn())
: null);
fillPaymentStatusInfo(payment, result);
return result;
}
}

View File

@ -0,0 +1,19 @@
package com.rbkmoney.anapi.v2.exception;
import com.rbkmoney.openapi.anapi_v2.model.DefaultLogicError;
import lombok.Getter;
public class BadRequestException extends IllegalArgumentException {
@Getter
private DefaultLogicError.CodeEnum errorCode = DefaultLogicError.CodeEnum.INVALIDREQUEST;
public BadRequestException(String s) {
super(s);
}
public BadRequestException(String s, DefaultLogicError.CodeEnum errorCode) {
super(s);
this.errorCode = errorCode;
}
}

View File

@ -1,16 +1,20 @@
package com.rbkmoney.anapi.v2.service;
import com.rbkmoney.anapi.v2.converter.search.response.StatPaymentToPaymentSearchResultConverter;
import com.rbkmoney.anapi.v2.util.OpenApiUtil;
import com.rbkmoney.geck.common.util.TypeUtil;
import com.rbkmoney.magista.*;
import com.rbkmoney.openapi.anapi_v2.model.*;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static com.rbkmoney.anapi.v2.util.OpenApiUtil.*;
@ -21,45 +25,22 @@ public class SearchService {
private final MerchantStatisticsServiceSrv.Iface magistaClient;
private final StatPaymentToPaymentSearchResultConverter paymentResponseConverter;
@Async
@SneakyThrows
public InlineResponse20010 findPayments(PaymentSearchQuery query) {
public Future<InlineResponse20010> findPayments(PaymentSearchQuery query) {
StatPaymentResponse magistaResponse = magistaClient.searchPayments(query);
List<PaymentSearchResult> results = new ArrayList<>(magistaResponse.getPaymentsSize());
for (StatPayment payment : magistaResponse.getPayments()) {
PaymentSearchResult result = new PaymentSearchResult()
.amount(payment.getAmount())
.createdAt(TypeUtil.stringToInstant(payment.getCreatedAt()).atOffset(ZoneOffset.UTC))
.currency(payment.getCurrencySymbolicCode())
.externalID(payment.getExternalId())
.fee(payment.getFee())
.flow(new PaymentFlow()
.type(payment.getFlow().isSetHold() ? PaymentFlow.TypeEnum.PAYMENTFLOWHOLD :
PaymentFlow.TypeEnum.PAYMENTFLOWINSTANT))
.geoLocationInfo(payment.getLocationInfo() != null ? new GeoLocationInfo()
.cityGeoID(payment.getLocationInfo().getCityGeoId())
.countryGeoID(payment.getLocationInfo().getCountryGeoId())
: null)
.id(payment.getId())
.invoiceID(payment.getInvoiceId())
.makeRecurrent(payment.isMakeRecurrent())
.payer(getPayer(payment))
.shopID(payment.getShopId())
.shortID(payment.getShortId())
.transactionInfo(payment.getAdditionalTransactionInfo() != null
? new TransactionInfo()
.approvalCode(payment.getAdditionalTransactionInfo().getApprovalCode())
.rrn(payment.getAdditionalTransactionInfo().getRrn())
: null);
fillPaymentStatusInfo(payment, result);
results.add(result);
}
return new InlineResponse20010()
.result(results)
.continuationToken(magistaResponse.getContinuationToken());
return new AsyncResult<>(new InlineResponse20010()
.result(magistaResponse.getPayments().stream()
.map(paymentResponseConverter::convert)
.collect(Collectors.toList()))
.continuationToken(magistaResponse.getContinuationToken()));
}
@Async
@SneakyThrows
public InlineResponse2008 findChargebacks(ChargebackSearchQuery query) {
public Future<InlineResponse2008> findChargebacks(ChargebackSearchQuery query) {
StatChargebackResponse magistaResponse = magistaClient.searchChargebacks(query);
List<Chargeback> results = new ArrayList<>(magistaResponse.getChargebacksSize());
for (StatChargeback chargeback : magistaResponse.getChargebacks()) {
@ -78,14 +59,15 @@ public class SearchService {
.bodyCurrency(chargeback.getCurrencyCode().getSymbolicCode());
results.add(result);
}
return new InlineResponse2008()
return new AsyncResult<>(new InlineResponse2008()
.result(results)
.continuationToken(magistaResponse.getContinuationToken());
.continuationToken(magistaResponse.getContinuationToken()));
}
@Async
@SneakyThrows
public InlineResponse2009 findInvoices(InvoiceSearchQuery query) {
public Future<InlineResponse2009> findInvoices(InvoiceSearchQuery query) {
StatInvoiceResponse magistaResponse = magistaClient.searchInvoices(query);
List<Invoice> results = new ArrayList<>(magistaResponse.getInvoicesSize());
for (StatInvoice invoice : magistaResponse.getInvoices()) {
@ -110,13 +92,14 @@ public class SearchService {
.status(OpenApiUtil.mapToInvoiceStatus(invoice.getStatus()));
results.add(result);
}
return new InlineResponse2009()
return new AsyncResult<>(new InlineResponse2009()
.result(results)
.continuationToken(magistaResponse.getContinuationToken());
.continuationToken(magistaResponse.getContinuationToken()));
}
@Async
@SneakyThrows
public InlineResponse20011 findPayouts(PayoutSearchQuery query) {
public Future<InlineResponse20011> findPayouts(PayoutSearchQuery query) {
StatPayoutResponse magistaResponse = magistaClient.searchPayouts(query);
List<Payout> results = new ArrayList<>(magistaResponse.getPayoutsSize());
for (StatPayout payout : magistaResponse.getPayouts()) {
@ -134,13 +117,14 @@ public class SearchService {
null);
results.add(result);
}
return new InlineResponse20011()
return new AsyncResult<>(new InlineResponse20011()
.result(results)
.continuationToken(magistaResponse.getContinuationToken());
.continuationToken(magistaResponse.getContinuationToken()));
}
@Async
@SneakyThrows
public InlineResponse20012 findRefunds(RefundSearchQuery query) {
public Future<InlineResponse20012> findRefunds(RefundSearchQuery query) {
StatRefundResponse magistaResponse = magistaClient.searchRefunds(query);
List<RefundSearchResult> results = new ArrayList<>(magistaResponse.getRefundsSize());
for (StatRefund refund : magistaResponse.getRefunds()) {
@ -163,9 +147,9 @@ public class SearchService {
.reason(refund.getReason());
results.add(result);
}
return new InlineResponse20012()
return new AsyncResult<>(new InlineResponse20012()
.result(results)
.continuationToken(magistaResponse.getContinuationToken());
.continuationToken(magistaResponse.getContinuationToken()));
}
}

View File

@ -3,12 +3,19 @@ package com.rbkmoney.anapi.v2.util;
import lombok.experimental.UtilityClass;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
@UtilityClass
public class CommonUtil {
private static final Pattern deadlinePattern = Pattern.compile("\\d+(?:\\.\\d+)?(?:ms|s|m)");
public static List<String> merge(@Nullable String id, @Nullable List<String> ids) {
if (id != null) {
if (ids == null) {
@ -19,4 +26,20 @@ public class CommonUtil {
return ids;
}
public static long getRequestDeadlineMillis(@NotNull String requestDeadLine) {
if (deadlinePattern.matcher(requestDeadLine).matches()) {
//150000ms, 540s, 3.5m, etc
if (requestDeadLine.endsWith("ms")) {
return Long.parseLong(requestDeadLine.substring(0, requestDeadLine.length() - 3));
}
String duration = "PT" + requestDeadLine.toUpperCase();
return Duration.parse(duration).toMillis();
}
//ISO 8601
OffsetDateTime odt = OffsetDateTime.parse(requestDeadLine);
return odt.toInstant().toEpochMilli() - Instant.now().toEpochMilli();
}
}

View File

@ -1,5 +1,6 @@
package com.rbkmoney.anapi.v2.util;
import com.rbkmoney.anapi.v2.exception.BadRequestException;
import com.rbkmoney.damsel.domain.*;
import com.rbkmoney.geck.common.util.TypeUtil;
import com.rbkmoney.magista.CommonSearchQueryParams;
@ -17,7 +18,7 @@ public class DamselUtil {
switch (paymentMethod) {
case "bankCard" -> paymentTool.setBankCard(new BankCard());
case "paymentTerminal" -> paymentTool.setPaymentTerminal(new PaymentTerminal());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Payment method %s cannot be processed", paymentMethod));
}
@ -29,7 +30,7 @@ public class DamselUtil {
switch (paymentFlow) {
case "instant" -> invoicePaymentFlow.setInstant(new InvoicePaymentFlowInstant());
case "hold" -> invoicePaymentFlow.setHold(new InvoicePaymentFlowHold());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Payment flow %s cannot be processed", paymentFlow));
}
return invoicePaymentFlow;
@ -58,7 +59,7 @@ public class DamselUtil {
case CANCELLED -> invoicePaymentStatus.setCancelled(new InvoicePaymentCancelled());
case REFUNDED -> invoicePaymentStatus.setRefunded(new InvoicePaymentRefunded());
case FAILED -> invoicePaymentStatus.setFailed(new InvoicePaymentFailed());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Payment status %s cannot be processed", paymentStatus));
}
return invoicePaymentStatus;
@ -71,7 +72,7 @@ public class DamselUtil {
case CHARGEBACK -> damselStage.setChargeback(new InvoicePaymentChargebackStageChargeback());
case PRE_ARBITRATION -> damselStage.setPreArbitration(new InvoicePaymentChargebackStagePreArbitration());
case ARBITRATION -> damselStage.setArbitration(new InvoicePaymentChargebackStageArbitration());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Chargeback stage %s cannot be processed", chargebackStage));
}
@ -86,7 +87,7 @@ public class DamselUtil {
case ACCEPTED -> damselStatus.setAccepted(new InvoicePaymentChargebackAccepted());
case REJECTED -> damselStatus.setRejected(new InvoicePaymentChargebackRejected());
case CANCELLED -> damselStatus.setCancelled(new InvoicePaymentChargebackCancelled());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Chargeback status %s cannot be processed", chargebackStatus));
}
@ -103,7 +104,7 @@ public class DamselUtil {
.setAuthorisation(new InvoicePaymentChargebackCategoryAuthorisation());
case PROCESSING_ERROR -> damselCategory
.setProcessingError(new InvoicePaymentChargebackCategoryProcessingError());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Chargeback category %s cannot be processed", chargebackCategory));
}
@ -118,7 +119,7 @@ public class DamselUtil {
case "Wallet" -> payoutToolInfo.setWalletInfo(new WalletInfo());
case "PaymentInstitutionAccount" -> payoutToolInfo
.setPaymentInstitutionAccount(new PaymentInstitutionAccount());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("PayoutToolType %s cannot be processed", payoutToolType));
}
@ -131,7 +132,7 @@ public class DamselUtil {
case PENDING -> invoicePaymentRefundStatus.setPending(new InvoicePaymentRefundPending());
case SUCCEEDED -> invoicePaymentRefundStatus.setSucceeded(new InvoicePaymentRefundSucceeded());
case FAILED -> invoicePaymentRefundStatus.setFailed(new InvoicePaymentRefundFailed());
default -> throw new IllegalArgumentException(
default -> throw new BadRequestException(
String.format("Refund status %s cannot be processed", refundStatus));
}
return invoicePaymentRefundStatus;