PROX-393: more actions for p2p (#64)

* PROX-393: more actions for p2p
This commit is contained in:
Anatoly Cherkasov 2020-03-13 12:09:36 +03:00 committed by GitHub
parent d1509861b3
commit bbe9102c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 1031 additions and 851 deletions

26
pom.xml
View File

@ -27,7 +27,8 @@
<dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag> <dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag>
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry> <dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
<shared.resources.version>0.3.6</shared.resources.version> <shared.resources.version>0.3.6</shared.resources.version>
<proxy-libs.version>2.1.18</proxy-libs.version> <adapter-client-lib.version>2.1.19</adapter-client-lib.version>
<adapter-thrift-lib.version>1.0.0</adapter-thrift-lib.version>
</properties> </properties>
<dependencies> <dependencies>
@ -66,24 +67,29 @@
<version>1.1.0</version> <version>1.1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney.proxy-libs</groupId> <groupId>com.rbkmoney.adapter-client-lib</groupId>
<artifactId>hellgate-adapter-client</artifactId> <artifactId>hellgate-adapter-client</artifactId>
<version>${proxy-libs.version}</version> <version>${adapter-client-lib.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney.proxy-libs</groupId> <groupId>com.rbkmoney.adapter-client-lib</groupId>
<artifactId>cds-client-storage</artifactId> <artifactId>cds-client-storage</artifactId>
<version>${proxy-libs.version}</version> <version>${adapter-client-lib.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney.proxy-libs</groupId> <groupId>com.rbkmoney.adapter-client-lib</groupId>
<artifactId>cds-client-identity-document-storage</artifactId> <artifactId>cds-client-identity-document-storage</artifactId>
<version>${proxy-libs.version}</version> <version>${adapter-client-lib.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney.adapter-client-lib</groupId>
<artifactId>fistful-client</artifactId>
<version>${adapter-client-lib.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney.adapter-thrift-lib</groupId>
<artifactId>damsel-utils</artifactId> <artifactId>damsel-utils</artifactId>
<version>${proxy-libs.version}</version> <version>${adapter-thrift-lib.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@ -98,7 +104,7 @@
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId> <artifactId>damsel</artifactId>
<version>1.388-e76b0f7</version> <version>1.391-8fe5f98</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.rbkmoney</groupId> <groupId>com.rbkmoney</groupId>

View File

@ -1,6 +1,6 @@
package com.rbkmoney.proxy.mocketbank.configuration; 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 com.rbkmoney.proxy.mocketbank.utils.model.Card;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

View File

@ -1,6 +1,6 @@
package com.rbkmoney.proxy.mocketbank.configuration; 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 com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhone;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

View File

@ -24,4 +24,7 @@ public class AdapterMockBankProperties {
@NotEmpty @NotEmpty
private String pathRecurrentCallbackUrl; private String pathRecurrentCallbackUrl;
@NotEmpty
private String pathP2pCallbackUrl;
} }

View File

@ -3,6 +3,9 @@ package com.rbkmoney.proxy.mocketbank.controller;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.rbkmoney.adapter.helpers.hellgate.HellgateAdapterClient; import com.rbkmoney.adapter.helpers.hellgate.HellgateAdapterClient;
import com.rbkmoney.adapter.helpers.hellgate.exception.HellgateException; 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.java.damsel.converter.CommonConverter;
import com.rbkmoney.proxy.mocketbank.utils.state.constant.SuspendPrefix; import com.rbkmoney.proxy.mocketbank.utils.state.constant.SuspendPrefix;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -29,6 +32,7 @@ import java.util.stream.Collectors;
public class MocketBankController { public class MocketBankController {
private final HellgateAdapterClient hellgateClient; private final HellgateAdapterClient hellgateClient;
private final FistfulClient fistfulClient;
@RequestMapping(value = "term_url", method = RequestMethod.POST) @RequestMapping(value = "term_url", method = RequestMethod.POST)
public String receiveIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { public String receiveIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException {
@ -48,7 +52,6 @@ public class MocketBankController {
return resp; return resp;
} }
@RequestMapping(value = "/rec_term_url", method = RequestMethod.POST) @RequestMapping(value = "/rec_term_url", method = RequestMethod.POST)
public String receiveRecurrentIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { public String receiveRecurrentIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException {
String tag = SuspendPrefix.RECURRENT + getTag(request); String tag = SuspendPrefix.RECURRENT + getTag(request);
@ -67,6 +70,27 @@ public class MocketBankController {
return resp; 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) { private String getTag(HttpServletRequest request) {
if (StringUtils.hasText(request.getParameter("MD"))) { if (StringUtils.hasText(request.getParameter("MD"))) {
return request.getParameter("MD"); return request.getParameter("MD");

View File

@ -1,8 +1,8 @@
package com.rbkmoney.proxy.mocketbank.decorator; package com.rbkmoney.proxy.mocketbank.decorator;
import com.rbkmoney.damsel.proxy_provider.*; 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.java.damsel.utils.extractors.ProxyProviderPackageExtractors;
import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
@ -43,7 +43,7 @@ public class MobileServerHandlerLog implements ProviderProxySrv.Iface {
public PaymentProxyResult processPayment(PaymentContext context) throws TException { public PaymentProxyResult processPayment(PaymentContext context) throws TException {
String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context);
String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(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); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId);
try { try {
PaymentProxyResult proxyResult = handler.processPayment(context); PaymentProxyResult proxyResult = handler.processPayment(context);

View File

@ -1,7 +1,7 @@
package com.rbkmoney.proxy.mocketbank.decorator; package com.rbkmoney.proxy.mocketbank.decorator;
import com.rbkmoney.damsel.p2p_adapter.*; 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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;

View File

@ -1,8 +1,8 @@
package com.rbkmoney.proxy.mocketbank.decorator; package com.rbkmoney.proxy.mocketbank.decorator;
import com.rbkmoney.damsel.proxy_provider.*; 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.java.damsel.utils.extractors.ProxyProviderPackageExtractors;
import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
@ -43,7 +43,7 @@ public class PaymentServerHandlerLog implements ProviderProxySrv.Iface {
public PaymentProxyResult processPayment(PaymentContext context) throws TException { public PaymentProxyResult processPayment(PaymentContext context) throws TException {
String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context);
String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(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); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId);
try { try {
PaymentProxyResult proxyResult = handler.processPayment(context); PaymentProxyResult proxyResult = handler.processPayment(context);

View File

@ -1,8 +1,8 @@
package com.rbkmoney.proxy.mocketbank.decorator; package com.rbkmoney.proxy.mocketbank.decorator;
import com.rbkmoney.damsel.proxy_provider.*; 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.java.damsel.utils.extractors.ProxyProviderPackageExtractors;
import com.rbkmoney.proxy.mocketbank.utils.converter.PaymentResourceTypeResolver;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
@ -43,7 +43,7 @@ public class TerminalServerHandlerLog implements ProviderProxySrv.Iface {
public PaymentProxyResult processPayment(PaymentContext context) throws TException { public PaymentProxyResult processPayment(PaymentContext context) throws TException {
String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context); String invoiceId = ProxyProviderPackageExtractors.extractInvoiceId(context);
String invoicePaymentStatus = ProxyProviderPackageExtractors.extractTargetInvoicePaymentStatus(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); log.info("Process payment handle resource={}, status={} start with invoiceId={}", paymentResourceType, invoicePaymentStatus, invoiceId);
try { try {
PaymentProxyResult proxyResult = handler.processPayment(context); PaymentProxyResult proxyResult = handler.processPayment(context);

View File

@ -8,9 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.damsel.proxy_provider.PaymentResource;
import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.java.damsel.constant.PaymentState;
import com.rbkmoney.proxy.mocketbank.utils.creator.ProxyProviderCreator; import com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors;
import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors;
import com.rbkmoney.proxy.mocketbank.handler.mobile.CommonMobileHandler; 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.MobilePhone;
import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneAction; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneAction;
import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneUtils; import com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhoneUtils;
@ -55,7 +55,7 @@ public class ProcessedMobileCommonHandler implements CommonMobileHandler {
return createProxyResultFailure(errorMapping.mapFailure(error, error)); return createProxyResultFailure(errorMapping.mapFailure(error, error));
} }
TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context);
return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo); return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo);
} }

View File

@ -5,7 +5,7 @@ import com.rbkmoney.damsel.msgpack.Value;
import com.rbkmoney.damsel.withdrawals.provider_adapter.*; import com.rbkmoney.damsel.withdrawals.provider_adapter.*;
import com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators; import com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators;
import com.rbkmoney.java.damsel.utils.creators.WithdrawalsProviderAdapterPackageCreators; 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 com.rbkmoney.proxy.mocketbank.validator.WithdrawalValidator;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -37,7 +37,7 @@ public class OctServerHandler implements AdapterSrv.Iface {
Cash cashFrom = new Cash().setCurrency(getQuoteParams.getCurrencyFrom()); Cash cashFrom = new Cash().setCurrency(getQuoteParams.getCurrencyFrom());
Cash cashTo = new Cash().setCurrency(getQuoteParams.getCurrencyTo()); Cash cashTo = new Cash().setCurrency(getQuoteParams.getCurrencyTo());
if (CurrencyConverter.isCryptoCurrency(getQuoteParams.getCurrencyTo())) { if (CurrencyVerification.isCryptoCurrency(getQuoteParams.getCurrencyTo())) {
cashFrom.setAmount(getQuoteParams.getExchangeCash().getAmount()); cashFrom.setAmount(getQuoteParams.getExchangeCash().getAmount());
cashTo.setAmount(getQuoteParams.getExchangeCash().getAmount() * 2); cashTo.setAmount(getQuoteParams.getExchangeCash().getAmount() * 2);
} else { } else {

View File

@ -1,30 +1,28 @@
package com.rbkmoney.proxy.mocketbank.handler.p2p; package com.rbkmoney.proxy.mocketbank.handler.p2p;
import com.rbkmoney.damsel.p2p_adapter.*; import com.rbkmoney.damsel.p2p_adapter.*;
import com.rbkmoney.proxy.mocketbank.utils.creator.P2pAdapterCreator; import com.rbkmoney.proxy.mocketbank.handler.p2p.callback.P2pCallbackHandler;
import com.rbkmoney.proxy.mocketbank.exception.UnsupportedOperationException; import com.rbkmoney.proxy.mocketbank.handler.p2p.payment.ProcessedP2pHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTransactionInfo;
@Slf4j @Slf4j
@Component @Component
@RequiredArgsConstructor
public class P2pServerHandler implements P2PAdapterSrv.Iface { public class P2pServerHandler implements P2PAdapterSrv.Iface {
private final P2pCallbackHandler p2pCallbackHandler;
private final ProcessedP2pHandler processedP2pHandler;
@Override @Override
public ProcessResult process(Context context) throws TException { public ProcessResult process(Context context) throws TException {
String transactionId = P2pAdapterCreator.createTransactionId(context); return processedP2pHandler.process(context);
return new ProcessResult()
.setIntent(P2pAdapterCreator.createFinishIntentSuccess())
.setTrx(createTransactionInfo(transactionId, Collections.emptyMap()));
} }
@Override @Override
public CallbackResult handleCallback(Callback callback, Context context) throws TException { public CallbackResult handleCallback(Callback callback, Context context) throws TException {
throw new UnsupportedOperationException("P2pHandler handleCallback not supported!"); return p2pCallbackHandler.handleCallback(callback, context);
} }
} }

View File

@ -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<Card> cardList;
public CallbackResult handleCallback(Callback callback, Context context) {
HashMap<String, String> 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);
}
}

View File

@ -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<Card> 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> 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<String, String> params = prepareRedirectParams(verifyEnrollmentResponse, tag, termUrl);
Map<String, String> options = context.getOptions();
int timerRedirectTimeout = extractRedirectTimeout(options, timerProperties.getRedirectTimeout());
String userInteractionID = P2pAdapterExtractors.extractSessionId(context);
return P2pAdapterCreators.createIntentWithSleepIntent(
timerRedirectTimeout,
P2pAdapterCreators.createPostUserInteraction(userInteractionID, url, params),
tag
);
}
}

View File

@ -10,11 +10,12 @@ import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.constant.Error; import com.rbkmoney.java.damsel.constant.Error;
import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.java.damsel.constant.PaymentState;
import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; 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.service.mpi.model.ValidatePaResResponse;
import com.rbkmoney.proxy.mocketbank.utils.Converter; 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.ErrorBuilder;
import com.rbkmoney.proxy.mocketbank.utils.model.Card; 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.model.CardUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -25,7 +26,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.*; 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; import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.TransactionStatus.isAuthenticationSuccessful;
@Slf4j @Slf4j
@ -43,7 +43,7 @@ public class PaymentCallbackHandler {
CardDataProxyModel cardData = cds.getCardData(context); CardDataProxyModel cardData = cds.getCardData(context);
ValidatePaResResponse validatePaResResponse = mpiApi.validatePaRes(cardData, parameters); ValidatePaResResponse validatePaResResponse = mpiApi.validatePaRes(cardData, parameters);
if (isAuthenticationSuccessful(validatePaResResponse.getTransactionStatus())) { if (isAuthenticationSuccessful(validatePaResResponse.getTransactionStatus())) {
TransactionInfo transactionInfo = createDefaultTransactionInfo(context); TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context);
PaymentCallbackProxyResult proxyResult = createCallbackProxyResult( PaymentCallbackProxyResult proxyResult = createCallbackProxyResult(
createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo
); );

View File

@ -10,11 +10,11 @@ import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.constant.Error; import com.rbkmoney.java.damsel.constant.Error;
import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.java.damsel.constant.PaymentState;
import com.rbkmoney.proxy.mocketbank.service.mpi.MpiApi; 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.service.mpi.model.ValidatePaResResponse;
import com.rbkmoney.proxy.mocketbank.utils.Converter; import com.rbkmoney.proxy.mocketbank.utils.Converter;
import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder;
import com.rbkmoney.proxy.mocketbank.utils.model.Card; 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.model.CardUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@ -13,16 +13,15 @@ import com.rbkmoney.damsel.proxy_provider.PaymentResource;
import com.rbkmoney.damsel.timeout_behaviour.TimeoutBehaviour; import com.rbkmoney.damsel.timeout_behaviour.TimeoutBehaviour;
import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.constant.PaymentState; 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.AdapterMockBankProperties;
import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties; import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties;
import com.rbkmoney.proxy.mocketbank.handler.payment.CommonPaymentHandler; 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.MpiApi;
import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus;
import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; 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.ErrorBuilder;
import com.rbkmoney.proxy.mocketbank.utils.UrlUtils; 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.Card;
import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils; import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils;
@ -38,14 +37,14 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; 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.creators.ProxyProviderPackageCreators.*;
import static com.rbkmoney.java.damsel.utils.extractors.OptionsExtractors.extractRedirectTimeout; 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.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.java.damsel.utils.verification.ProxyProviderVerification.isMakeRecurrent;
import static com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus.isAuthenticationAvailable; 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.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.*; import static com.rbkmoney.proxy.mocketbank.utils.model.CardAction.*;
@Slf4j @Slf4j
@ -74,7 +73,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler {
} }
// Applepay, Samsungpay, Googlepay - always successful and does not depends on card // Applepay, Samsungpay, Googlepay - always successful and does not depends on card
TransactionInfo transactionInfo = createDefaultTransactionInfo(context); TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context);
if (hasBankCardTokenProvider(context)) { if (hasBankCardTokenProvider(context)) {
return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo); return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo);
} }
@ -103,7 +102,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler {
Intent currentIntent = intent; Intent currentIntent = intent;
VerifyEnrollmentResponse verifyEnrollmentResponse = mpiApi.verifyEnrollment(cardData); VerifyEnrollmentResponse verifyEnrollmentResponse = mpiApi.verifyEnrollment(cardData);
if (isAuthenticationAvailable(verifyEnrollmentResponse.getEnrolled())) { 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()); String termUrl = UrlUtils.getCallbackUrl(mockBankProperties.getCallbackUrl(), mockBankProperties.getPathCallbackUrl());
currentIntent = prepareRedirect(context, verifyEnrollmentResponse, tag, termUrl); currentIntent = prepareRedirect(context, verifyEnrollmentResponse, tag, termUrl);
} }
@ -120,7 +119,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler {
Intent intent = createIntentWithSuspendIntent( Intent intent = createIntentWithSuspendIntent(
tag, timerRedirectTimeout, createPostUserInteraction(url, params) 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))); intent.getSuspend().setTimeoutBehaviour(TimeoutBehaviour.operation_failure(OperationFailure.failure(failure)));
return intent; return intent;
} }

View File

@ -12,7 +12,6 @@ import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.constant.PaymentState; import com.rbkmoney.java.damsel.constant.PaymentState;
import com.rbkmoney.proxy.mocketbank.configuration.properties.AdapterMockBankProperties; import com.rbkmoney.proxy.mocketbank.configuration.properties.AdapterMockBankProperties;
import com.rbkmoney.proxy.mocketbank.configuration.properties.TimerProperties; 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.MpiApi;
import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse;
import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder; import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder;
@ -31,12 +30,13 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import static com.rbkmoney.java.damsel.constant.Error.DEFAULT_ERROR_CODE; 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.creators.ProxyProviderPackageCreators.*;
import static com.rbkmoney.java.damsel.utils.extractors.OptionsExtractors.extractRedirectTimeout; 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.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.service.mpi.constant.EnrollmentStatus.isAuthenticationAvailable;
import static com.rbkmoney.proxy.mocketbank.utils.UrlUtils.prepareRedirectParams; 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.*; import static com.rbkmoney.proxy.mocketbank.utils.model.CardAction.*;
@Slf4j @Slf4j
@ -101,7 +101,7 @@ public class GenerateTokenHandler {
RecurrentTokenIntent recurrentTokenIntent = createRecurrentTokenWithSuspendIntent( RecurrentTokenIntent recurrentTokenIntent = createRecurrentTokenWithSuspendIntent(
tag, timerRedirectTimeout, createPostUserInteraction(url, params) 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))); recurrentTokenIntent.getSuspend().setTimeoutBehaviour(TimeoutBehaviour.operation_failure(OperationFailure.failure(failure)));
return recurrentTokenIntent; return recurrentTokenIntent;
} }

View File

@ -7,8 +7,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.damsel.proxy_provider.PaymentResource;
import com.rbkmoney.java.damsel.constant.PaymentState; 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.handler.payment.CommonPaymentHandler;
import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
@ -36,7 +36,7 @@ public class ProcessedRecurrentCommonPaymentHandler implements CommonPaymentHand
intent = createFinishIntentSuccessWithToken(invoiceId); intent = createFinishIntentSuccessWithToken(invoiceId);
} }
TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context);
return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo); return createPaymentProxyResult(intent, PaymentState.CAPTURED.getBytes(), transactionInfo);
} }
} }

View File

@ -6,8 +6,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.damsel.proxy_provider.PaymentResource; import com.rbkmoney.damsel.proxy_provider.PaymentResource;
import com.rbkmoney.java.damsel.constant.PaymentState; 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.handler.terminal.CommonTerminalHandler;
import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
@ -28,7 +28,7 @@ public class ProcessedTerminalCommonHandler implements CommonTerminalHandler {
@Override @Override
public PaymentProxyResult handler(PaymentContext context) throws TException { public PaymentProxyResult handler(PaymentContext context) throws TException {
TransactionInfo transactionInfo = ProxyProviderCreator.createDefaultTransactionInfo(context); TransactionInfo transactionInfo = CreatorUtils.createDefaultTransactionInfo(context);
return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo); return createPaymentProxyResult(createFinishIntentSuccess(), PaymentState.CAPTURED.getBytes(), transactionInfo);
} }

View File

@ -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";
}

View File

@ -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.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -16,7 +16,7 @@ public enum CryptoCurrencies {
NAMECOIN("Namecoin", "NMC"), NAMECOIN("Namecoin", "NMC"),
PEERCOIN("Peercoin", "PPC"), PEERCOIN("Peercoin", "PPC"),
DOGECOIN("Dogecoin", "DOGE"), DOGECOIN("Dogecoin", "DOGE"),
DOGECOIN_XDG( "Dogecoin", "XDG"), DOGECOIN_XDG("Dogecoin", "XDG"),
GRIDCOIN("Gridcoin", "GRC"), GRIDCOIN("Gridcoin", "GRC"),
PRIMECOIN("Primecoin", "XPM"), PRIMECOIN("Primecoin", "XPM"),
NXT("Nxt", "NXT"), NXT("Nxt", "NXT"),

View File

@ -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.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.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.Arrays; import java.util.Arrays;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CurrencyConverter { public class CurrencyVerification {
public static boolean isCryptoCurrency(com.rbkmoney.damsel.domain.Currency currency) { public static boolean isCryptoCurrency(com.rbkmoney.damsel.domain.Currency currency) {
return Arrays.asList(CryptoCurrencies.toArraySymbol()).contains(currency.getSymbolicCode()); return Arrays.asList(CryptoCurrencies.toArraySymbol()).contains(currency.getSymbolicCode());

View File

@ -15,7 +15,7 @@ import java.util.Map;
public class Converter { public class Converter {
public static Map byteBufferToMap(ByteBuffer byteBuffer) throws IOException { 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<String, String> map) throws JsonProcessingException { public static ByteBuffer mapToByteBuffer(Map<String, String> map) throws JsonProcessingException {

View File

@ -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());
}
}

View File

@ -1,11 +1,14 @@
package com.rbkmoney.proxy.mocketbank.utils; package com.rbkmoney.proxy.mocketbank.utils;
import com.rbkmoney.damsel.domain.Failure; 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.PaymentCallbackResult;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.damsel.proxy_provider.RecurrentTokenCallbackResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenCallbackResult;
import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult;
import com.rbkmoney.error.mapping.ErrorMapping; import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.damsel.utils.creators.P2pAdapterCreators;
import com.rbkmoney.proxy.mocketbank.utils.model.CardAction; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -15,6 +18,19 @@ import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreato
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ErrorBuilder { 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) { public static PaymentProxyResult prepareError(ErrorMapping errorMapping, String code, String message) {
Failure failure = errorMapping.mapFailure(code, message); Failure failure = errorMapping.mapFailure(code, message);
return createProxyResultFailure(failure); return createProxyResultFailure(failure);
@ -41,6 +57,15 @@ public class ErrorBuilder {
return createRecurrentTokenProxyResultFailure(failure); 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) { public static PaymentCallbackResult prepareCallbackError(ErrorMapping errorMapping, String code, String message) {
Failure failure = errorMapping.mapFailure(code, message); Failure failure = errorMapping.mapFailure(code, message);
return createCallbackResultFailure(failure); return createCallbackResultFailure(failure);

View File

@ -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
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -14,6 +14,10 @@ public enum MobilePhoneAction {
UNSUPPORTED_PHONE("Unsupported phone"), UNSUPPORTED_PHONE("Unsupported phone"),
INSUFFICIENT_FUNDS("Insufficient Funds"); INSUFFICIENT_FUNDS("Insufficient Funds");
private static final MobilePhoneAction[] MOBILE_PHONE_FAILED = {
UNKNOWN, UNSUPPORTED_PHONE, INSUFFICIENT_FUNDS
};
private final String action; private final String action;
public static MobilePhoneAction findByValue(String value) { public static MobilePhoneAction findByValue(String value) {
@ -23,18 +27,12 @@ public enum MobilePhoneAction {
.orElse(UNKNOWN); .orElse(UNKNOWN);
} }
public static MobilePhoneAction[] failedActions() {
return new MobilePhoneAction[]{
UNKNOWN, UNSUPPORTED_PHONE, INSUFFICIENT_FUNDS
};
}
public static boolean hasStatus(MobilePhoneAction[] actions, String value) { public static boolean hasStatus(MobilePhoneAction[] actions, String value) {
return Arrays.stream(actions).anyMatch(action -> action.getAction().equalsIgnoreCase(value)); return Arrays.stream(actions).anyMatch(action -> action.getAction().equalsIgnoreCase(value));
} }
public static boolean isFailedAction(String action) { public static boolean isFailedAction(String action) {
return hasStatus(failedActions(), action); return hasStatus(MOBILE_PHONE_FAILED, action);
} }
} }

View File

@ -51,10 +51,29 @@ public enum CardAction {
SAMSUNG_PAY_SUCCESS 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 = { private static final CardAction[] MPI_FAILED_CARDS = {
FAILURE_3DS, FAILURE_3DS,
TIMEOUT_3DS, TIMEOUT_3DS
UNKNOWN_FAILURE };
private static final CardAction[] MPI_TIMEOUT_CARDS = {
TIMEOUT_3DS
};
private static final CardAction[] MPI_SUCCESS_CARDS = {
SUCCESS_3DS
}; };
private final String action; private final String action;
@ -74,16 +93,76 @@ public enum CardAction {
return Arrays.asList(ENROLLED_CARDS).contains(action); 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) { public static boolean isCardFailed(CardAction action) {
return Arrays.asList(FAILED_CARDS).contains(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) { public static boolean isCardSuccess(CardAction action) {
return Arrays.asList(SUCCESS_CARDS).contains(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) { public static boolean isMpiCardFailed(CardAction action) {
return Arrays.asList(MPI_FAILED_CARDS).contains(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);
}
} }

View File

@ -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.BufferedReader;
import java.io.InputStream; import java.io.InputStream;

View File

@ -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 com.rbkmoney.proxy.mocketbank.utils.model.Card;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -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 com.rbkmoney.proxy.mocketbank.utils.mobilephone.MobilePhone;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -8,7 +8,8 @@ import lombok.RequiredArgsConstructor;
public enum SuspendPrefix { public enum SuspendPrefix {
RECURRENT("REC_MPI-"), RECURRENT("REC_MPI-"),
PAYMENT("COM_MPI-"); PAYMENT("COM_MPI-"),
P2P("P2P_MPI-");
private final String prefix; private final String prefix;
} }

View File

@ -3,8 +3,8 @@ package com.rbkmoney.proxy.mocketbank.validator;
import com.rbkmoney.damsel.domain.PaymentTool; import com.rbkmoney.damsel.domain.PaymentTool;
import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentResource; 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.exception.MobileException;
import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
import static com.rbkmoney.java.damsel.utils.extractors.ProxyProviderPackageExtractors.extractPaymentResource; 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 @Component
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)

View File

@ -3,8 +3,8 @@ package com.rbkmoney.proxy.mocketbank.validator;
import com.rbkmoney.damsel.domain.PaymentTool; import com.rbkmoney.damsel.domain.PaymentTool;
import com.rbkmoney.damsel.proxy_provider.PaymentContext; import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentResource; 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.exception.TerminalException;
import com.rbkmoney.proxy.mocketbank.utils.extractor.proxy.ProxyProviderPackageExtractors;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -2,7 +2,7 @@ package com.rbkmoney.proxy.mocketbank.validator;
import com.rbkmoney.damsel.withdrawals.provider_adapter.GetQuoteParams; import com.rbkmoney.damsel.withdrawals.provider_adapter.GetQuoteParams;
import com.rbkmoney.proxy.mocketbank.exception.WithdrawalException; 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.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -15,13 +15,13 @@ public class WithdrawalValidator implements Validator<GetQuoteParams> {
public void validate(GetQuoteParams getQuoteParams, Map<String, String> options) { public void validate(GetQuoteParams getQuoteParams, Map<String, String> options) {
validateRequiredFields(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"); 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"); 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"); throw new WithdrawalException("Can't exchange equals currency, all currency is different");
} }
} }

View File

@ -27,6 +27,7 @@ adapter-mock-bank:
callbackUrl: http://127.0.0.1:8019 callbackUrl: http://127.0.0.1:8019
pathCallbackUrl: /${server.rest.endpoint}/term_url{?termination_uri} pathCallbackUrl: /${server.rest.endpoint}/term_url{?termination_uri}
pathRecurrentCallbackUrl: /${server.rest.endpoint}/term_rec_url{?termination_uri} pathRecurrentCallbackUrl: /${server.rest.endpoint}/term_rec_url{?termination_uri}
pathP2pCallbackUrl: /${server.rest.endpoint}/p2p{?termination_uri}
--- ---
cds: cds:
client: client:
@ -43,6 +44,12 @@ hellgate:
url: http://127.0.0.1:8023/v1/proxyhost/provider url: http://127.0.0.1:8023/v1/proxyhost/provider
networkTimeout: 30000 networkTimeout: 30000
--- ---
fistful:
client:
adapter:
url: http://127.0.0.1:8025/v1/ff_p2p_adapter_host
networkTimeout: 30000
---
timer: timer:
redirectTimeout: 600 redirectTimeout: 600
--- ---

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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!");
}
}

View File

@ -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.constant.TransactionStatus;
import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse; import com.rbkmoney.proxy.mocketbank.service.mpi.model.ValidatePaResResponse;
import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse; import com.rbkmoney.proxy.mocketbank.service.mpi.model.VerifyEnrollmentResponse;
import com.rbkmoney.proxy.mocketbank.utils.model.Card;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createDisposablePaymentResource; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createDisposablePaymentResource;
@ -45,6 +47,9 @@ public abstract class IntegrationTest {
@Autowired @Autowired
protected PaymentServerHandlerMdcLog handler; protected PaymentServerHandlerMdcLog handler;
@Autowired
protected List<Card> cardList;
@MockBean @MockBean
protected CdsClientStorage cdsStorage; 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) { protected void mockCds(CardData cardData, BankCard bankCard) {
CardDataProxyModel proxyModel = CardDataProxyModel.builder() CardDataProxyModel proxyModel = CardDataProxyModel.builder()
.cardholderName(bankCard.getCardholderName()) .cardholderName(bankCard.getCardholderName())

View File

@ -4,9 +4,8 @@ import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.domain.BankCard; import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.creators.DomainPackageCreators.createTargetProcessed;
import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isFailure; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isFailure;
import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData;
@ -33,21 +34,9 @@ public class MocketBankServerHandlerFailIntegrationTest extends IntegrationTest
@Test @Test
public void testProcessPaymentFail() throws TException { public void testProcessPaymentFail() throws TException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardFailed);
Visa.INSUFFICIENT_FUNDS, for (String pan : pans) {
Mastercard.INSUFFICIENT_FUNDS, CardData cardData = createCardData(pan);
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());
processPaymentFail(cardData); processPaymentFail(cardData);
} }
} }

View File

@ -8,10 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; 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.constant.TransactionStatus;
import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.Converter; import com.rbkmoney.proxy.mocketbank.utils.Converter;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
@ -23,9 +22,11 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; 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.java.damsel.utils.verification.ProxyProviderVerification.isSuspend;
import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -44,20 +45,14 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest extends Integrati
@Test @Test
public void testProcessPaymentFail() throws TException, IOException { public void testProcessPaymentFail() throws TException, IOException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardFailed);
Visa.FAILURE_3DS, for (String pan : pans) {
Mastercard.FAILURE_3DS, CardData cardData = createCardData(pan);
Visa.TIMEOUT_3DS, processPayment(cardData);
Mastercard.TIMEOUT_3DS
};
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPaymentFail(cardData);
} }
} }
private void processPaymentFail(CardData cardData) throws TException, IOException { private void processPayment(CardData cardData) throws TException, IOException {
BankCard bankCard = TestData.createBankCard(cardData); BankCard bankCard = TestData.createBankCard(cardData);
mockCds(cardData, bankCard); mockCds(cardData, bankCard);
mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE);
@ -74,7 +69,7 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest extends Integrati
ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback);
PaymentCallbackResult callbackResult = handler.handlePaymentCallback(callbackMap, paymentContext); PaymentCallbackResult callbackResult = handler.handlePaymentCallback(callbackMap, paymentContext);
assertTrue("CallbackResult isn`t failure", isCallbackFailure(callbackResult)); assertTrue("CallbackResult isn`t failure", isFailure(callbackResult));
} }
} }

View File

@ -6,10 +6,9 @@ import com.rbkmoney.damsel.proxy_provider.*;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; 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.constant.TransactionStatus;
import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.Converter; import com.rbkmoney.proxy.mocketbank.utils.Converter;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
@ -21,6 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured;
@ -43,13 +43,9 @@ public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest extends I
@Test @Test
public void testProcessPaymentSuccess() throws TException, IOException { public void testProcessPaymentSuccess() throws TException, IOException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardSuccess);
Visa.SUCCESS_3DS, for (String pan : pans) {
Mastercard.SUCCESS_3DS CardData cardData = createCardData(pan);
};
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPayment(cardData); processPayment(cardData);
} }
} }
@ -72,7 +68,7 @@ public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest extends I
ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback);
RecurrentTokenCallbackResult tokenCallbackResult = handler.handleRecurrentTokenCallback(callbackMap, context); RecurrentTokenCallbackResult tokenCallbackResult = handler.handleRecurrentTokenCallback(callbackMap, context);
assertTrue("HandleRecurrentTokenCallback isn`t success", isRecurrentTokenCallbackSuccess(tokenCallbackResult)); assertTrue("HandleRecurrentTokenCallback isn`t success", isSuccess(tokenCallbackResult));
// process // process
String token = tokenCallbackResult.getResult().getIntent().getFinish().getStatus().getSuccess().getToken(); String token = tokenCallbackResult.getResult().getIntent().getFinish().getStatus().getSuccess().getToken();

