From bbe9102c789902cfad202abec8fb73fae749ff6b Mon Sep 17 00:00:00 2001 From: Anatoly Cherkasov Date: Fri, 13 Mar 2020 12:09:36 +0300 Subject: [PATCH] PROX-393: more actions for p2p (#64) * PROX-393: more actions for p2p --- pom.xml | 26 +-- .../configuration/CardListConfiguration.java | 2 +- .../MobilePhoneConfiguration.java | 2 +- .../properties/AdapterMockBankProperties.java | 3 + .../controller/MocketBankController.java | 26 ++- .../decorator/MobileServerHandlerLog.java | 4 +- .../decorator/P2pServerHandlerLog.java | 2 +- .../decorator/PaymentServerHandlerLog.java | 4 +- .../decorator/TerminalServerHandlerLog.java | 4 +- .../payment/ProcessedMobileCommonHandler.java | 6 +- .../handler/oct/OctServerHandler.java | 4 +- .../handler/p2p/P2pServerHandler.java | 20 ++- .../p2p/callback/P2pCallbackHandler.java | 66 ++++++++ .../p2p/payment/ProcessedP2pHandler.java | 111 +++++++++++++ .../callback/PaymentCallbackHandler.java | 6 +- .../RecurrentTokenCallbackHandler.java | 2 +- .../common/ProcessedCommonPaymentHandler.java | 15 +- .../recurrent/GenerateTokenHandler.java | 6 +- ...rocessedRecurrentCommonPaymentHandler.java | 4 +- .../ProcessedTerminalCommonHandler.java | 4 +- .../service/bank/constant/CustomError.java | 9 -- .../oct/constant/CryptoCurrencies.java | 4 +- .../verification/CurrencyVerification.java} | 6 +- .../proxy/mocketbank/utils/Converter.java | 2 +- .../proxy/mocketbank/utils/CreatorUtils.java | 26 +++ .../proxy/mocketbank/utils/ErrorBuilder.java | 25 +++ .../utils/converter/PaymentResourceType.java | 12 -- .../PaymentResourceTypeResolver.java | 26 --- .../utils/creator/P2pAdapterCreator.java | 24 --- .../utils/creator/ProxyProviderCreator.java | 25 --- .../extractor/p2p/P2pAdapterExtractors.java | 18 --- .../proxy/ProxyProviderPackageExtractors.java | 52 ------ .../utils/mobilephone/MobilePhoneAction.java | 12 +- .../mocketbank/utils/model/CardAction.java | 83 +++++++++- .../{extractor => reader}/BeanReader.java | 2 +- .../{extractor => reader}/CardReader.java | 2 +- .../MobilePhoneReader.java | 2 +- .../utils/state/constant/SuspendPrefix.java | 3 +- .../mocketbank/validator/MobileValidator.java | 2 +- .../validator/PaymentValidator.java | 2 +- .../validator/TerminalValidator.java | 2 +- .../validator/WithdrawalValidator.java | 8 +- src/main/resources/application.yml | 7 + .../configuration/DeadlineTest.java | 124 -------------- .../ExternalPortRestrictingTest.java | 50 ------ .../configuration/TestBankController.java | 22 --- .../mocketbank/handler/IntegrationTest.java | 17 +- ...tBankServerHandlerFailIntegrationTest.java | 25 +-- ...rverHandlerFailWith3DSIntegrationTest.java | 25 ++- ...lerRecurrent3DSSuccessIntegrationTest.java | 18 +-- ...andlerRecurrentSuccessIntegrationTest.java | 16 +- ...rHandlerSuccessApplePayntegrationTest.java | 15 +- ...andlerSuccessGooglePayIntegrationTest.java | 17 +- ...nkServerHandlerSuccessIntegrationTest.java | 20 +-- ...ndlerSuccessSamsungPayIntegrationTest.java | 15 +- ...rHandlerSuccessWith3DSIntegrationTest.java | 22 ++- .../handler/oct/OctIntegrationTest.java | 79 +++++++++ .../handler/oct/OctServerHandlerTest.java | 73 +-------- .../handler/p2p/P2PIntegrationTest.java | 152 ++++++++++++++++++ .../p2p/P2pServerHandlerFail3dsTest.java | 66 ++++++++ .../P2pServerHandlerFail3dsTimeoutTest.java | 56 +++++++ .../handler/p2p/P2pServerHandlerFailTest.java | 46 ++++++ .../p2p/P2pServerHandlerSuccess3dsTest.java | 66 ++++++++ .../p2p/P2pServerHandlerSuccessTest.java | 46 ++++++ .../handler/p2p/P2pServerHandlerTest.java | 41 ----- .../proxy/mocketbank/utils/CardListUtils.java | 21 +++ .../utils/constant/testcards/Maestro.java | 12 -- .../utils/constant/testcards/Mastercard.java | 24 --- .../utils/constant/testcards/Mir.java | 12 -- .../utils/constant/testcards/TestCard.java | 5 - .../utils/constant/testcards/Visa.java | 22 --- .../utils/p2p/constant/P2pConstant.java | 12 -- .../utils/p2p/creator/P2pCreator.java | 79 --------- .../p2p/verification/P2pVerification.java | 13 -- 74 files changed, 1031 insertions(+), 851 deletions(-) create mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/callback/P2pCallbackHandler.java create mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/payment/ProcessedP2pHandler.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/service/bank/constant/CustomError.java rename src/main/java/com/rbkmoney/proxy/mocketbank/{handler => service}/oct/constant/CryptoCurrencies.java (92%) rename src/main/java/com/rbkmoney/proxy/mocketbank/{handler/oct/converter/CurrencyConverter.java => service/oct/verification/CurrencyVerification.java} (88%) create mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/CreatorUtils.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceType.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceTypeResolver.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/P2pAdapterCreator.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/ProxyProviderCreator.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/p2p/P2pAdapterExtractors.java delete mode 100644 src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/proxy/ProxyProviderPackageExtractors.java rename src/main/java/com/rbkmoney/proxy/mocketbank/utils/{extractor => reader}/BeanReader.java (90%) rename src/main/java/com/rbkmoney/proxy/mocketbank/utils/{extractor => reader}/CardReader.java (90%) rename src/main/java/com/rbkmoney/proxy/mocketbank/utils/{extractor => reader}/MobilePhoneReader.java (91%) delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/configuration/DeadlineTest.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/configuration/ExternalPortRestrictingTest.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/configuration/TestBankController.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctIntegrationTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2PIntegrationTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTimeoutTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFailTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccess3dsTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccessTest.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerTest.java create mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/CardListUtils.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Maestro.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mastercard.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mir.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/TestCard.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Visa.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/constant/P2pConstant.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/creator/P2pCreator.java delete mode 100644 src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/verification/P2pVerification.java diff --git a/pom.xml b/pom.xml index fe94360..f5ec369 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,8 @@ bc95d0d6dc13c693acd2b274531a7d604b877bf3 dr2.rbkmoney.com 0.3.6 - 2.1.18 + 2.1.19 + 1.0.0 @@ -66,24 +67,29 @@ 1.1.0 - com.rbkmoney.proxy-libs + com.rbkmoney.adapter-client-lib hellgate-adapter-client - ${proxy-libs.version} + ${adapter-client-lib.version} - com.rbkmoney.proxy-libs + com.rbkmoney.adapter-client-lib cds-client-storage - ${proxy-libs.version} + ${adapter-client-lib.version} - com.rbkmoney.proxy-libs + com.rbkmoney.adapter-client-lib cds-client-identity-document-storage - ${proxy-libs.version} + ${adapter-client-lib.version} - com.rbkmoney + com.rbkmoney.adapter-client-lib + fistful-client + ${adapter-client-lib.version} + + + com.rbkmoney.adapter-thrift-lib damsel-utils - ${proxy-libs.version} + ${adapter-thrift-lib.version} org.projectlombok @@ -98,7 +104,7 @@ com.rbkmoney damsel - 1.388-e76b0f7 + 1.391-8fe5f98 com.rbkmoney diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/CardListConfiguration.java b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/CardListConfiguration.java index 57e5693..c0624d1 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/CardListConfiguration.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/CardListConfiguration.java @@ -1,6 +1,6 @@ package com.rbkmoney.proxy.mocketbank.configuration; -import com.rbkmoney.proxy.mocketbank.utils.extractor.CardReader; +import com.rbkmoney.proxy.mocketbank.utils.reader.CardReader; import com.rbkmoney.proxy.mocketbank.utils.model.Card; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/MobilePhoneConfiguration.java b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/MobilePhoneConfiguration.java index 7264c21..7f8abaa 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/MobilePhoneConfiguration.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/MobilePhoneConfiguration.java @@ -1,6 +1,6 @@ package com.rbkmoney.proxy.mocketbank.configuration; -import com.rbkmoney.proxy.mocketbank.utils.extractor.MobilePhoneReader; +import com.rbkmoney.proxy.mocketbank.utils.reader.MobilePhoneReader; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhone; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/properties/AdapterMockBankProperties.java b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/properties/AdapterMockBankProperties.java index de8265c..6710fb9 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/properties/AdapterMockBankProperties.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/configuration/properties/AdapterMockBankProperties.java @@ -24,4 +24,7 @@ public class AdapterMockBankProperties { @NotEmpty private String pathRecurrentCallbackUrl; + @NotEmpty + private String pathP2pCallbackUrl; + } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/controller/MocketBankController.java b/src/main/java/com/rbkmoney/proxy/mocketbank/controller/MocketBankController.java index 64782f4..d72f2bf 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/controller/MocketBankController.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/controller/MocketBankController.java @@ -3,6 +3,9 @@ package com.rbkmoney.proxy.mocketbank.controller; import com.fasterxml.jackson.core.JsonProcessingException; import com.rbkmoney.adapter.helpers.hellgate.HellgateAdapterClient; import com.rbkmoney.adapter.helpers.hellgate.exception.HellgateException; +import com.rbkmoney.damsel.p2p_adapter.Callback; +import com.rbkmoney.damsel.p2p_adapter.ProcessCallbackResult; +import com.rbkmoney.fistful.client.FistfulClient; import com.rbkmoney.java.damsel.converter.CommonConverter; import com.rbkmoney.proxy.mocketbank.utils.state.constant.SuspendPrefix; import lombok.RequiredArgsConstructor; @@ -29,6 +32,7 @@ import java.util.stream.Collectors; public class MocketBankController { private final HellgateAdapterClient hellgateClient; + private final FistfulClient fistfulClient; @RequestMapping(value = "term_url", method = RequestMethod.POST) public String receiveIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { @@ -48,7 +52,6 @@ public class MocketBankController { return resp; } - @RequestMapping(value = "/rec_term_url", method = RequestMethod.POST) public String receiveRecurrentIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { String tag = SuspendPrefix.RECURRENT + getTag(request); @@ -67,6 +70,27 @@ public class MocketBankController { return resp; } + @RequestMapping(value = "/p2p", method = RequestMethod.POST) + public String receiveP2pIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { + String tag = SuspendPrefix.P2P + getTag(request); + log.info("receiveP2pIncomingParameters with tag {}, info {}", tag, httpServletRequestToString(request)); + String resp = ""; + try { + ByteBuffer callbackParams = prepareCallbackParams(request); + Callback callback = new Callback(); + callback.setTag(tag); + callback.setPayload(callbackParams); + ProcessCallbackResult result = fistfulClient.processCallback(callback); + log.info("P2P Callback Result {}", result); + } catch (HellgateException e) { + log.warn("Failed handle callback for p2p", e); + } catch (Exception e) { + log.error("Failed handle callback for p2p", e); + } + sendRedirect(request, servletResponse); + return resp; + } + private String getTag(HttpServletRequest request) { if (StringUtils.hasText(request.getParameter("MD"))) { return request.getParameter("MD"); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/MobileServerHandlerLog.java b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/MobileServerHandlerLog.java index bb68c70..f7971aa 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/MobileServerHandlerLog.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/MobileServerHandlerLog.java @@ -1,8 +1,8 @@ package com.rbkmoney.proxy.mocketbank.decorator; import com.rbkmoney.damsel.proxy_provider.*; +import com.rbkmoney.java.damsel.utils.extractors.PaymentResourceTypeExtractors; import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; -import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; @@ -43,7 +43,7 @@ public class MobileServerHandlerLog implements ProviderProxySrv.Iface { public PaymentProxyResult processPayment(PaymentContext context) throws TException { String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(context); - String paymentResourceType = PaymentResourceTypeResolver.extractPaymentResourceType(context); + String paymentResourceType = PaymentResourceTypeExtractors.extractPaymentResourceType(context); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId); try { PaymentProxyResult proxyResult = handler.processPayment(context); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/P2pServerHandlerLog.java b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/P2pServerHandlerLog.java index 759cf8b..c67c117 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/P2pServerHandlerLog.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/P2pServerHandlerLog.java @@ -1,7 +1,7 @@ package com.rbkmoney.proxy.mocketbank.decorator; import com.rbkmoney.damsel.p2p_adapter.*; -import com.rbkmoney.proxy.mocketbank.utils.extractor.p2p.P2pAdapterExtractors; +import com.rbkmoney.java.damsel.utils.extractors.P2pAdapterExtractors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/PaymentServerHandlerLog.java b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/PaymentServerHandlerLog.java index 16198dd..6841ab4 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/PaymentServerHandlerLog.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/PaymentServerHandlerLog.java @@ -1,8 +1,8 @@ package com.rbkmoney.proxy.mocketbank.decorator; import com.rbkmoney.damsel.proxy_provider.*; +import com.rbkmoney.java.damsel.utils.extractors.PaymentResourceTypeExtractors; import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; -import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; @@ -43,7 +43,7 @@ public class PaymentServerHandlerLog implements ProviderProxySrv.Iface { public PaymentProxyResult processPayment(PaymentContext context) throws TException { String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(context); - String paymentResourceType = PaymentResourceTypeResolver.extractPaymentResourceType(context); + String paymentResourceType = PaymentResourceTypeExtractors.extractPaymentResourceType(context); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId); try { PaymentProxyResult proxyResult = handler.processPayment(context); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/TerminalServerHandlerLog.java b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/TerminalServerHandlerLog.java index fe73fb4..15eb828 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/TerminalServerHandlerLog.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/decorator/TerminalServerHandlerLog.java @@ -1,8 +1,8 @@ package com.rbkmoney.proxy.mocketbank.decorator; import com.rbkmoney.damsel.proxy_provider.*; +import com.rbkmoney.java.damsel.utils.extractors.PaymentResourceTypeExtractors; import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; -import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; @@ -43,7 +43,7 @@ public class TerminalServerHandlerLog implements ProviderProxySrv.Iface { public PaymentProxyResult processPayment(PaymentContext context) throws TException { String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(context); - String paymentResourceType = PaymentResourceTypeResolver.extractPaymentResourceType(context); + String paymentResourceType = PaymentResourceTypeExtractors.extractPaymentResourceType(context); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId); try { PaymentProxyResult proxyResult = handler.processPayment(context); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/mobile/payment/ProcessedMobileCommonHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/mobile/payment/ProcessedMobileCommonHandler.java index b754592..7cb428a 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/mobile/payment/ProcessedMobileCommonHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/mobile/payment/ProcessedMobileCommonHandler.java @@ -8,9 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.java.damsel.constant.PaymentState; -import com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator; -import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors; +import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; import com.rbkmoney.proxy.mocketbank.handler.mobile.CommonMobileHandler; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhone; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneAction; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneUtils; @@ -55,7 +55,7 @@ public class ProcessedMobileCommonHandler implements CommonMobileHandler { return createProxyResultFailure(errorMapping.mapFailure(error, error)); } - TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo); } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandler.java index f5dd66d..3cc059c 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandler.java @@ -5,7 +5,7 @@ import com.rbkmoney.damsel.msgpack.Value; import com.rbkmoney.damsel.withdrawals.provider_adapter.*; import com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators; import com.rbkmoney.java.damsel.utils.creators.WithdrawalsProviderAdapterPackageCreators; -import com.rbkmoney.proxy.mocketbank.handler.oct.converter.CurrencyConverter; +import com.rbkmoney.proxy.mocketbank.service.oct.verification.CurrencyVerification; import com.rbkmoney.proxy.mocketbank.validator.WithdrawalValidator; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -37,7 +37,7 @@ public class OctServerHandler implements AdapterSrv.Iface { Cash cashFrom = new Cash().setCurrency(getQuoteParams.getCurrencyFrom()); Cash cashTo = new Cash().setCurrency(getQuoteParams.getCurrencyTo()); - if (CurrencyConverter.isCryptoCurrency(getQuoteParams.getCurrencyTo())) { + if (CurrencyVerification.isCryptoCurrency(getQuoteParams.getCurrencyTo())) { cashFrom.setAmount(getQuoteParams.getExchangeCash().getAmount()); cashTo.setAmount(getQuoteParams.getExchangeCash().getAmount() * 2); } else { diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandler.java index 33fd850..32d050b 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandler.java @@ -1,30 +1,28 @@ package com.rbkmoney.proxy.mocketbank.handler.p2p; import com.rbkmoney.damsel.p2p_adapter.*; -import com.rbkmoney.proxy.mocketbank.utils.creator.P2pAdapterCreator; -import com.rbkmoney.proxy.mocketbank.exception.UnsupportedOperationException; +import com.rbkmoney.proxy.mocketbank.handler.p2p.callback.P2pCallbackHandler; +import com.rbkmoney.proxy.mocketbank.handler.p2p.payment.ProcessedP2pHandler; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.springframework.stereotype.Component; -import java.util.Collections; - -import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTransactionInfo; - @Slf4j @Component +@RequiredArgsConstructor public class P2pServerHandler implements P2PAdapterSrv.Iface { + private final P2pCallbackHandler p2pCallbackHandler; + private final ProcessedP2pHandler processedP2pHandler; + @Override public ProcessResult process(Context context) throws TException { - String transactionId = P2pAdapterCreator.createTransactionId(context); - return new ProcessResult() - .setIntent(P2pAdapterCreator.createFinishIntentSuccess()) - .setTrx(createTransactionInfo(transactionId, Collections.emptyMap())); + return processedP2pHandler.process(context); } @Override public CallbackResult handleCallback(Callback callback, Context context) throws TException { - throw new UnsupportedOperationException("P2pHandler handleCallback not supported!"); + return p2pCallbackHandler.handleCallback(callback, context); } } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/callback/P2pCallbackHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/callback/P2pCallbackHandler.java new file mode 100644 index 0000000..6a76ad9 --- /dev/null +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/callback/P2pCallbackHandler.java @@ -0,0 +1,66 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p.callback; + +import com.rbkmoney.cds.client.storage.CdsClientStorage; +import com.rbkmoney.cds.client.storage.model.CardDataProxyModel; +import com.rbkmoney.cds.client.storage.utils.BankCardExtractor; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.domain.TransactionInfo; +import com.rbkmoney.damsel.p2p_adapter.Callback; +import com.rbkmoney.damsel.p2p_adapter.CallbackResult; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.error.mapping.ErrorMapping; +import com.rbkmoney.java.damsel.constant.PaymentState; +import com.rbkmoney.java.damsel.utils.creators.P2pAdapterCreators; +import com.rbkmoney.java.damsel.utils.extractors.P2pAdapterExtractors; +import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; +import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; +import com.rbkmoney.proxy.mocketbank.utils.Converter; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; +import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; +import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.List; + +import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; +import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus.isAuthenticationSuccessful; + +@Slf4j +@Component +@RequiredArgsConstructor +public class P2pCallbackHandler { + + private final CdsClientStorage cds; + private final MpiApi mpiApi; + private final ErrorMapping errorMapping; + private final List cardList; + + public CallbackResult handleCallback(Callback callback, Context context) { + HashMap parameters = Converter.mergeParams(ByteBuffer.wrap(callback.getPayload()), context.getSession().getState()); + + BankCard bankCard = P2pAdapterExtractors.extractBankCardSender(context); + CardData cardData = cds.getCardData(bankCard.getToken()); + CardDataProxyModel cardDataProxyModel = BankCardExtractor.initCardDataProxyModel(bankCard, cardData); + + ValidatePaResResponse validatePaResResponse = mpiApi.validatePaRes(cardDataProxyModel, parameters); + if (isAuthenticationSuccessful(validatePaResResponse.getTransactionStatus())) { + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); + return P2pAdapterCreators.createP2pCallbackResult( + P2pAdapterCreators.createFinishIntentSuccess(), + PaymentState.CAPTURED.getBytes(), + transactionInfo + ); + } + + CardAction action = CardUtils.extractActionFromCard(cardList, cardDataProxyModel); + return ErrorBuilder.prepareP2pCallbackResultFailure(errorMapping, DEFAULT_ERROR_CODE, action); + } + +} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/payment/ProcessedP2pHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/payment/ProcessedP2pHandler.java new file mode 100644 index 0000000..f35c0af --- /dev/null +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/p2p/payment/ProcessedP2pHandler.java @@ -0,0 +1,111 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p.payment; + +import com.rbkmoney.cds.client.storage.CdsClientStorage; +import com.rbkmoney.cds.client.storage.model.CardDataProxyModel; +import com.rbkmoney.cds.client.storage.utils.BankCardExtractor; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.domain.TransactionInfo; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.error.mapping.ErrorMapping; +import com.rbkmoney.java.damsel.constant.PaymentState; +import com.rbkmoney.java.damsel.utils.creators.P2pAdapterCreators; +import com.rbkmoney.java.damsel.utils.extractors.P2pAdapterExtractors; +import com.rbkmoney.proxy.mocketbank.configuration.properties.AdapterMockBankProperties; +import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties; +import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; +import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; +import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; +import com.rbkmoney.proxy.mocketbank.utils.UrlUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; +import com.rbkmoney.proxy.mocketbank.utils.state.StateUtils; +import com.rbkmoney.proxy.mocketbank.utils.state.constant.SuspendPrefix; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.thrift.TException; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; +import static com.rbkmoney.java.damsel.constant.Error.THREE_DS_NOT_FINISHED; +import static com.rbkmoney.java.damsel.utils.extractors.OptionsExtractors.extractRedirectTimeout; +import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus.isAuthenticationAvailable; +import static com.rbkmoney.proxy.mocketbank.utils.UrlUtils.prepareRedirectParams; +import static com.rbkmoney.proxy.mocketbank.utils.model.CardAction.*; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ProcessedP2pHandler { + + private final CdsClientStorage cds; + private final MpiApi mpiApi; + private final ErrorMapping errorMapping; + private final List cardList; + private final TimerProperties timerProperties; + private final AdapterMockBankProperties mockBankProperties; + + public ProcessResult process(Context context) throws TException { + byte[] state = context.getSession().getState(); + if (state != null && state.length > 0) { + return ErrorBuilder.prepareP2pError(errorMapping, DEFAULT_ERROR_CODE, THREE_DS_NOT_FINISHED); + } + + BankCard bankCard = P2pAdapterExtractors.extractBankCardSender(context); + CardData cardData = cds.getCardData(bankCard.getToken()); + CardDataProxyModel cardDataProxyModel = BankCardExtractor.initCardDataProxyModel(bankCard, cardData); + + Optional card = CardUtils.extractCardByPan(cardList, cardData.getPan()); + if (card.isPresent()) { + com.rbkmoney.damsel.p2p_adapter.Intent intent = P2pAdapterCreators.createFinishIntentSuccess(); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); + CardAction action = CardAction.findByValue(card.get().getAction()); + if (CardAction.isCardEnrolled(card.get())) { + return prepareEnrolledP2pResult(context, intent, transactionInfo, cardDataProxyModel); + } + return prepareNotEnrolledP2pResult(intent, transactionInfo, action); + } + return ErrorBuilder.prepareP2pError(errorMapping, UNSUPPORTED_CARD); + } + + private ProcessResult prepareNotEnrolledP2pResult(com.rbkmoney.damsel.p2p_adapter.Intent intent, TransactionInfo transactionInfo, CardAction action) { + if (isCardSuccess(action)) { + return P2pAdapterCreators.createP2pResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo); + } + CardAction currentAction = isCardFailed(action) ? action : UNKNOWN_FAILURE; + return ErrorBuilder.prepareP2pError(errorMapping, currentAction); + } + + private ProcessResult prepareEnrolledP2pResult(Context context, com.rbkmoney.damsel.p2p_adapter.Intent intent, TransactionInfo transactionInfo, CardDataProxyModel cardData) { + com.rbkmoney.damsel.p2p_adapter.Intent currentIntent = intent; + VerifyEnrollmentResponse verifyEnrollmentResponse = mpiApi.verifyEnrollment(cardData); + if (isAuthenticationAvailable(verifyEnrollmentResponse.getEnrolled())) { + String tag = SuspendPrefix.P2P.getPrefix() + P2pAdapterCreators.createTransactionId(context); + String termUrl = UrlUtils.getCallbackUrl(mockBankProperties.getCallbackUrl(), mockBankProperties.getPathP2pCallbackUrl()); + currentIntent = prepareRedirect(context, verifyEnrollmentResponse, tag, termUrl); + } + byte[] state = StateUtils.prepareState(verifyEnrollmentResponse); + return P2pAdapterCreators.createP2pResult(currentIntent, state, transactionInfo); + } + + private com.rbkmoney.damsel.p2p_adapter.Intent prepareRedirect(Context context, VerifyEnrollmentResponse verifyEnrollmentResponse, String tag, String termUrl) { + String url = verifyEnrollmentResponse.getAcsUrl(); + Map params = prepareRedirectParams(verifyEnrollmentResponse, tag, termUrl); + Map options = context.getOptions(); + int timerRedirectTimeout = extractRedirectTimeout(options, timerProperties.getRedirectTimeout()); + String userInteractionID = P2pAdapterExtractors.extractSessionId(context); + + return P2pAdapterCreators.createIntentWithSleepIntent( + timerRedirectTimeout, + P2pAdapterCreators.createPostUserInteraction(userInteractionID, url, params), + tag + ); + } +} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/PaymentCallbackHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/PaymentCallbackHandler.java index 3f809b6..7955fe0 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/PaymentCallbackHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/PaymentCallbackHandler.java @@ -10,11 +10,12 @@ import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.java.damsel.constant.Error; import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; -import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; import com.rbkmoney.proxy.mocketbank.utils.Converter; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,7 +26,6 @@ import java.util.HashMap; import java.util.List; import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.*; -import static com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator.createDefaultTransactionInfo; import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus.isAuthenticationSuccessful; @Slf4j @@ -43,7 +43,7 @@ public class PaymentCallbackHandler { CardDataProxyModel cardData = cds.getCardData(context); ValidatePaResResponse validatePaResResponse = mpiApi.validatePaRes(cardData, parameters); if (isAuthenticationSuccessful(validatePaResResponse.getTransactionStatus())) { - TransactionInfo transactionInfo = createDefaultTransactionInfo(context); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); PaymentCallbackProxyResult proxyResult = createCallbackProxyResult( createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo ); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/RecurrentTokenCallbackHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/RecurrentTokenCallbackHandler.java index 409f63f..16ca282 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/RecurrentTokenCallbackHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/callback/RecurrentTokenCallbackHandler.java @@ -10,11 +10,11 @@ import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.java.damsel.constant.Error; import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; -import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; import com.rbkmoney.proxy.mocketbank.utils.Converter; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/common/ProcessedCommonPaymentHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/common/ProcessedCommonPaymentHandler.java index 871c62d..c9647dc 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/common/ProcessedCommonPaymentHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/common/ProcessedCommonPaymentHandler.java @@ -13,16 +13,15 @@ import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.damsel.timeout_behaviour.TimeoutBehaviour; import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.java.damsel.constant.PaymentState; +import com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators; import com.rbkmoney.proxy.mocketbank.configuration.properties.AdapterMockBankProperties; import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties; import com.rbkmoney.proxy.mocketbank.handler.payment.CommonPaymentHandler; -import com.rbkmoney.proxy.mocketbank.service.bank.constant.CustomError; import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; -import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; import com.rbkmoney.proxy.mocketbank.utils.UrlUtils; -import com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator; import com.rbkmoney.proxy.mocketbank.utils.model.Card; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; @@ -38,14 +37,14 @@ import java.util.Map; import java.util.Optional; import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; +import static com.rbkmoney.java.damsel.constant.Error.THREE_DS_NOT_FINISHED; import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.*; import static com.rbkmoney.java.damsel.utils.extractors.OptionsExtractors.extractRedirectTimeout; import static com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors.extractInvoiceId; +import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.hasBankCardTokenProvider; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isMakeRecurrent; import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus.isAuthenticationAvailable; import static com.rbkmoney.proxy.mocketbank.utils.UrlUtils.prepareRedirectParams; -import static com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator.createDefaultTransactionInfo; -import static com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors.hasBankCardTokenProvider; import static com.rbkmoney.proxy.mocketbank.utils.model.CardAction.*; @Slf4j @@ -74,7 +73,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler { } // Applepay, Samsungpay, Googlepay - always successful and does not depends on card - TransactionInfo transactionInfo = createDefaultTransactionInfo(context); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); if (hasBankCardTokenProvider(context)) { return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo); } @@ -103,7 +102,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler { Intent currentIntent = intent; VerifyEnrollmentResponse verifyEnrollmentResponse = mpiApi.verifyEnrollment(cardData); if (isAuthenticationAvailable(verifyEnrollmentResponse.getEnrolled())) { - String tag = SuspendPrefix.PAYMENT.getPrefix() + ProxyProviderCreator.createTransactionId(context.getPaymentInfo()); + String tag = SuspendPrefix.PAYMENT.getPrefix() + ProxyProviderPackageCreators.createInvoiceWithPayment(context.getPaymentInfo()); String termUrl = UrlUtils.getCallbackUrl(mockBankProperties.getCallbackUrl(), mockBankProperties.getPathCallbackUrl()); currentIntent = prepareRedirect(context, verifyEnrollmentResponse, tag, termUrl); } @@ -120,7 +119,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler { Intent intent = createIntentWithSuspendIntent( tag, timerRedirectTimeout, createPostUserInteraction(url, params) ); - Failure failure = errorMapping.mapFailure(DEFAULT_ERROR_CODE, CustomError.THREE_DS_NOT_FINISHED); + Failure failure = errorMapping.mapFailure(DEFAULT_ERROR_CODE, THREE_DS_NOT_FINISHED); intent.getSuspend().setTimeoutBehaviour(TimeoutBehaviour.operation_failure(OperationFailure.failure(failure))); return intent; } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/GenerateTokenHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/GenerateTokenHandler.java index fc4fcc9..16d2b69 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/GenerateTokenHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/GenerateTokenHandler.java @@ -12,7 +12,6 @@ import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.proxy.mocketbank.configuration.properties.AdapterMockBankProperties; import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties; -import com.rbkmoney.proxy.mocketbank.service.bank.constant.CustomError; import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; @@ -31,12 +30,13 @@ import java.util.Map; import java.util.Optional; import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; +import static com.rbkmoney.java.damsel.constant.Error.THREE_DS_NOT_FINISHED; import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.*; import static com.rbkmoney.java.damsel.utils.extractors.OptionsExtractors.extractRedirectTimeout; import static com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors.extractRecurrentId; +import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.hasBankCardTokenProvider; import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus.isAuthenticationAvailable; import static com.rbkmoney.proxy.mocketbank.utils.UrlUtils.prepareRedirectParams; -import static com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors.hasBankCardTokenProvider; import static com.rbkmoney.proxy.mocketbank.utils.model.CardAction.*; @Slf4j @@ -101,7 +101,7 @@ public class GenerateTokenHandler { RecurrentTokenIntent recurrentTokenIntent = createRecurrentTokenWithSuspendIntent( tag, timerRedirectTimeout, createPostUserInteraction(url, params) ); - Failure failure = errorMapping.mapFailure(DEFAULT_ERROR_CODE, CustomError.THREE_DS_NOT_FINISHED); + Failure failure = errorMapping.mapFailure(DEFAULT_ERROR_CODE, THREE_DS_NOT_FINISHED); recurrentTokenIntent.getSuspend().setTimeoutBehaviour(TimeoutBehaviour.operation_failure(OperationFailure.failure(failure))); return recurrentTokenIntent; } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/ProcessedRecurrentCommonPaymentHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/ProcessedRecurrentCommonPaymentHandler.java index c81a6b4..5e02b5a 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/ProcessedRecurrentCommonPaymentHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/payment/recurrent/ProcessedRecurrentCommonPaymentHandler.java @@ -7,8 +7,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.java.damsel.constant.PaymentState; -import com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator; import com.rbkmoney.proxy.mocketbank.handler.payment.CommonPaymentHandler; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; @@ -36,7 +36,7 @@ public class ProcessedRecurrentCommonPaymentHandler implements CommonPaymentHand intent = createFinishIntentSuccessWithToken(invoiceId); } - TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo); } } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/terminal/payment/ProcessedTerminalCommonHandler.java b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/terminal/payment/ProcessedTerminalCommonHandler.java index 39f0aa9..6b2a1b8 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/terminal/payment/ProcessedTerminalCommonHandler.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/handler/terminal/payment/ProcessedTerminalCommonHandler.java @@ -6,8 +6,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.java.damsel.constant.PaymentState; -import com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator; import com.rbkmoney.proxy.mocketbank.handler.terminal.CommonTerminalHandler; +import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; @@ -28,7 +28,7 @@ public class ProcessedTerminalCommonHandler implements CommonTerminalHandler { @Override public PaymentProxyResult handler(PaymentContext context) throws TException { - TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); + TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context); return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo); } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/service/bank/constant/CustomError.java b/src/main/java/com/rbkmoney/proxy/mocketbank/service/bank/constant/CustomError.java deleted file mode 100644 index fc053a7..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/service/bank/constant/CustomError.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.service.bank.constant; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CustomError { - public static final String THREE_DS_NOT_FINISHED = "3DS_NOT_FINISHED"; -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/constant/CryptoCurrencies.java b/src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/constant/CryptoCurrencies.java similarity index 92% rename from src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/constant/CryptoCurrencies.java rename to src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/constant/CryptoCurrencies.java index 4ffc8a6..af3a056 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/constant/CryptoCurrencies.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/constant/CryptoCurrencies.java @@ -1,4 +1,4 @@ -package com.rbkmoney.proxy.mocketbank.handler.oct.constant; +package com.rbkmoney.proxy.mocketbank.service.oct.constant; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -16,7 +16,7 @@ public enum CryptoCurrencies { NAMECOIN("Namecoin", "NMC"), PEERCOIN("Peercoin", "PPC"), DOGECOIN("Dogecoin", "DOGE"), - DOGECOIN_XDG( "Dogecoin", "XDG"), + DOGECOIN_XDG("Dogecoin", "XDG"), GRIDCOIN("Gridcoin", "GRC"), PRIMECOIN("Primecoin", "XPM"), NXT("Nxt", "NXT"), diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/converter/CurrencyConverter.java b/src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/verification/CurrencyVerification.java similarity index 88% rename from src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/converter/CurrencyConverter.java rename to src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/verification/CurrencyVerification.java index deea30c..2c5fa84 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/handler/oct/converter/CurrencyConverter.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/service/oct/verification/CurrencyVerification.java @@ -1,14 +1,14 @@ -package com.rbkmoney.proxy.mocketbank.handler.oct.converter; +package com.rbkmoney.proxy.mocketbank.service.oct.verification; import com.rbkmoney.damsel.withdrawals.provider_adapter.GetQuoteParams; -import com.rbkmoney.proxy.mocketbank.handler.oct.constant.CryptoCurrencies; +import com.rbkmoney.proxy.mocketbank.service.oct.constant.CryptoCurrencies; import lombok.AccessLevel; import lombok.NoArgsConstructor; import java.util.Arrays; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CurrencyConverter { +public class CurrencyVerification { public static boolean isCryptoCurrency(com.rbkmoney.damsel.domain.Currency currency) { return Arrays.asList(CryptoCurrencies.toArraySymbol()).contains(currency.getSymbolicCode()); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/Converter.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/Converter.java index c1f0657..39da293 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/Converter.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/Converter.java @@ -15,7 +15,7 @@ import java.util.Map; public class Converter { public static Map byteBufferToMap(ByteBuffer byteBuffer) throws IOException { - return new ObjectMapper().readValue(new String(byteBuffer.array(), StandardCharsets.UTF_8), HashMap.class); + return new ObjectMapper().readValue(new String(byteBuffer.array(), StandardCharsets.UTF_8), HashMap.class); } public static ByteBuffer mapToByteBuffer(Map map) throws JsonProcessingException { diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/CreatorUtils.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/CreatorUtils.java new file mode 100644 index 0000000..15f0b84 --- /dev/null +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/CreatorUtils.java @@ -0,0 +1,26 @@ +package com.rbkmoney.proxy.mocketbank.utils; + +import com.rbkmoney.damsel.domain.TransactionInfo; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.proxy_provider.PaymentContext; +import com.rbkmoney.java.damsel.utils.creators.P2pAdapterCreators; +import com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Collections; + +import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTransactionInfo; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CreatorUtils { + + public static TransactionInfo createDefaultTransactionInfo(Context context) { + return createTransactionInfo(P2pAdapterCreators.createTransactionId(context), Collections.emptyMap()); + } + + public static TransactionInfo createDefaultTransactionInfo(PaymentContext context) { + return createTransactionInfo(ProxyProviderPackageCreators.createInvoiceWithPayment(context.getPaymentInfo()), Collections.emptyMap()); + } + +} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/ErrorBuilder.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/ErrorBuilder.java index 135655e..51558c5 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/ErrorBuilder.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/ErrorBuilder.java @@ -1,11 +1,14 @@ package com.rbkmoney.proxy.mocketbank.utils; import com.rbkmoney.damsel.domain.Failure; +import com.rbkmoney.damsel.p2p_adapter.CallbackResult; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; import com.rbkmoney.damsel.proxy_provider.PaymentCallbackResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenCallbackResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult; import com.rbkmoney.error.mapping.ErrorMapping; +import com.rbkmoney.java.damsel.utils.creators.P2pAdapterCreators; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -15,6 +18,19 @@ import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreato @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ErrorBuilder { + public static ProcessResult prepareP2pError(ErrorMapping errorMapping, String code, String message) { + Failure failure = errorMapping.mapFailure(code, message); + return P2pAdapterCreators.createP2pResultFailure(failure); + } + + public static ProcessResult prepareP2pError(ErrorMapping errorMapping, CardAction action) { + return prepareP2pError(errorMapping, action.getAction()); + } + + public static ProcessResult prepareP2pError(ErrorMapping errorMapping, String code) { + return prepareP2pError(errorMapping, code, code); + } + public static PaymentProxyResult prepareError(ErrorMapping errorMapping, String code, String message) { Failure failure = errorMapping.mapFailure(code, message); return createProxyResultFailure(failure); @@ -41,6 +57,15 @@ public class ErrorBuilder { return createRecurrentTokenProxyResultFailure(failure); } + public static CallbackResult prepareP2pCallbackError(ErrorMapping errorMapping, String code, String message) { + Failure failure = errorMapping.mapFailure(code, message); + return P2pAdapterCreators.createP2pCallbackResultFailure(failure); + } + + public static CallbackResult prepareP2pCallbackResultFailure(ErrorMapping errorMapping, String code, CardAction action) { + return prepareP2pCallbackError(errorMapping, code, action.getAction()); + } + public static PaymentCallbackResult prepareCallbackError(ErrorMapping errorMapping, String code, String message) { Failure failure = errorMapping.mapFailure(code, message); return createCallbackResultFailure(failure); diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceType.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceType.java deleted file mode 100644 index ab8cbe9..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceType.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.converter; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public enum PaymentResourceType { - RECURRENT, - PAYMENT -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceTypeResolver.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceTypeResolver.java deleted file mode 100644 index b7e545e..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/converter/PaymentResourceTypeResolver.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.converter; - -import com.rbkmoney.damsel.proxy_provider.PaymentContext; -import com.rbkmoney.damsel.proxy_provider.PaymentResource; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PaymentResourceTypeResolver { - - public static String extractPaymentResourceType(PaymentContext paymentContext) { - if (paymentContext == null) { - throw new IllegalArgumentException("PaymentContext cannot be empty"); - } else if (paymentContext.getSession() == null) { - throw new IllegalArgumentException("Payment context session cannot be empty"); - } - return extractPaymentResourceType(paymentContext.getPaymentInfo().getPayment().getPaymentResource()); - } - - private static String extractPaymentResourceType(PaymentResource paymentResource) { - return (paymentResource.isSetRecurrentPaymentResource()) - ? PaymentResourceType.RECURRENT.name() - : PaymentResourceType.PAYMENT.name(); - } - -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/P2pAdapterCreator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/P2pAdapterCreator.java deleted file mode 100644 index 948bb08..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/P2pAdapterCreator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.creator; - -import com.rbkmoney.damsel.p2p_adapter.*; -import com.rbkmoney.proxy.mocketbank.utils.extractor.p2p.P2pAdapterExtractors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class P2pAdapterCreator { - - public static final String DELIMITER = "."; - - public static String createTransactionId(Context context) { - String operationId = P2pAdapterExtractors.extractOperationId(context); - String sessionId = P2pAdapterExtractors.extractSessionId(context); - return sessionId + DELIMITER + operationId; - } - - public static Intent createFinishIntentSuccess() { - FinishIntent finishIntent = new FinishIntent().setStatus(FinishStatus.success(new Success())); - return Intent.finish(finishIntent); - } - -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/ProxyProviderCreator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/ProxyProviderCreator.java deleted file mode 100644 index f3f4a53..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/creator/ProxyProviderCreator.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.creator; - -import com.rbkmoney.damsel.domain.TransactionInfo; -import com.rbkmoney.damsel.proxy_provider.PaymentContext; -import com.rbkmoney.damsel.proxy_provider.PaymentInfo; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Collections; - -import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTransactionInfo; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ProxyProviderCreator { - - public static final String DELIMITER = "."; - - public static TransactionInfo createDefaultTransactionInfo(PaymentContext context) { - return createTransactionInfo(createTransactionId(context.getPaymentInfo()), Collections.emptyMap()); - } - - public static String createTransactionId(PaymentInfo payment) { - return payment.getInvoice().getId() + DELIMITER + payment.getPayment().getId(); - } -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/p2p/P2pAdapterExtractors.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/p2p/P2pAdapterExtractors.java deleted file mode 100644 index 2107efb..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/p2p/P2pAdapterExtractors.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.extractor.p2p; - -import com.rbkmoney.damsel.p2p_adapter.Context; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class P2pAdapterExtractors { - - public static String extractOperationId(Context context) { - return context.getOperation().getProcess().getId(); - } - - public static String extractSessionId(Context context) { - return context.getSession().getId(); - } - -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/proxy/ProxyProviderPackageExtractors.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/proxy/ProxyProviderPackageExtractors.java deleted file mode 100644 index 5b1bcda..0000000 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/proxy/ProxyProviderPackageExtractors.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.extractor.proxy; - -import com.rbkmoney.damsel.domain.BankCardTokenProvider; -import com.rbkmoney.damsel.domain.PaymentTool; -import com.rbkmoney.damsel.proxy_provider.PaymentContext; -import com.rbkmoney.damsel.proxy_provider.PaymentResource; -import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext; -import com.rbkmoney.proxy.mocketbank.exception.MobileException; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ProxyProviderPackageExtractors { - - public static PaymentTool extractPaymentTool(PaymentResource paymentResource) { - if (paymentResource.isSetDisposablePaymentResource()) { - return paymentResource.getDisposablePaymentResource().getPaymentTool(); - } else if (paymentResource.isSetRecurrentPaymentResource()) { - return paymentResource.getRecurrentPaymentResource().getPaymentTool(); - } - throw new MobileException("Unknown Payment Resource"); - } - - public static BankCardTokenProvider extractBankCardTokenProvider(PaymentContext context) { - PaymentResource paymentResource = context.getPaymentInfo().getPayment().getPaymentResource(); - if (paymentResource.isSetDisposablePaymentResource()) { - PaymentTool paymentTool = paymentResource.getDisposablePaymentResource().getPaymentTool(); - if (paymentTool.isSetBankCard() && paymentTool.getBankCard().isSetTokenProvider()) { - return paymentTool.getBankCard().getTokenProvider(); - } - } - return null; - } - - public static BankCardTokenProvider extractBankCardTokenProvider(RecurrentTokenContext context) { - PaymentTool paymentTool = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool(); - if (paymentTool.isSetBankCard() && paymentTool.getBankCard().isSetTokenProvider()) { - return paymentTool.getBankCard().getTokenProvider(); - } - return null; - } - - public static boolean hasBankCardTokenProvider(Object object) { - BankCardTokenProvider bankCardTokenProvider; - if (object instanceof RecurrentTokenContext) { - bankCardTokenProvider = extractBankCardTokenProvider((RecurrentTokenContext) object); - } else { - bankCardTokenProvider = extractBankCardTokenProvider((PaymentContext) object); - } - return (bankCardTokenProvider != null); - } -} diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/mobilephone/MobilePhoneAction.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/mobilephone/MobilePhoneAction.java index b68a9f0..2e8b066 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/mobilephone/MobilePhoneAction.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/mobilephone/MobilePhoneAction.java @@ -14,6 +14,10 @@ public enum MobilePhoneAction { UNSUPPORTED_PHONE("Unsupported phone"), INSUFFICIENT_FUNDS("Insufficient Funds"); + private static final MobilePhoneAction[] MOBILE_PHONE_FAILED = { + UNKNOWN, UNSUPPORTED_PHONE, INSUFFICIENT_FUNDS + }; + private final String action; public static MobilePhoneAction findByValue(String value) { @@ -23,18 +27,12 @@ public enum MobilePhoneAction { .orElse(UNKNOWN); } - public static MobilePhoneAction[] failedActions() { - return new MobilePhoneAction[]{ - UNKNOWN, UNSUPPORTED_PHONE, INSUFFICIENT_FUNDS - }; - } - public static boolean hasStatus(MobilePhoneAction[] actions, String value) { return Arrays.stream(actions).anyMatch(action -> action.getAction().equalsIgnoreCase(value)); } public static boolean isFailedAction(String action) { - return hasStatus(failedActions(), action); + return hasStatus(MOBILE_PHONE_FAILED, action); } } \ No newline at end of file diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/model/CardAction.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/model/CardAction.java index 75cac7d..94fc38d 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/model/CardAction.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/model/CardAction.java @@ -51,10 +51,29 @@ public enum CardAction { SAMSUNG_PAY_SUCCESS }; + private static final CardAction[] SUCCESS_CARDS_APPLE_PAY = { + APPLE_PAY_SUCCESS, + }; + + private static final CardAction[] SUCCESS_CARDS_GOOGLE_PAY = { + GOOGLE_PAY_SUCCESS, + }; + + private static final CardAction[] SUCCESS_CARDS_SAMSUNG_PAY = { + SAMSUNG_PAY_SUCCESS + }; + private static final CardAction[] MPI_FAILED_CARDS = { FAILURE_3DS, - TIMEOUT_3DS, - UNKNOWN_FAILURE + TIMEOUT_3DS + }; + + private static final CardAction[] MPI_TIMEOUT_CARDS = { + TIMEOUT_3DS + }; + + private static final CardAction[] MPI_SUCCESS_CARDS = { + SUCCESS_3DS }; private final String action; @@ -74,16 +93,76 @@ public enum CardAction { return Arrays.asList(ENROLLED_CARDS).contains(action); } + public static boolean isCardFailed(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return CardAction.isCardFailed(action); + } + public static boolean isCardFailed(CardAction action) { return Arrays.asList(FAILED_CARDS).contains(action); } + public static boolean isCardSuccess(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return CardAction.isCardSuccess(action); + } + public static boolean isCardSuccess(CardAction action) { return Arrays.asList(SUCCESS_CARDS).contains(action); } + public static boolean isCardSuccessApplePay(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return CardAction.isCardSuccess(action); + } + + public static boolean isCardSuccessApplePay(CardAction action) { + return Arrays.asList(SUCCESS_CARDS_APPLE_PAY).contains(action); + } + + public static boolean isCardSuccessSamsungPay(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return CardAction.isCardSuccess(action); + } + + public static boolean isCardSuccessSamsungPay(CardAction action) { + return Arrays.asList(SUCCESS_CARDS_SAMSUNG_PAY).contains(action); + } + + public static boolean isCardSuccessGooglePay(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return CardAction.isCardSuccess(action); + } + + public static boolean isCardSuccessGooglePay(CardAction action) { + return Arrays.asList(SUCCESS_CARDS_GOOGLE_PAY).contains(action); + } + public static boolean isMpiCardFailed(CardAction action) { return Arrays.asList(MPI_FAILED_CARDS).contains(action); } + public static boolean isMpiCardFailed(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return isMpiCardFailed(action); + } + + public static boolean isMpiCardSuccess(CardAction action) { + return Arrays.asList(MPI_SUCCESS_CARDS).contains(action); + } + + public static boolean isMpiCardSuccess(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return isMpiCardSuccess(action); + } + + public static boolean isMpiCardTimeout(CardAction action) { + return Arrays.asList(MPI_TIMEOUT_CARDS).contains(action); + } + + public static boolean isMpiCardTimeout(Card card) { + CardAction action = CardAction.findByValue(card.getAction()); + return isMpiCardTimeout(action); + } + } \ No newline at end of file diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/BeanReader.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/BeanReader.java similarity index 90% rename from src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/BeanReader.java rename to src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/BeanReader.java index 8f8f211..126a3f0 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/BeanReader.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/BeanReader.java @@ -1,4 +1,4 @@ -package com.rbkmoney.proxy.mocketbank.utils.extractor; +package com.rbkmoney.proxy.mocketbank.utils.reader; import java.io.BufferedReader; import java.io.InputStream; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/CardReader.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/CardReader.java similarity index 90% rename from src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/CardReader.java rename to src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/CardReader.java index 5aae297..68196f8 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/CardReader.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/CardReader.java @@ -1,4 +1,4 @@ -package com.rbkmoney.proxy.mocketbank.utils.extractor; +package com.rbkmoney.proxy.mocketbank.utils.reader; import com.rbkmoney.proxy.mocketbank.utils.model.Card; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/MobilePhoneReader.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/MobilePhoneReader.java similarity index 91% rename from src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/MobilePhoneReader.java rename to src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/MobilePhoneReader.java index c2091ad..52e1bc1 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/extractor/MobilePhoneReader.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/reader/MobilePhoneReader.java @@ -1,4 +1,4 @@ -package com.rbkmoney.proxy.mocketbank.utils.extractor; +package com.rbkmoney.proxy.mocketbank.utils.reader; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhone; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/state/constant/SuspendPrefix.java b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/state/constant/SuspendPrefix.java index cfb146b..f5385f3 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/utils/state/constant/SuspendPrefix.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/utils/state/constant/SuspendPrefix.java @@ -8,7 +8,8 @@ import lombok.RequiredArgsConstructor; public enum SuspendPrefix { RECURRENT("REC_MPI-"), - PAYMENT("COM_MPI-"); + PAYMENT("COM_MPI-"), + P2P("P2P_MPI-"); private final String prefix; } diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/MobileValidator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/MobileValidator.java index fe435d0..f200b9a 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/MobileValidator.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/MobileValidator.java @@ -3,8 +3,8 @@ package com.rbkmoney.proxy.mocketbank.validator; import com.rbkmoney.damsel.domain.PaymentTool; import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentResource; +import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; import com.rbkmoney.proxy.mocketbank.exception.MobileException; -import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/PaymentValidator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/PaymentValidator.java index bd79e0e..635ad98 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/PaymentValidator.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/PaymentValidator.java @@ -11,7 +11,7 @@ import org.springframework.stereotype.Component; import java.util.Map; import static com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors.extractPaymentResource; -import static com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors.extractPaymentTool; +import static com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors.extractPaymentTool; @Component @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/TerminalValidator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/TerminalValidator.java index ca0df7f..43b1ee8 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/TerminalValidator.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/TerminalValidator.java @@ -3,8 +3,8 @@ package com.rbkmoney.proxy.mocketbank.validator; import com.rbkmoney.damsel.domain.PaymentTool; import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentResource; +import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors; import com.rbkmoney.proxy.mocketbank.exception.TerminalException; -import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/WithdrawalValidator.java b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/WithdrawalValidator.java index e4e727d..a7588e4 100644 --- a/src/main/java/com/rbkmoney/proxy/mocketbank/validator/WithdrawalValidator.java +++ b/src/main/java/com/rbkmoney/proxy/mocketbank/validator/WithdrawalValidator.java @@ -2,7 +2,7 @@ package com.rbkmoney.proxy.mocketbank.validator; import com.rbkmoney.damsel.withdrawals.provider_adapter.GetQuoteParams; import com.rbkmoney.proxy.mocketbank.exception.WithdrawalException; -import com.rbkmoney.proxy.mocketbank.handler.oct.converter.CurrencyConverter; +import com.rbkmoney.proxy.mocketbank.service.oct.verification.CurrencyVerification; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; @@ -15,13 +15,13 @@ public class WithdrawalValidator implements Validator { public void validate(GetQuoteParams getQuoteParams, Map options) { validateRequiredFields(options); - if (CurrencyConverter.isCryptoCurrency(getQuoteParams.getCurrencyFrom()) && CurrencyConverter.isCryptoCurrency(getQuoteParams.getCurrencyTo())) { + if (CurrencyVerification.isCryptoCurrency(getQuoteParams.getCurrencyFrom()) && CurrencyVerification.isCryptoCurrency(getQuoteParams.getCurrencyTo())) { throw new WithdrawalException("Can't exchange crypto currency to crypto currency"); } - if (CurrencyConverter.isCurrencyEquals(getQuoteParams.getCurrencyFrom(), getQuoteParams.getCurrencyTo())) { + if (CurrencyVerification.isCurrencyEquals(getQuoteParams.getCurrencyFrom(), getQuoteParams.getCurrencyTo())) { throw new WithdrawalException("Can't exchange equals currency"); } - if (!CurrencyConverter.isExchangeCurrencyEqualsOtherCurrency(getQuoteParams)) { + if (!CurrencyVerification.isExchangeCurrencyEqualsOtherCurrency(getQuoteParams)) { throw new WithdrawalException("Can't exchange equals currency, all currency is different"); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a528b15..35cb791 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,6 +27,7 @@ adapter-mock-bank: callbackUrl: http://127.0.0.1:8019 pathCallbackUrl: /${server.rest.endpoint}/term_url{?termination_uri} pathRecurrentCallbackUrl: /${server.rest.endpoint}/term_rec_url{?termination_uri} + pathP2pCallbackUrl: /${server.rest.endpoint}/p2p{?termination_uri} --- cds: client: @@ -43,6 +44,12 @@ hellgate: url: http://127.0.0.1:8023/v1/proxyhost/provider networkTimeout: 30000 --- +fistful: + client: + adapter: + url: http://127.0.0.1:8025/v1/ff_p2p_adapter_host + networkTimeout: 30000 +--- timer: redirectTimeout: 600 --- diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/DeadlineTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/DeadlineTest.java deleted file mode 100644 index b63a852..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/DeadlineTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.configuration; - -import com.rbkmoney.cds.client.storage.CdsClientStorage; -import com.rbkmoney.damsel.domain.*; -import com.rbkmoney.damsel.proxy_provider.Shop; -import com.rbkmoney.damsel.proxy_provider.*; -import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; -import com.rbkmoney.woody.api.flow.error.WRuntimeException; -import com.rbkmoney.woody.api.flow.error.WUnavailableResultException; -import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder; -import org.apache.thrift.TException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; - -import java.net.URI; -import java.net.URISyntaxException; - -import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*; -import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.createDisposablePaymentResource; -import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.*; -import static com.rbkmoney.woody.api.flow.error.WErrorType.UNAVAILABLE_RESULT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; - -@RunWith(SpringRunner.class) -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, - properties = { - "restTemplate.networkTimeout=10000", - "server.port=7021", - "server.rest.port=7022", - "proxy-mocketbank-mpi.url=http://127.0.0.1:${server.port}" - } -) -public class DeadlineTest { - - public static int SLEEP_FOR_BANK_CONTROLLER = 5000; - - private static final int TIMEOUT = 5000; - private static final String token = "card_token"; - - @LocalServerPort - private int port; - - @MockBean - private CdsClientStorage cds; - - private ProviderProxySrv.Iface client; - - @Before - public void setup() throws Exception { - createThriftClient(); - mockCdsBean(); - } - - @Test - public void lessThenDeadlineTest() throws TException { - try { - SLEEP_FOR_BANK_CONTROLLER = TIMEOUT - 2000; - deadlineTest(); - fail(); - } catch (WRuntimeException ex) { - assertEquals(UNAVAILABLE_RESULT, ex.getErrorDefinition().getErrorType()); - } - } - - @Test(expected = WUnavailableResultException.class) - public void moreThenDeadlineTest() throws TException { - SLEEP_FOR_BANK_CONTROLLER = TIMEOUT + 2000; - deadlineTest(); - } - - private void createThriftClient() throws URISyntaxException { - client = new THSpawnClientBuilder() - .withAddress(new URI("http://localhost:" + port + "/proxy/mocketbank")) - .withNetworkTimeout(TIMEOUT) - .build(ProviderProxySrv.Iface.class); - } - - private void mockCdsBean() { - Mockito.when(cds.getCardData((RecurrentTokenContext) any())).thenReturn(TestData.createCardDataProxyModel(Visa.SUCCESS_3DS.getCardNumber())); - } - - private void deadlineTest() throws TException { - RecurrentTokenContext context = new RecurrentTokenContext(); - context.setSession(new RecurrentTokenSession()); - context.setTokenInfo( - createRecurrentTokenInfo( - createRecurrentPaymentTool( - "Recurrent" + (int) (Math.random() * 500 + 1), - createDisposablePaymentResource( - "session_id", - createPaymentTool( - new BankCard(token, BankCardPaymentSystem.visa, "bin", "masked_pan").setExpDate(createBankCardExpDate("12","2020")) - ) - ), - createCash( - createCurrency("Rubles", (short) 643, "RUB", (short) 1), - 1000L - ) - ) - ).setShop(prepareShop()) - ); - client.generateToken(context); - } - - private Shop prepareShop() { - ShopLocation shopLocation = new ShopLocation(); - shopLocation.setUrl("url"); - return new Shop() - .setId("shop_id") - .setCategory(new Category().setName("CategoryName").setDescription("Category description")) - .setDetails(new ShopDetails().setName("ShopName").setDescription("Shop description")) - .setLocation(shopLocation); - } -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/ExternalPortRestrictingTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/ExternalPortRestrictingTest.java deleted file mode 100644 index 31c2703..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/ExternalPortRestrictingTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.configuration; - -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; - -import static com.rbkmoney.proxy.mocketbank.configuration.TomcatEmbeddedConfiguration.HEALTH; -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = {"server.rest.port=65434"} -) -public class ExternalPortRestrictingTest { - - private static final String FAKE_REST_PATH = "/you-not-found"; - private static final String MAPPED_REST_ENDPATH = "/term_url"; - - @Value("${server.rest.port}") - private int restPort; - - @Value("/${server.rest.endpoint}") - private String restEndpoint; - - @Test - public void test() throws IOException { - String baseUrl = "http://localhost:" + restPort; - String restUrl = baseUrl + restEndpoint; - HttpGet httpGetTransaction = new HttpGet(restUrl + MAPPED_REST_ENDPATH); - HttpGet httpGetHealth = new HttpGet(baseUrl + HEALTH); - HttpGet httpGetWrongAddress = new HttpGet(baseUrl + FAKE_REST_PATH); - - assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, getHttpClient().execute(httpGetTransaction).getStatusLine().getStatusCode()); - assertEquals(HttpStatus.SC_OK, getHttpClient().execute(httpGetHealth).getStatusLine().getStatusCode()); - assertEquals(HttpStatus.SC_NOT_FOUND, getHttpClient().execute(httpGetWrongAddress).getStatusLine().getStatusCode()); - } - - private CloseableHttpClient getHttpClient() { - return HttpClientBuilder.create().build(); - } -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/TestBankController.java b/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/TestBankController.java deleted file mode 100644 index 242a14f..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/configuration/TestBankController.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.configuration; - - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import static com.rbkmoney.proxy.mocketbank.configuration.DeadlineTest.SLEEP_FOR_BANK_CONTROLLER; - -@RestController -@RequestMapping(value = "/mpi") -public class TestBankController { - - @RequestMapping(value = "verifyEnrollment", method = RequestMethod.POST) - public String verifyEnrollment(@RequestParam(value = "pan", required = true) String pan, - @RequestParam(value = "year", required = true) String year, - @RequestParam(value = "month", required = true) String month) throws Exception { - Thread.sleep(SLEEP_FOR_BANK_CONTROLLER); - throw new RuntimeException("Runtime exception from bank!"); - } -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/IntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/IntegrationTest.java index c756241..953a88a 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/IntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/IntegrationTest.java @@ -19,12 +19,14 @@ import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; +import com.rbkmoney.proxy.mocketbank.utils.model.Card; import lombok.extern.slf4j.Slf4j; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createDisposablePaymentResource; @@ -45,6 +47,9 @@ public abstract class IntegrationTest { @Autowired protected PaymentServerHandlerMdcLog handler; + @Autowired + protected List cardList; + @MockBean protected CdsClientStorage cdsStorage; @@ -170,18 +175,6 @@ public abstract class IntegrationTest { ); } - protected boolean isCallbackFailure(PaymentCallbackResult callbackResult) { - return callbackResult.getResult().getIntent().getFinish().getStatus().isSetFailure(); - } - - protected boolean isCallbackSuccess(PaymentCallbackResult callbackResult) { - return callbackResult.getResult().getIntent().getFinish().getStatus().isSetSuccess(); - } - - protected boolean isRecurrentTokenCallbackSuccess(RecurrentTokenCallbackResult tokenCallbackResult) { - return tokenCallbackResult.getResult().getIntent().getFinish().getStatus().isSetSuccess(); - } - protected void mockCds(CardData cardData, BankCard bankCard) { CardDataProxyModel proxyModel = CardDataProxyModel.builder() .cardholderName(bankCard.getCardholderName()) diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailIntegrationTest.java index f807b72..9251e7f 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailIntegrationTest.java @@ -4,9 +4,8 @@ import com.rbkmoney.damsel.cds.CardData; import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -15,6 +14,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; + import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isFailure; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; @@ -33,21 +34,9 @@ public class MocketBankServerHandlerFailIntegrationTest extends IntegrationTest @Test public void testProcessPaymentFail() throws TException { - TestCard[] cards = { - Visa.INSUFFICIENT_FUNDS, - Mastercard.INSUFFICIENT_FUNDS, - Visa.INVALID_CARD, - Mastercard.INVALID_CARD, - Visa.CVV_MATCH_FAIL, - Mastercard.CVV_MATCH_FAIL, - Visa.EXPIRED, - Mastercard.EXPIRED, - Visa.UNKNOWN_FAILURE, - Mastercard.UNKNOWN_FAILURE - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardFailed); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPaymentFail(cardData); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailWith3DSIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailWith3DSIntegrationTest.java index 7e9db8e..7ce7205 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailWith3DSIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerFailWith3DSIntegrationTest.java @@ -8,10 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; import com.rbkmoney.proxy.mocketbank.utils.Converter; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -23,9 +22,11 @@ import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.nio.ByteBuffer; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; +import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isFailure; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuspend; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static org.junit.Assert.assertTrue; @@ -44,20 +45,14 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest extends Integrati @Test public void testProcessPaymentFail() throws TException, IOException { - TestCard[] cards = { - Visa.FAILURE_3DS, - Mastercard.FAILURE_3DS, - Visa.TIMEOUT_3DS, - Mastercard.TIMEOUT_3DS - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); - processPaymentFail(cardData); + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardFailed); + for (String pan : pans) { + CardData cardData = createCardData(pan); + processPayment(cardData); } } - private void processPaymentFail(CardData cardData) throws TException, IOException { + private void processPayment(CardData cardData) throws TException, IOException { BankCard bankCard = TestData.createBankCard(cardData); mockCds(cardData, bankCard); mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); @@ -74,7 +69,7 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest extends Integrati ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); PaymentCallbackResult callbackResult = handler.handlePaymentCallback(callbackMap, paymentContext); - assertTrue("CallbackResult isn`t failure", isCallbackFailure(callbackResult)); + assertTrue("CallbackResult isn`t failure", isFailure(callbackResult)); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest.java index 4d9c0b7..f53d5ac 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest.java @@ -6,10 +6,9 @@ import com.rbkmoney.damsel.proxy_provider.*; import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; import com.rbkmoney.proxy.mocketbank.utils.Converter; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -21,6 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.nio.ByteBuffer; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured; @@ -43,13 +43,9 @@ public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest extends I @Test public void testProcessPaymentSuccess() throws TException, IOException { - TestCard[] cards = { - Visa.SUCCESS_3DS, - Mastercard.SUCCESS_3DS - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPayment(cardData); } } @@ -72,7 +68,7 @@ public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest extends I ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); RecurrentTokenCallbackResult tokenCallbackResult = handler.handleRecurrentTokenCallback(callbackMap, context); - assertTrue("HandleRecurrentTokenCallback isn`t success", isRecurrentTokenCallbackSuccess(tokenCallbackResult)); + assertTrue("HandleRecurrentTokenCallback isn`t success", isSuccess(tokenCallbackResult)); // process String token = tokenCallbackResult.getResult().getIntent().getFinish().getStatus().getSuccess().getToken(); diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrentSuccessIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrentSuccessIntegrationTest.java index 97b5bd5..5bca2e6 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrentSuccessIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerRecurrentSuccessIntegrationTest.java @@ -7,7 +7,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.*; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -17,6 +18,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; +import java.util.List; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; @@ -37,15 +39,9 @@ public class MocketBankServerHandlerRecurrentSuccessIntegrationTest extends Inte @Test public void testProcessPaymentSuccess() throws TException, IOException { - TestCard[] cards = { - Visa.SUCCESS, - Mastercard.SUCCESS, - Maestro.SUCCESS, - Mir.SUCCESS - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPayment(cardData); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessApplePayntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessApplePayntegrationTest.java index be5328e..b074906 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessApplePayntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessApplePayntegrationTest.java @@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -15,6 +15,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; + import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; @@ -33,12 +35,9 @@ public class MocketBankServerHandlerSuccessApplePayntegrationTest extends Integr @Test public void testProcessPaymentFail() throws TException { - TestCard[] cards = { - Visa.APPLE_PAY_FAILURE - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessApplePay); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPayment(cardData); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessGooglePayIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessGooglePayIntegrationTest.java index 35e0a30..f70bb2c 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessGooglePayIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessGooglePayIntegrationTest.java @@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -15,6 +15,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; + import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; @@ -29,16 +31,13 @@ import static org.junit.Assert.assertTrue; } ) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -public class MocketBankServerHandlerSuccessGooglePayIntegrationTest extends IntegrationTest { +public class MocketBankServerHandlerSuccessGooglePayIntegrationTest extends IntegrationTest { @Test public void testProcessPaymentSuccess() throws TException { - TestCard[] cards = { - Mastercard.GOOGLE_PAY_SUCCESS, - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessGooglePay); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPayment(cardData); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessIntegrationTest.java index d020ca7..f6b7aad 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessIntegrationTest.java @@ -5,7 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.domain.TransactionInfo; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.*; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -15,6 +16,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import java.util.Collections; +import java.util.List; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; @@ -34,20 +36,14 @@ public class MocketBankServerHandlerSuccessIntegrationTest extends IntegrationTe @Test public void testProcessPaymentSuccess() throws TException { - TestCard[] cards = { - Visa.SUCCESS, - Mastercard.SUCCESS, - Maestro.SUCCESS, - Mir.SUCCESS - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); - processPaymentSuccess(cardData); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); + processPayment(cardData); } } - private void processPaymentSuccess(CardData cardData) throws TException { + private void processPayment(CardData cardData) throws TException { BankCard bankCard = TestData.createBankCard(cardData); mockCds(cardData, bankCard); diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessSamsungPayIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessSamsungPayIntegrationTest.java index 006bd43..b25cd8c 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessSamsungPayIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessSamsungPayIntegrationTest.java @@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -15,6 +15,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; + import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; @@ -33,12 +35,9 @@ public class MocketBankServerHandlerSuccessSamsungPayIntegrationTest extends Int @Test public void testProcessPaymentSuccess() throws TException { - TestCard[] cards = { - Mastercard.SAMSUNG_PAY_SUCCESS, - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessSamsungPay); + for (String pan : pans) { + CardData cardData = createCardData(pan); processPayment(cardData); } } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessWith3DSIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessWith3DSIntegrationTest.java index 4e8cb4d..3926ede 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessWith3DSIntegrationTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/MocketBankServerHandlerSuccessWith3DSIntegrationTest.java @@ -8,10 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; import com.rbkmoney.proxy.mocketbank.utils.Converter; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; -import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; @@ -23,6 +22,7 @@ import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.nio.ByteBuffer; import java.util.HashMap; +import java.util.List; import java.util.Map; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured; @@ -46,18 +46,14 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest extends Integr @Test public void testProcessPaymentSuccess() throws TException, IOException { - TestCard[] cards = { - Visa.SUCCESS_3DS, - Mastercard.SUCCESS_3DS - }; - - for (TestCard card : cards) { - CardData cardData = createCardData(card.getCardNumber()); - processPaymentSuccess(cardData); + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); + processPayment(cardData); } } - private void processPaymentSuccess(CardData cardData) throws TException, IOException { + private void processPayment(CardData cardData) throws TException, IOException { BankCard bankCard = TestData.createBankCard(cardData); mockCds(cardData, bankCard); mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); @@ -74,7 +70,7 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest extends Integr ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); PaymentCallbackResult callbackResult = handler.handlePaymentCallback(callbackMap, paymentContext); - assertTrue("CallbackResult isn`t success", isCallbackSuccess(callbackResult)); + assertTrue("CallbackResult isn`t success", isSuccess(callbackResult)); paymentContext.getSession().setTarget(createTargetCaptured()); paymentContext.getSession().setState(callbackResult.getResult().getNextState()); diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctIntegrationTest.java new file mode 100644 index 0000000..16f5d99 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctIntegrationTest.java @@ -0,0 +1,79 @@ +package com.rbkmoney.proxy.mocketbank.handler.oct; + +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.withdrawals.domain.*; +import com.rbkmoney.damsel.withdrawals.provider_adapter.Cash; +import com.rbkmoney.damsel.withdrawals.provider_adapter.Withdrawal; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.decorator.WithdrawalServerHandlerLog; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createCurrency; + +public abstract class OctIntegrationTest { + + @Autowired + protected WithdrawalServerHandlerLog handler; + + protected String WITHDRAWALID = "TEST_WITHDRAWAL_ID"; + + + protected Withdrawal createWithdrawal() { + BankCard bankCard = TestData.createBankCard(TestData.createCardData()); + Destination destination = createDestination(bankCard); + + List identityDocumentList = createIdentityDocumentsList(TestData.WITHDRAWAL_TOKEN); + Identity identity = createIdentity(identityDocumentList); + return new Withdrawal() + .setId(WITHDRAWALID) + .setDestination(destination) + .setBody(createCash()) + .setSender(identity); + } + + protected List createIdentityDocumentsList(String token) { + List identityDocumentList = new ArrayList<>(); + identityDocumentList.add(createIdentityDocument(token)); + return identityDocumentList; + } + + protected Destination createDestination(BankCard bankCard) { + Destination destination = new Destination(); + destination.setBankCard(bankCard); + return destination; + } + + protected Identity createIdentity(List identityDocumentList) { + return new Identity() + .setContact(createContactDetailsList()) + .setDocuments(identityDocumentList); + } + + protected IdentityDocument createIdentityDocument(String token) { + return IdentityDocument.rus_domestic_passport(new RUSDomesticPassport().setToken(token)); + } + + protected Cash createCash() { + return new Cash() + .setAmount(1000L) + .setCurrency(createCurrency("Rubles", (short) 643, "RUB", (short) 2)); + } + + protected Map createProxyOptions() { + return Collections.emptyMap(); + } + + protected List createContactDetailsList() { + List contactDetailList = new ArrayList<>(); + ContactDetail contactDetail = new ContactDetail(); + contactDetail.setPhoneNumber(TestData.PHONE_NUMBER); + contactDetailList.add(contactDetail); + return contactDetailList; + } + +} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandlerTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandlerTest.java index c61a48f..b1e4f97 100644 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandlerTest.java +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/oct/OctServerHandlerTest.java @@ -1,28 +1,15 @@ package com.rbkmoney.proxy.mocketbank.handler.oct; -import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.msgpack.Value; -import com.rbkmoney.damsel.withdrawals.domain.*; -import com.rbkmoney.damsel.withdrawals.provider_adapter.AdapterSrv; -import com.rbkmoney.damsel.withdrawals.provider_adapter.Cash; import com.rbkmoney.damsel.withdrawals.provider_adapter.ProcessResult; -import com.rbkmoney.damsel.withdrawals.provider_adapter.Withdrawal; -import com.rbkmoney.proxy.mocketbank.TestData; import lombok.extern.slf4j.Slf4j; import org.apache.thrift.TException; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createCurrency; import static com.rbkmoney.java.damsel.utils.extractors.WithdrawalsProviderAdapterPackageExtractors.isSuccess; import static org.junit.Assert.assertTrue; @@ -35,12 +22,7 @@ import static org.junit.Assert.assertTrue; } ) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -public class OctServerHandlerTest { - - @Autowired - protected AdapterSrv.Iface handler; - - private String WithdrawalId = "TWithId" + (int) (Math.random() * 50 + 1); +public class OctServerHandlerTest extends OctIntegrationTest { @Test public void testProcessWithdrawal() throws TException { @@ -53,57 +35,4 @@ public class OctServerHandlerTest { assertTrue("Result processWithdrawal isn`t success", isSuccess(result)); } - private Withdrawal createWithdrawal() { - BankCard bankCard = TestData.createBankCard(TestData.createCardData()); - Destination destination = createDestination(bankCard); - - List identityDocumentList = createIdentityDocumentsList(TestData.WITHDRAWAL_TOKEN); - Identity identity = createIdentity(identityDocumentList); - return new Withdrawal() - .setId(WithdrawalId) - .setDestination(destination) - .setBody(createCash()) - .setSender(identity); - } - - private List createIdentityDocumentsList(String token) { - List identityDocumentList = new ArrayList<>(); - identityDocumentList.add(createIdentityDocument(token)); - return identityDocumentList; - } - - private Destination createDestination(BankCard bankCard) { - Destination destination = new Destination(); - destination.setBankCard(bankCard); - return destination; - } - - private Identity createIdentity(List identityDocumentList) { - return new Identity() - .setContact(createContactDetailsList()) - .setDocuments(identityDocumentList); - } - - private IdentityDocument createIdentityDocument(String token) { - return IdentityDocument.rus_domestic_passport(new RUSDomesticPassport().setToken(token)); - } - - private Cash createCash() { - return new Cash() - .setAmount(1000L) - .setCurrency(createCurrency("Rubles", (short) 643, "RUB", (short) 2)); - } - - private Map createProxyOptions() { - return Collections.emptyMap(); - } - - private List createContactDetailsList() { - List contactDetailList = new ArrayList<>(); - ContactDetail contactDetail = new ContactDetail(); - contactDetail.setPhoneNumber(TestData.PHONE_NUMBER); - contactDetailList.add(contactDetail); - return contactDetailList; - } - } diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2PIntegrationTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2PIntegrationTest.java new file mode 100644 index 0000000..54ec549 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2PIntegrationTest.java @@ -0,0 +1,152 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.rbkmoney.cds.client.storage.CdsClientStorage; +import com.rbkmoney.cds.client.storage.model.CardDataProxyModel; +import com.rbkmoney.damsel.cds.AuthData; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.cds.CardSecurityCode; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.domain.BankCardPaymentSystem; +import com.rbkmoney.damsel.domain.BankCardTokenProvider; +import com.rbkmoney.damsel.domain.Currency; +import com.rbkmoney.damsel.p2p_adapter.*; +import com.rbkmoney.damsel.proxy_provider.PaymentContext; +import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext; +import com.rbkmoney.java.damsel.utils.creators.CdsPackageCreators; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.decorator.P2pServerHandlerLog; +import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; +import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; +import com.rbkmoney.proxy.mocketbank.utils.Converter; +import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import lombok.extern.slf4j.Slf4j; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; + +@Slf4j +public abstract class P2PIntegrationTest { + + protected String SESSION_ID = "TEST_SESSION_ID"; + protected String OPERATION_ID = "TEST_OPERATION_ID"; + protected String PAYMENT_SESSION_ID = "TEST_PAYMENT_SESSION_ID"; + protected String RECEIVER_TOKEN = "receiver"; + protected String SENDER_TOKEN = "sender"; + + @Autowired + protected P2pServerHandlerLog handler; + + @Autowired + protected List cardList; + + @MockBean + protected CdsClientStorage cdsStorage; + + @MockBean + protected MpiApi mpiApi; + + protected Context createContext(BankCard bankCard) { + Context context = new Context(); + context.setOperation(createOperationInfo(bankCard)); + context.setSession(createSession()); + context.setOptions(createOptions()); + return context; + } + + protected Map createOptions() { + return new HashMap<>(); + } + + protected Session createSession() { + Session session = new Session(); + return session.setId(SESSION_ID); + } + + protected OperationInfo createOperationInfo(BankCard bankCard) { + OperationInfo operation = new OperationInfo(); + + operation.setProcess(new ProcessOperationInfo() + .setBody(prepareCash()) + .setReceiver(createPaymentResource(bankCard, RECEIVER_TOKEN)) + .setSender(createPaymentResource(bankCard, SENDER_TOKEN)) + .setId(OPERATION_ID) + ); + + return operation; + } + + protected Cash prepareCash() { + return new Cash() + .setAmount(6000L + (long) (Math.random() * 1000 + 1)) + .setCurrency(new Currency("Rubles", "RUB", (short) 643, (short) 2)); + } + + protected PaymentResource createPaymentResource(BankCard bankCard, String token) { + PaymentResource paymentResource = new PaymentResource(); + bankCard.setToken(token); + paymentResource.setDisposable( + createDisposablePaymentResource( + createClientInfo( + TestData.FINGERPRINT, + TestData.IP_ADDRESS), PAYMENT_SESSION_ID, + createPaymentTool(bankCard) + ) + ); + return paymentResource; + } + + protected BankCard createBankCard(String token) { + return new BankCard().setTokenProvider(BankCardTokenProvider.applepay) + .setToken(token) + .setPaymentSystem(BankCardPaymentSystem.mastercard) + .setBin(TestData.DEFAULT_BIN); + } + + protected Callback prepareCallback(Map payload) throws JsonProcessingException { + return new Callback() + .setTag(payload.get("MD")) + .setPayload(Converter.mapToByteBuffer(payload)); + } + + protected void mockCds(CardData cardData, BankCard bankCard) { + CardDataProxyModel proxyModel = CardDataProxyModel.builder() + .cardholderName(bankCard.getCardholderName()) + .expMonth(cardData.getExpDate().getMonth()) + .expYear(cardData.getExpDate().getYear()) + .pan(cardData.getPan()) + .build(); + + Mockito.when(cdsStorage.getCardData(anyString())).thenReturn(cardData); + Mockito.when(cdsStorage.getCardData((RecurrentTokenContext) any())).thenReturn(proxyModel); + Mockito.when(cdsStorage.getCardData((PaymentContext) any())).thenReturn(proxyModel); + Mockito.when(cdsStorage.getSessionData((RecurrentTokenContext) any())).thenReturn(CdsPackageCreators.createSessionData(AuthData.card_security_code(new CardSecurityCode(cardData.getCvv())))); + Mockito.when(cdsStorage.getSessionData((PaymentContext) any())).thenReturn(CdsPackageCreators.createSessionData(AuthData.card_security_code(new CardSecurityCode(cardData.getCvv())))); + } + + protected void mockMpiVerify(EnrollmentStatus mpiEnrollmentStatus) { + VerifyEnrollmentResponse response = new VerifyEnrollmentResponse(); + response.setAcsUrl(TestData.DEFAULT_ACS_URL); + response.setEnrolled(mpiEnrollmentStatus.getStatus()); + response.setPaReq(TestData.DEFAULT_PAREQ); + Mockito.when(mpiApi.verifyEnrollment((CardDataProxyModel) any())).thenReturn(response); + } + + protected void mockMpi(TransactionStatus mpiTransactionStatus) { + ValidatePaResResponse paResResponse = new ValidatePaResResponse(); + paResResponse.setTransactionStatus(mpiTransactionStatus.getStatus()); + Mockito.when(mpiApi.validatePaRes(any(), any())).thenReturn(paResResponse); + } + +} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTest.java new file mode 100644 index 0000000..eaf0ba7 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTest.java @@ -0,0 +1,66 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.p2p_adapter.Callback; +import com.rbkmoney.damsel.p2p_adapter.CallbackResult; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import org.apache.thrift.TException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isFailure; +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isSleep; +import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class P2pServerHandlerFail3dsTest extends P2PIntegrationTest { + + @Test + public void testProcessFail3ds() throws TException, JsonProcessingException { + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardFailed); + for (String pan : pans) { + CardData cardData = createCardData(pan); + process(cardData); + } + } + + private void process(CardData cardData) throws TException, JsonProcessingException { + BankCard bankCard = TestData.createBankCard(cardData); + mockCds(cardData, bankCard); + mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); + mockMpi(TransactionStatus.AUTHENTICATION_FAILED); + + Context context = createContext(bankCard); + ProcessResult result = handler.process(context); + assertTrue("P2P process isn`t sleep", isSleep(result)); + + Map payload = new HashMap<>(); + payload.put("MD", "MD-TAG"); + payload.put("paRes", "SomePaRes"); + + context.getSession().setState(result.getNextState()); + Callback callback = prepareCallback(payload); + + CallbackResult callbackResult = handler.handleCallback(callback, context); + assertTrue("CallbackResult isn`t failure", isFailure(callbackResult)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTimeoutTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTimeoutTest.java new file mode 100644 index 0000000..0154e44 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFail3dsTimeoutTest.java @@ -0,0 +1,56 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import org.apache.thrift.TException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isFailure; +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isSleep; +import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class P2pServerHandlerFail3dsTimeoutTest extends P2PIntegrationTest { + + @Test + public void testProcessFail3dsTimeout() throws TException, JsonProcessingException { + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardTimeout); + for (String pan : pans) { + CardData cardData = createCardData(pan); + process(cardData); + } + } + + private void process(CardData cardData) throws TException, JsonProcessingException { + BankCard bankCard = TestData.createBankCard(cardData); + mockCds(cardData, bankCard); + mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); + mockMpi(TransactionStatus.AUTHENTICATION_SUCCESSFUL); + + Context context = createContext(bankCard); + ProcessResult result = handler.process(context); + assertTrue("P2P process isn`t sleep", isSleep(result)); + + context.getSession().setState(result.getNextState()); + result = handler.process(context); + assertTrue("CallbackResult isn`t success", isFailure(result)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFailTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFailTest.java new file mode 100644 index 0000000..5583940 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerFailTest.java @@ -0,0 +1,46 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import org.apache.thrift.TException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isFailure; +import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class P2pServerHandlerFailTest extends P2PIntegrationTest { + + @Test + public void testProcessFail() throws TException { + List pans = CardListUtils.extractPans(cardList, CardAction::isCardFailed); + for (String pan : pans) { + CardData cardData = createCardData(pan); + process(cardData); + } + } + + private void process(CardData cardData) throws TException { + BankCard bankCard = TestData.createBankCard(cardData); + mockCds(cardData, bankCard); + + Context context = createContext(bankCard); + ProcessResult result = handler.process(context); + assertTrue("P2P process isn`t failure", isFailure(result)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccess3dsTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccess3dsTest.java new file mode 100644 index 0000000..399b550 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccess3dsTest.java @@ -0,0 +1,66 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.p2p_adapter.Callback; +import com.rbkmoney.damsel.p2p_adapter.CallbackResult; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; +import com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import org.apache.thrift.TException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isSleep; +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isSuccess; +import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class P2pServerHandlerSuccess3dsTest extends P2PIntegrationTest { + + @Test + public void testProcessSuccess3ds() throws TException, JsonProcessingException { + List pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); + process(cardData); + } + } + + private void process(CardData cardData) throws TException, JsonProcessingException { + BankCard bankCard = TestData.createBankCard(cardData); + mockCds(cardData, bankCard); + mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); + mockMpi(TransactionStatus.AUTHENTICATION_SUCCESSFUL); + + Context context = createContext(bankCard); + ProcessResult result = handler.process(context); + assertTrue("P2P process isn`t sleep", isSleep(result)); + + Map payload = new HashMap<>(); + payload.put("MD", "MD-TAG"); + payload.put("paRes", "SomePaRes"); + + context.getSession().setState(result.getNextState()); + Callback callback = prepareCallback(payload); + + CallbackResult callbackResult = handler.handleCallback(callback, context); + assertTrue("CallbackResult isn`t success", isSuccess(callbackResult)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccessTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccessTest.java new file mode 100644 index 0000000..f5c9895 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerSuccessTest.java @@ -0,0 +1,46 @@ +package com.rbkmoney.proxy.mocketbank.handler.p2p; + +import com.rbkmoney.damsel.cds.CardData; +import com.rbkmoney.damsel.domain.BankCard; +import com.rbkmoney.damsel.p2p_adapter.Context; +import com.rbkmoney.damsel.p2p_adapter.ProcessResult; +import com.rbkmoney.proxy.mocketbank.TestData; +import com.rbkmoney.proxy.mocketbank.utils.CardListUtils; +import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; +import org.apache.thrift.TException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static com.rbkmoney.java.damsel.utils.verification.P2pAdapterVerification.isSuccess; +import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class P2pServerHandlerSuccessTest extends P2PIntegrationTest { + + @Test + public void testProcessSuccess() throws TException { + List pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccess); + for (String pan : pans) { + CardData cardData = createCardData(pan); + process(cardData); + } + } + + private void process(CardData cardData) throws TException { + BankCard bankCard = TestData.createBankCard(cardData); + mockCds(cardData, bankCard); + + Context context = createContext(bankCard); + ProcessResult result = handler.process(context); + assertTrue("Process payment isn`t success", isSuccess(result)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerTest.java b/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerTest.java deleted file mode 100644 index e4ca11f..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/handler/p2p/P2pServerHandlerTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.handler.p2p; - -import com.rbkmoney.damsel.p2p_adapter.Callback; -import com.rbkmoney.damsel.p2p_adapter.Context; -import com.rbkmoney.damsel.p2p_adapter.ProcessResult; -import com.rbkmoney.proxy.mocketbank.utils.p2p.creator.P2pCreator; -import com.rbkmoney.proxy.mocketbank.utils.p2p.verification.P2pVerification; -import com.rbkmoney.proxy.mocketbank.exception.UnsupportedOperationException; -import org.apache.thrift.TException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -public class P2pServerHandlerTest { - - @Autowired - private P2pServerHandler handler; - - @Test - public void testProcess() throws TException { - Context context = P2pCreator.createContext(); - ProcessResult result = handler.process(context); - assertTrue("P2P process isn`t success", P2pVerification.isSuccess(result)); - } - - @Test(expected = UnsupportedOperationException.class) - public void testHandleCallback() throws TException { - Context context = P2pCreator.createContext(); - Callback callback = P2pCreator.createCallback(); - handler.handleCallback(callback, context); - } - -} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/CardListUtils.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/CardListUtils.java new file mode 100644 index 0000000..702ee38 --- /dev/null +++ b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/CardListUtils.java @@ -0,0 +1,21 @@ +package com.rbkmoney.proxy.mocketbank.utils; + +import com.rbkmoney.proxy.mocketbank.utils.model.Card; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CardListUtils { + + public static List extractPans(List cardList, Predicate cardPredicate) { + return cardList.stream() + .filter(cardPredicate) + .map(Card::getPan) + .collect(Collectors.toList()); + } + +} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Maestro.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Maestro.java deleted file mode 100644 index 7b96432..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Maestro.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.constant.testcards; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Maestro implements TestCard { - SUCCESS("586824160825533338"); - - private final String cardNumber; -} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mastercard.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mastercard.java deleted file mode 100644 index edc7299..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mastercard.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.constant.testcards; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Mastercard implements TestCard { - SUCCESS("5555555555554444"), - SUCCESS_3DS("5169147129584558"), - FAILURE_3DS("5123456789012346"), - TIMEOUT_3DS("5112000200000002"), - INSUFFICIENT_FUNDS("5100000000000412"), - INVALID_CARD("5100000000000511"), - CVV_MATCH_FAIL("5496198584584769"), - EXPIRED("5105105105105100"), - UNKNOWN_FAILURE("5124990000000002"), - GOOGLE_PAY_FAILURE("2222405343248877"), - GOOGLE_PAY_SUCCESS("2222990905257051"), - SAMSUNG_PAY_FAILURE("2223007648726984"), - SAMSUNG_PAY_SUCCESS("2223577120017656"); - - private final String cardNumber; -} \ No newline at end of file diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mir.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mir.java deleted file mode 100644 index 7e92717..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Mir.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.constant.testcards; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Mir implements TestCard { - SUCCESS("2201382000000013"); - - private final String cardNumber; -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/TestCard.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/TestCard.java deleted file mode 100644 index 0bbd85a..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/TestCard.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.constant.testcards; - -public interface TestCard { - String getCardNumber(); -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Visa.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Visa.java deleted file mode 100644 index 240d472..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/constant/testcards/Visa.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.constant.testcards; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Visa implements TestCard { - SUCCESS("4242424242424242"), - SUCCESS_3DS("4012888888881881"), - FAILURE_3DS("4987654321098769"), - TIMEOUT_3DS("4342561111111118"), - INSUFFICIENT_FUNDS("4000000000000002"), - INVALID_CARD("4222222222222220"), - CVV_MATCH_FAIL("4003830171874018"), - EXPIRED("4000000000000069"), - UNKNOWN_FAILURE("4111110000000112"), - APPLE_PAY_FAILURE("5000000000000009"), - APPLE_PAY_SUCCESS("4300000000000777"); - - private final String cardNumber; -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/constant/P2pConstant.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/constant/P2pConstant.java deleted file mode 100644 index 263176e..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/constant/P2pConstant.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.p2p.constant; - -import lombok.NoArgsConstructor; - -@NoArgsConstructor -public class P2pConstant { - public static final String RECEIVER_TOKEN = "receiver"; - public static final String SENDER_TOKEN = "sender"; - public static final String FINGERPRINT = "fingerprint"; - public static final String IP_ADDRESS = "0.0.0.0"; - public static final String CALLBACK_TAG = "callback_tag"; -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/creator/P2pCreator.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/creator/P2pCreator.java deleted file mode 100644 index 4eb92db..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/creator/P2pCreator.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.p2p.creator; - -import com.rbkmoney.damsel.domain.BankCard; -import com.rbkmoney.damsel.domain.BankCardPaymentSystem; -import com.rbkmoney.damsel.domain.BankCardTokenProvider; -import com.rbkmoney.damsel.domain.Currency; -import com.rbkmoney.damsel.p2p_adapter.*; -import com.rbkmoney.proxy.mocketbank.utils.p2p.constant.P2pConstant; -import lombok.NoArgsConstructor; - -import java.util.HashMap; -import java.util.Map; - -import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*; - -@NoArgsConstructor -public class P2pCreator { - - public static Context createContext() { - Context context = new Context(); - context.setOperation(createOperationInfo()); - context.setSession(createSession()); - context.setOptions(createOptions()); - return context; - } - - public static Callback createCallback() { - Callback callback = new Callback(); - callback.setTag(P2pConstant.CALLBACK_TAG); - callback.setPayload(new byte[0]); - return callback; - } - - public static Map createOptions() { - return new HashMap<>(); - } - - public static Session createSession() { - return new Session(); - } - - public static OperationInfo createOperationInfo() { - OperationInfo operation = new OperationInfo(); - - operation.setProcess(new ProcessOperationInfo() - .setBody(prepareCash()) - .setReceiver(createPaymentResource(P2pConstant.RECEIVER_TOKEN)) - .setSender(createPaymentResource(P2pConstant.SENDER_TOKEN))); - - return operation; - } - - public static Cash prepareCash() { - return new Cash() - .setAmount(6000L + (long) (Math.random() * 1000 + 1)) - .setCurrency(new Currency("Rubles", "RUB", (short) 643, (short) 2)); - } - - public static PaymentResource createPaymentResource(String token) { - PaymentResource paymentResource = new PaymentResource(); - paymentResource.setDisposable( - createDisposablePaymentResource( - createClientInfo( - P2pConstant.FINGERPRINT, - P2pConstant.IP_ADDRESS), token, - createPaymentTool(createBankCardMobile(token)) - ) - ); - return paymentResource; - } - - public static BankCard createBankCardMobile(String token) { - return new BankCard().setTokenProvider(BankCardTokenProvider.applepay) - .setToken(token) - .setPaymentSystem(BankCardPaymentSystem.mastercard) - .setBin("1234"); - } - -} diff --git a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/verification/P2pVerification.java b/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/verification/P2pVerification.java deleted file mode 100644 index f3a44e8..0000000 --- a/src/test/java/com/rbkmoney/proxy/mocketbank/utils/p2p/verification/P2pVerification.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.rbkmoney.proxy.mocketbank.utils.p2p.verification; - -import com.rbkmoney.damsel.p2p_adapter.ProcessResult; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -public class P2pVerification { - - public static boolean isSuccess(ProcessResult processResult) { - return processResult.getIntent().getFinish().getStatus().isSetSuccess(); - } - -}