示例#1
0
    def deposit(self, deposit_amount):
        '''
        Deposing money on the account, writes to a json file for specific user. Checks for type validations.
        :param deposit_amount: Amount to deposit
        :return:None
        '''
        try:
            deposit_amount = float(deposit_amount)
            if deposit_amount < 0:
                transaction_description = "Deposit failed - Amount incorrect."
                transaction = Transaction(self, datetime.datetime.now(),
                                          "deposit", self.balance,
                                          self.balance, "failed",
                                          transaction_description)
                self.transaction_list.append(transaction._to_dict())
                return False
        except ValueError:
            return False

        balance_before = self.balance
        self.balance += deposit_amount
        transaction_description = "Deposit succeeded."
        transaction = Transaction(self, datetime.datetime.now(), "deposit",
                                  balance_before, self.balance, "succeeded",
                                  transaction_description)
        self.transaction_list.append(transaction._to_dict())
        return True
示例#2
0
    def withdraw(self, withdraw_amount):

        try:
            withdraw_amount = float(withdraw_amount)
            if withdraw_amount < 0:
                transaction_description = "Withdrawal failed - Amount incorrect."
                transaction = Transaction(self, datetime.datetime.now(),
                                          "withdrawal", self.balance,
                                          self.balance, "failed",
                                          transaction_description)
                self.transaction_list.append(transaction._to_dict())
                return False
        except ValueError:
            return False

        if self.balance - withdraw_amount - self.fees._get_fee(
                "withdraw_fee") > 0:
            balance_before = self.balance
            self.balance -= withdraw_amount
            transaction_description = "Withdrawal succeeded."
            transaction = Transaction(self, datetime.datetime.now(),
                                      "withdrawal", balance_before,
                                      self.balance, "succeeded",
                                      transaction_description)
            self.transaction_list.append(transaction._to_dict())

            self.fees._charge_fee("withdraw_fee")
            return True
        elif self.balance - withdraw_amount - self.fees._get_fee("overdraft_fee") < 0 and self.balance - withdraw_amount - self.fees._get_fee("overdraft_fee") > self.__overdraft\
                or self.balance - withdraw_amount - self.fees._get_fee("withdraw_fee")  and self.balance - withdraw_amount - self.fees._get_fee("withdraw_fee") > self.__overdraft < 0:
            balance_before = self.balance
            self.balance -= withdraw_amount
            transaction_description = "Withdrawal succeeded."
            transaction = Transaction(self, datetime.datetime.now(),
                                      "withdrawal", balance_before,
                                      self.balance, "success",
                                      transaction_description)
            self.transaction_list.append(transaction._to_dict())

            self.fees._charge_fee("overdraft_fee")
            return True
        else:
            transaction_description = "Withdrawal failed - Balance not enough."
            transaction = Transaction(self, datetime.datetime.now(),
                                      "withdrawal", self.balance, self.balance,
                                      "failed", transaction_description)
            self.transaction_list.append(transaction._to_dict())
            return False
示例#3
0
    def withdraw(self, withdraw_amount):
        '''
                withdraw money from the account, writes to a json file for specific user. Checks for type validations.
                :param withdraw_amount: amount to withdraw from account
                :return:None
                '''
        try:
            withdraw_amount = float(withdraw_amount)
            if withdraw_amount < 0:
                transaction_description = "Withdrawal failed - Amount incorrect."
                transaction = Transaction(self, datetime.datetime.now(),
                                          "withdrawal", self.balance,
                                          self.balance, "failed",
                                          transaction_description)
                self.transaction_list.append(transaction._to_dict())
                return False
        except ValueError:
            return False

        if self.balance - withdraw_amount - self.fees._get_fee(
                "withdraw_fee") > 0:
            balance_before = self.balance
            self.balance -= withdraw_amount
            transaction_description = "Withdrawal successful."
            transaction = Transaction(self, datetime.datetime.now(),
                                      "withdrawal", balance_before,
                                      self.balance, "succeeded",
                                      transaction_description)
            self.transaction_list.append(transaction._to_dict())

            self.fees._charge_fee("withdraw_fee")
            return True
        else:
            transaction_description = "Withdrawal failed - Balance not enough."
            transaction = Transaction(self, datetime.datetime.now(),
                                      "withdrawal", self.balance, self.balance,
                                      "failed", transaction_description)
            self.transaction_list.append(transaction._to_dict())
            return False
示例#4
0
    def _charge_fee(self, fee_type):
        '''
        Charges fees from the current account of the current user.
        :param fee_type: Amount of fees to charge
        :return:
        '''
        before_balance = self.__account.balance
        transaction_description = "Fee charged - " + fee_type + '.'
        if self.__fee_list[fee_type]['type'] == "set_amount":
            self.__account.balance -= self.__fee_list[fee_type]['amount']
            transaction = Transaction(self.__account, datetime.datetime.now(),
                                      "transaction fee", before_balance,
                                      self.__account.balance, "success",
                                      transaction_description)
            self.__account.transaction_list.append(transaction._to_dict())

        elif self.__fee_list[fee_type]['type'] == "percentage":
            self.__account.balance -= abs(self.__account.balance *
                                          self.__fee_list[fee_type]['amount'])
            transaction = Transaction(self.__account, datetime.datetime.now(),
                                      "transaction fee", before_balance,
                                      self.__account.balance, "success",
                                      transaction_description)
            self.__account.transaction_list.append(transaction._to_dict())