Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<dependency>
<groupId>dev.vality</groupId>
<artifactId>damsel</artifactId>
<version>1.699-7280b62</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
@RequiredArgsConstructor
public class OctServerHandler implements AdapterSrv.Iface {

private static final int AMOUNT_CHANGE_DIVISOR = 2;

private final CdsService cdsService;
private final ErrorMapping errorMapping;
private final List<CardPayout> cardPayoutList;
Expand All @@ -48,6 +50,12 @@ public ProcessResult processWithdrawal(
Optional<CardPayout> cardPayout = PayoutUtils.extractCardPayoutByPan(cardPayoutList, cardData.getPan());
if (cardPayout.isPresent()) {
log.info("Found card payout with action {}", cardPayout.get().getAction());
if (CardPayoutAction.isAmountChanged(cardPayout.get())) {
return createSuccessResult(withdrawal).setNewBody(
new Cash(withdrawal.getBody())
.setAmount(withdrawal.getBody().getAmount() / AMOUNT_CHANGE_DIVISOR)
);
}
if (CardPayoutAction.isCardFailed(cardPayout.get())) {
CardPayoutAction action = CardPayoutAction.findByValue(cardPayout.get().getAction());
log.info("Failed card payout with action {}", action);
Expand All @@ -56,10 +64,7 @@ public ProcessResult processWithdrawal(
}
}

TransactionInfo transactionInfo =
DomainPackageCreators.createTransactionInfo(withdrawal.getId(), Collections.emptyMap());
Intent intent = WithdrawalsProviderAdapterPackageCreators.createFinishIntentSuccess(transactionInfo);
return WithdrawalsProviderAdapterPackageCreators.createProcessResult(intent);
return createSuccessResult(withdrawal);
}

@Override
Expand Down Expand Up @@ -102,4 +107,11 @@ private static String getCurrentDateTimeByPattern(Long timestamp) {
return Instant.ofEpochMilli(timestamp).toString();
}

private static ProcessResult createSuccessResult(Withdrawal withdrawal) {
TransactionInfo transactionInfo =
DomainPackageCreators.createTransactionInfo(withdrawal.getId(), Collections.emptyMap());
Intent intent = WithdrawalsProviderAdapterPackageCreators.createFinishIntentSuccess(transactionInfo);
return WithdrawalsProviderAdapterPackageCreators.createProcessResult(intent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum CardPayoutAction {
INSUFFICIENT_FUNDS("Insufficient Funds"),
INVALID_CARD("Invalid Card"),
EXPIRED_CARD("Expired Card"),
UNKNOWN_FAILURE("Unknown Failure");
UNKNOWN_FAILURE("Unknown Failure"),
CHANGE_AMOUNT("Change Amount");

private static final CardPayoutAction[] FAILED_CARDS = {
INSUFFICIENT_FUNDS,
Expand All @@ -39,4 +40,8 @@ public static boolean isCardFailed(CardPayoutAction action) {
return Arrays.asList(FAILED_CARDS).contains(action);
}

public static boolean isAmountChanged(CardPayout card) {
return CHANGE_AMOUNT == findByValue(card.getAction());
}

}
1 change: 1 addition & 0 deletions src/main/resources/fixture/payout.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cardPan, action, paymentSystem
5105105105105100, Expired Card, MasterCard
4111110000000112, Unknown Failure, Visa
5124990000000002, Unknown Failure, MasterCard
4000000000000077, Change Amount, Visa
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import static dev.vality.adapter.common.damsel.WithdrawalsProviderVerification.isSuccess;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.AssertionErrors.assertTrue;

@Slf4j
@SpringBootTest
Expand All @@ -41,7 +42,31 @@ void testProcessWithdrawal() throws Exception {
createProxyOptions()
);
log.info("Response processWithdrawal {}", result);
assertTrue("Result processWithdrawal isn`t success", isSuccess(result));
assertTrue(isSuccess(result), "Result processWithdrawal isn`t success");
}

@Test
void testProcessWithdrawalWithChangedAmount() throws Exception {
CardData cardData = new CardData()
.setPan("4000000000000077")
.setCardholderName(randomString());
BankCard bankCard = new BankCard()
.setToken(randomString())
.setCardholderName(randomString())
.setBin(randomString());
when(cdsStorageClient.getCardData(anyString())).thenReturn(cardData);

var withdrawal = createWithdrawal(bankCard);
ProcessResult result = handler.processWithdrawal(
withdrawal,
Value.str(""),
createProxyOptions()
);

assertTrue(isSuccess(result), "Result processWithdrawal isn`t success");
assertTrue(result.isSetNewBody(), "Result processWithdrawal doesn`t contain new body");
assertEquals(withdrawal.getBody().getAmount() / 2, result.getNewBody().getAmount());
assertEquals(withdrawal.getBody().getCurrency(), result.getNewBody().getCurrency());
}

}
Loading