Skip to content

Fees #65

Merged
merged 3 commits into from Oct 22, 2022
Merged

Fees #65

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/BundleController.py
Expand Up @@ -335,9 +335,9 @@ def sellBundle(self, jsonReqData):
bundleTransactionFE.setBundleAddress(bundleFE.getBundleAddress())
bundleTransactionFE.setTransactionDatetime(int(time.time()))
if Utility.isWithinHoldingPeriod(bundleTransactionDA.getTransactionDatetime(), bundleDA.getHoldingPeriod()):
bundleTransactionFE.setChargeApplied(Utility.calculateChargesApplied(bundleTransactionFE.getAmount()))
bundleTransactionFE.setChargeApplied(Utility.calculateDeduction(bundleTransactionFE.getAmount(), float(0.10)))
else:
bundleTransactionFE.setChargeApplied(Utility.roundDecimals(0.0))
bundleTransactionFE.setChargeApplied(Utility.calculateDeduction(bundleTransactionFE.getAmount(), float(0.01)))
bundleTransactionFE.setAction("SELL")

self.BDA.updateBundleStatus(bundleFE)
Expand Down
4 changes: 2 additions & 2 deletions controllers/WalletController.py
Expand Up @@ -308,9 +308,9 @@ def sellWallet(self, jsonReqData):
walletTransactionFE.setWalletAddress(walletFE.getWalletAddress())
walletTransactionFE.setTransactionDatetime(int(time.time()))
if Utility.isWithinHoldingPeriod(walletTransactionDA.getTransactionDatetime(), walletDA.getHoldingPeriod()):
walletTransactionFE.setChargeApplied(Utility.calculateChargesApplied(walletTransactionFE.getAmount()))
walletTransactionFE.setChargeApplied(Utility.calculateDeduction(walletTransactionFE.getAmount(), float(0.10)))
else:
walletTransactionFE.setChargeApplied(Utility.roundDecimals(0.0))
walletTransactionFE.setChargeApplied(Utility.calculateDeduction(walletTransactionFE.getAmount(), float(0.01)))
walletTransactionFE.setAction("SELL")

self.WDA.updateWalletCurrentBalance(walletFE)
Expand Down
21 changes: 21 additions & 0 deletions data_access/BundleDataAccess.py
Expand Up @@ -102,9 +102,18 @@ def insertDayZeroData(self):
bundleThree.setPurchaseDatetime(1664645865)
bundleThree.setStatus("ACTIVE")

bundleFour = Bundle()
bundleFour.setBundleAddress("1G6ftEHoxst84caX2EUd")
bundleFour.setBundleID("5")
bundleFour.setCustomerID("1WNJKpBpYfWwKIlvbaz0")
bundleFour.setHoldingPeriod(3)
bundleFour.setPurchaseDatetime(1654645865)
bundleFour.setStatus("ACTIVE")

self.insertBundle(bundleOne)
self.insertBundle(bundleTwo)
self.insertBundle(bundleThree)
self.insertBundle(bundleFour)

cur.execute("SELECT EXISTS (SELECT * FROM BundleTransactionHistory)")
if not cur.fetchone()[0]:
Expand Down Expand Up @@ -142,9 +151,21 @@ def insertDayZeroData(self):
bundleTransactionObjThree.setExpiry("03/23")
bundleTransactionObjThree.setInitialRate(735.23)

bundleTransactionObjFour = BundleTransactionHistory()
bundleTransactionObjFour.setTransactionID("h0YrN10TzimnB05aYkCc")
bundleTransactionObjFour.setBundleAddress("1G6ftEHoxst84caX2EUd")
bundleTransactionObjFour.setAction("BUY")
bundleTransactionObjFour.setTransactionDatetime(1654645865)
bundleTransactionObjFour.setChargeApplied(0.00)
bundleTransactionObjFour.setAmount(89046.3456)
bundleTransactionObjFour.setCardNumber("4857037529348105")
bundleTransactionObjFour.setExpiry("03/23")
bundleTransactionObjFour.setInitialRate(56748.3421)

