Skip to content
Permalink
Browse files
Merge pull request #13 from markusgeiss/develop
fixed reversed charges included behavior
  • Loading branch information
markusgeiss committed Sep 15, 2017
2 parents fd0d1bf + be11e1b commit f2756be4f59dd109df4e21c2ff11b9c90abb8832
Showing 2 changed files with 93 additions and 6 deletions.
@@ -15,6 +15,7 @@
*/
package io.mifos.teller;

import com.google.common.collect.Lists;
import io.mifos.accounting.api.v1.domain.Account;
import io.mifos.core.lang.DateConverter;
import io.mifos.deposit.api.v1.definition.domain.ProductDefinition;
@@ -23,6 +24,7 @@
import io.mifos.teller.api.v1.client.TellerNotFoundException;
import io.mifos.teller.api.v1.client.TellerTransactionValidationException;
import io.mifos.teller.api.v1.client.TransactionProcessingException;
import io.mifos.teller.api.v1.domain.Charge;
import io.mifos.teller.api.v1.domain.Cheque;
import io.mifos.teller.api.v1.domain.MICR;
import io.mifos.teller.api.v1.domain.Teller;
@@ -712,4 +714,82 @@ public void shouldNotProcessChequeAlreadyUsed() throws Exception {

super.testSubject.post(teller.getCode(), chequeTransaction);
}

@Test(expected = TransactionProcessingException.class)
public void shouldNotWithdrawExcludingCharges() throws Exception {
final Teller teller = this.prepareTeller();

final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
unlockDrawerCommand.setPassword(teller.getPassword());

super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);

super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());

final TellerTransaction tellerTransaction = new TellerTransaction();
tellerTransaction.setTransactionType(ServiceConstants.TX_CASH_WITHDRAWAL);
tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
tellerTransaction.setAmount(BigDecimal.valueOf(2000.00D));

final Account account = new Account();
account.setBalance(2000.00D);
account.setState(Account.State.OPEN.name());
Mockito.doAnswer(invocation -> Optional.of(account))
.when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());

final Charge charge = new Charge();
charge.setAmount(BigDecimal.valueOf(15.00D));
Mockito.doAnswer(invocation -> Lists.newArrayList(charge))
.when(super.depositAccountManagementServiceSpy).getCharges(Matchers.any(TellerTransaction.class));
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());

final TellerTransactionCosts tellerTransactionCosts = super.testSubject.post(teller.getCode(), tellerTransaction);

super.testSubject.confirm(teller.getCode(), tellerTransactionCosts.getTellerTransactionIdentifier(), "CONFIRM", null);
}

@Test
public void shouldWithdrawIncludingCharges() throws Exception {
final Teller teller = this.prepareTeller();

final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
unlockDrawerCommand.setPassword(teller.getPassword());

super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);

super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());

final TellerTransaction tellerTransaction = new TellerTransaction();
tellerTransaction.setTransactionType(ServiceConstants.TX_CASH_WITHDRAWAL);
tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
tellerTransaction.setAmount(BigDecimal.valueOf(2000.00D));

final Account account = new Account();
account.setBalance(2000.00D);
account.setState(Account.State.OPEN.name());
Mockito.doAnswer(invocation -> Optional.of(account))
.when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());

final Charge charge = new Charge();
charge.setAmount(BigDecimal.valueOf(15.00D));
Mockito.doAnswer(invocation -> Lists.newArrayList(charge))
.when(super.depositAccountManagementServiceSpy).getCharges(Matchers.any(TellerTransaction.class));
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());

final TellerTransactionCosts tellerTransactionCosts = super.testSubject.post(teller.getCode(), tellerTransaction);

super.testSubject.confirm(teller.getCode(), tellerTransactionCosts.getTellerTransactionIdentifier(), "CONFIRM", "included");
}
}
@@ -39,6 +39,7 @@
import io.mifos.teller.service.internal.service.TellerOperationService;
import io.mifos.teller.service.internal.service.helper.AccountingService;
import io.mifos.teller.service.internal.service.helper.ChequeService;
import io.mifos.teller.service.internal.service.helper.OrganizationService;
import io.mifos.teller.service.internal.util.MICRParser;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -71,6 +72,7 @@ public class TellerOperationRestController {
private final AccountingService accountingService;
private final ChequeService chequeService;
private final TellerTransactionProcessor tellerTransactionProcessor;
private final OrganizationService organizationService;

@Autowired
public TellerOperationRestController(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger,
@@ -79,14 +81,16 @@ public TellerOperationRestController(@Qualifier(ServiceConstants.LOGGER_NAME) fi
final TellerManagementService tellerManagementService,
final AccountingService accountingService,
final ChequeService chequeService,
final TellerTransactionProcessor tellerTransactionProcessor) {
final TellerTransactionProcessor tellerTransactionProcessor,
final OrganizationService organizationService) {
this.logger = logger;
this.commandGateway = commandGateway;
this.tellerOperationService = tellerOperationService;
this.tellerManagementService = tellerManagementService;
this.accountingService = accountingService;
this.chequeService = chequeService;
this.tellerTransactionProcessor = tellerTransactionProcessor;
this.organizationService = organizationService;
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.TELLER_OPERATION)
@@ -286,16 +290,18 @@ private void verifyAccounts(final TellerTransaction tellerTransaction) {

if (tellerTransaction.getTransactionType().equals(ServiceConstants.TX_CHEQUE)) {
final MICR micr = tellerTransaction.getCheque().getMicr();
this.verifyAccount(micr.getAccountNumber());
if (this.organizationService.officeExists(micr.getBranchSortCode())) {
this.verifyAccount(micr.getAccountNumber());
}
}
}

private void verifyAccount(final String accountIdentifier) {
final Account account = this.accountingService.findAccount(accountIdentifier).orElseThrow(
() -> ServiceException.conflict("Account {0} not found."));
() -> ServiceException.conflict("Account {0} not found.", accountIdentifier));

if (!account.getState().equals(Account.State.OPEN.name())) {
throw ServiceException.conflict("Account {0} is not open.", account.getIdentifier());
throw ServiceException.conflict("Account {0} is not open.", accountIdentifier);
}
}

@@ -314,13 +320,14 @@ private void verifyWithdrawalTransaction(final String tellerTransactionIdentifie

final Account account = this.accountingService.findAccount(tellerTransaction.getCustomerAccountIdentifier()).orElseThrow(
() -> ServiceException.notFound("Customer account {0} not found.", tellerTransaction.getCustomerAccountIdentifier()));

final BigDecimal currentBalance = BigDecimal.valueOf(account.getBalance());

final TellerTransactionCosts tellerTransactionCosts =
this.tellerTransactionProcessor.getCosts(tellerTransaction);
final BigDecimal transactionAmount = confirmTellerTransactionCommand.chargesIncluded()
? tellerTransactionCosts.getTotalAmount()
: tellerTransaction.getAmount();
? tellerTransaction.getAmount()
: tellerTransactionCosts.getTotalAmount();

if (transactionAmount.compareTo(currentBalance) > 0) {
throw ServiceException.conflict("Account has not enough balance.");

0 comments on commit f2756be

Please sign in to comment.