Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion method/resources/Payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from method.resource import Resource, RequestOpts
from method.configuration import Configuration
from method.errors import ResourceError
from method.resources.Reversal import ReversalResource


PaymentStatusesLiterals = Literal[
Expand All @@ -11,7 +12,9 @@
'processing',
'failed',
'sent',
'reversed'
'reversed',
'reversal_required',
'reversal_processing'
]


Expand All @@ -33,6 +36,9 @@

class Payment(TypedDict):
id: str
reversal_id: Optional[str]
source_trace_id: Optional[str]
destination_trace_id: Optional[str]
source: str
destination: str
amount: int
Expand All @@ -55,10 +61,20 @@ class PaymentCreateOpts(TypedDict):
metadata: Optional[Dict[str, Any]]


class PaymentSubResources:
reversals: ReversalResource

def __init__(self, _id: str, config: Configuration):
self.reversals = ReversalResource(config.add_path(_id))


class PaymentResource(Resource):
def __init__(self, config: Configuration):
super(PaymentResource, self).__init__(config.add_path('payments'))

def __call__(self, _id: str) -> PaymentSubResources:
return PaymentSubResources(_id, self.config)

def get(self, _id: str) -> Payment:
return super(PaymentResource, self)._get_with_id(_id)

Expand Down
53 changes: 53 additions & 0 deletions method/resources/Reversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import TypedDict, List, Literal, Dict, Any, Optional

from method.resource import Resource
from method.configuration import Configuration
from method.errors import ResourceError


ReversalStatusesLiterals = Literal[
'pending_approval',
'pending',
'processing',
'sent',
'failed'
]


ReversalDirectionsLiterals = Literal[
'debit',
'credit'
]


class Reversal(TypedDict):
id: str
pmt_id: str
target_account: str
trace_id: Optional[str]
direction: ReversalDirectionsLiterals
description: str
amount: int
status: ReversalStatusesLiterals
error: Optional[ResourceError]
created_at: str
updated_at: str


class ReversalUpdateOpts(TypedDict):
status: ReversalStatusesLiterals
description: Optional[str]


class ReversalResource(Resource):
def __init__(self, config: Configuration):
super(ReversalResource, self).__init__(config.add_path('reversals'))

def get(self, _id: str) -> Reversal:
return super(ReversalResource, self)._get_with_id(_id)

def update(self, _id: str, opts: ReversalUpdateOpts) -> Reversal:
return super(ReversalResource, self)._update_with_id(_id, opts)

def list(self) -> List[Reversal]:
return super(ReversalResource, self)._list(None)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='method-python',
version='0.0.14',
version='0.0.15',
description='Python library for the Method API',
author='Marco del Carmen',
author_email='marco@mdelcarmen.me',
Expand Down