PROX-159: added card apple pay (#24)

* PROX-159: added card apple pay
This commit is contained in:
Anatoly Cherkasov 2018-05-08 14:22:22 +03:00 committed by GitHub
parent ab4922f625
commit c585aa869d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 636 additions and 109 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<version>1.5.8.RELEASE</version>
<relativePath/>
</parent>
@ -71,7 +71,7 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
<version>1.220-cdf69d5</version>
<version>1.232-5e54b26</version>
</dependency>
<!--Test libs-->
<dependency>

View File

@ -22,7 +22,7 @@ public class ErrorMappingConfiguration {
ErrorMapping errorMapping() throws IOException {
ErrorMapping errorMapping = new ErrorMapping(filePath.getInputStream(), patternReason);
errorMapping.validateMappingFormat();
return new ErrorMapping(filePath.getInputStream(), patternReason);
return errorMapping;
}
}

View File

@ -2,6 +2,7 @@ package com.rbkmoney.proxy.mocketbank.handler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.*;
@ -73,7 +74,8 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
String token = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool().getBankCard().getToken();
RecurrentTokenIntent intent = ProxyProviderWrapper.makeRecurrentTokenFinishIntentSuccess(token);
CardData cardData = cds.getSessionCardData(context);
CardData cardData = cds.getCardData(token);
CardUtils cardUtils = new CardUtils(cardList);
Optional<Card> card = cardUtils.getCardByPan(cardData.getPan());
@ -204,8 +206,8 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
throw new IllegalArgumentException(message, ex);
}
CardData cardData = cds.getSessionCardData(context);
String token = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool().getBankCard().getToken();
CardData cardData = cds.getCardData(token);
ValidatePaResResponse validatePaResResponse;
try {
@ -219,7 +221,6 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
if (validatePaResResponse.getTransactionStatus().equals(MocketBankMpiTransactionStatus.AUTHENTICATION_SUCCESSFUL)) {
byte[] callbackResponse = new byte[0];
String token = context.getTokenInfo().getPaymentTool().getPaymentResource().getPaymentTool().getBankCard().getToken();
RecurrentTokenIntent intent = ProxyProviderWrapper.makeRecurrentTokenFinishIntentSuccess(token);
RecurrentTokenProxyResult proxyResult = ProxyProviderWrapper.makeRecurrentTokenProxyResult(
@ -306,7 +307,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
if (invoicePayment.getPaymentResource().isSetRecurrentPaymentResource()) {
cardData = cds.getCardData(invoicePayment.getPaymentResource().getRecurrentPaymentResource().getRecToken());
} else {
cardData = cds.getSessionCardData(context);
cardData = cds.getCardData(context);
}
TransactionInfo transactionInfo = null;
@ -331,9 +332,28 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
case CVV_MATCH_FAIL:
error = CVV_MATCH_FAIL.getAction();
break;
case APPLE_PAY_FAILURE:
error = APPLE_PAY_FAILURE.getAction();
break;
case EXPIRED_CARD:
error = EXPIRED_CARD.getAction();
break;
case APPLE_PAY_SUCCESS:
Optional<BankCardTokenProvider> bankCardTokenProvider = Optional.of(
context.getPaymentInfo().getPayment()
.getPaymentResource().getDisposablePaymentResource()
.getPaymentTool().getBankCard().getTokenProvider()
);
if (!bankCardTokenProvider.isPresent() || !BankCardTokenProvider.applepay.equals(bankCardTokenProvider.get())) {
String message = "Processed: bankCardTokenProvider is missing or not APPLE PAY with invoiceId " + invoiceId;
log.error(message);
throw new IllegalArgumentException(message);
}
case SUCCESS:
transactionInfo = DomainWrapper.makeTransactionInfo(
MocketBankMpiUtils.generateInvoice(context.getPaymentInfo()),
@ -501,7 +521,7 @@ public class MocketBankServerHandler implements ProviderProxySrv.Iface {
throw new IllegalArgumentException(message, ex);
}
CardData cardData = cds.getSessionCardData(context);
CardData cardData = cds.getCardData(context);
ValidatePaResResponse validatePaResResponse;
try {
validatePaResResponse = mocketBankMpiApi.validatePaRes(cardData.getPan(), parameters.get("paRes"));

View File

@ -2,11 +2,11 @@ package com.rbkmoney.proxy.mocketbank.utils.cds;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.SessionData;
import com.rbkmoney.damsel.cds.StorageSrv;
import com.rbkmoney.damsel.domain.DisposablePaymentResource;
import com.rbkmoney.damsel.proxy_provider.InvoicePayment;
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.RecurrentTokenContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,15 +15,22 @@ import org.springframework.stereotype.Component;
@Component
public class CdsApi {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private static final Logger LOGGER = LoggerFactory.getLogger(CdsApi.class);
private final StorageSrv.Iface storageSrv;
private StorageSrv.Iface storageSrv;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Constructs a new {@link CdsApi CdsApi} instance.
*/
public CdsApi() {
// Constructs default a new {@link CdsApi CdsApi} instance.
}
/**
* Constructs a new {@link CdsApi CdsApi} instance with the given
* initial parameters to be constructed.
@ -48,77 +55,48 @@ public class CdsApi {
* @throws CdsException
*/
public CardData getCardData(final String token) {
log.info("getCardData: token: {}", token);
LOGGER.info("getCardData: token: {}", token);
try {
CardData cardData = storageSrv.getCardData(token);
log.info("getCardData: response, token: {}");
LOGGER.info("getCardData: response, token: {}");
return cardData;
} catch (Exception ex) {
throw new CdsException(String.format("Exception in getCardData with token: %s", token), ex);
}
}
/**
* Get the card data with CVV
*
* @param token String
* @param session String
* @return CardData
* @throws CdsException
*/
public CardData getSessionCardData(final String token, final String session) {
log.info("getSessionCardData: token: {}, session: {} ", token, session);
try {
CardData cardData = storageSrv.getSessionCardData(token, session);
log.info("getSessionCardData: response, token: {}, session: {}", token, session);
return cardData;
} catch (Exception ex) {
throw new CdsException(String.format("Exception in getSessionCardData with token: %s, session: %s", token, session), ex);
public CardData getCardData(final PaymentContext context) {
String invoiceId = context.getPaymentInfo().getInvoice().getId();
InvoicePayment invoicePayment = context.getPaymentInfo().getPayment();
DisposablePaymentResource disposablePaymentResource = invoicePayment.getPaymentResource().getDisposablePaymentResource();
if (!disposablePaymentResource.getPaymentTool().getBankCard().isSetToken()) {
throw new CdsException("getSessionCardData: Token must be set, invoiceId " + invoiceId);
}
String token = disposablePaymentResource.getPaymentTool().getBankCard().getToken();
return getCardData(token);
}
/**
* Get the card data with CVV
*
* @param context PaymentContext
* @return CardData
* @throws CdsException
*/
public CardData getSessionCardData(final PaymentContext context) {
public SessionData getSessionData(final PaymentContext context) {
String invoiceId = context.getPaymentInfo().getInvoice().getId();
InvoicePayment invoicePayment = context.getPaymentInfo().getPayment();
DisposablePaymentResource disposablePaymentResource = invoicePayment.getPaymentResource().getDisposablePaymentResource();
if (!disposablePaymentResource.isSetPaymentSessionId()) {
throw new CdsException("getSessionCardData: Session must be set, invoiceId " + invoiceId);
}
if (!disposablePaymentResource.getPaymentTool().getBankCard().isSetToken()) {
throw new CdsException("getSessionCardData: Token must be set, invoiceId " + invoiceId);
throw new CdsException("getSessionData: Session must be set, invoiceId " + invoiceId);
}
String session = disposablePaymentResource.getPaymentSessionId();
String token = disposablePaymentResource.getPaymentTool().getBankCard().getToken();
return getSessionCardData(token, session);
}
public CardData getSessionCardData(final RecurrentTokenContext context) {
String recurrentId = context.getTokenInfo().getPaymentTool().getId();
DisposablePaymentResource disposablePaymentResource = context.getTokenInfo().getPaymentTool().getPaymentResource();
if (!disposablePaymentResource.isSetPaymentSessionId()) {
throw new CdsException("getSessionCardData: Session must be set, recurrentId " + recurrentId);
try {
SessionData sessionData = storageSrv.getSessionData(session);
LOGGER.info("Storage getSessionData: finish");
return sessionData;
} catch (Exception ex) {
throw new CdsException("Exception in getSessionData with SessionData", ex);
}
if (!disposablePaymentResource.getPaymentTool().getBankCard().isSetToken()) {
throw new CdsException("getSessionCardData: Token must be set, recurrentId " + recurrentId);
}
String session = disposablePaymentResource.getPaymentSessionId();
String token = disposablePaymentResource.getPaymentTool().getBankCard().getToken();
return getSessionCardData(token, session);
}
/**
@ -128,11 +106,11 @@ public class CdsApi {
* @return PutCardDataResult
* @throws CdsException
*/
public PutCardDataResult putCardData(CardData cardData) throws CdsException {
log.info("Storage putCardData - start");
public PutCardDataResult putCardData(CardData cardData, SessionData sessionData) throws CdsException {
LOGGER.info("Storage putCardData - start");
try {
PutCardDataResult result = storageSrv.putCardData(cardData);
log.info("Storage putCardData: finish");
PutCardDataResult result = storageSrv.putCardData(cardData, sessionData);
LOGGER.info("Storage putCardData: finish");
return result;
} catch (Exception ex) {
throw new CdsException("Exception in putCardData with cardData", ex);
@ -140,3 +118,4 @@ public class CdsApi {
}
}

View File

@ -26,6 +26,55 @@ public class CdsWrapper {
return CdsWrapper.makeCardData(cardholderName, cvv, pan, CdsWrapper.makeExpDate(month, year));
}
public static SessionData makeSessionData(AuthData authData) {
SessionData sessionData = new SessionData();
sessionData.setAuthData(authData);
return sessionData;
}
public static AuthData makeAuthData(Auth3DS auth3DS, CardSecurityCode cardSecurityCode) {
AuthData authData = new AuthData();
authData.setAuth3ds(auth3DS);
authData.setCardSecurityCode(cardSecurityCode);
return authData;
}
public static AuthData makeAuthData(CardSecurityCode cardSecurityCode) {
AuthData authData = new AuthData();
authData.setCardSecurityCode(cardSecurityCode);
return authData;
}
public static AuthData makeAuthData(Auth3DS auth3DS) {
AuthData authData = new AuthData();
authData.setAuth3ds(auth3DS);
return authData;
}
public static AuthData makeAuthData(Auth3DS auth3DS, String cvv) {
AuthData authData = new AuthData();
authData.setAuth3ds(auth3DS);
authData.setCardSecurityCode(makeCardSecurityCode(cvv));
return authData;
}
public static CardSecurityCode makeCardSecurityCode(String cvv) {
CardSecurityCode cardSecurityCode = new CardSecurityCode();
cardSecurityCode.setValue(cvv);
return cardSecurityCode;
}
public static Auth3DS makeAuth3DS(String cryptogram, String eci) {
Auth3DS auth3DS = new Auth3DS();
auth3DS.setCryptogram(cryptogram);
auth3DS.setEci(eci);
return auth3DS;
}
public static Auth3DS makeAuth3DS(String cryptogram) {
return makeAuth3DS(cryptogram, null);
}
public static PutCardDataResult makePutCardDataResult(BankCard bankCard, String session) {
PutCardDataResult putCardDataResult = new PutCardDataResult();
putCardDataResult.setBankCard(bankCard);

View File

@ -15,6 +15,8 @@ public enum MocketBankMpiAction {
INVALID_CARD("Invalid Card"),
CVV_MATCH_FAIL("CVV Match Fail"),
EXPIRED_CARD("Expired Card"),
APPLE_PAY_FAILURE("Apple Pay Failure"),
APPLE_PAY_SUCCESS("Apple Pay Success"),
UNKNOWN_FAILURE("Unknown Failure");
private final String action;

View File

@ -19,3 +19,5 @@ cardPan, action, paymentSystem
5105105105105100, Expired Card, MasterCard
4111110000000112, Unknown Failure, Visa
5124990000000002, Unknown Failure, MasterCard
5000000000000009, Apple Pay Failure, Visa
4300000000000777, Apple Pay Success, Visa

1 cardPan action paymentSystem
19 5105105105105100 Expired Card MasterCard
20 4111110000000112 Unknown Failure Visa
21 5124990000000002 Unknown Failure MasterCard
22 5000000000000009 Apple Pay Failure Visa
23 4300000000000777 Apple Pay Success Visa

View File

@ -47,10 +47,16 @@
"regexp":"Unknown",
"mapping":"authorization_failed:unknown"
},
{
"code":"Apple Pay Failure",
"description":"Apple Pay Failure",
"regexp":"Apple Pay Failure",
"mapping":"authorization_failed:unknown"
},
{
"code":"Unknown Failure",
"description":"Unknown Failure",
"regexp":"Unknown Failure",
"mapping":"authorization_failed:unknown"
}
]
]

View File

@ -0,0 +1,215 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentInfo;
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;
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;
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.annotation.DirtiesContext;
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 org.junit.Assert.assertTrue;
@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",
}
)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Ignore("Integration test")
public class MocketBankServerHandlerFailIApplePayntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerFailIApplePayntegrationTest.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 testProcessPaymentFail() throws TException, IOException, URISyntaxException {
String[] cards = {
"5000000000000009",
};
// 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")
);
processPaymentFail(cardData);
}
}
private void processPaymentFail(CardData cardData) throws TException, URISyntaxException, IOException {
PutCardDataResult putCardDataResponse = cdsPutCardData(cardData);
PaymentProxyResult processResultPayment = handler.processPayment(
getContext(
putCardDataResponse,
ProxyProviderWrapper.makeTargetProcessed(),
null
)
);
assertTrue("Process payment ", processResultPayment.getIntent().getFinish().getStatus().getFailure().isSetCode());
}
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(PutCardDataResult putCardDataResponse, TransactionInfo transactionInfo) {
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",
getPaymentResource(putCardDataResponse),
getCost(),
transactionInfo
)
);
}
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
DomainWrapper.makeDisposablePaymentResource(
DomainWrapper.makeClientInfo("fingerprint", "ip"),
putCardDataResponse.getSessionId(),
DomainWrapper.makePaymentTool(
getBankCardWithToken(putCardDataResponse.getBankCard())
)
)
);
}
private BankCard getBankCardWithToken(BankCard bankCard) {
bankCard.setTokenProvider(BankCardTokenProvider.applepay);
return bankCard;
}
private byte[] getSessionState() throws IOException {
return Converter.mapToByteArray(Collections.emptyMap());
}
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
return ProxyProviderWrapper.makeContext(
getPaymentInfo(putCardDataResult, transactionInfo),
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
);
}
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
@ -200,11 +199,16 @@ public class MocketBankServerHandlerFailIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info(putCardDataResponse.toString());
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.*;
@ -201,11 +200,16 @@ public class MocketBankServerHandlerFailWith3DSIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info(putCardDataResponse.toString());
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.PaymentTool;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
@ -328,14 +327,16 @@ public class MocketBankServerHandlerRecurrent3DSSuccessIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: prepare card");
// CardData cardData = TestData.makeCardData();
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
LOGGER.info(putCardDataResponse.toString());
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.*;
@ -237,14 +236,16 @@ public class MocketBankServerHandlerRecurrentSuccessIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: prepare card");
// CardData cardData = TestData.makeCardData();
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
LOGGER.info(putCardDataResponse.toString());
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}

View File

@ -0,0 +1,239 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.BankCardTokenProvider;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
import com.rbkmoney.damsel.proxy_provider.PaymentInfo;
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;
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.annotation.DirtiesContext;
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 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",
}
)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Ignore("Integration test")
public class MocketBankServerHandlerSuccessApplePayIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(MocketBankServerHandlerSuccessApplePayIntegrationTest.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 = {
"4300000000000777",
};
// 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);
PaymentProxyResult processResultPayment = handler.processPayment(
getContext(
putCardDataResponse,
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(
putCardDataResponse,
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(PutCardDataResult putCardDataResponse, TransactionInfo transactionInfo) {
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",
getPaymentResource(putCardDataResponse),
getCost(),
transactionInfo
)
);
}
private PaymentResource getPaymentResource(PutCardDataResult putCardDataResponse) {
return ProxyProviderWrapper.makePaymentResourceDisposablePaymentResource(
DomainWrapper.makeDisposablePaymentResource(
DomainWrapper.makeClientInfo("fingerprint", "ip"),
putCardDataResponse.getSessionId(),
DomainWrapper.makePaymentTool(
getBankCardWithToken(putCardDataResponse.getBankCard())
)
)
);
}
private BankCard getBankCardWithToken(BankCard bankCard) {
bankCard.setTokenProvider(BankCardTokenProvider.applepay);
return bankCard;
}
private byte[] getSessionState() throws IOException {
return Converter.mapToByteArray(Collections.emptyMap());
}
private PaymentContext getContext(PutCardDataResult putCardDataResult, TargetInvoicePaymentStatus target, TransactionInfo transactionInfo) throws IOException {
return ProxyProviderWrapper.makeContext(
getPaymentInfo(putCardDataResult, transactionInfo),
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
);
}
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.PaymentContext;
@ -218,14 +217,16 @@ public class MocketBankServerHandlerSuccessIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: prepare card");
// CardData cardData = TestData.makeCardData();
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
LOGGER.info(putCardDataResponse.toString());
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}

View File

@ -1,7 +1,6 @@
package com.rbkmoney.proxy.mocketbank.handler;
import com.rbkmoney.damsel.cds.CardData;
import com.rbkmoney.damsel.cds.PutCardDataResult;
import com.rbkmoney.damsel.cds.*;
import com.rbkmoney.damsel.domain.TargetInvoicePaymentStatus;
import com.rbkmoney.damsel.domain.TransactionInfo;
import com.rbkmoney.damsel.proxy_provider.*;
@ -218,11 +217,16 @@ public class MocketBankServerHandlerSuccessWith3DSIntegrationTest {
);
}
private PutCardDataResult cdsPutCardData(CardData cardData) throws TException, URISyntaxException, IOException {
LOGGER.info("CDS: put card");
PutCardDataResult putCardDataResponse = cds.putCardData(cardData);
protected PutCardDataResult cdsPutCardData(CardData cardData) {
LOGGER.info("CDS: put card request start");
LOGGER.info(putCardDataResponse.toString());
Auth3DS auth3DS = CdsWrapper.makeAuth3DS("jKfi3B417+zcCBFYbFp3CBUAAAA=", "5");
AuthData authData = CdsWrapper.makeAuthData(auth3DS);
SessionData sessionData = CdsWrapper.makeSessionData(authData);
PutCardDataResult putCardDataResponse = cds.putCardData(cardData, sessionData);
LOGGER.info("CDS: put card response {}", putCardDataResponse);
return putCardDataResponse;
}