View File

@ -7,7 +7,8 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext;
import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult; import com.rbkmoney.damsel.proxy_provider.RecurrentTokenProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; 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 lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
@ -17,6 +18,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException; 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.createTargetCaptured;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetProcessed;
@ -37,15 +39,9 @@ public class MocketBankServerHandlerRecurrentSuccessIntegrationTest extends Inte
@Test @Test
public void testProcessPaymentSuccess() throws TException, IOException { public void testProcessPaymentSuccess() throws TException, IOException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccess);
Visa.SUCCESS, for (String pan : pans) {
Mastercard.SUCCESS, CardData cardData = createCardData(pan);
Maestro.SUCCESS,
Mir.SUCCESS
};
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPayment(cardData); processPayment(cardData);
} }
} }

View File

@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.creators.DomainPackageCreators.createTargetProcessed;
import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess;
import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData;
@ -33,12 +35,9 @@ public class MocketBankServerHandlerSuccessApplePayntegrationTest extends Integr
@Test @Test
public void testProcessPaymentFail() throws TException { public void testProcessPaymentFail() throws TException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessApplePay);
Visa.APPLE_PAY_FAILURE for (String pan : pans) {
}; CardData cardData = createCardData(pan);
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPayment(cardData); processPayment(cardData);
} }
} }

