From ed20a714a5ceaa5197004a39021cf7cca03e3239 Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Wed, 6 Oct 2021 11:28:37 +0200 Subject: [PATCH 1/3] Created buildup for the project --- main.py | 10 +++++++++- src/bank/data/allCards.py | 5 +++++ src/cards/__pycache__/cards.cpython-38.pyc | Bin 0 -> 385 bytes src/cards/cards.py | 6 ++++++ src/modules/Card.py | 7 +++++++ src/modules/__pycache__/Card.cpython-38.pyc | Bin 0 -> 491 bytes src/tools/__pycache__/tools.cpython-38.pyc | Bin 0 -> 422 bytes src/tools/tools.py | 5 +++++ 8 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/bank/data/allCards.py create mode 100644 src/cards/__pycache__/cards.cpython-38.pyc create mode 100644 src/cards/cards.py create mode 100644 src/modules/Card.py create mode 100644 src/modules/__pycache__/Card.cpython-38.pyc create mode 100644 src/tools/__pycache__/tools.cpython-38.pyc create mode 100644 src/tools/tools.py diff --git a/main.py b/main.py index 515b526..b964256 100644 --- a/main.py +++ b/main.py @@ -1 +1,9 @@ -print("It's alive!") \ No newline at end of file +from src.cards.cards import cards +from src.tools.tools import * +from src.modules.Card import Card + +card = cards[int(input("Chose a card from 1 to " + str(len(cards)) + ": ")) - 1] + + + +PrintCardInfo(Card(card["number"], card["name"], card["surname"], card["type"])) \ No newline at end of file diff --git a/src/bank/data/allCards.py b/src/bank/data/allCards.py new file mode 100644 index 0000000..277c58b --- /dev/null +++ b/src/bank/data/allCards.py @@ -0,0 +1,5 @@ +cards = [ + {"number": "1111222233334444", "name": "John", "surname": "Doe", "type": "Credit", "pin": "1234", "clientID": "1234abcd"}, + {"number": "2222333344445555", "name": "Jane", "surname": "Doe", "type": "Prepaid", "pin": "2345", "clientID": "2345bcde"}, + {"number": "3333444455556666", "name": "Eric", "surname": "Gudmundson", "type": "ATM", "pin": "3456", "clientID": "3456cdef"}, +] \ No newline at end of file diff --git a/src/cards/__pycache__/cards.cpython-38.pyc b/src/cards/__pycache__/cards.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b11601eaa0197e9eba6a558aac914f8b92a5cee GIT binary patch literal 385 zcmYk2&q@O^5XQ4@x~;XV>l=98Lk0g-L`1Ewh=N+Ey@d4;cY;PuvLw5O`YgVHue4X+ zLOeJd5&8@B@eRXFl9@$OpCBjlfxCc^uO?Zhhsi01J3s*f0kohE^n*eNLiAnld$0n1 zSoMAY5v;*_q!L?xBi4_Hxz~cYmO>rM#^uo%V^)D+>l?G?GtJmdP+C|(W= gE9aTBdFDI+bgNj@y(49ydK1U3W|hrO2Z297zu7QloB#j- literal 0 HcmV?d00001 diff --git a/src/cards/cards.py b/src/cards/cards.py new file mode 100644 index 0000000..14babe9 --- /dev/null +++ b/src/cards/cards.py @@ -0,0 +1,6 @@ +cards = [ + {"number": "1111222233334444", "name": "John", "surname": "Doe", "type": "Credit"}, + {"number": "2222333344445555", "name": "Jane", "surname": "Doe", "type": "Prepaid"}, + {"number": "3333444455556666", "name": "Eric", "surname": "Gudmundson", "type": "ATM"}, + {"number": "444666", "name": "Adam", "surname": "Somm", "type": "University ID"}, +] \ No newline at end of file diff --git a/src/modules/Card.py b/src/modules/Card.py new file mode 100644 index 0000000..e034e24 --- /dev/null +++ b/src/modules/Card.py @@ -0,0 +1,7 @@ +class Card: + def __init__(self, ownerName, ownerSurname, number, type): + self.ownerName = ownerName + self.ownerSurname = ownerSurname + self.number = number + self.type = type + \ No newline at end of file diff --git a/src/modules/__pycache__/Card.cpython-38.pyc b/src/modules/__pycache__/Card.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bdef05f51e527d2c8c4c3af8019fac87cc42dc5d GIT binary patch literal 491 zcmY*Uu};H44E0^ol2+}482Nz=Wn@4I6^g`GkSdla=oE4X3N%UaC7_~g^k?{`W8@Rq zn6ML7Dn7ku`_6v$-HyjYAbZU2k}vY#oa~xM$&_ICiLO9{78}Bcj6ll;gkDPb|4dRg zCD;QZ1Ch`WNiDS8K;&tUdVJ^464Ysr3bw{Ecg_g*kf;$2C}#1$&%^^i0r$xL9zUJLmt|V# zrl@Ruesj&3TqMPFnJ3j`h1qLtF^%(5*Gpq#-u`H{c7ak^kyT2uwhf3t^xN}3Zfmyh zye<{6hpMZ}#Mg>K4F+Jwzr zUDf9&E!p*Y4Na$C7p`L_^_N4W)Mp36u*B((z)T5PWFcGrKOX2uM%EJZz zPUnO8N~UF=38UkS>BORcnTThZC#DbUmsqPbHc~Eh!zabE3Z`~Xdy;GMAnm*8Hi%fa d{!|P3IArx&Z?r=`{#ET^E_u1g&g|?jK>w-oV^IJA literal 0 HcmV?d00001 diff --git a/src/tools/tools.py b/src/tools/tools.py new file mode 100644 index 0000000..ebd6502 --- /dev/null +++ b/src/tools/tools.py @@ -0,0 +1,5 @@ +def PrintCardInfo(card): + print("Owner's Name: " + card.ownerName) + print("Owner's Surname: " + card.ownerSurname) + print("Card's Number: " + card.number) + print("Card's Type: " + card.type) \ No newline at end of file From cb8758d60291525260283ed6458a4b5bf7d7b53f Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Tue, 12 Oct 2021 21:26:15 +0200 Subject: [PATCH 2/3] APO-1 Created base for the projects --- .gitignore | 50 ++++++++++++++++++++ init.py | 13 +++++ main.py | 9 ++-- src/bank/data/allCards.py | 5 -- src/cards/__pycache__/cards.cpython-38.pyc | Bin 385 -> 0 bytes src/cards/cards.py | 6 --- src/modules/Account.py | 10 ++++ src/modules/Card.py | 13 +++-- src/modules/__pycache__/Card.cpython-38.pyc | Bin 491 -> 0 bytes src/tools/__pycache__/tools.cpython-38.pyc | Bin 422 -> 0 bytes src/tools/tools.py | 9 ++-- 11 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 .gitignore create mode 100644 init.py delete mode 100644 src/bank/data/allCards.py delete mode 100644 src/cards/__pycache__/cards.cpython-38.pyc delete mode 100644 src/cards/cards.py create mode 100644 src/modules/Account.py delete mode 100644 src/modules/__pycache__/Card.cpython-38.pyc delete mode 100644 src/tools/__pycache__/tools.cpython-38.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88315da --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Django stuff: +*.log +*.pot + +# Sphinx documentation +docs/_build/ \ No newline at end of file diff --git a/init.py b/init.py new file mode 100644 index 0000000..de33c21 --- /dev/null +++ b/init.py @@ -0,0 +1,13 @@ +cards = [ + {"number": "1111222233334444", "type": "Credit", "pin": "1234"}, + {"number": "2222333344445555", "type": "Prepaid", "pin": "2345"}, + {"number": "3333444455556666", "type": "ATM", "pin": "3456"}, + {"number": "444666", "type": "University ID", }, +] + +accounts = [ + {}, + {}, + {}, + {}, +] \ No newline at end of file diff --git a/main.py b/main.py index b964256..279ec4a 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ -from src.cards.cards import cards from src.tools.tools import * from src.modules.Card import Card +from src.modules.Account import Acount +import init + + card = cards[int(input("Chose a card from 1 to " + str(len(cards)) + ": ")) - 1] - - -PrintCardInfo(Card(card["number"], card["name"], card["surname"], card["type"])) \ No newline at end of file +PrintCardInfo(Card(card["number"], card["pin"], card["type"])) \ No newline at end of file diff --git a/src/bank/data/allCards.py b/src/bank/data/allCards.py deleted file mode 100644 index 277c58b..0000000 --- a/src/bank/data/allCards.py +++ /dev/null @@ -1,5 +0,0 @@ -cards = [ - {"number": "1111222233334444", "name": "John", "surname": "Doe", "type": "Credit", "pin": "1234", "clientID": "1234abcd"}, - {"number": "2222333344445555", "name": "Jane", "surname": "Doe", "type": "Prepaid", "pin": "2345", "clientID": "2345bcde"}, - {"number": "3333444455556666", "name": "Eric", "surname": "Gudmundson", "type": "ATM", "pin": "3456", "clientID": "3456cdef"}, -] \ No newline at end of file diff --git a/src/cards/__pycache__/cards.cpython-38.pyc b/src/cards/__pycache__/cards.cpython-38.pyc deleted file mode 100644 index 5b11601eaa0197e9eba6a558aac914f8b92a5cee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 385 zcmYk2&q@O^5XQ4@x~;XV>l=98Lk0g-L`1Ewh=N+Ey@d4;cY;PuvLw5O`YgVHue4X+ zLOeJd5&8@B@eRXFl9@$OpCBjlfxCc^uO?Zhhsi01J3s*f0kohE^n*eNLiAnld$0n1 zSoMAY5v;*_q!L?xBi4_Hxz~cYmO>rM#^uo%V^)D+>l?G?GtJmdP+C|(W= gE9aTBdFDI+bgNj@y(49ydK1U3W|hrO2Z297zu7QloB#j- diff --git a/src/cards/cards.py b/src/cards/cards.py deleted file mode 100644 index 14babe9..0000000 --- a/src/cards/cards.py +++ /dev/null @@ -1,6 +0,0 @@ -cards = [ - {"number": "1111222233334444", "name": "John", "surname": "Doe", "type": "Credit"}, - {"number": "2222333344445555", "name": "Jane", "surname": "Doe", "type": "Prepaid"}, - {"number": "3333444455556666", "name": "Eric", "surname": "Gudmundson", "type": "ATM"}, - {"number": "444666", "name": "Adam", "surname": "Somm", "type": "University ID"}, -] \ No newline at end of file diff --git a/src/modules/Account.py b/src/modules/Account.py new file mode 100644 index 0000000..a87b874 --- /dev/null +++ b/src/modules/Account.py @@ -0,0 +1,10 @@ +class Acount: + def __init__(self, number, name, surname, credit): + self.number = number + self.name = name + self.surname = surname + self.credit = credit + self.cards = [] + + def addCard(self, card): + self.cards.append(card) \ No newline at end of file diff --git a/src/modules/Card.py b/src/modules/Card.py index e034e24..8957e40 100644 --- a/src/modules/Card.py +++ b/src/modules/Card.py @@ -1,7 +1,10 @@ class Card: - def __init__(self, ownerName, ownerSurname, number, type): - self.ownerName = ownerName - self.ownerSurname = ownerSurname - self.number = number - self.type = type + def __init__(self, number, pin, type, account): + self.number = number + self.pin = pin + self.type = type + self.account = account + account.addCard(self) + + \ No newline at end of file diff --git a/src/modules/__pycache__/Card.cpython-38.pyc b/src/modules/__pycache__/Card.cpython-38.pyc deleted file mode 100644 index bdef05f51e527d2c8c4c3af8019fac87cc42dc5d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 491 zcmY*Uu};H44E0^ol2+}482Nz=Wn@4I6^g`GkSdla=oE4X3N%UaC7_~g^k?{`W8@Rq zn6ML7Dn7ku`_6v$-HyjYAbZU2k}vY#oa~xM$&_ICiLO9{78}Bcj6ll;gkDPb|4dRg zCD;QZ1Ch`WNiDS8K;&tUdVJ^464Ysr3bw{Ecg_g*kf;$2C}#1$&%^^i0r$xL9zUJLmt|V# zrl@Ruesj&3TqMPFnJ3j`h1qLtF^%(5*Gpq#-u`H{c7ak^kyT2uwhf3t^xN}3Zfmyh zye<{6hpMZ}#Mg>K4F+Jwzr zUDf9&E!p*Y4Na$C7p`L_^_N4W)Mp36u*B((z)T5PWFcGrKOX2uM%EJZz zPUnO8N~UF=38UkS>BORcnTThZC#DbUmsqPbHc~Eh!zabE3Z`~Xdy;GMAnm*8Hi%fa d{!|P3IArx&Z?r=`{#ET^E_u1g&g|?jK>w-oV^IJA diff --git a/src/tools/tools.py b/src/tools/tools.py index ebd6502..4478a0f 100644 --- a/src/tools/tools.py +++ b/src/tools/tools.py @@ -1,5 +1,6 @@ def PrintCardInfo(card): - print("Owner's Name: " + card.ownerName) - print("Owner's Surname: " + card.ownerSurname) - print("Card's Number: " + card.number) - print("Card's Type: " + card.type) \ No newline at end of file + print("Owner's Name: " + card.account.name) + print("Owner's Surname: " + card.account.surname) + print("Card's Number: " + card.number) + print("Card's Type: " + card.type) + print("Card's PIN: " + card.pin) \ No newline at end of file From e64c2db473d55ba403570b561cc4c5e5364b89ab Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Wed, 13 Oct 2021 00:06:54 +0200 Subject: [PATCH 3/3] APO-1 Final build for meetings #1 --- init.py | 39 +++++++++++++------ main.py | 53 ++++++++++++++++++++++--- src/modules/Account.py | 17 ++++++++- src/modules/Card.py | 5 ++- src/tools/tools.py | 87 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 181 insertions(+), 20 deletions(-) diff --git a/init.py b/init.py index de33c21..9114ecf 100644 --- a/init.py +++ b/init.py @@ -1,13 +1,30 @@ -cards = [ - {"number": "1111222233334444", "type": "Credit", "pin": "1234"}, - {"number": "2222333344445555", "type": "Prepaid", "pin": "2345"}, - {"number": "3333444455556666", "type": "ATM", "pin": "3456"}, - {"number": "444666", "type": "University ID", }, +from src.modules.Card import Card +from src.modules.Account import Account + +# This will immitate all bank accounts that exist +accounts = [ + {"number": "0123456789", "name": "John", "surname": "Doe", "credit": 50000}, + {"number": "0122222222", "name": "John", "surname": "Two", "credit": 50}, + {"number": "0123444444", "name": "John", "surname": "Digit", "credit": 150}, + {"number": "0111111111", "name": "John", "surname": "Button", "credit": 400}, ] -accounts = [ - {}, - {}, - {}, - {}, -] \ No newline at end of file +# This will immitate banks API +bank = {} + +for account in accounts: + bank[account["number"]] = Account(account["number"], account["name"], account["surname"], account["credit"]) + +#This will immitate all cards that exist +cardsInit = [ + {"number": "1111222233334444", "type": "Credit", "pin": "1234", "account": bank["0123456789"]}, + {"number": "2222333344445555", "type": "Prepaid", "pin": "2345", "account": bank["0122222222"]}, + {"number": "3333444455556666", "type": "ATM", "pin": "3456", "account": bank["0123444444"]}, + {"number": "444666", "type": "University ID", "pin": None, "account": None}, +] + +# This will immitate card providers API +cards = {} + +for card in cardsInit: + cards[card["number"]] = Card(card["number"], card["pin"], card["type"], card["account"]) diff --git a/main.py b/main.py index 279ec4a..3c26280 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,53 @@ from src.tools.tools import * -from src.modules.Card import Card -from src.modules.Account import Acount -import init +from init import * +mode = "running" +while mode != "exit": + input() -card = cards[int(input("Chose a card from 1 to " + str(len(cards)) + ": ")) - 1] + counter = 1 + for card in cards: + print(str(counter) + ": " + card) + counter += 1 -PrintCardInfo(Card(card["number"], card["pin"], card["type"])) \ No newline at end of file + card = cards[input("Enter number of card you wish to use: ")] + + if VerifyInvalidCard(card): + print("That is not a valid ATM card") + continue + + if VerifyOwner(card): + print("What do you want to do?") + print("1. Check your account") + print("2. Withdraw Money") + print("3. Deposit Money") + print("4. Add credits to your pre-paid phone card") + print("5. Transfer Money") + print("6. Exit") + + operation = input() + + if operation == "1": + CheckAccount(card.account) + elif operation == "2": + amount = int(input ("How much money do you want to withdraw?")) + WithdrawMoney(amount, card.account) + elif operation == "3": + notes = [] + value = int(input("Value of the inserted note: ")) + notes.append(value) + while value != 0: + value = int(input("Value of the next note (0 to exit): ")) + notes.append(value) + DepositMoney(notes, card.account) + elif operation == "4": + operator = input("Enter name of your phone card operator: ") + amount = int(input("How much credits do you wish to add?")) + GeneratePrepaidPhoneCode(amount, operator, card.account) + elif operation == "5": + accountTo = input("Enter account number to which money should be transfered: ") + amount = int(input("How much money should be transfered?: ")) + TransferMoney(card.account, bank[accountTo], amount) + elif operation == "6": + mode = "exit" \ No newline at end of file diff --git a/src/modules/Account.py b/src/modules/Account.py index a87b874..42c6cfa 100644 --- a/src/modules/Account.py +++ b/src/modules/Account.py @@ -1,10 +1,23 @@ -class Acount: +class Account: def __init__(self, number, name, surname, credit): self.number = number self.name = name self.surname = surname self.credit = credit self.cards = [] + self.acceptTransfers = True def addCard(self, card): - self.cards.append(card) \ No newline at end of file + self.cards.append(card) + + def addCredit(self, amount): + self.credit += amount + + def subCredit(self, amount): + self.credit -= amount + + def allowTransfers(self): + self.acceptTransfers = True + + def disallowTransfers(self): + self.acceptTransfers = False \ No newline at end of file diff --git a/src/modules/Card.py b/src/modules/Card.py index 8957e40..50c8c8c 100644 --- a/src/modules/Card.py +++ b/src/modules/Card.py @@ -4,7 +4,10 @@ class Card: self.pin = pin self.type = type self.account = account - account.addCard(self) + if self.account: + account.addCard(self) + self.blocked = False + self.wrongCounter = 0 \ No newline at end of file diff --git a/src/tools/tools.py b/src/tools/tools.py index 4478a0f..e290f10 100644 --- a/src/tools/tools.py +++ b/src/tools/tools.py @@ -1,6 +1,91 @@ +import random +import string + def PrintCardInfo(card): print("Owner's Name: " + card.account.name) print("Owner's Surname: " + card.account.surname) print("Card's Number: " + card.number) print("Card's Type: " + card.type) - print("Card's PIN: " + card.pin) \ No newline at end of file + print("Card's PIN: " + card.pin) + +def VerifyInvalidCard(card): + if card.type not in ["ATM", "Credit", "Prepaid"]: + return True + return False + +def VerifyOwner(card): + inputPin = input("Enter PIN for this card, please: ") + if inputPin == card.pin: + card.wrongCounter = 0 + return True + else: + card.wrongCounter += 1 + if card.wrongCounter == 3: + card.wrongCounter = 0 + card.blocked = True + print("You've entered wrong PIN three times. This card will be blocked.") + return False + continueAnswer = input("Do you want to try again? (Y/N): ") + if continueAnswer in ["Y", "y", "Yes", "yes"]: + VerifyOwner(card) + else: + return False + +def WithdrawMoney(amount, account): + if amount > account.credit: + print("You dont't have enough money on your account") + return 0 + if amount%10 != 0: + print("Enter multiple of 10") + return 0 + account.subCredit(amount) + out = "" + while amount >= 200: + amount -= 200 + out = out + "200 " + while amount >= 100: + amount -= 100 + out = out + "100 " + while amount >= 50: + amount -= 50 + out = out + "50 " + while amount >= 20: + amount -= 20 + out = out + "20 " + while amount >= 10: + amount -= 10 + out = out + "10 " + print (out) + return 1 + +def GeneratePrepaidPhoneCode(amount, operator, account): + if amount > account.credit: + print("You dont't have enough money on your account") + return 0 + # print(operatorAPI(amount, operator)) + print(''.join(random.choices(string.ascii_uppercase + string.digits, k=14))) + account.subCredit(amount) + return 1 + +def DepositMoney(notes, account): + amount = 0 + for note in notes: + amount += int(note) + account.addCredit(amount) + return 1 + +def CheckAccount(account): + print("Stored money: " + str(account.credit)) + return 1 + +def TransferMoney(accountFrom, accountTo, amount): + if amount > accountFrom.credit: + print("You dont't have enough money on your account") + return 0 + accountFrom.subCredit(amount) + accountTo.addCredit(amount) + return 1 + + + +