-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpayment.py
92 lines (70 loc) · 1.88 KB
/
payment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""payment management system using proxy pattern
"""
from abc import ABC, abstractmethod
class Pay(ABC):
"""Payment Abstract Class"""
@abstractmethod
def do_pay(self):
"""do pay
"""
class Bank(Pay):
"""Bank Management
"""
def __init__(self):
self.card = None
self.account = None
def __get_card(self):
"""get card number
"""
return self.card
def __check_inventory(self):
print("Bank: Checking that account of [", self.__get_card(
), "] have enough money or not..")
return False
def set_card(self, card):
"""set card number
"""
self.card = card
def do_pay(self):
"""do payment
Returns:
bool: True for paid False for not enough money
"""
if self.__check_inventory():
print("Bank: Successfully paid.")
return True
print("Bank: Your money is not enough.")
return False
class Card(Pay):
"""Card Class
"""
def __init__(self):
self.bank = Bank()
def do_pay(self):
"""do payment with this card
Returns:
bool: True for paid False for not enough money
"""
card = input("Enter your card number: ")
self.bank.set_card(card)
return self.bank.do_pay()
class You:
"""Manage User
"""
def __init__(self):
print("You: I want to buy a product.")
self.card = Card()
self.is_bought = None
def pay(self):
"""pay with card
is_bought = True if paid and False if not enough money
"""
self.is_bought = self.card.do_pay()
def __del__(self):
if self.is_bought:
print("You: I bought the product.")
else:
print("You: My money is not enough to buy.")
if __name__ == "__main__":
you = You()
you.pay()