self.insertBundleTransactionHistory(bundleTransactionObj)
self.insertBundleTransactionHistory(bundleTransactionObjTwo)
self.insertBundleTransactionHistory(bundleTransactionObjThree)
self.insertBundleTransactionHistory(bundleTransactionObjFour)

cur.close()
con.commit()
Expand Down
22 changes: 22 additions & 0 deletions data_access/WalletDataAccess.py
Expand Up @@ -109,6 +109,15 @@ def insertDayZeroData(self):
walletOne.setHoldingPeriod(12)
self.insertWallet(walletOne)

walletTwo = Wallet()
walletTwo.setCustomerID("1WNJKpBpYfWwKIlvbaz0")
walletTwo.setWalletAddress("t5vumA246YH7dX6k7Hfn")
walletTwo.setInitialBalance(1.4326)
walletTwo.setCurrentBalance(1.4326)
walletTwo.setCryptocurrencyCode('dogecoin')
walletTwo.setHoldingPeriod(5)
self.insertWallet(walletTwo)

cur.execute("select exists (SELECT * FROM Wallet)")
if not cur.fetchone()[0]:
walletTransZero = WalletTransactionHistory()
Expand All @@ -135,8 +144,21 @@ def insertDayZeroData(self):
walletTransOne.setWalletAddress("hrD3IxwVUWloVP0nrIct")
walletTransOne.setUnitsSold(0.0)

walletTransTwo = WalletTransactionHistory()
walletTransTwo.setTransactionID("0ueLmcfLy8DPtMObBKEv")
walletTransTwo.setTransactionDatetime(1554541119)
walletTransTwo.setChargeApplied(0.0)
walletTransTwo.setAmount(36487.2188)
walletTransTwo.setAction("BUY")
walletTransTwo.setCardNumber("7436281956743846")
walletTransTwo.setExpiry("07/25")
walletTransTwo.setInitialRate(25469.23)
walletTransTwo.setWalletAddress("t5vumA246YH7dX6k7Hfn")
walletTransTwo.setUnitsSold(0.0)

self.insertWalletTransactionHistory(walletTransZero)
self.insertWalletTransactionHistory(walletTransOne)
self.insertWalletTransactionHistory(walletTransTwo)

cur.close()
con.commit()
Expand Down
6 changes: 3 additions & 3 deletions models/Utility.py
Expand Up @@ -79,16 +79,16 @@ def roundDecimals(decimalValue):
return round(float(decimalValue), 4)

@staticmethod
def calculateChargesApplied(amount):
return round(float(amount) * 0.10, 4)
def calculateDeduction(amount, charge):
return round(float(amount) * charge, 4)

@staticmethod
def isWithinHoldingPeriod(startDateTime, holdingPeriod):
startTime = datetime.fromtimestamp(int(startDateTime))
endTime = startTime + relativedelta(months=holdingPeriod)
currentTime = datetime.fromtimestamp(int(time.time()))

if currentTime > startTime and currentTime < endTime:
if currentTime >= startTime and currentTime <= endTime:
return True
else:
return False
Expand Down
51 changes: 38 additions & 13 deletions tests/test_BundleController.py
Expand Up @@ -995,18 +995,6 @@ def test_success_reponse_key_bundleCryptocurrencies_is_exists(self):
response = self.BController.getAllBundlesFromCustomerID(reqData)
self.assertTrue("bundleCryptocurrencies" in response.get("bundles")[0].keys())

def test_success_reponse_cryptocurrencies_for_bundles(self):
reqData = {
"customerID": "1WNJKpBpYfWwKIlvbaz0"
}
response = self.BController.getAllBundlesFromCustomerID(reqData)

def test_success_reponse_cryptocurrencies_for_bundles(self):
reqData = {
"customerID": "Debo32tKqJBeZwHHgkvx"
}
response = self.BController.getAllBundlesFromCustomerID(reqData)


class TestPurchaseBundle(unittest.TestCase):

Expand Down Expand Up @@ -1602,7 +1590,7 @@ def test_success_response_key_chargeApplied_exists(self):
self.assertTrue("chargeApplied" in response.get("bundleTransaction").keys())