View File

@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.creators.DomainPackageCreators.createTargetProcessed;
import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess;
import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData;
@ -29,16 +31,13 @@ import static org.junit.Assert.assertTrue;
} }
) )
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class MocketBankServerHandlerSuccessGooglePayIntegrationTest extends IntegrationTest { public class MocketBankServerHandlerSuccessGooglePayIntegrationTest extends IntegrationTest {
@Test @Test
public void testProcessPaymentSuccess() throws TException { public void testProcessPaymentSuccess() throws TException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessGooglePay);
Mastercard.GOOGLE_PAY_SUCCESS, for (String pan : pans) {
}; CardData cardData = createCardData(pan);
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPayment(cardData); processPayment(cardData);
} }
} }

View File

@ -5,7 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.TransactionInfo; import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; 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 lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
@ -15,6 +16,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.*;
import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess;
@ -34,20 +36,14 @@ public class MocketBankServerHandlerSuccessIntegrationTest extends IntegrationTe
@Test @Test
public void testProcessPaymentSuccess() throws TException { public void testProcessPaymentSuccess() throws TException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccess);
Visa.SUCCESS, for (String pan : pans) {
Mastercard.SUCCESS, CardData cardData = createCardData(pan);
Maestro.SUCCESS, processPayment(cardData);
Mir.SUCCESS
};
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPaymentSuccess(cardData);
} }
} }
private void processPaymentSuccess(CardData cardData) throws TException { private void processPayment(CardData cardData) throws TException {
BankCard bankCard = TestData.createBankCard(cardData); BankCard bankCard = TestData.createBankCard(cardData);
mockCds(cardData, bankCard); mockCds(cardData, bankCard);

View File

@ -5,8 +5,8 @@ import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.BankCardTokenProvider; import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult; import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.creators.DomainPackageCreators.createTargetProcessed;
import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess; import static com.rbkmoney.java.damsel.utils.verification.ProxyProviderVerification.isSuccess;
import static com.rbkmoney.proxy.mocketbank.TestData.createCardData; import static com.rbkmoney.proxy.mocketbank.TestData.createCardData;
@ -33,12 +35,9 @@ public class MocketBankServerHandlerSuccessSamsungPayIntegrationTest extends Int
@Test @Test
public void testProcessPaymentSuccess() throws TException { public void testProcessPaymentSuccess() throws TException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isCardSuccessSamsungPay);
Mastercard.SAMSUNG_PAY_SUCCESS, for (String pan : pans) {
}; CardData cardData = createCardData(pan);
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPayment(cardData); processPayment(cardData);
} }
} }

