mirror of
https://github.com/valitydev/adapter-common-lib.git
synced 2024-11-06 02:05:18 +00:00
Add method for load card holder from custom list (#32)
This commit is contained in:
parent
fa36fd28dd
commit
cd97e11756
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>adapter-common-lib</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>adapter-common-lib</name>
|
||||
|
@ -10,6 +10,7 @@ import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@ -19,11 +20,19 @@ public class BankCardExtractor {
|
||||
private static final String NAME_REGEXP = "[^a-zA-Z +]";
|
||||
|
||||
public static CardDataProxyModel initCardDataProxyModel(BankCard bankCard, CardData cardData) {
|
||||
return initCardDataProxyModel(bankCard, cardData, null);
|
||||
}
|
||||
|
||||
public static CardDataProxyModel initCardDataProxyModel(BankCard bankCard,
|
||||
CardData cardData,
|
||||
List<String> cardHoldersNames) {
|
||||
String cardHolder;
|
||||
if (bankCard.isSetCardholderName()) {
|
||||
cardHolder = bankCard.getCardholderName();
|
||||
} else if (cardData.isSetCardholderName()) {
|
||||
cardHolder = cardData.getCardholderName();
|
||||
} else if (cardHoldersNames != null && cardHoldersNames.size() > 0) {
|
||||
cardHolder = getCardHolderFromList(cardHoldersNames, bankCard.getToken());
|
||||
} else {
|
||||
cardHolder = (FAKER_NAME.firstName() + StringUtils.SPACE + FAKER_NAME.lastName())
|
||||
.replaceAll(NAME_REGEXP, StringUtils.EMPTY)
|
||||
@ -41,4 +50,8 @@ public class BankCardExtractor {
|
||||
.expYear(bankCard.isSetExpDate() ? bankCard.getExpDate().getYear() : cardData.getExpDate().getYear())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static String getCardHolderFromList(List<String> cardHoldersNames, String cardToken) {
|
||||
return cardHoldersNames.get(Math.abs(cardToken.hashCode() % cardHoldersNames.size()));
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static dev.vality.adapter.common.damsel.ProxyProviderPackageExtractors.*;
|
||||
|
||||
@Slf4j
|
||||
@ -47,9 +49,7 @@ public class CdsStorageClient {
|
||||
}
|
||||
|
||||
public CardDataProxyModel getCardData(PaymentContext context) {
|
||||
CardData cardData = getCardData(extractBankCardToken(extractPaymentResource(context)));
|
||||
BankCard bankCard = extractBankCard(context.getPaymentInfo());
|
||||
return BankCardExtractor.initCardDataProxyModel(bankCard, cardData);
|
||||
return getCardDataWithListHolders(context, null);
|
||||
}
|
||||
|
||||
public CardDataProxyModel getCardData(Withdrawal withdrawal) {
|
||||
@ -80,6 +80,12 @@ public class CdsStorageClient {
|
||||
return BankCardExtractor.initCardDataProxyModel(bankCard, getCardData(bankCard.getToken()));
|
||||
}
|
||||
|
||||
public CardDataProxyModel getCardDataWithListHolders(PaymentContext context, List<String> cardHoldersNames) {
|
||||
CardData cardData = getCardData(extractBankCardToken(extractPaymentResource(context)));
|
||||
BankCard bankCard = extractBankCard(context.getPaymentInfo());
|
||||
return BankCardExtractor.initCardDataProxyModel(bankCard, cardData, cardHoldersNames);
|
||||
}
|
||||
|
||||
public SessionData getSessionData(PaymentContext context) {
|
||||
DisposablePaymentResource disposablePaymentResource = extractDisposablePaymentResource(context);
|
||||
if (!disposablePaymentResource.isSetPaymentSessionId()) {
|
||||
|
@ -0,0 +1,30 @@
|
||||
package dev.vality.adapter.common.cds;
|
||||
|
||||
import dev.vality.adapter.common.cds.model.CardDataProxyModel;
|
||||
import dev.vality.cds.storage.CardData;
|
||||
import dev.vality.damsel.domain.BankCard;
|
||||
import dev.vality.damsel.domain.BankCardExpDate;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class BankCardExtractorTest {
|
||||
|
||||
public static final String TEST_2 = "test_2";
|
||||
public static final String TEST_1 = "test_1";
|
||||
|
||||
@Test
|
||||
void initCardDataProxyModel() {
|
||||
CardDataProxyModel cardDataProxyModel =
|
||||
BankCardExtractor.initCardDataProxyModel(
|
||||
new BankCard()
|
||||
.setToken("test")
|
||||
.setExpDate(new BankCardExpDate()),
|
||||
new CardData(),
|
||||
List.of(TEST_1, TEST_2));
|
||||
|
||||
assertEquals(cardDataProxyModel.getCardholderName(), TEST_1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user