def test_success_response_key_chargeApplied_correct(self):
def test_success_response_key_chargeApplied_correct_value_zero(self):
reqData = {
"customerID": "1WNJKpBpYfWwKIlvbaz0",
"bundleID": "1",
Expand Down Expand Up @@ -2529,6 +2517,43 @@ def test_success_response_key_initialRate_correct(self):
.get("initialRate"),
expected)

def test_success_response_key_chargeApplied_calculated_correct(self):
reqData = {
"customerID": "1WNJKpBpYfWwKIlvbaz0",
"bundleID": "1",
"holdingPeriod": 6,
"initialRate": 22000.00,
"amount": 1000.00,
"cardNumber": "1234567890123456",
"expiry": "12/24"
}
response = self.BController.purchaseBundle(reqData)

reqData = {
"bundleAddress": response.get("bundle").get("bundleAddress"),
"customerID": "1WNJKpBpYfWwKIlvbaz0",
"bundleID": "5",
"initialRate": 56748.3421,
"amount": 89046.3456,
"cardNumber": "1234567890123456",
"expiry": "12/24"
}
response = self.BController.sellBundle(reqData)
self.assertEqual(8904.6346, response.get("bundleTransaction").get("chargeApplied"))

def test_success_response_key_fees_correct(self):
reqData = {
"bundleAddress": "1G6ftEHoxst84caX2EUd",
"customerID": "1WNJKpBpYfWwKIlvbaz0",
"bundleID": "5",
"initialRate": 56748.3421,
"amount": 89046.3456,
"cardNumber": "1234567890123456",
"expiry": "12/24"
}
response = self.BController.sellBundle(reqData)
self.assertEqual(890.4635, response.get("bundleTransaction").get("chargeApplied"))


if __name__ == '__main__':
unittest.main()
39 changes: 38 additions & 1 deletion tests/test_WalletController.py
Expand Up @@ -21,7 +21,7 @@ def test_success_response_cryptocurrencyName_key_present_in_res(self):
response = self.wController.getAllAvailableCryptocurrencies()
self.assertTrue("cryptocurrencyName" in response.get("availableCryptocurrencies")[0].keys())

def test_success_response_cryptocurrencyCode_key_present_in_res(self):
def test_success_response_symbol_key_present_in_res(self):
response = self.wController.getAllAvailableCryptocurrencies()
self.assertTrue("symbol" in response.get("availableCryptocurrencies")[0].keys())

Expand Down Expand Up @@ -1971,6 +1971,43 @@ def test_failure_message_unitsSold_exceeding_currentBalance(self):
expected = "Units to sell must not be greater than the Current Balance"
self.assertEqual(expected, response.get("status")["statusMessage"])

def test_success_response_chargeApplied_value_correct(self):
jsonReqData = {
"customerID": "Debo32tKqJBeZwHHgkvx",
"initialBalance": 1.9492,
"cryptocurrencyCode": "bitcoin",
"holdingPeriod": 4,
"initialRate": 38291.34,
"amount": 74638.99,
"cardNumber": "7281726537281963",
"expiry": "12/23"
}
response = self.wController.purchaseWallet(jsonReqData)

jsonReqData = {
"customerID": "Debo32tKqJBeZwHHgkvx",
"walletAddress": response.get("wallet").get("walletAddress"),
"unitsSold": 1.9492,
"initialRate": 42710.34,
"amount": 83250.9947,
"cardNumber": "7281726537281963",
"expiry": "12/23"
}
response = self.wController.sellWallet(jsonReqData)
self.assertEqual(8325.0995, response.get("walletTransaction")["chargeApplied"])

def test_success_response_fees_value_correct(self):
jsonReqData = {
"customerID": "1WNJKpBpYfWwKIlvbaz0",
"walletAddress": "t5vumA246YH7dX6k7Hfn",
"unitsSold": 1.4326,
"initialRate": 42710.34,
"amount": 61186.8330,
"cardNumber": "7281726537281963",
"expiry": "12/25"
}
response = self.wController.sellWallet(jsonReqData)
self.assertEqual(611.8683, response.get("walletTransaction")["chargeApplied"])

if __name__ == '__main__':
unittest.main()