mirror of
https://github.com/valitydev/proxy-mocketbank.git
synced 2024-11-06 10:05:16 +00:00
parent
5e0b1aa432
commit
44f6395191
20
pom.xml
20
pom.xml
@ -70,19 +70,13 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>damsel</artifactId>
|
||||
<version>1.199-c49c94f</version>
|
||||
<version>1.204-478235a</version>
|
||||
</dependency>
|
||||
<!--Test libs-->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.10.19</version>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -90,6 +84,12 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.palantir.docker.compose</groupId>
|
||||
<artifactId>docker-compose-rule</artifactId>
|
||||
<version>0.28.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -2,6 +2,7 @@ package com.rbkmoney.proxy.mocketbank.controller;
|
||||
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.hellgate.HellGateApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankTag;
|
||||
import org.apache.thrift.TException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -21,10 +22,10 @@ import java.nio.ByteBuffer;
|
||||
@RequestMapping(value = "/mocketbank")
|
||||
public class MocketBankController {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankController.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MocketBankController.class);
|
||||
|
||||
@Autowired
|
||||
HellGateApi hellGateApi;
|
||||
private HellGateApi hellGateApi;
|
||||
|
||||
@RequestMapping(value = "term_url", method = RequestMethod.POST)
|
||||
public String receiveIncomingParameters(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException {
|
||||
@ -47,9 +48,17 @@ public class MocketBankController {
|
||||
LOGGER.warn("Missing a required parameter 'MD' ");
|
||||
}
|
||||
|
||||
// Узнать рекурент или нет, после чего вызвать тот или иной метод
|
||||
try {
|
||||
ByteBuffer response = hellGateApi.processCallback(tag, callback);
|
||||
resp = new String(response.array(), "UTF-8");
|
||||
|
||||
ByteBuffer response;
|
||||
if (tag.startsWith(MocketBankTag.RECURRENT_SUSPEND_TAG)) {
|
||||
response = hellGateApi.processRecurrentTokenCallback(tag, callback);
|
||||
} else {
|
||||
response = hellGateApi.processPaymentCallback(tag, callback);
|
||||
}
|
||||
|
||||
resp = new String(response.array(), "UTF-8");
|
||||
} catch (TException | UnsupportedEncodingException e) {
|
||||
LOGGER.error("Exception in processCallback", e);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.rbkmoney.proxy.mocketbank.utils.mocketbank.MocketBankMpiUtils;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankMpiAction;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankMpiEnrollmentStatus;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankMpiTransactionStatus;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankTag;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.model.ValidatePaResResponse;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.model.VerifyEnrollmentResponse;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.model.Card;
|
||||
@ -35,15 +36,13 @@ import static com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBank
|
||||
@Component
|
||||
public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandler.class);
|
||||
|
||||
private Map<String, String> options;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandler.class);
|
||||
|
||||
@Autowired
|
||||
private CdsApi cds;
|
||||
|
||||
@Autowired
|
||||
MocketBankMpiApi mocketBankMpiApi;
|
||||
private MocketBankMpiApi mocketBankMpiApi;
|
||||
|
||||
@Value("${proxy-mocketbank.callbackUrl}")
|
||||
private String callbackUrl;
|
||||
@ -61,21 +60,247 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
cardList = CardUtils.getCardListFromFile(fixtureCards.getInputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Запрос к прокси на создание многоразового токена
|
||||
*/
|
||||
@Override
|
||||
public ProxyResult processPayment(Context context) throws TException {
|
||||
public RecurrentTokenProxyResult generateToken(RecurrentTokenContext context) throws TException {
|
||||
LOGGER.info("GenerateToken start");
|
||||
|
||||
options = (context.getOptions().size() > 0) ? context.getOptions() : new HashMap<>();
|
||||
String session = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentSessionId();
|
||||
String token = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool().getBankCard().getToken();
|
||||
|
||||
String recurrentToken = token;
|
||||
RecurrentTokenIntent intent = ProxyProviderWrapper.makeRecurrentTokenFinishIntentSuccess(token);
|
||||
|
||||
CardData cardData;
|
||||
try {
|
||||
LOGGER.info("GenerateToken: call CDS. Token {}, session: {}", token, session);
|
||||
cardData = cds.getSessionCardData(token, session);
|
||||
} catch (TException e) {
|
||||
LOGGER.error("GenerateToken: CDS Exception", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenProxyResultFailure("GenerateToken: CDS Exception", e.getMessage());
|
||||
}
|
||||
|
||||
CardUtils cardUtils = new CardUtils(cardList);
|
||||
Optional<Card> card = cardUtils.getCardByPan(cardData.getPan());
|
||||
|
||||
if (card.isPresent()) {
|
||||
MocketBankMpiAction action = MocketBankMpiAction.findByValue(card.get().getAction());
|
||||
|
||||
if (!cardUtils.isEnrolled(card)) {
|
||||
String error;
|
||||
switch (action) {
|
||||
case INSUFFICIENT_FUNDS:
|
||||
error = INSUFFICIENT_FUNDS.getAction();
|
||||
break;
|
||||
case INVALID_CARD:
|
||||
error = INVALID_CARD.getAction();
|
||||
break;
|
||||
case CVV_MATCH_FAIL:
|
||||
error = CVV_MATCH_FAIL.getAction();
|
||||
break;
|
||||
case EXPIRED_CARD:
|
||||
error = EXPIRED_CARD.getAction();
|
||||
break;
|
||||
case SUCCESS:
|
||||
RecurrentTokenProxyResult proxyResult = ProxyProviderWrapper.makeRecurrentTokenProxyResult(
|
||||
intent,
|
||||
"processed".getBytes(),
|
||||
recurrentToken
|
||||
);
|
||||
LOGGER.info("GenerateToken: success {}", proxyResult);
|
||||
return proxyResult;
|
||||
default:
|
||||
error = UNKNOWN_FAILURE.getAction();
|
||||
|
||||
}
|
||||
RecurrentTokenProxyResult proxyResult = ProxyProviderWrapper.makeRecurrentTokenProxyResultFailure(error, error);
|
||||
LOGGER.info("GenerateToken: failure {}", proxyResult);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
} else {
|
||||
RecurrentTokenProxyResult proxyResult = ProxyProviderWrapper.makeRecurrentTokenProxyResultFailure(
|
||||
UNSUPPORTED_CARD.getAction(),
|
||||
UNSUPPORTED_CARD.getAction()
|
||||
);
|
||||
LOGGER.info("GenerateToken: failure {}", proxyResult);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
VerifyEnrollmentResponse verifyEnrollmentResponse = null;
|
||||
try {
|
||||
verifyEnrollmentResponse = mocketBankMpiApi.verifyEnrollment(
|
||||
cardData.getPan(),
|
||||
cardData.getExpDate().getYear(),
|
||||
cardData.getExpDate().getMonth()
|
||||
);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("GenerateToken: Exception in verifyEnrollment", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenProxyResultFailure(
|
||||
UNKNOWN_FAILURE.getAction(),
|
||||
UNKNOWN_FAILURE.getAction()
|
||||
);
|
||||
}
|
||||
|
||||
if (verifyEnrollmentResponse.getEnrolled().equals(MocketBankMpiEnrollmentStatus.AUTHENTICATION_AVAILABLE)) {
|
||||
String tag = MocketBankTag.RECURRENT_SUSPEND_TAG + context.getTokenInfo().getPaymentTool().getId();
|
||||
LOGGER.info("GenerateToken: suspend tag {}", tag);
|
||||
|
||||
String url = verifyEnrollmentResponse.getAcsUrl();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("PaReq", verifyEnrollmentResponse.getPaReq());
|
||||
params.put("MD", tag);
|
||||
params.put("TermUrl", MocketBankMpiUtils.getCallbackUrl(callbackUrl, "/mocketbank/term_url{?termination_uri}"));
|
||||
|
||||
LOGGER.info("GenerateToken: prepare redirect params {}", params);
|
||||
|
||||
intent = ProxyProviderWrapper.makeRecurrentTokenWithSuspendIntent(
|
||||
tag, BaseWrapper.makeTimerTimeout(timerTimeout),
|
||||
UserInteractionWrapper.makeUserInteraction(
|
||||
UserInteractionWrapper.makeBrowserPostRequest(
|
||||
url,
|
||||
params
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, String> extra = new HashMap<>();
|
||||
extra.put(MocketBankMpiUtils.PA_REQ, verifyEnrollmentResponse.getPaReq());
|
||||
|
||||
LOGGER.info("GenerateToken: Extra map {}", extra);
|
||||
|
||||
byte[] state;
|
||||
try {
|
||||
state = Converter.mapToByteArray(extra);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("GenerateToken: Converter Exception", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenProxyResultFailure("Converter", e.getMessage());
|
||||
}
|
||||
|
||||
RecurrentTokenProxyResult result = ProxyProviderWrapper.makeRecurrentTokenProxyResult(
|
||||
intent, state, recurrentToken
|
||||
);
|
||||
|
||||
LOGGER.info("GenerateToken: finish {}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Запрос к прокси на обработку обратного вызова от провайдера в рамках сессии получения
|
||||
* многоразового токена.
|
||||
*/
|
||||
@Override
|
||||
public RecurrentTokenCallbackResult handleRecurrentTokenCallback(ByteBuffer byteBuffer, RecurrentTokenContext context) throws TException {
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: start");
|
||||
|
||||
String session = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentSessionId();
|
||||
String token = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool().getBankCard().getToken();
|
||||
|
||||
Map<String, String> options = context.getOptions();
|
||||
String recurrentToken = token;
|
||||
HashMap<String, String> parameters;
|
||||
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: merge input parameters");
|
||||
try {
|
||||
parameters = (HashMap<String, String>) Converter.byteArrayToMap(context.getSession().getState());
|
||||
parameters.putAll(Converter.byteBufferToMap(byteBuffer));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("RecurrentTokenGenerationCallbackResult: Parse ByteBuffer Exception", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenCallbackResultFailure(
|
||||
"error".getBytes(),
|
||||
"RecurrentTokenGenerationCallbackResult: Parse ByteBuffer Exception",
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: merge input parameters {}", parameters);
|
||||
|
||||
CardData cardData;
|
||||
try {
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: call CDS. Token {}, session: {}", token, session);
|
||||
cardData = cds.getSessionCardData(token, session);
|
||||
} catch (TException e) {
|
||||
LOGGER.error("RecurrentTokenGenerationCallbackResult: CDS Exception", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenCallbackResultFailure(
|
||||
"error".getBytes(),
|
||||
"RecurrentTokenGenerationCallbackResult: CDS Exception",
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
ValidatePaResResponse validatePaResResponse;
|
||||
try {
|
||||
validatePaResResponse = mocketBankMpiApi.validatePaRes(cardData.getPan(), parameters.get("paRes"));
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("RecurrentTokenGenerationCallbackResult: Exception", e);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenCallbackResultFailure(
|
||||
"error".getBytes(),
|
||||
"RecurrentTokenGenerationCallbackResult: Exception",
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: validatePaResResponse {}", validatePaResResponse);
|
||||
|
||||
if (validatePaResResponse.getTransactionStatus().equals(MocketBankMpiTransactionStatus.AUTHENTICATION_SUCCESSFUL)) {
|
||||
byte[] callbackResponse = new byte[0];
|
||||
RecurrentTokenIntent intent = ProxyProviderWrapper.makeRecurrentTokenFinishIntentSuccess(token);
|
||||
|
||||
|
||||
RecurrentTokenProxyResult proxyResult = ProxyProviderWrapper.makeRecurrentTokenProxyResult(
|
||||
intent,
|
||||
"processed".getBytes(),
|
||||
recurrentToken
|
||||
);
|
||||
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: callbackResponse {}, proxyResult {}", callbackResponse, proxyResult);
|
||||
return ProxyProviderWrapper.makeRecurrentTokenCallbackResult(callbackResponse, proxyResult);
|
||||
}
|
||||
|
||||
CardUtils cardUtils = new CardUtils(cardList);
|
||||
Optional<Card> card = cardUtils.getCardByPan(cardData.getPan());
|
||||
MocketBankMpiAction action = MocketBankMpiAction.findByValue(card.get().getAction());
|
||||
String error;
|
||||
|
||||
switch (action) {
|
||||
case THREE_D_SECURE_FAILURE:
|
||||
error = THREE_D_SECURE_FAILURE.getAction();
|
||||
break;
|
||||
case THREE_D_SECURE_TIMEOUT:
|
||||
error = THREE_D_SECURE_TIMEOUT.getAction();
|
||||
break;
|
||||
default:
|
||||
error = UNKNOWN_FAILURE.getAction();
|
||||
|
||||
}
|
||||
|
||||
RecurrentTokenCallbackResult callbackResult = ProxyProviderWrapper.makeRecurrentTokenCallbackResultFailure(
|
||||
"error".getBytes(), "RecurrentTokenGenerationCallbackResult: error", error
|
||||
);
|
||||
|
||||
LOGGER.info("RecurrentTokenGenerationCallbackResult: callbackResult {}", callbackResult);
|
||||
return callbackResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Тут токен
|
||||
@Override
|
||||
public PaymentProxyResult processPayment(PaymentContext context) throws TException {
|
||||
|
||||
Map<String, String> options = (context.getOptions().size() > 0) ? context.getOptions() : new HashMap<>();
|
||||
|
||||
TargetInvoicePaymentStatus target = context.getSession().getTarget();
|
||||
|
||||
if (target.isSetProcessed()) {
|
||||
return processed(context);
|
||||
return processed(context, options);
|
||||
} else if (target.isSetCaptured()) {
|
||||
return captured(context);
|
||||
return captured(context, options);
|
||||
} else if (target.isSetCancelled()) {
|
||||
return cancelled(context);
|
||||
return cancelled(context, options);
|
||||
} else if (target.isSetRefunded()) {
|
||||
return refunded(context);
|
||||
return refunded(context, options);
|
||||
} else {
|
||||
LOGGER.error("Error unsupported method");
|
||||
return ProxyProviderWrapper.makeProxyResultFailure("Unsupported method", "Unsupported method");
|
||||
@ -83,24 +308,31 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
|
||||
}
|
||||
|
||||
private ProxyResult processed(Context context) {
|
||||
LOGGER.info("processed start");
|
||||
private PaymentProxyResult processed(PaymentContext context, Map<String, String> options) {
|
||||
LOGGER.info("Processed start");
|
||||
com.rbkmoney.damsel.proxy_provider.InvoicePayment invoicePayment = context.getPaymentInfo().getPayment();
|
||||
String session = invoicePayment.getPayer().getSessionId();
|
||||
String token = invoicePayment.getPayer().getPaymentTool().getBankCard().getToken();
|
||||
|
||||
CardData cardData;
|
||||
TransactionInfo transactionInfo = null;
|
||||
|
||||
com.rbkmoney.damsel.proxy.Intent intent = ProxyWrapper.makeFinishIntentSuccess();
|
||||
|
||||
try {
|
||||
LOGGER.info("Processed: call CDS. Token {}, session: {}", token, session);
|
||||
cardData = cds.getSessionCardData(token, session);
|
||||
|
||||
if(invoicePayment.getPaymentResource().isSetRecurrentPaymentResource()) {
|
||||
cardData = cds.getCardData(invoicePayment.getPaymentResource().getRecurrentPaymentResource().getRecToken());
|
||||
} else {
|
||||
String session = invoicePayment.getPaymentResource().getDisposablePaymentResource().getPaymentSessionId();
|
||||
String token = invoicePayment.getPaymentResource().getDisposablePaymentResource().getPaymentTool().getBankCard().getToken();
|
||||
LOGGER.info("Processed: call CDS. Token {}, session: {}", token, session);
|
||||
cardData = cds.getSessionCardData(token, session);
|
||||
}
|
||||
|
||||
} catch (TException e) {
|
||||
LOGGER.error("Processed: CDS Exception", e);
|
||||
return ProxyProviderWrapper.makeProxyResultFailure("Processed: CDS Exception", e.getMessage());
|
||||
}
|
||||
|
||||
TransactionInfo transactionInfo = null;
|
||||
com.rbkmoney.damsel.proxy.Intent intent = ProxyWrapper.makeFinishIntentSuccess();
|
||||
|
||||
|
||||
CardUtils cardUtils = new CardUtils(cardList);
|
||||
Optional<Card> card = cardUtils.getCardByPan(cardData.getPan());
|
||||
|
||||
@ -127,7 +359,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
MocketBankMpiUtils.generateInvoice(context.getPaymentInfo()),
|
||||
Collections.emptyMap()
|
||||
);
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(
|
||||
intent,
|
||||
"captured".getBytes(),
|
||||
transactionInfo
|
||||
@ -138,13 +370,13 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
error = UNKNOWN_FAILURE.getAction();
|
||||
|
||||
}
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResultFailure(error, error);
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makeProxyResultFailure(error, error);
|
||||
LOGGER.info("Processed: failure {}", proxyResult);
|
||||
return ProxyProviderWrapper.makeProxyResultFailure(error, error);
|
||||
}
|
||||
|
||||
} else {
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResultFailure(
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makeProxyResultFailure(
|
||||
UNSUPPORTED_CARD.getAction(),
|
||||
UNSUPPORTED_CARD.getAction()
|
||||
);
|
||||
@ -152,6 +384,20 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
if(invoicePayment.getPaymentResource().isSetRecurrentPaymentResource()) {
|
||||
transactionInfo = DomainWrapper.makeTransactionInfo(
|
||||
MocketBankMpiUtils.generateInvoice(context.getPaymentInfo()),
|
||||
Collections.emptyMap()
|
||||
);
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(
|
||||
intent,
|
||||
"captured".getBytes(),
|
||||
transactionInfo
|
||||
);
|
||||
LOGGER.info("Processed: success {}", proxyResult);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
VerifyEnrollmentResponse verifyEnrollmentResponse = null;
|
||||
try {
|
||||
verifyEnrollmentResponse = mocketBankMpiApi.verifyEnrollment(
|
||||
@ -168,7 +414,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
}
|
||||
|
||||
if (verifyEnrollmentResponse.getEnrolled().equals(MocketBankMpiEnrollmentStatus.AUTHENTICATION_AVAILABLE)) {
|
||||
String tag = "MPI-" + MocketBankMpiUtils.generateInvoice(context.getPaymentInfo());
|
||||
String tag = MocketBankTag.PAYMENT_SUSPEND_TAG + MocketBankMpiUtils.generateInvoice(context.getPaymentInfo());
|
||||
LOGGER.info("Processed: suspend tag {}", tag);
|
||||
|
||||
String url = verifyEnrollmentResponse.getAcsUrl();
|
||||
@ -204,12 +450,12 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
return ProxyProviderWrapper.makeProxyResultFailure("Converter", e.getMessage());
|
||||
}
|
||||
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(intent, state, transactionInfo);
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(intent, state, transactionInfo);
|
||||
LOGGER.info("Processed: finish {}", proxyResult);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
private ProxyResult captured(Context context) {
|
||||
private PaymentProxyResult captured(PaymentContext context, Map<String, String> options) {
|
||||
LOGGER.info("Captured: start");
|
||||
com.rbkmoney.damsel.proxy_provider.InvoicePayment payment = context.getPaymentInfo().getPayment();
|
||||
TransactionInfo transactionInfoContractor = payment.getTrx();
|
||||
@ -221,14 +467,14 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
context.getSession().setState("confirm".getBytes());
|
||||
|
||||
Intent intent = ProxyWrapper.makeFinishIntentSuccess();
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(intent, "confirm".getBytes(), transactionInfo);
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(intent, "confirm".getBytes(), transactionInfo);
|
||||
|
||||
LOGGER.info("Captured: proxyResult {}", proxyResult);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
private ProxyResult cancelled(Context context) {
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(
|
||||
private PaymentProxyResult cancelled(PaymentContext context, Map<String, String> options) {
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(
|
||||
ProxyWrapper.makeFinishIntentSuccess(),
|
||||
"cancelled".getBytes(),
|
||||
context.getPaymentInfo().getPayment().getTrx()
|
||||
@ -237,8 +483,8 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
private ProxyResult refunded(Context context) {
|
||||
ProxyResult proxyResult = ProxyProviderWrapper.makeProxyResult(
|
||||
private PaymentProxyResult refunded(PaymentContext context, Map<String, String> options) {
|
||||
PaymentProxyResult proxyResult = ProxyProviderWrapper.makePaymentProxyResult(
|
||||
ProxyWrapper.makeFinishIntentSuccess(),
|
||||
"refunded".getBytes(),
|
||||
context.getPaymentInfo().getPayment().getTrx()
|
||||
@ -248,12 +494,12 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallbackResult handlePaymentCallback(ByteBuffer byteBuffer, Context context) throws TException {
|
||||
public PaymentCallbackResult handlePaymentCallback(ByteBuffer byteBuffer, PaymentContext context) throws TException {
|
||||
LOGGER.info("HandlePaymentCallback: start");
|
||||
InvoicePayment invoicePayment = context.getPaymentInfo().getPayment();
|
||||
String token = invoicePayment.getPayer().getPaymentTool().getBankCard().getToken();
|
||||
String session = invoicePayment.getPayer().getSessionId();
|
||||
options = context.getOptions();
|
||||
String session = invoicePayment.getPaymentResource().getDisposablePaymentResource().getPaymentSessionId();
|
||||
String token = invoicePayment.getPaymentResource().getDisposablePaymentResource().getPaymentTool().getBankCard().getToken();
|
||||
Map<String, String> options = context.getOptions();
|
||||
|
||||
HashMap<String, String> parameters;
|
||||
|
||||
@ -306,7 +552,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
Collections.emptyMap()
|
||||
);
|
||||
|
||||
CallbackProxyResult proxyResult = ProxyProviderWrapper.makeCallbackProxyResult(
|
||||
PaymentCallbackProxyResult proxyResult = ProxyProviderWrapper.makeCallbackProxyResult(
|
||||
intent, "captured".getBytes(), transactionInfo
|
||||
);
|
||||
|
||||
@ -331,7 +577,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
|
||||
|
||||
}
|
||||
|
||||
CallbackResult callbackResult = ProxyProviderWrapper.makeCallbackResultFailure(
|
||||
PaymentCallbackResult callbackResult = ProxyProviderWrapper.makeCallbackResultFailure(
|
||||
"error".getBytes(), "HandlePaymentCallback: error", error
|
||||
);
|
||||
|
||||
|
@ -47,12 +47,24 @@ public class DomainWrapper {
|
||||
return paymentTool;
|
||||
}
|
||||
|
||||
public static Payer makePayer(ContactInfo contactInfo, ClientInfo clientInfo, PaymentTool paymentTool, String session) {
|
||||
public static DisposablePaymentResource makeDisposablePaymentResource(ClientInfo clientInfo, String paymentSessionId, PaymentTool paymentTool) {
|
||||
DisposablePaymentResource resource = new DisposablePaymentResource();
|
||||
resource.setClientInfo(clientInfo);
|
||||
resource.setPaymentSessionId(paymentSessionId);
|
||||
resource.setPaymentTool(paymentTool);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static PaymentResourcePayer makePaymentResourcePayer(ContactInfo contactInfo, DisposablePaymentResource disposablePaymentResource) {
|
||||
PaymentResourcePayer paymentResourcePayer = new PaymentResourcePayer();
|
||||
paymentResourcePayer.setContactInfo(contactInfo);
|
||||
paymentResourcePayer.setResource(disposablePaymentResource);
|
||||
return paymentResourcePayer;
|
||||
}
|
||||
|
||||
public static Payer makePayer(PaymentResourcePayer paymentResourcePayer) {
|
||||
Payer payer = new Payer();
|
||||
payer.setContactInfo(contactInfo);
|
||||
payer.setClientInfo(clientInfo);
|
||||
payer.setPaymentTool(paymentTool);
|
||||
payer.setSessionId(session);
|
||||
payer.setPaymentResource(paymentResourcePayer);
|
||||
return payer;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,22 @@
|
||||
package com.rbkmoney.proxy.mocketbank.utils.damsel;
|
||||
|
||||
import com.rbkmoney.damsel.base.Timer;
|
||||
import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.ExpDate;
|
||||
import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.proxy.Intent;
|
||||
import com.rbkmoney.damsel.proxy_provider.*;
|
||||
import com.rbkmoney.damsel.proxy_provider.Invoice;
|
||||
import com.rbkmoney.damsel.proxy_provider.InvoicePayment;
|
||||
import com.rbkmoney.damsel.proxy_provider.*;
|
||||
import com.rbkmoney.damsel.proxy_provider.Shop;
|
||||
import com.rbkmoney.damsel.user_interaction.UserInteraction;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyWrapper.makeFailure;
|
||||
|
||||
|
||||
public class ProxyProviderWrapper {
|
||||
|
||||
public static TargetInvoicePaymentStatus makeTargetProcessed() {
|
||||
@ -32,6 +37,12 @@ public class ProxyProviderWrapper {
|
||||
return target;
|
||||
}
|
||||
|
||||
public static TargetInvoicePaymentStatus makeTargetRefunded() {
|
||||
TargetInvoicePaymentStatus target = new TargetInvoicePaymentStatus();
|
||||
target.setRefunded(new InvoicePaymentRefunded());
|
||||
return target;
|
||||
}
|
||||
|
||||
public static Session makeSession(TargetInvoicePaymentStatus target, byte[] state) {
|
||||
Session session = new Session();
|
||||
session.setTarget(target);
|
||||
@ -43,25 +54,145 @@ public class ProxyProviderWrapper {
|
||||
return ProxyProviderWrapper.makeSession(target, null);
|
||||
}
|
||||
|
||||
|
||||
// RecurrentTokenIntent
|
||||
public static RecurrentTokenSuccess makeRecurrentTokenSuccess(String token) {
|
||||
RecurrentTokenSuccess recurrentTokenSuccess = new RecurrentTokenSuccess();
|
||||
recurrentTokenSuccess.setToken(token);
|
||||
return recurrentTokenSuccess;
|
||||
}
|
||||
|
||||
public static RecurrentTokenFinishIntent makeRecurrentTokenStatusSuccess(String token) {
|
||||
RecurrentTokenFinishIntent intent = new RecurrentTokenFinishIntent();
|
||||
|
||||
RecurrentTokenFinishStatus status = new RecurrentTokenFinishStatus();
|
||||
status.setSuccess(makeRecurrentTokenSuccess(token));
|
||||
intent.setStatus(status);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static RecurrentTokenFinishIntent makeRecurrentTokenStatusFailure(String code, String description) {
|
||||
RecurrentTokenFinishIntent intent = new RecurrentTokenFinishIntent();
|
||||
|
||||
RecurrentTokenFinishStatus status = new RecurrentTokenFinishStatus();
|
||||
status.setFailure(makeFailure(code, description));
|
||||
intent.setStatus(status);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static RecurrentTokenIntent makeRecurrentTokenFinishIntentFailure(String code, String description) {
|
||||
RecurrentTokenIntent intent = new RecurrentTokenIntent();
|
||||
intent.setFinish(makeRecurrentTokenStatusFailure(code, description));
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static RecurrentTokenIntent makeRecurrentTokenFinishIntentSuccess(String token) {
|
||||
RecurrentTokenIntent intent = new RecurrentTokenIntent();
|
||||
intent.setFinish(makeRecurrentTokenStatusSuccess(token));
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static RecurrentTokenIntent makeRecurrentTokenWithSuspendIntent(String tag, Timer timer, UserInteraction userInteraction) {
|
||||
RecurrentTokenIntent intent = new RecurrentTokenIntent();
|
||||
intent.setSuspend(ProxyWrapper.makeSuspendIntent(tag, timer, userInteraction));
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static RecurrentTokenIntent makeRecurrentTokenWithSuspendIntent(String tag, Timer timer) {
|
||||
return makeRecurrentTokenWithSuspendIntent(tag, timer, null);
|
||||
}
|
||||
|
||||
// RecurrentTokenInfo
|
||||
public static RecurrentTokenInfo makeRecurrentTokenInfo(RecurrentPaymentTool recurrentPaymentTool) {
|
||||
RecurrentTokenInfo recurrentTokenInfo = new RecurrentTokenInfo();
|
||||
recurrentTokenInfo.setPaymentTool(recurrentPaymentTool);
|
||||
return recurrentTokenInfo;
|
||||
}
|
||||
|
||||
// DisposablePaymentResource
|
||||
public static DisposablePaymentResource makeDisposablePaymentResource(String sessionId, PaymentTool paymentTool) {
|
||||
DisposablePaymentResource disposablePaymentResource = new DisposablePaymentResource();
|
||||
disposablePaymentResource.setPaymentSessionId(sessionId);
|
||||
disposablePaymentResource.setPaymentTool(paymentTool);
|
||||
return disposablePaymentResource;
|
||||
}
|
||||
|
||||
// RecurrentPaymentTool
|
||||
public static RecurrentPaymentTool makeRecurrentPaymentTool(DisposablePaymentResource disposablePaymentResource) {
|
||||
RecurrentPaymentTool recurrentPaymentTool = new RecurrentPaymentTool();
|
||||
recurrentPaymentTool.setPaymentResource(disposablePaymentResource);
|
||||
return recurrentPaymentTool;
|
||||
}
|
||||
|
||||
public static RecurrentPaymentTool makeRecurrentPaymentTool(DisposablePaymentResource disposablePaymentResource, com.rbkmoney.damsel.proxy_provider.Cash cash) {
|
||||
RecurrentPaymentTool recurrentPaymentTool = new RecurrentPaymentTool();
|
||||
recurrentPaymentTool.setPaymentResource(disposablePaymentResource);
|
||||
recurrentPaymentTool.setMinimalPaymentCost(cash);
|
||||
return recurrentPaymentTool;
|
||||
}
|
||||
|
||||
public static RecurrentPaymentTool makeRecurrentPaymentTool(String id, DisposablePaymentResource disposablePaymentResource, com.rbkmoney.damsel.proxy_provider.Cash cash) {
|
||||
RecurrentPaymentTool recurrentPaymentTool = new RecurrentPaymentTool();
|
||||
recurrentPaymentTool.setPaymentResource(disposablePaymentResource);
|
||||
recurrentPaymentTool.setMinimalPaymentCost(cash);
|
||||
recurrentPaymentTool.setId(id);
|
||||
return recurrentPaymentTool;
|
||||
}
|
||||
|
||||
|
||||
// RecurrentTokenProxyResult
|
||||
public static RecurrentTokenProxyResult makeRecurrentTokenProxyResult(
|
||||
RecurrentTokenIntent intent, byte[] nextState, String token, TransactionInfo trx
|
||||
) {
|
||||
RecurrentTokenProxyResult result = new RecurrentTokenProxyResult();
|
||||
result.setIntent(intent);
|
||||
result.setNextState(nextState);
|
||||
result.setToken(token);
|
||||
result.setTrx(trx);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static RecurrentTokenProxyResult makeRecurrentTokenProxyResult(RecurrentTokenIntent intent) {
|
||||
return makeRecurrentTokenProxyResult(intent, null, null, null);
|
||||
}
|
||||
|
||||
public static RecurrentTokenProxyResult makeRecurrentTokenProxyResult(
|
||||
RecurrentTokenIntent intent, byte[] nextState
|
||||
) {
|
||||
return makeRecurrentTokenProxyResult(intent, nextState, null, null);
|
||||
}
|
||||
|
||||
public static RecurrentTokenProxyResult makeRecurrentTokenProxyResult(
|
||||
RecurrentTokenIntent intent, byte[] nextState, String token
|
||||
) {
|
||||
return makeRecurrentTokenProxyResult(intent, nextState, token, null);
|
||||
}
|
||||
|
||||
public static RecurrentTokenProxyResult makeRecurrentTokenProxyResultFailure(String code, String description) {
|
||||
return makeRecurrentTokenProxyResult(makeRecurrentTokenFinishIntentFailure(code, description));
|
||||
}
|
||||
|
||||
// ProxyResult
|
||||
public static ProxyResult makeProxyResult(Intent intent, byte[] next_state, TransactionInfo trx) {
|
||||
ProxyResult proxyResult = new ProxyResult();
|
||||
public static PaymentProxyResult makePaymentProxyResult(Intent intent, byte[] next_state, TransactionInfo trx) {
|
||||
PaymentProxyResult proxyResult = new PaymentProxyResult();
|
||||
proxyResult.setIntent(intent);
|
||||
proxyResult.setNextState(next_state);
|
||||
proxyResult.setTrx(trx);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
public static ProxyResult makeProxyResult(Intent intent, byte[] next_state) {
|
||||
return makeProxyResult(intent, next_state, null);
|
||||
public static PaymentProxyResult makePaymentProxyResult(Intent intent, byte[] next_state) {
|
||||
return makePaymentProxyResult(intent, next_state, null);
|
||||
}
|
||||
|
||||
public static ProxyResult makeProxyResult(Intent intent) {
|
||||
return makeProxyResult(intent, null, null);
|
||||
public static PaymentProxyResult makePaymentProxyResult(Intent intent) {
|
||||
return makePaymentProxyResult(intent, null, null);
|
||||
}
|
||||
|
||||
public static ProxyResult makeProxyResultFailure(String code, String description) {
|
||||
ProxyResult proxyResult = new ProxyResult();
|
||||
public static PaymentProxyResult makeProxyResultFailure(String code, String description) {
|
||||
PaymentProxyResult proxyResult = new PaymentProxyResult();
|
||||
proxyResult.setIntent(ProxyWrapper.makeFinishIntentFailure(code, description));
|
||||
return proxyResult;
|
||||
}
|
||||
@ -81,6 +212,13 @@ public class ProxyProviderWrapper {
|
||||
return cash;
|
||||
}
|
||||
|
||||
public static com.rbkmoney.damsel.domain.Cash makeCash(CurrencyRef currency, Long amount) {
|
||||
com.rbkmoney.damsel.domain.Cash cash = new com.rbkmoney.damsel.domain.Cash();
|
||||
cash.setAmount(amount);
|
||||
cash.setCurrency(currency);
|
||||
return cash;
|
||||
}
|
||||
|
||||
public static CardData makeCardData(String cardholderName, String cvv, String pan, ExpDate expDate) {
|
||||
return CdsWrapper.makeCardData(cardholderName, cvv, pan, expDate);
|
||||
}
|
||||
@ -101,12 +239,12 @@ public class ProxyProviderWrapper {
|
||||
return paymentInfo;
|
||||
}
|
||||
|
||||
public static Context makeContext(
|
||||
public static PaymentContext makeContext(
|
||||
com.rbkmoney.damsel.proxy_provider.PaymentInfo paymentInfo,
|
||||
com.rbkmoney.damsel.proxy_provider.Session session,
|
||||
Map<String, String> options
|
||||
) {
|
||||
Context context = new Context();
|
||||
PaymentContext context = new PaymentContext();
|
||||
context.setPaymentInfo(paymentInfo);
|
||||
context.setSession(session);
|
||||
context.setOptions(options);
|
||||
@ -129,20 +267,38 @@ public class ProxyProviderWrapper {
|
||||
}
|
||||
|
||||
|
||||
public static InvoicePayment makeInvoicePayment(String invoicePaymentId, String created_at, com.rbkmoney.damsel.domain.Payer payer, com.rbkmoney.damsel.proxy_provider.Cash cost) {
|
||||
public static InvoicePayment makeInvoicePayment(String invoicePaymentId, String created_at, PaymentResource paymentResource, com.rbkmoney.damsel.proxy_provider.Cash cost) {
|
||||
InvoicePayment invoicePayment = new InvoicePayment();
|
||||
invoicePayment.setId(invoicePaymentId);
|
||||
invoicePayment.setCreatedAt(created_at);
|
||||
invoicePayment.setPayer(payer);
|
||||
invoicePayment.setPaymentResource(paymentResource);
|
||||
invoicePayment.setCost(cost);
|
||||
return invoicePayment;
|
||||
}
|
||||
|
||||
public static InvoicePayment makeInvoicePaymentWithTrX(String invoicePaymentId, String created_at, com.rbkmoney.damsel.domain.Payer payer, com.rbkmoney.damsel.proxy_provider.Cash cost, TransactionInfo transactionInfo) {
|
||||
public static PaymentResource makePaymentResourceDisposablePaymentResource(DisposablePaymentResource disposablePaymentResource) {
|
||||
PaymentResource paymentResource = new PaymentResource();
|
||||
paymentResource.setDisposablePaymentResource(disposablePaymentResource);
|
||||
return paymentResource;
|
||||
}
|
||||
|
||||
public static RecurrentPaymentResource makeRecurrentPaymentResource(String token) {
|
||||
RecurrentPaymentResource resource = new RecurrentPaymentResource();
|
||||
resource.setRecToken(token);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static PaymentResource makePaymentResourceRecurrentPaymentResource(RecurrentPaymentResource recurrentPaymentResource) {
|
||||
PaymentResource paymentResource = new PaymentResource();
|
||||
paymentResource.setRecurrentPaymentResource(recurrentPaymentResource);
|
||||
return paymentResource;
|
||||
}
|
||||
|
||||
public static InvoicePayment makeInvoicePaymentWithTrX(String invoicePaymentId, String created_at, PaymentResource paymentResource, com.rbkmoney.damsel.proxy_provider.Cash cost, TransactionInfo transactionInfo) {
|
||||
InvoicePayment invoicePayment = new InvoicePayment();
|
||||
invoicePayment.setId(invoicePaymentId);
|
||||
invoicePayment.setCreatedAt(created_at);
|
||||
invoicePayment.setPayer(payer);
|
||||
invoicePayment.setPaymentResource(paymentResource);
|
||||
invoicePayment.setCost(cost);
|
||||
invoicePayment.setTrx(transactionInfo);
|
||||
return invoicePayment;
|
||||
@ -160,33 +316,55 @@ public class ProxyProviderWrapper {
|
||||
return session;
|
||||
}
|
||||
|
||||
public static CallbackProxyResult makeCallbackProxyResult(Intent intent, byte[] next_state, TransactionInfo trx) {
|
||||
CallbackProxyResult proxyResult = new CallbackProxyResult();
|
||||
public static PaymentCallbackProxyResult makeCallbackProxyResult(Intent intent, byte[] next_state, TransactionInfo trx) {
|
||||
PaymentCallbackProxyResult proxyResult = new PaymentCallbackProxyResult();
|
||||
proxyResult.setIntent(intent);
|
||||
proxyResult.setNextState(next_state);
|
||||
proxyResult.setTrx(trx);
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
public static CallbackProxyResult makeCallbackProxyResultFailure(String code, String description) {
|
||||
CallbackProxyResult proxyResult = new CallbackProxyResult();
|
||||
public static PaymentCallbackProxyResult makeCallbackProxyResultFailure(String code, String description) {
|
||||
PaymentCallbackProxyResult proxyResult = new PaymentCallbackProxyResult();
|
||||
proxyResult.setIntent(ProxyWrapper.makeFinishIntentFailure(code, description));
|
||||
return proxyResult;
|
||||
}
|
||||
|
||||
public static CallbackResult makeCallbackResult(byte[] callbackResponse, CallbackProxyResult proxyResult) {
|
||||
CallbackResult callbackResult = new CallbackResult();
|
||||
public static PaymentCallbackResult makeCallbackResult(byte[] callbackResponse, PaymentCallbackProxyResult proxyResult) {
|
||||
PaymentCallbackResult callbackResult = new PaymentCallbackResult();
|
||||
callbackResult.setResponse(callbackResponse);
|
||||
callbackResult.setResult(proxyResult);
|
||||
return callbackResult;
|
||||
}
|
||||
|
||||
|
||||
public static CallbackResult makeCallbackResultFailure(byte[] callbackResponse, String code, String description) {
|
||||
CallbackResult callbackResult = new CallbackResult();
|
||||
public static PaymentCallbackResult makeCallbackResultFailure(byte[] callbackResponse, String code, String description) {
|
||||
PaymentCallbackResult callbackResult = new PaymentCallbackResult();
|
||||
callbackResult.setResponse(callbackResponse);
|
||||
callbackResult.setResult(ProxyProviderWrapper.makeCallbackProxyResultFailure(code, description));
|
||||
return callbackResult;
|
||||
}
|
||||
|
||||
public static PaymentCallbackResult makeCallbackResultFailure(String code, String description) {
|
||||
return makeCallbackResultFailure("error".getBytes(), code, description);
|
||||
}
|
||||
|
||||
// RecurrentTokenCallbackResult
|
||||
public static RecurrentTokenCallbackResult makeRecurrentTokenCallbackResult(byte[] callbackResponse, RecurrentTokenProxyResult proxyResult) {
|
||||
RecurrentTokenCallbackResult result = new RecurrentTokenCallbackResult();
|
||||
result.setResponse(callbackResponse);
|
||||
result.setResult(proxyResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static RecurrentTokenCallbackResult makeRecurrentTokenCallbackResultFailure(byte[] callbackResponse, String code, String description) {
|
||||
RecurrentTokenCallbackResult result = new RecurrentTokenCallbackResult();
|
||||
result.setResponse(callbackResponse);
|
||||
result.setResult(makeRecurrentTokenProxyResult(makeRecurrentTokenFinishIntentFailure(code, description)));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static RecurrentTokenCallbackResult makeRecurrentTokenCallbackResultFailure(String code, String description) {
|
||||
return makeRecurrentTokenCallbackResultFailure("error".getBytes(), code, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,9 +17,17 @@ public class HellGateApi {
|
||||
@Autowired
|
||||
private ProviderProxyHostSrv.Iface providerProxyHostSrv;
|
||||
|
||||
public ByteBuffer processCallback(String tag, ByteBuffer callback) throws TException {
|
||||
public ByteBuffer processPaymentCallback(String tag, ByteBuffer callback) throws TException {
|
||||
LOGGER.info("Hellgate: processCallback start");
|
||||
ByteBuffer callbackResponse = providerProxyHostSrv.processCallback(tag, callback);
|
||||
ByteBuffer callbackResponse = providerProxyHostSrv.processPaymentCallback(tag, callback);
|
||||
LOGGER.info("Hellgate: processCallback finish");
|
||||
return callbackResponse;
|
||||
}
|
||||
|
||||
|
||||
public ByteBuffer processRecurrentTokenCallback(String tag, ByteBuffer callback) throws TException {
|
||||
LOGGER.info("Hellgate: processCallback start");
|
||||
ByteBuffer callbackResponse = providerProxyHostSrv.processRecurrentTokenCallback(tag, callback);
|
||||
LOGGER.info("Hellgate: processCallback finish");
|
||||
return callbackResponse;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant;
|
||||
|
||||
|
||||
public class MocketBankTag {
|
||||
|
||||
public static final String RECURRENT_SUSPEND_TAG = "REC_MPI-";
|
||||
public static final String PAYMENT_SUSPEND_TAG = "COM_MPI-";
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.rbkmoney.proxy.mocketbank.handler;
|
||||
|
||||
import com.palantir.docker.compose.DockerComposeRule;
|
||||
import com.palantir.docker.compose.connection.waiting.HealthChecks;
|
||||
import com.palantir.docker.compose.execution.DockerComposeExecArgument;
|
||||
import com.palantir.docker.compose.execution.DockerComposeExecOption;
|
||||
import org.junit.rules.ExternalResource;
|
||||
|
||||
public class IntegrationBaseRule extends ExternalResource {
|
||||
|
||||
private static final String CDS = "cds";
|
||||
private static final String HOLMES = "holmes";
|
||||
private static final String PROXY_MOCKETBANK_MPI = "proxy-mocketbank-mpi";
|
||||
|
||||
public static final DockerComposeRule docker = DockerComposeRule.builder()
|
||||
.file("src/test/resources/docker-compose.yml")
|
||||
.waitingForService(CDS, HealthChecks.toHaveAllPortsOpen())
|
||||
.waitingForService(HOLMES, HealthChecks.toHaveAllPortsOpen())
|
||||
.waitingForService(PROXY_MOCKETBANK_MPI, HealthChecks.toHaveAllPortsOpen())
|
||||
.build();
|
||||
|
||||
protected void before() throws Throwable {
|
||||
docker.before();
|
||||
executeHolmesScripts();
|
||||
}
|
||||
|
||||
protected void after() {
|
||||
docker.after();
|
||||
}
|
||||
|
||||
private void executeHolmesScripts() {
|
||||
try {
|
||||
docker.dockerCompose().exec(
|
||||
DockerComposeExecOption.noOptions(),
|
||||
HOLMES,
|
||||
DockerComposeExecArgument.arguments("/opt/holmes/scripts/cds/init-keyring.sh")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,10 @@ import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.PutCardDataResult;
|
||||
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.Context;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.ProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentResource;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.cds.CdsApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.CdsWrapper;
|
||||
@ -14,6 +15,7 @@ import com.rbkmoney.proxy.mocketbank.utils.damsel.DomainWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -42,6 +44,8 @@ import static org.junit.Assert.assertTrue;
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
@ -49,6 +53,9 @@ public class MocketBankServerHandlerFailIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerFailIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@ -115,7 +122,7 @@ public class MocketBankServerHandlerFailIntegrationTest {
|
||||
private void processPaymentFail(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
ProxyResult processResultPayment = handler.processPayment(
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
@ -151,23 +158,28 @@ public class MocketBankServerHandlerFailIntegrationTest {
|
||||
ProxyProviderWrapper.makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
DomainWrapper.makePayer(
|
||||
DomainWrapper.makeContactInfo("email", "phone"),
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard()),
|
||||
putCardDataResponse.getSessionId()
|
||||
),
|
||||
getPaymentResource(putCardDataResponse),
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
return Converter.mapToByteArray(Collections.emptyMap());
|
||||
}
|
||||
|
||||
private Context getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return ProxyProviderWrapper.makeContext(
|
||||
getPaymentInfo(putCardDataResult, transactionInfo),
|
||||
ProxyProviderWrapper.makeSession(
|
||||
|
@ -4,10 +4,7 @@ import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.PutCardDataResult;
|
||||
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.CallbackResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.Context;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.ProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.*;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.cds.CdsApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.CdsWrapper;
|
||||
@ -15,6 +12,7 @@ import com.rbkmoney.proxy.mocketbank.utils.damsel.DomainWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -44,6 +42,9 @@ import static org.junit.Assert.assertTrue;
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
"proxy-mocketbank-mpi.url=http://127.0.0.1:8018",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
@ -51,6 +52,9 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerFailWith3DSIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@ -107,7 +111,7 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
|
||||
private void processPaymentFail(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
ProxyResult processResultPayment = handler.processPayment(
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
@ -127,7 +131,7 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
|
||||
ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback);
|
||||
|
||||
// handlePaymentCallback
|
||||
CallbackResult callbackResult = handler.handlePaymentCallback(
|
||||
PaymentCallbackResult callbackResult = handler.handlePaymentCallback(
|
||||
callbackMap, getContext(putCardDataResponse, null, null)
|
||||
);
|
||||
|
||||
@ -153,25 +157,30 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
|
||||
ProxyProviderWrapper.makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
DomainWrapper.makePayer(
|
||||
DomainWrapper.makeContactInfo("email", "phone"),
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard()),
|
||||
putCardDataResponse.getSessionId()
|
||||
),
|
||||
getPaymentResource(putCardDataResponse),
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
Map<String, String> extra = new HashMap<>();
|
||||
extra.put("paReq","paReq");
|
||||
return Converter.mapToByteArray(extra);
|
||||
}
|
||||
|
||||
private Context getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return ProxyProviderWrapper.makeContext(
|
||||
getPaymentInfo(putCardDataResult, transactionInfo),
|
||||
ProxyProviderWrapper.makeSession(
|
||||
|
@ -0,0 +1,392 @@
|
||||
package com.rbkmoney.proxy.mocketbank.handler;
|
||||
|
||||
import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.PutCardDataResult;
|
||||
import com.rbkmoney.damsel.domain.PaymentTool;
|
||||
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.*;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.cds.CdsApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.CdsWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.DomainWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.Converter.byteArrayToMap;
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.Converter.mapToByteBuffer;
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.damsel.DomainWrapper.makeCurrency;
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper.*;
|
||||
import static org.apache.commons.lang3.StringUtils.trim;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
||||
properties = {
|
||||
"merchant.id=24275801",
|
||||
"merchant.name=RBKmoney1",
|
||||
"merchant.url=http://localhost",
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
protected String recurrentId = "Recurrent" + (int) (Math.random() * 500 + 1);
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@Autowired
|
||||
private CdsApi cds;
|
||||
|
||||
@Value("${merchant.id}")
|
||||
private String merchantId;
|
||||
|
||||
@Value("${merchant.name}")
|
||||
private String merchantName;
|
||||
|
||||
@Value("${merchant.url}")
|
||||
private String merchantUrl;
|
||||
|
||||
@Value("${merchant.acquirerBin}")
|
||||
private String merchantAcquirerBin;
|
||||
|
||||
@Value("${merchant.password}")
|
||||
private String merchantPassword;
|
||||
|
||||
@Value("${merchant.countryCode}")
|
||||
private String merchantCountryCode;
|
||||
|
||||
private String invoiceId = "TEST_INVOICE" + (int) (Math.random() * 50 + 1);
|
||||
private String paymentId = "TEST_PAYMENT" + (int) (Math.random() * 50 + 1);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Connect to CDS
|
||||
// TODO используется лишь в первый раз при запуске теста для разблокировки ключа
|
||||
// UnlockStatus unlockStatus = cdsUnlockKey((short) 1, (short) 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessPaymentSuccess() throws TException, IOException, URISyntaxException {
|
||||
String[] cards = {
|
||||
"4012888888881881",
|
||||
"5169147129584558",
|
||||
};
|
||||
|
||||
// Put the card and save the response to a subsequent request
|
||||
for (String card : cards) {
|
||||
CardData cardData = CdsWrapper.makeCardDataWithExpDate(
|
||||
"NONAME",
|
||||
"123",
|
||||
card,
|
||||
Byte.parseByte("12"),
|
||||
Short.parseShort("2020")
|
||||
);
|
||||
processPaymentSuccess(cardData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processPaymentSuccess(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
RecurrentTokenContext context = new RecurrentTokenContext();
|
||||
context.setTokenInfo(
|
||||
makeRecurrentTokenInfo(
|
||||
makeRecurrentPaymentTool(
|
||||
recurrentId,
|
||||
makeDisposablePaymentResource(
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(
|
||||
putCardDataResponse.getBankCard()
|
||||
)
|
||||
),
|
||||
makeCash(
|
||||
makeCurrency(
|
||||
"Rubles",
|
||||
(short) 643,
|
||||
"RUB",
|
||||
(short) 1
|
||||
),
|
||||
1000L
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
LOGGER.info("Prepare RecurrentTokenContext - finish");
|
||||
// ------------------------------------------------------------------------
|
||||
// generate Token
|
||||
// ------------------------------------------------------------------------
|
||||
RecurrentTokenProxyResult generationProxyResult = handler.generateToken(context);
|
||||
LOGGER.info("Response generate Token {}", generationProxyResult);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// ACS PAGE
|
||||
// ------------------------------------------------------------------------
|
||||
Map<String, String> extraParams = byteArrayToMap(generationProxyResult.getNextState());
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
headers.add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
||||
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
params.add("MD", trim(extraParams.get("MD")));
|
||||
params.add("TermUrl", trim(extraParams.get("TermUrl")));
|
||||
params.add("PaReq", trim(extraParams.get("PaReq")));
|
||||
|
||||
HttpEntity<?> entity = new HttpEntity<>(params, headers);
|
||||
String acsUrl = generationProxyResult.getIntent().getSuspend().getUserInteraction().getRedirect().getPostRequest().getUri();
|
||||
|
||||
ResponseEntity responseThreeDS = new RestTemplate().exchange(acsUrl, HttpMethod.POST, entity, String.class);
|
||||
|
||||
Document doc = Jsoup.parse(responseThreeDS.getBody().toString());
|
||||
Elements elements = doc.getElementsByTag("input");
|
||||
|
||||
HashMap<String, String> threeDSparams = new HashMap<>();
|
||||
elements.forEach(
|
||||
element -> {
|
||||
if (!element.attributes().get("name").isEmpty()) {
|
||||
threeDSparams.put(element.attributes().get("name"), trim(element.attributes().get("value")));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// handleRecurrentTokenCallback
|
||||
// ------------------------------------------------------------------------
|
||||
ByteBuffer callback = mapToByteBuffer(threeDSparams);
|
||||
|
||||
RecurrentTokenSession recurrentTokenSession = new RecurrentTokenSession();
|
||||
context.setSession(recurrentTokenSession);
|
||||
|
||||
context.getSession().setState(generationProxyResult.getNextState());
|
||||
|
||||
RecurrentTokenCallbackResult recurrentTokenCallback = handler.handleRecurrentTokenCallback(callback, context);
|
||||
LOGGER.info("Response handleRecurrentTokenCallback {}", recurrentTokenCallback);
|
||||
|
||||
assertEquals("recurrentTokenCallback ", true, recurrentTokenCallback.getResult().getIntent().getFinish().getStatus().isSetSuccess());
|
||||
|
||||
PaymentResource paymentResource = new PaymentResource();
|
||||
RecurrentPaymentResource recurrentPaymentResource = new RecurrentPaymentResource();
|
||||
recurrentPaymentResource.setRecToken(recurrentTokenCallback.getResult().getToken());
|
||||
recurrentPaymentResource.setPaymentTool(DomainWrapper.makePaymentTool(
|
||||
putCardDataResponse.getBankCard()
|
||||
));
|
||||
paymentResource.setRecurrentPaymentResource(recurrentPaymentResource);
|
||||
|
||||
PaymentInfo paymentInfo = getPaymentInfo(putCardDataResponse, null, paymentResource);
|
||||
PaymentContext contextProcessed = ProxyProviderWrapper.makeContext(
|
||||
paymentInfo,
|
||||
ProxyProviderWrapper.makeSession(
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
"init".getBytes()
|
||||
),
|
||||
getOptionsProxy()
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// processed payment
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(contextProcessed);
|
||||
LOGGER.info("Response process payment {}", processResultPayment.toString());
|
||||
|
||||
assertEquals("Process payment ", ProxyWrapper.makeFinishStatusSuccess(), processResultPayment.getIntent().getFinish().getStatus());
|
||||
|
||||
|
||||
if (processResultPayment.getIntent().getFinish().getStatus().equals(ProxyWrapper.makeFinishStatusSuccess())) {
|
||||
|
||||
LOGGER.info("Update payment {} ", paymentInfo.getPayment());
|
||||
contextProcessed.getPaymentInfo().getPayment().setTrx(processResultPayment.getTrx());
|
||||
contextProcessed.getSession().setState("captured".getBytes());
|
||||
contextProcessed.getSession().setTarget(ProxyProviderWrapper.makeTargetCaptured());
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// captured payment
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
PaymentProxyResult processResultCapture = handler.processPayment(contextProcessed);
|
||||
LOGGER.info("Response capture payment {}", processResultCapture);
|
||||
|
||||
assertEquals("Process Capture ", ProxyWrapper.makeFinishStatusSuccess(), processResultCapture.getIntent().getFinish().getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, String> getOptionsProxy() {
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("merchantId", merchantId);
|
||||
options.put("merchantName", merchantName);
|
||||
options.put("merchantUrl", merchantUrl);
|
||||
options.put("merchantAcquirerBin", merchantAcquirerBin);
|
||||
options.put("merchantPassword", merchantPassword);
|
||||
options.put("merchantCountryCode", merchantCountryCode);
|
||||
return options;
|
||||
}
|
||||
|
||||
private PaymentInfo getPaymentInfo(TransactionInfo transactionInfo, PaymentResource paymentResource) {
|
||||
return makePaymentInfo(
|
||||
makeInvoice(
|
||||
invoiceId,
|
||||
"2016-06-02",
|
||||
getCost()
|
||||
),
|
||||
makeShop(
|
||||
DomainWrapper.makeCategory("CategoryName", "Category description"),
|
||||
DomainWrapper.makeShopDetails("ShopName", "Shop description")
|
||||
),
|
||||
makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
paymentResource,
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private PaymentResource getPaymentResourceRecurrent(String token) {
|
||||
return makePaymentResourceRecurrentPaymentResource(
|
||||
makeRecurrentPaymentResource(token)
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
return Converter.mapToByteArray(Collections.emptyMap());
|
||||
}
|
||||
|
||||
private PaymentContext getContext(PaymentResource paymentResource, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return makeContext(
|
||||
getPaymentInfo(transactionInfo, paymentResource),
|
||||
makeSession(
|
||||
target,
|
||||
getSessionState()
|
||||
),
|
||||
getOptionsProxy()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private Cash getCost() {
|
||||
return makeCash(
|
||||
makeCurrency("Rubles", (short) 643, "RUB", (short) 2),
|
||||
10000L
|
||||
);
|
||||
}
|
||||
|
||||
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
LOGGER.info("CDS: prepare card");
|
||||
// CardData cardData = TestData.makeCardData();
|
||||
|
||||
LOGGER.info("CDS: put card");
|
||||
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
|
||||
|
||||
LOGGER.info(putCardDataResponse.toString());
|
||||
return putCardDataResponse;
|
||||
}
|
||||
|
||||
|
||||
protected PaymentInfo getPaymentInfo(PutCardDataResult putCardDataResponse, TransactionInfo transactionInfo, PaymentResource paymentResource) {
|
||||
Invoice invoice = ProxyProviderWrapper.makeInvoice(
|
||||
invoiceId,
|
||||
"2016-06-02",
|
||||
ProxyProviderWrapper.makeCash(
|
||||
ProxyProviderWrapper.makeCurrency(
|
||||
"Rubles",
|
||||
(short) 643,
|
||||
"RUB",
|
||||
(short) 1
|
||||
),
|
||||
1000L
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
PaymentInfo paymentInfo = new PaymentInfo();
|
||||
paymentInfo.setInvoice(invoice);
|
||||
|
||||
InvoicePayment payment = getInvoicePayment(
|
||||
putCardDataResponse,
|
||||
paymentResource,
|
||||
DomainWrapper.makePaymentTool(
|
||||
putCardDataResponse.getBankCard()
|
||||
),
|
||||
transactionInfo
|
||||
);
|
||||
|
||||
paymentInfo.setPayment(payment);
|
||||
return paymentInfo;
|
||||
}
|
||||
|
||||
protected InvoicePayment getInvoicePayment(PutCardDataResult putCardDataResponse, PaymentResource paymentResource, PaymentTool paymentTool, TransactionInfo transactionInfo) {
|
||||
InvoicePayment payment = new InvoicePayment();
|
||||
payment.setId(paymentId);
|
||||
payment.setCreatedAt("2016-06-02");
|
||||
payment.setPaymentResource(paymentResource);
|
||||
payment.setCost(
|
||||
ProxyProviderWrapper.makeCash(
|
||||
ProxyProviderWrapper.makeCurrency(
|
||||
"Rubles",
|
||||
(short) 643,
|
||||
"RUB",
|
||||
(short) 1
|
||||
),
|
||||
1000L
|
||||
)
|
||||
);
|
||||
payment.setTrx(transactionInfo);
|
||||
return payment;
|
||||
}
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
package com.rbkmoney.proxy.mocketbank.handler;
|
||||
|
||||
import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.PutCardDataResult;
|
||||
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.*;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.cds.CdsApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.CdsWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.DomainWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
||||
properties = {
|
||||
"merchant.id=24275801",
|
||||
"merchant.name=RBKmoney1",
|
||||
"merchant.url=http://localhost",
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
public class MocketBankServerHandlerRecurrentSuccessIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerRecurrentSuccessIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@Autowired
|
||||
private CdsApi cds;
|
||||
|
||||
@Value("${merchant.id}")
|
||||
private String merchantId;
|
||||
|
||||
@Value("${merchant.name}")
|
||||
private String merchantName;
|
||||
|
||||
@Value("${merchant.url}")
|
||||
private String merchantUrl;
|
||||
|
||||
@Value("${merchant.acquirerBin}")
|
||||
private String merchantAcquirerBin;
|
||||
|
||||
@Value("${merchant.password}")
|
||||
private String merchantPassword;
|
||||
|
||||
@Value("${merchant.countryCode}")
|
||||
private String merchantCountryCode;
|
||||
|
||||
private String invoiceId = "TEST_INVOICE" + (int) (Math.random() * 50 + 1);
|
||||
private String paymentId = "TEST_PAYMENT" + (int) (Math.random() * 50 + 1);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Connect to CDS
|
||||
// TODO используется лишь в первый раз при запуске теста для разблокировки ключа
|
||||
// UnlockStatus unlockStatus = cdsUnlockKey((short) 1, (short) 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessPaymentSuccess() throws TException, IOException, URISyntaxException {
|
||||
String[] cards = {
|
||||
"4242424242424242",
|
||||
"5555555555554444",
|
||||
"586824160825533338",
|
||||
};
|
||||
|
||||
// Put the card and save the response to a subsequent request
|
||||
for (String card : cards) {
|
||||
CardData cardData = CdsWrapper.makeCardDataWithExpDate(
|
||||
"NONAME",
|
||||
"123",
|
||||
card,
|
||||
Byte.parseByte("12"),
|
||||
Short.parseShort("2020")
|
||||
);
|
||||
processPaymentSuccess(cardData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processPaymentSuccess(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
RecurrentTokenContext context = new RecurrentTokenContext();
|
||||
context.setTokenInfo(
|
||||
makeRecurrentTokenInfo(
|
||||
makeRecurrentPaymentTool(
|
||||
makeDisposablePaymentResource(
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(
|
||||
putCardDataResponse.getBankCard()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
RecurrentTokenProxyResult generationProxyResult = handler.generateToken(context);
|
||||
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(
|
||||
getContext(
|
||||
getPaymentResourceRecurrent(generationProxyResult.getToken()),
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
null
|
||||
)
|
||||
);
|
||||
|
||||
assertEquals("Process payment ", ProxyWrapper.makeFinishStatusSuccess(), processResultPayment.getIntent().getFinish().getStatus());
|
||||
|
||||
if (processResultPayment.getIntent().getFinish().getStatus().equals(ProxyWrapper.makeFinishStatusSuccess())) {
|
||||
|
||||
LOGGER.info("Call capture payment");
|
||||
// Обрабатываем ответ и вызываем CapturePayment
|
||||
PaymentProxyResult processResultCapture = handler.processPayment(
|
||||
getContext(
|
||||
getPaymentResourceRecurrent(generationProxyResult.getToken()),
|
||||
ProxyProviderWrapper.makeTargetCaptured(),
|
||||
DomainWrapper.makeTransactionInfo(
|
||||
processResultPayment.getTrx().getId(),
|
||||
Collections.emptyMap()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
assertEquals("Process Capture ", ProxyWrapper.makeFinishStatusSuccess(), processResultCapture.getIntent().getFinish().getStatus());
|
||||
|
||||
// Обрабатываем ответ
|
||||
LOGGER.info("Response capture payment {}", processResultCapture.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getOptionsProxy() {
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("merchantId", merchantId);
|
||||
options.put("merchantName", merchantName);
|
||||
options.put("merchantUrl", merchantUrl);
|
||||
options.put("merchantAcquirerBin", merchantAcquirerBin);
|
||||
options.put("merchantPassword", merchantPassword);
|
||||
options.put("merchantCountryCode", merchantCountryCode);
|
||||
return options;
|
||||
}
|
||||
|
||||
private PaymentInfo getPaymentInfo(TransactionInfo transactionInfo, PaymentResource paymentResource) {
|
||||
return ProxyProviderWrapper.makePaymentInfo(
|
||||
ProxyProviderWrapper.makeInvoice(
|
||||
invoiceId,
|
||||
"2016-06-02",
|
||||
getCost()
|
||||
),
|
||||
ProxyProviderWrapper.makeShop(
|
||||
DomainWrapper.makeCategory("CategoryName", "Category description"),
|
||||
DomainWrapper.makeShopDetails("ShopName", "Shop description")
|
||||
),
|
||||
ProxyProviderWrapper.makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
paymentResource,
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private PaymentResource getPaymentResourceRecurrent(String token) {
|
||||
return ProxyProviderWrapper.makePaymentResourceRecurrentPaymentResource(
|
||||
ProxyProviderWrapper.makeRecurrentPaymentResource(token)
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
return Converter.mapToByteArray(Collections.emptyMap());
|
||||
}
|
||||
|
||||
private PaymentContext getContext(PaymentResource paymentResource, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return ProxyProviderWrapper.makeContext(
|
||||
getPaymentInfo(transactionInfo, paymentResource),
|
||||
ProxyProviderWrapper.makeSession(
|
||||
target,
|
||||
getSessionState()
|
||||
),
|
||||
getOptionsProxy()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private com.rbkmoney.damsel.proxy_provider.Cash getCost() {
|
||||
return ProxyProviderWrapper.makeCash(
|
||||
ProxyProviderWrapper.makeCurrency("Rubles", (short) 643, "RUB", (short) 2),
|
||||
10000L
|
||||
);
|
||||
}
|
||||
|
||||
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
LOGGER.info("CDS: prepare card");
|
||||
// CardData cardData = TestData.makeCardData();
|
||||
|
||||
LOGGER.info("CDS: put card");
|
||||
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
|
||||
|
||||
LOGGER.info(putCardDataResponse.toString());
|
||||
return putCardDataResponse;
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,10 @@ import com.rbkmoney.damsel.cds.CardData;
|
||||
import com.rbkmoney.damsel.cds.PutCardDataResult;
|
||||
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
|
||||
import com.rbkmoney.damsel.domain.TransactionInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.Context;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentInfo;
|
||||
import com.rbkmoney.damsel.proxy_provider.ProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentResource;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.Converter;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.cds.CdsApi;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.CdsWrapper;
|
||||
@ -15,6 +16,7 @@ import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -43,6 +45,8 @@ import static org.junit.Assert.assertEquals;
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
@ -50,6 +54,9 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerSuccessIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@ -109,7 +116,7 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
|
||||
private void processPaymentSuccess(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
ProxyResult processResultPayment = handler.processPayment(
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
@ -123,7 +130,7 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
|
||||
|
||||
LOGGER.info("Call capture payment");
|
||||
// Обрабатываем ответ и вызываем CapturePayment
|
||||
ProxyResult processResultCapture = handler.processPayment(
|
||||
PaymentProxyResult processResultCapture = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetCaptured(),
|
||||
@ -166,23 +173,30 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
|
||||
ProxyProviderWrapper.makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
DomainWrapper.makePayer(
|
||||
DomainWrapper.makeContactInfo("email", "phone"),
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard()),
|
||||
putCardDataResponse.getSessionId()
|
||||
),
|
||||
getPaymentResource(putCardDataResponse),
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
return Converter.mapToByteArray(Collections.emptyMap());
|
||||
}
|
||||
|
||||
private Context getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return ProxyProviderWrapper.makeContext(
|
||||
getPaymentInfo(putCardDataResult, transactionInfo),
|
||||
ProxyProviderWrapper.makeSession(
|
||||
|
@ -13,6 +13,7 @@ import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyProviderWrapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.damsel.ProxyWrapper;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -43,6 +44,9 @@ import static org.junit.Assert.assertTrue;
|
||||
"merchant.acquirerBin=422538",
|
||||
"merchant.password=",
|
||||
"merchant.countryCode=643",
|
||||
"cds.url.keyring=http://127.0.0.1:8021/v1/keyring",
|
||||
"cds.url.storage=http://127.0.0.1:8021/v1/storage",
|
||||
"proxy-mocketbank-mpi.url=http://127.0.0.1:8018",
|
||||
}
|
||||
)
|
||||
@Ignore("Integration test")
|
||||
@ -50,6 +54,9 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerSuccessWith3DSIntegrationTest.class);
|
||||
|
||||
@ClassRule
|
||||
public final static IntegrationBaseRule rule = new IntegrationBaseRule();
|
||||
|
||||
@Autowired
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@ -104,7 +111,7 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
|
||||
private void processPaymentSuccess(CardData cardData) throws TException, URISyntaxException, IOException {
|
||||
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
|
||||
|
||||
ProxyResult processResultPayment = handler.processPayment(
|
||||
PaymentProxyResult processResultPayment = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetProcessed(),
|
||||
@ -124,7 +131,7 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
|
||||
ByteBuffer callbackMap = Converter.mapToByteBuffer(mapCallback);
|
||||
|
||||
// handlePaymentCallback
|
||||
CallbackResult callbackResult = handler.handlePaymentCallback(
|
||||
PaymentCallbackResult callbackResult = handler.handlePaymentCallback(
|
||||
callbackMap, getContext(putCardDataResponse, null, null)
|
||||
);
|
||||
|
||||
@ -132,7 +139,7 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
|
||||
|
||||
LOGGER.info("Call capture payment");
|
||||
// Обрабатываем ответ и вызываем CapturePayment
|
||||
ProxyResult processResultCapture = handler.processPayment(
|
||||
PaymentProxyResult processResultCapture = handler.processPayment(
|
||||
getContext(
|
||||
putCardDataResponse,
|
||||
ProxyProviderWrapper.makeTargetCaptured(),
|
||||
@ -167,25 +174,30 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
|
||||
ProxyProviderWrapper.makeInvoicePaymentWithTrX(
|
||||
paymentId,
|
||||
"2016-06-02",
|
||||
DomainWrapper.makePayer(
|
||||
DomainWrapper.makeContactInfo("email", "phone"),
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard()),
|
||||
putCardDataResponse.getSessionId()
|
||||
),
|
||||
getPaymentResource(putCardDataResponse),
|
||||
getCost(),
|
||||
transactionInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
|
||||
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
|
||||
DomainWrapper.makeDisposablePaymentResource(
|
||||
DomainWrapper.makeClientInfo("fingerprint", "ip"),
|
||||
putCardDataResponse.getSessionId(),
|
||||
DomainWrapper.makePaymentTool(putCardDataResponse.getBankCard())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private byte[] getSessionState() throws IOException {
|
||||
Map<String, String> extra = new HashMap<>();
|
||||
extra.put("paReq","paReq");
|
||||
return Converter.mapToByteArray(extra);
|
||||
}
|
||||
|
||||
private Context getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
|
||||
return ProxyProviderWrapper.makeContext(
|
||||
getPaymentInfo(putCardDataResult, transactionInfo),
|
||||
ProxyProviderWrapper.makeSession(
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.rbkmoney.proxy.mocketbank.handler;
|
||||
|
||||
import com.rbkmoney.damsel.proxy_provider.CallbackResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.Context;
|
||||
import com.rbkmoney.damsel.proxy_provider.ProxyResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentCallbackResult;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
|
||||
import com.rbkmoney.damsel.proxy_provider.PaymentProxyResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
@ -17,19 +17,19 @@ import static org.junit.Assert.assertEquals;
|
||||
public class MocketBankServerHandlerTest {
|
||||
|
||||
@Mock
|
||||
ProxyResult proxyResult;
|
||||
private PaymentProxyResult proxyResult;
|
||||
|
||||
@Mock
|
||||
CallbackResult callbackResult;
|
||||
private PaymentCallbackResult callbackResult;
|
||||
|
||||
@Mock
|
||||
ByteBuffer byteBuffer;
|
||||
private ByteBuffer byteBuffer;
|
||||
|
||||
@Mock
|
||||
Context context;
|
||||
private PaymentContext context;
|
||||
|
||||
@Mock
|
||||
MocketBankServerHandler handler;
|
||||
private MocketBankServerHandler handler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
@ -2,6 +2,7 @@ package com.rbkmoney.proxy.mocketbank.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rbkmoney.proxy.mocketbank.utils.mocketbank.constant.MocketBankTag;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -12,12 +13,24 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class ConverterTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(ConverterTest.class);
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
String tag = MocketBankTag.RECURRENT_SUSPEND_TAG + "1112";
|
||||
|
||||
assertTrue(tag.startsWith(MocketBankTag.RECURRENT_SUSPEND_TAG));
|
||||
|
||||
tag = MocketBankTag.PAYMENT_SUSPEND_TAG + "1112";
|
||||
|
||||
assertTrue(tag.startsWith(MocketBankTag.PAYMENT_SUSPEND_TAG));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byteBufferToMap() throws IOException {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
@ -12,6 +12,9 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class HellGateApiTest {
|
||||
|
||||
private ByteBuffer bbuf = ByteBuffer.wrap("some_byte".getBytes());
|
||||
private ByteBuffer response = ByteBuffer.wrap("some_response_byte".getBytes());
|
||||
|
||||
@Mock
|
||||
private HellGateApi hellGate;
|
||||
|
||||
@ -24,14 +27,16 @@ public class HellGateApiTest {
|
||||
|
||||
@Test
|
||||
public void testProcessCallback() throws Exception {
|
||||
ByteBuffer bbuf = ByteBuffer.wrap("some_byte".getBytes());
|
||||
ByteBuffer response = ByteBuffer.wrap("some_response_byte".getBytes());
|
||||
String tag = "common_tag";
|
||||
Mockito.when(hellGate.processPaymentCallback(tag, bbuf)).thenReturn(response);
|
||||
assertEquals(response, hellGate.processPaymentCallback(tag, bbuf));
|
||||
}
|
||||
|
||||
String tag = "some_tag";
|
||||
|
||||
Mockito.when(hellGate.processCallback(tag, bbuf)).thenReturn(response);
|
||||
|
||||
assertEquals(response, hellGate.processCallback(tag, bbuf));
|
||||
@Test
|
||||
public void testProcessRecurrentTokenCallback() throws Exception {
|
||||
String tag = "recurrent_tag";
|
||||
Mockito.when(hellGate.processRecurrentTokenCallback(tag, bbuf)).thenReturn(response);
|
||||
assertEquals(response, hellGate.processRecurrentTokenCallback(tag, bbuf));
|
||||
}
|
||||
|
||||
}
|
||||
|
31
src/test/resources/docker-compose.yml
Normal file
31
src/test/resources/docker-compose.yml
Normal file
@ -0,0 +1,31 @@
|
||||
version: '2'
|
||||
services:
|
||||
|
||||
cds:
|
||||
image: dr.rbkmoney.com/rbkmoney/cds:b2f40fa0353c6b067c71a18316277a6499e0b707
|
||||
environment:
|
||||
- SERVICE_NAME=cds
|
||||
ports:
|
||||
- "8021:8022"
|
||||
command: /opt/cds/bin/cds foreground
|
||||
|
||||
holmes:
|
||||
depends_on:
|
||||
- cds
|
||||
image: dr.rbkmoney.com/rbkmoney/holmes:a8ec6a15ddc60a2c1dc4f3a40a756ba527b21f77
|
||||
environment:
|
||||
- SERVICE_NAME=holmes
|
||||
|
||||
proxy-mocketbank-mpi:
|
||||
image: dr.rbkmoney.com/rbkmoney/proxy-mocketbank-mpi:2c4f622428d086ecbeac71d6490f8e8ece37c12b
|
||||
environment:
|
||||
- SERVICE_NAME=proxy-mocketbank-mpi
|
||||
ports:
|
||||
- "8018:8080"
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
driver_opts:
|
||||
com.docker.network.enable_ipv6: "true"
|
||||
com.docker.network.bridge.enable_ip_masquerade: "true"
|
9
src/test/resources/logback-test.xml
Normal file
9
src/test/resources/logback-test.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user