View File

@ -8,10 +8,9 @@ import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
import com.rbkmoney.proxy.mocketbank.TestData; import com.rbkmoney.proxy.mocketbank.TestData;
import com.rbkmoney.proxy.mocketbank.service.mpi.constant.EnrollmentStatus; 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.constant.TransactionStatus;
import com.rbkmoney.proxy.mocketbank.utils.CardListUtils;
import com.rbkmoney.proxy.mocketbank.utils.Converter; import com.rbkmoney.proxy.mocketbank.utils.Converter;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Mastercard; import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.TestCard;
import com.rbkmoney.proxy.mocketbank.utils.constant.testcards.Visa;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
@ -23,6 +22,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured; import static com.rbkmoney.java.damsel.utils.creators.DomainPackageCreators.createTargetCaptured;
@ -46,18 +46,14 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest extends Integr
@Test @Test
public void testProcessPaymentSuccess() throws TException, IOException { public void testProcessPaymentSuccess() throws TException, IOException {
TestCard[] cards = { List<String> pans = CardListUtils.extractPans(cardList, CardAction::isMpiCardSuccess);
Visa.SUCCESS_3DS, for (String pan : pans) {
Mastercard.SUCCESS_3DS CardData cardData = createCardData(pan);
}; processPayment(cardData);
for (TestCard card : cards) {
CardData cardData = createCardData(card.getCardNumber());
processPaymentSuccess(cardData);
} }
} }
private void processPaymentSuccess(CardData cardData) throws TException, IOException { private void processPayment(CardData cardData) throws TException, IOException {
BankCard bankCard = TestData.createBankCard(cardData); BankCard bankCard = TestData.createBankCard(cardData);
mockCds(cardData, bankCard); mockCds(cardData, bankCard);
mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE); mockMpiVerify(EnrollmentStatus.AUTHENTICATION_AVAILABLE);
@ -74,7 +70,7 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest extends Integr
ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback); ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback);
PaymentCallbackResult callbackResult = handler.handlePaymentCallback(callbackMap, paymentContext); 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().setTarget(createTargetCaptured());
paymentContext.getSession().setState(callbackResult.getResult().getNextState()); paymentContext.getSession().setState(callbackResult.getResult().getNextState());

