Skip to content

Commit fcebea7

Browse files
authored
Add reversals resource. (#4)
1 parent 078b217 commit fcebea7

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

method/resources/Payment.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from method.resource import Resource, RequestOpts
44
from method.configuration import Configuration
55
from method.errors import ResourceError
6+
from method.resources.Reversal import ReversalResource
67

78

89
PaymentStatusesLiterals = Literal[
@@ -11,7 +12,9 @@
1112
'processing',
1213
'failed',
1314
'sent',
14-
'reversed'
15+
'reversed',
16+
'reversal_required',
17+
'reversal_processing'
1518
]
1619

1720

@@ -33,6 +36,9 @@
3336

3437
class Payment(TypedDict):
3538
id: str
39+
reversal_id: Optional[str]
40+
source_trace_id: Optional[str]
41+
destination_trace_id: Optional[str]
3642
source: str
3743
destination: str
3844
amount: int
@@ -55,10 +61,20 @@ class PaymentCreateOpts(TypedDict):
5561
metadata: Optional[Dict[str, Any]]
5662

5763

64+
class PaymentSubResources:
65+
reversals: ReversalResource
66+
67+
def __init__(self, _id: str, config: Configuration):
68+
self.reversals = ReversalResource(config.add_path(_id))
69+
70+
5871
class PaymentResource(Resource):
5972
def __init__(self, config: Configuration):
6073
super(PaymentResource, self).__init__(config.add_path('payments'))
6174

75+
def __call__(self, _id: str) -> PaymentSubResources:
76+
return PaymentSubResources(_id, self.config)
77+
6278
def get(self, _id: str) -> Payment:
6379
return super(PaymentResource, self)._get_with_id(_id)
6480

method/resources/Reversal.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from typing import TypedDict, List, Literal, Dict, Any, Optional
2+
3+
from method.resource import Resource
4+
from method.configuration import Configuration
5+
from method.errors import ResourceError
6+
7+
8+
ReversalStatusesLiterals = Literal[
9+
'pending_approval',
10+
'pending',
11+
'processing',
12+
'sent',
13+
'failed'
14+
]
15+
16+
17+
ReversalDirectionsLiterals = Literal[
18+
'debit',
19+
'credit'
20+
]
21+
22+
23+
class Reversal(TypedDict):
24+
id: str
25+
pmt_id: str
26+
target_account: str
27+
trace_id: Optional[str]
28+
direction: ReversalDirectionsLiterals
29+
description: str
30+
amount: int
31+
status: ReversalStatusesLiterals
32+
error: Optional[ResourceError]
33+
created_at: str
34+
updated_at: str
35+
36+
37+
class ReversalUpdateOpts(TypedDict):
38+
status: ReversalStatusesLiterals
39+
description: Optional[str]
40+
41+
42+
class ReversalResource(Resource):
43+
def __init__(self, config: Configuration):
44+
super(ReversalResource, self).__init__(config.add_path('reversals'))
45+
46+
def get(self, _id: str) -> Reversal:
47+
return super(ReversalResource, self)._get_with_id(_id)
48+
49+
def update(self, _id: str, opts: ReversalUpdateOpts) -> Reversal:
50+
return super(ReversalResource, self)._update_with_id(_id, opts)
51+
52+
def list(self) -> List[Reversal]:
53+
return super(ReversalResource, self)._list(None)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='method-python',
5-
version='0.0.14',
5+
version='0.0.15',
66
description='Python library for the Method API',
77
author='Marco del Carmen',
88
author_email='marco@mdelcarmen.me',

0 commit comments

Comments
 (0)