-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpayment.py
40 lines (29 loc) · 1.04 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
from abc import ABC, abstractmethod
class PaymentMethodFactory:
'''
This 'cooks' the payment methods
Gets the method and the processor class
and returns the preferred payment method
-> register a method by providing the method the its payment class
-> it the method gets mapped to the class, and the class is returned
eg payment_methods.register_payment_method('rave_payment', RavePayment)
'''
def __init__(self):
self.payment_methods = {}
def register_payment_method(self, method, processor):
self.payment_methods[method] = processor
def select_payment_method(self, method):
preferred_payment_method = self.payment_methods.get(method.lower())
if preferred_payment_method is None:
return ValueError(method)
return preferred_payment_method
class PaymentInterface(ABC):
'''
Abstract Skeleton class for the payment class
'''
@abstractmethod
def pay(self, payload):
pass
@abstractmethod
def verify(self, payload):
pass