View File

@ -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<IdentityDocument> identityDocumentList = createIdentityDocumentsList(TestData.WITHDRAWAL_TOKEN);
Identity identity = createIdentity(identityDocumentList);
return new Withdrawal()
.setId(WITHDRAWALID)
.setDestination(destination)
.setBody(createCash())
.setSender(identity);
}
protected List<IdentityDocument> createIdentityDocumentsList(String token) {
List<IdentityDocument> 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<IdentityDocument> 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<String, String> createProxyOptions() {
return Collections.emptyMap();
}
protected List<ContactDetail> createContactDetailsList() {
List<ContactDetail> contactDetailList = new ArrayList<>();
ContactDetail contactDetail = new ContactDetail();
contactDetail.setPhoneNumber(TestData.PHONE_NUMBER);
contactDetailList.add(contactDetail);
return contactDetailList;
}
}

View File

@ -1,28 +1,15 @@
package com.rbkmoney.proxy.mocketbank.handler.oct; package com.rbkmoney.proxy.mocketbank.handler.oct;
import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.msgpack.Value; 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.ProcessResult;
import com.rbkmoney.damsel.withdrawals.provider_adapter.Withdrawal;
import com.rbkmoney.proxy.mocketbank.TestData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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 com.rbkmoney.java.damsel.utils.extractors.WithdrawalsProviderAdapterPackageExtractors.isSuccess;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -35,12 +22,7 @@ import static org.junit.Assert.assertTrue;
} }
) )
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class OctServerHandlerTest { public class OctServerHandlerTest extends OctIntegrationTest {
@Autowired
protected AdapterSrv.Iface handler;
private String WithdrawalId = "TWithId" + (int) (Math.random() * 50 + 1);
@Test @Test
public void testProcessWithdrawal() throws TException { public void testProcessWithdrawal() throws TException {
@ -53,57 +35,4 @@ public class OctServerHandlerTest {
assertTrue("Result processWithdrawal isn`t success", isSuccess(result)); assertTrue("Result processWithdrawal isn`t success", isSuccess(result));
} }
private Withdrawal createWithdrawal() {
BankCard bankCard = TestData.createBankCard(TestData.createCardData());
Destination destination = createDestination(bankCard);
List<IdentityDocument> identityDocumentList = createIdentityDocumentsList(TestData.WITHDRAWAL_TOKEN);
Identity identity = createIdentity(identityDocumentList);
return new Withdrawal()
.setId(WithdrawalId)
.setDestination(destination)
.setBody(createCash())
.setSender(identity);
}
private List<IdentityDocument> createIdentityDocumentsList(String token) {
List<IdentityDocument> 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<IdentityDocument> 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<String, String> createProxyOptions() {
return Collections.emptyMap();
}
private List<ContactDetail> createContactDetailsList() {
List<ContactDetail> contactDetailList = new ArrayList<>();
ContactDetail contactDetail = new ContactDetail();
contactDetail.setPhoneNumber(TestData.PHONE_NUMBER);
contactDetailList.add(contactDetail);
return contactDetailList;
}
} }

View File

@ -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<Card> 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<String, String> 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<String, String> 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);
}
}

View File

@ -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<String> 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<String, String> 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));
}
}

View File

@ -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<String> 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));
}
}

View File

@ -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<String> 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));
}
}

View File

@ -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<String> 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<String, String> 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));
}
}

View File

@ -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<String> 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));
}
}

View File

@ -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);
}
}

View File

@ -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<String> extractPans(List<Card> cardList, Predicate<Card> cardPredicate) {
return cardList.stream()
.filter(cardPredicate)
.map(Card::getPan)
.collect(Collectors.toList());
}
}

View File

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

View File

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

View File

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

View File

@ -1,5 +0,0 @@
package com.rbkmoney.proxy.mocketbank.utils.constant.testcards;
public interface TestCard {
String getCardNumber();
}

View File

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

View File

@ -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";
}

View File

@ -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<String, String> 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");
}
}

View File

@ -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();
}
}