|
4 | 4 | from moyasar.actions.refund import Refund |
5 | 5 | from moyasar.actions.capture import Capture |
6 | 6 | from moyasar.actions.void import Void |
7 | | -from moyasar.helpers import Constructor |
8 | | -from moyasar.helpers import Format |
| 7 | +from moyasar.helpers import Constructor, Format |
9 | 8 |
|
10 | 9 |
|
11 | 10 | class Source(Constructor, Format): |
12 | | - |
13 | 11 | @classmethod |
14 | 12 | def build(cls, source): |
15 | | - if source['type'] == "creditcard": |
16 | | - source = Source.source_to_creditcard(source) |
17 | | - else: |
18 | | - source = Source.source_to_sadad(source) |
19 | | - return source |
20 | | - |
21 | | - @classmethod |
22 | | - def source_to_creditcard(cls, data): |
23 | | - data.pop('type') |
24 | | - return CreditCard(data) |
25 | | - |
26 | | - @classmethod |
27 | | - def source_to_sadad(cls, data): |
28 | | - data.pop('type') |
29 | | - return Sadad(data) |
| 13 | + source_klass = sources[source.pop('type')] |
| 14 | + return source_klass(source) |
30 | 15 |
|
31 | 16 |
|
32 | 17 | class CreditCard(Source): |
33 | 18 | def __str__(self): |
34 | 19 | return json.dumps(self.__dict__) |
35 | 20 |
|
36 | | - |
37 | 21 | class Sadad(Source): |
38 | 22 | pass |
39 | 23 |
|
| 24 | +class ApplePay(Source): |
| 25 | + pass |
40 | 26 |
|
41 | | -class Payment(Resource, Refund, Capture, Void, Format): |
| 27 | +class STCPay(Source): |
| 28 | + pass |
42 | 29 |
|
| 30 | +sources = { |
| 31 | + 'creditcard': CreditCard, |
| 32 | + 'sadad': Sadad, |
| 33 | + 'applepay': ApplePay, |
| 34 | + 'stcpay': STCPay, |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +class Payment(Resource, Refund, Capture, Void, Format): |
43 | 39 | def __init__(self, data): |
44 | 40 | super().__init__(data) |
45 | 41 | self.source = Source.build(self.source) |
|
0 commit comments