11from abc import ABC , abstractmethod
22
3+
34class Order :
45
56 def __init__ (self ):
@@ -19,6 +20,7 @@ def total_price(self):
1920 total += self .quantities [i ] * self .prices [i ]
2021 return total
2122
23+
2224class Authorizer (ABC ):
2325 @abstractmethod
2426 def is_authorized (self ) -> bool :
@@ -37,6 +39,7 @@ def verify_code(self, code):
3739 def is_authorized (self ) -> bool :
3840 return self .authorized
3941
42+
4043class Authorizer_Google (Authorizer ):
4144
4245 def __init__ (self ):
@@ -49,6 +52,7 @@ def verify_code(self, code):
4952 def is_authorized (self ) -> bool :
5053 return self .authorized
5154
55+
5256class Authorizer_Robot (Authorizer ):
5357
5458 def __init__ (self ):
@@ -73,14 +77,15 @@ class DebitPaymentProcessor(PaymentProcessor):
7377 def __init__ (self , security_code , authorizer : Authorizer ):
7478 self .security_code = security_code
7579 self .authorizer = authorizer
76-
80+
7781 def pay (self , order ):
7882 if not self .authorizer .is_authorized ():
7983 raise Exception ("Not authorized" )
8084 print ("Processing debit payment type" )
8185 print (f"Verifying security code: { self .security_code } " )
8286 order .status = "paid"
8387
88+
8489class CreditPaymentProcessor (PaymentProcessor ):
8590
8691 def __init__ (self , security_code ):
@@ -91,6 +96,7 @@ def pay(self, order):
9196 print (f"Verifying security code: { self .security_code } " )
9297 order .status = "paid"
9398
99+
94100class PaypalPaymentProcessor (PaymentProcessor ):
95101
96102 def __init__ (self , email_address , authorizer : Authorizer ):
@@ -115,4 +121,4 @@ def pay(self, order):
115121# authorizer.verify_code(465839)
116122authorizer .not_a_robot ()
117123processor = PaypalPaymentProcessor (
"[email protected] " ,
authorizer )
118- processor .pay (order )
124+ processor .pay (order )
0 commit comments