1
1
from abc import ABC , abstractmethod
2
2
3
+
3
4
class Order :
4
5
5
6
def __init__ (self ):
@@ -19,13 +20,14 @@ def total_price(self):
19
20
total += self .quantities [i ] * self .prices [i ]
20
21
return total
21
22
23
+
22
24
class Authorizer (ABC ):
23
25
@abstractmethod
24
26
def is_authorized (self ) -> bool :
25
27
pass
26
28
27
29
28
- class Authorizer_SMS (Authorizer ):
30
+ class AuthorizerSMS (Authorizer ):
29
31
30
32
def __init__ (self ):
31
33
self .authorized = False
@@ -37,7 +39,8 @@ def verify_code(self, code):
37
39
def is_authorized (self ) -> bool :
38
40
return self .authorized
39
41
40
- class Authorizer_Google (Authorizer ):
42
+
43
+ class AuthorizerGoogle (Authorizer ):
41
44
42
45
def __init__ (self ):
43
46
self .authorized = False
@@ -49,7 +52,8 @@ def verify_code(self, code):
49
52
def is_authorized (self ) -> bool :
50
53
return self .authorized
51
54
52
- class Authorizer_Robot (Authorizer ):
55
+
56
+ class AuthorizerRobot (Authorizer ):
53
57
54
58
def __init__ (self ):
55
59
self .authorized = False
@@ -73,14 +77,15 @@ class DebitPaymentProcessor(PaymentProcessor):
73
77
def __init__ (self , security_code , authorizer : Authorizer ):
74
78
self .security_code = security_code
75
79
self .authorizer = authorizer
76
-
80
+
77
81
def pay (self , order ):
78
82
if not self .authorizer .is_authorized ():
79
83
raise Exception ("Not authorized" )
80
84
print ("Processing debit payment type" )
81
85
print (f"Verifying security code: { self .security_code } " )
82
86
order .status = "paid"
83
87
88
+
84
89
class CreditPaymentProcessor (PaymentProcessor ):
85
90
86
91
def __init__ (self , security_code ):
@@ -91,6 +96,7 @@ def pay(self, order):
91
96
print (f"Verifying security code: { self .security_code } " )
92
97
order .status = "paid"
93
98
99
+
94
100
class PaypalPaymentProcessor (PaymentProcessor ):
95
101
96
102
def __init__ (self , email_address , authorizer : Authorizer ):
@@ -111,8 +117,8 @@ def pay(self, order):
111
117
order .add_item ("USB cable" , 2 , 5 )
112
118
113
119
print (order .total_price ())
114
- authorizer = Authorizer_Robot ()
120
+ authorizer = AuthorizerRobot ()
115
121
# authorizer.verify_code(465839)
116
122
authorizer .not_a_robot ()
117
123
processor = PaypalPaymentProcessor (
"[email protected] " ,
authorizer )
118
- processor .pay (order )
124
+ processor .pay (order )
0 commit comments