updating credit amount functionality
This commit is contained in:
14
compose.yml
Normal file
14
compose.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
velocity-pay-backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: velocity-pay-backend:0.0.2-RELEASE
|
||||||
|
restart: always
|
||||||
|
container_name: velocity-pay-backend
|
||||||
|
ports:
|
||||||
|
- 8085:8085
|
||||||
|
- 6950:6950
|
||||||
|
network_mode: host
|
||||||
|
environment:
|
||||||
|
- TZ=Africa/Harare
|
||||||
@@ -72,6 +72,7 @@ public class Transaction extends BaseEntity {
|
|||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private CurrencyType creditCurrency;
|
private CurrencyType creditCurrency;
|
||||||
private BigDecimal creditAmount;
|
private BigDecimal creditAmount;
|
||||||
|
private BigDecimal creditTotalAmount;
|
||||||
private String creditName;
|
private String creditName;
|
||||||
private String creditCard;
|
private String creditCard;
|
||||||
private String creditRef;
|
private String creditRef;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.springframework.data.domain.Pageable;
|
|||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import zw.qantra.tm.domain.enums.CurrencyType;
|
||||||
import zw.qantra.tm.domain.enums.RequestType;
|
import zw.qantra.tm.domain.enums.RequestType;
|
||||||
import zw.qantra.tm.domain.models.AdditionalData;
|
import zw.qantra.tm.domain.models.AdditionalData;
|
||||||
import zw.qantra.tm.domain.models.Currency;
|
import zw.qantra.tm.domain.models.Currency;
|
||||||
@@ -33,23 +34,16 @@ public class TransactionService {
|
|||||||
private final AdditionalDataService additionalDataService;
|
private final AdditionalDataService additionalDataService;
|
||||||
private final CurrencyService currencyService;
|
private final CurrencyService currencyService;
|
||||||
|
|
||||||
public BigDecimal calculateCreditAmount(Transaction transaction) {
|
public BigDecimal calculateCurrencyExchangeValue(CurrencyType from, CurrencyType to, BigDecimal amount) {
|
||||||
if (transaction.getCreditCurrency() == null) {
|
Currency debitCurrency = currencyService.findCurrencyByIsoCode(from.name());
|
||||||
return BigDecimal.ZERO;
|
Currency creditCurrency = currencyService.findCurrencyByIsoCode(to.name());
|
||||||
}
|
|
||||||
|
|
||||||
Currency debitCurrency = currencyService.findCurrencyByIsoCode(transaction.getDebitCurrency().name());
|
|
||||||
Currency creditCurrency = currencyService.findCurrencyByIsoCode(transaction.getCreditCurrency().name());
|
|
||||||
|
|
||||||
BigDecimal debitBankRate = new BigDecimal(debitCurrency.getBankRate());
|
BigDecimal debitBankRate = new BigDecimal(debitCurrency.getBankRate());
|
||||||
BigDecimal creditBankRate = new BigDecimal(creditCurrency.getBankRate());
|
BigDecimal creditBankRate = new BigDecimal(creditCurrency.getBankRate());
|
||||||
|
|
||||||
BigDecimal bankRate = creditBankRate.divide(debitBankRate, 4, RoundingMode.HALF_UP);
|
BigDecimal bankRate = creditBankRate.divide(debitBankRate, 4, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
BigDecimal creditAmount = transaction.getAmount().multiply(bankRate).setScale(4, RoundingMode.HALF_UP);
|
return amount.multiply(bankRate).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
transaction.setCreditAmount(creditAmount);
|
|
||||||
return creditAmount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reassignTransactions(UUID oldWorkspaceId, UUID newWorkspaceId){
|
public void reassignTransactions(UUID oldWorkspaceId, UUID newWorkspaceId){
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class VelocityPaymentService {
|
|||||||
? "VMC" : transaction.getPaymentProcessorLabel();
|
? "VMC" : transaction.getPaymentProcessorLabel();
|
||||||
VelocityTransactionDto payload = VelocityTransactionDto.builder()
|
VelocityTransactionDto payload = VelocityTransactionDto.builder()
|
||||||
.salesOrderId(transaction.getOrderId())
|
.salesOrderId(transaction.getOrderId())
|
||||||
.amount(transaction.getCreditAmount())
|
.amount(transaction.getCreditTotalAmount())
|
||||||
.debitPhone(transaction.getDebitPhone())
|
.debitPhone(transaction.getDebitPhone())
|
||||||
.debitRegion("ZW")
|
.debitRegion("ZW")
|
||||||
.type("REQUEST")
|
.type("REQUEST")
|
||||||
|
|||||||
@@ -56,8 +56,9 @@ public class NetoneConfirmationHotProcessor implements TransactionProcessorInter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.setCreditCurrency(CurrencyType.USD);
|
transaction.setCreditCurrency(transaction.getDebitCurrency());
|
||||||
transaction.setCreditAmount(transaction.getAmount());
|
transaction.setCreditAmount(transaction.getAmount());
|
||||||
|
transaction.setCreditTotalAmount(transaction.getTotalAmount());
|
||||||
transaction.setCreditAccount(Utils.formatPhoneNumber(transaction.getCreditAccount(), "ZW"));
|
transaction.setCreditAccount(Utils.formatPhoneNumber(transaction.getCreditAccount(), "ZW"));
|
||||||
transaction.setStatus(Status.SUCCESS);
|
transaction.setStatus(Status.SUCCESS);
|
||||||
transaction.setResponseCode("00");
|
transaction.setResponseCode("00");
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import zw.qantra.tm.domain.enums.CurrencyType;
|
import zw.qantra.tm.domain.enums.CurrencyType;
|
||||||
import zw.qantra.tm.domain.enums.RequestType;
|
import zw.qantra.tm.domain.enums.RequestType;
|
||||||
import zw.qantra.tm.domain.enums.Status;
|
import zw.qantra.tm.domain.enums.Status;
|
||||||
import zw.qantra.tm.domain.models.AdditionalData;
|
import zw.qantra.tm.domain.models.AdditionalData;
|
||||||
import zw.qantra.tm.domain.models.Provider;
|
|
||||||
import zw.qantra.tm.domain.models.Transaction;
|
import zw.qantra.tm.domain.models.Transaction;
|
||||||
import zw.qantra.tm.domain.services.*;
|
import zw.qantra.tm.domain.services.*;
|
||||||
import zw.qantra.tm.domain.services.processors.TransactionProcessorInterface;
|
import zw.qantra.tm.domain.services.processors.TransactionProcessorInterface;
|
||||||
@@ -20,7 +17,6 @@ import zw.qantra.tm.exceptions.ApiException;
|
|||||||
import zw.qantra.tm.rest.RestService;
|
import zw.qantra.tm.rest.RestService;
|
||||||
import zw.qantra.tm.utils.Utils;
|
import zw.qantra.tm.utils.Utils;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Service("CONFIRM_ZESA_HOT")
|
@Service("CONFIRM_ZESA_HOT")
|
||||||
@@ -69,7 +65,14 @@ public class ZesaConfirmationHotProcessor implements TransactionProcessorInterfa
|
|||||||
transaction.setCreditCurrency(CurrencyType.USD);
|
transaction.setCreditCurrency(CurrencyType.USD);
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.setCreditAmount(transactionService.calculateCreditAmount(transaction));
|
transaction.setCreditAmount(transactionService.calculateCurrencyExchangeValue(
|
||||||
|
transaction.getDebitCurrency(),
|
||||||
|
transaction.getCreditCurrency(),
|
||||||
|
transaction.getAmount()));
|
||||||
|
transaction.setCreditTotalAmount(transactionService.calculateCurrencyExchangeValue(
|
||||||
|
transaction.getDebitCurrency(),
|
||||||
|
transaction.getCreditCurrency(),
|
||||||
|
transaction.getTotalAmount()));
|
||||||
|
|
||||||
// token should've been updated by checkCustomer
|
// token should've been updated by checkCustomer
|
||||||
if (!hotRechargeBalanceService.checkBalance(token, transaction.getCreditAmount(), accId)) {
|
if (!hotRechargeBalanceService.checkBalance(token, transaction.getCreditAmount(), accId)) {
|
||||||
|
|||||||
@@ -1,23 +1,8 @@
|
|||||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||||
<changeSet author="khoza (generated)" id="1782340507017-3">
|
<changeSet author="khoza (generated)" id="1783202068979-3">
|
||||||
<addColumn tableName="transaction">
|
<addColumn tableName="transaction">
|
||||||
<column name="batch_description" type="varchar(255)"/>
|
<column name="credit_total_amount" type="numeric(38, 2)"/>
|
||||||
</addColumn>
|
|
||||||
</changeSet>
|
|
||||||
<changeSet author="khoza (generated)" id="1782340507017-4">
|
|
||||||
<addColumn tableName="group_batch_item">
|
|
||||||
<column name="credit_address" type="varchar(255)"/>
|
|
||||||
</addColumn>
|
|
||||||
</changeSet>
|
|
||||||
<changeSet author="khoza (generated)" id="1782340507017-5">
|
|
||||||
<addColumn tableName="payment_processor">
|
|
||||||
<column name="currency" type="varchar(255)"/>
|
|
||||||
</addColumn>
|
|
||||||
</changeSet>
|
|
||||||
<changeSet author="khoza (generated)" id="1782340507017-6">
|
|
||||||
<addColumn tableName="transaction">
|
|
||||||
<column name="username" type="varchar(255)"/>
|
|
||||||
</addColumn>
|
</addColumn>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class TransactionServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Should calculate credit amount using bank rate")
|
@DisplayName("Should calculate credit amount using bank rate")
|
||||||
void shouldCalculateCreditAmount() {
|
void shouldCalculateCurrencyExchangeValue() {
|
||||||
Currency currencyUsd = new Currency();
|
Currency currencyUsd = new Currency();
|
||||||
currencyUsd.setBankRate("1.0");
|
currencyUsd.setBankRate("1.0");
|
||||||
Currency currencyZwl = new Currency();
|
Currency currencyZwl = new Currency();
|
||||||
@@ -130,7 +130,7 @@ class TransactionServiceTest {
|
|||||||
when(currencyService.findCurrencyByIsoCode("USD")).thenReturn(currencyUsd);
|
when(currencyService.findCurrencyByIsoCode("USD")).thenReturn(currencyUsd);
|
||||||
when(currencyService.findCurrencyByIsoCode("ZWL")).thenReturn(currencyZwl);
|
when(currencyService.findCurrencyByIsoCode("ZWL")).thenReturn(currencyZwl);
|
||||||
|
|
||||||
BigDecimal creditAmount = transactionService.calculateCreditAmount(transaction);
|
BigDecimal creditAmount = transactionService.calculateCurrencyExchangeValue(transaction);
|
||||||
|
|
||||||
assertEquals(new BigDecimal("1500.0000"), creditAmount);
|
assertEquals(new BigDecimal("1500.0000"), creditAmount);
|
||||||
assertEquals(new BigDecimal("1500.0000"), transaction.getCreditAmount());
|
assertEquals(new BigDecimal("1500.0000"), transaction.getCreditAmount());
|
||||||
@@ -141,7 +141,7 @@ class TransactionServiceTest {
|
|||||||
void shouldReturnZeroWhenCreditCurrencyNull() {
|
void shouldReturnZeroWhenCreditCurrencyNull() {
|
||||||
transaction.setCreditCurrency(null);
|
transaction.setCreditCurrency(null);
|
||||||
|
|
||||||
BigDecimal result = transactionService.calculateCreditAmount(transaction);
|
BigDecimal result = transactionService.calculateCurrencyExchangeValue(transaction);
|
||||||
|
|
||||||
assertEquals(BigDecimal.ZERO, result);
|
assertEquals(BigDecimal.ZERO, result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user