Skip to content

Commit

Permalink
Update bank.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 10, 2024
1 parent f62245d commit 709cd5d
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions banking/bank.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
from banking.accounts import BankAccount
from banking.transactions import transfer
from banking.accounts import BankAccount, SavingsAccount, CheckingAccount, InsufficientFundsError
from banking.transactions import transfer, pay_bill

def create_account(account_number):
def create_account(account_type, account_number):
"""
Creates a new bank account with the specified account number.
Creates a new bank account with the specified account type and account number.
"""
return BankAccount(account_number)
if account_type == "savings":
account = SavingsAccount(account_number)
elif account_type == "checking":
account = CheckingAccount(account_number)
else:
raise ValueError(f"Invalid account type: {account_type}")

return account

def get_account(account_number):
"""
Retrieves the bank account with the specified account number.
Retrieves the bank account with the specified account number.
"""
# Load account data from database or other storage system
account_data = load_account_data(account_number)

# Create new account if it doesn't exist
if account_data is None:
account = create_account(account_number)
account_type = None
else:
account = BankAccount(account_number, balance=account_data["balance"])
account_type = account_data["type"]

account = create_account(account_type, account_number)

return account

Expand All @@ -27,17 +36,35 @@ def save_account(account):
Saves the specified bank account to the database or other storage system.
"""
# Save account data to database or other storage system
save_account_data(account.account_number, account.balance)
save_account_data(account.account_number, account.type, account.balance)

def process_transaction(transaction):
"""
Processes the specified transaction by transferring funds between bank accounts.
Processes the specified transaction by transferring funds between bank accounts or paying a bill.
"""
from_account = get_account(transaction["from_account"])
to_account = get_account(transaction["to_account"])
amount = transaction["amount"]
transaction_type = transaction["type"]

if transaction_type == "transfer":
from_account_number = transaction["from_account"]
to_account_number = transaction["to_account"]
amount = transaction["amount"]

from_account = get_account(from_account_number)
to_account = get_account(to_account_number)

transfer(from_account, to_account, amount)

save_account(from_account)
save_account(to_account)

elif transaction_type == "pay_bill":
account_number = transaction["account"]
payee = transaction["payee"]
amount = transaction["amount"]
due_date = transaction["due_date"]

account = get_account(account_number)

transfer(from_account, to_account, amount)
pay_bill(account, payee, amount, due_date)

save_account(from_account)
save_account(to_account)
save_account(account)

0 comments on commit 709cd5d

Please sign in to comment.