Skip to content

Commit 2f47244

Browse files
authored
Add connection resource and more type definitions (#5)
1 parent fcebea7 commit 2f47244

7 files changed

Lines changed: 148 additions & 5 deletions

File tree

method/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, opts: MethodErrorOpts):
3333
def catch(fn):
3434
def wrapper(*args, **kwargs):
3535
res = fn(*args, **kwargs)
36-
if (res is not None) and ('error' in res):
36+
if (res is not None) and ('error' in res) and ('id' not in res):
3737
raise MethodError.generate(res['error'])
3838
return res
3939
return wrapper

method/method.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from method.resources.RoutingNumber import RoutingNumberResource
1010
from method.resources.Webhook import WebhookResource
1111
from method.resources.HealthCheck import PingResponse, HealthCheckResource
12+
from method.resources.Connection import ConnectionResource
1213

1314

1415
class Method:
@@ -22,6 +23,7 @@ class Method:
2223
routing_numbers: RoutingNumberResource
2324
webhooks: WebhookResource
2425
healthcheck: HealthCheckResource
26+
connections: ConnectionResource
2527

2628
def __init__(self, opts: ConfigurationOpts = None, **kwargs: ConfigurationOpts):
2729
_opts: ConfigurationOpts = {**(opts or {}), **kwargs} # type: ignore
@@ -37,6 +39,7 @@ def __init__(self, opts: ConfigurationOpts = None, **kwargs: ConfigurationOpts):
3739
self.routing_numbers = RoutingNumberResource(config)
3840
self.webhooks = WebhookResource(config)
3941
self.healthcheck = HealthCheckResource(config)
42+
self.connections = ConnectionResource(config)
4043

4144
def ping(self) -> PingResponse:
4245
return self.healthcheck.get()

method/resources/Account.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
AccountCapabilitiesLiterals = Literal[
2323
'payments:receive',
24-
'payments:send'
24+
'payments:send',
25+
'data:retrieve'
2526
]
2627

2728

@@ -30,6 +31,13 @@
3031
'disabled'
3132
]
3233

34+
AccountDetailTypesLiterals = Literal[
35+
'bnpl_loan',
36+
'depository',
37+
'credit_card',
38+
'student_loan'
39+
]
40+
3341

3442
class AccountACH(TypedDict):
3543
routing: int
@@ -74,6 +82,68 @@ class AccountCreateOpts(TypedDict):
7482
metadata: Optional[Dict[str, Any]]
7583

7684

85+
class AccountDetailBNPLLoanUpcomingPaymentDue(TypedDict):
86+
amount: int
87+
date: str
88+
89+
90+
class AccountDetailBNPLLoan(TypedDict):
91+
name: Optional[str]
92+
reference_id: str
93+
balance: int
94+
purchase_date: str
95+
next_payment_due_date: Optional[str]
96+
total_payments_count: int
97+
payments_made_count: int
98+
remaining_payments_count: int
99+
autopay_enabled: bool
100+
payoff_progress: int
101+
interest_rate: int
102+
description: Optional[str]
103+
total_cost: int
104+
total_paid: int
105+
status: Literal['paid_off', 'refunded', 'in_progress']
106+
upcoming_payments_due: List[AccountDetailBNPLLoanUpcomingPaymentDue]
107+
108+
109+
class AccountDetailDepository(TypedDict):
110+
name: Optional[str]
111+
reference_number: str
112+
balance: int
113+
114+
115+
class AccountDetailCreditCard(TypedDict):
116+
name: Optional[str]
117+
reference_number: str
118+
balance: int
119+
last_payment_amount: int
120+
last_payment_date: Optional[str]
121+
next_payment_due_date: Optional[str]
122+
next_payment_minimum_amount: int
123+
124+
125+
# TODO[mdelcarmen]
126+
class AccountDetailStudentLoan(TypedDict):
127+
pass
128+
129+
130+
class AccountDetail(TypedDict):
131+
type: AccountDetailTypesLiterals
132+
bnpl_loan: Optional[AccountDetailBNPLLoan]
133+
depository: Optional[AccountDetailDepository]
134+
credit_card: Optional[AccountDetailCreditCard]
135+
student_loan: Optional[AccountDetailStudentLoan]
136+
137+
138+
class AccountTransaction(TypedDict):
139+
id: str
140+
reference_id: str
141+
date: str
142+
amount: int
143+
status: Literal['pending', 'success']
144+
description: Optional[str]
145+
146+
77147
class AccountListOpts(TypedDict):
78148
holder_id: Optional[str]
79149

@@ -100,3 +170,9 @@ def list(self, params: Optional[AccountListOpts] = None) -> List[Account]:
100170

101171
def create(self, opts: AccountCreateOpts, request_opts: Optional[RequestOpts] = None) -> Account:
102172
return super(AccountResource, self)._create(opts, request_opts)
173+
174+
def get_detail(self, _id: str) -> AccountDetail:
175+
return super(AccountResource, self)._get_with_sub_path('{_id}/detail'.format(_id=_id))
176+
177+
def get_transactions(self, _id: str) -> List[AccountTransaction]:
178+
return super(AccountResource, self)._get_with_sub_path('{_id}/transactions'.format(_id=_id))

method/resources/Connection.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import TypedDict, Optional, List, Dict, Any, Literal
2+
3+
from method.resources import Account
4+
from method.errors import ResourceError
5+
from method.resource import Resource
6+
from method.configuration import Configuration
7+
8+
9+
ConnectionSourcesLiterals = Literal[
10+
'plaid',
11+
'mch_5500'
12+
]
13+
14+
15+
ConnectionStatusesLiterals = Literal[
16+
'success',
17+
'reauth_required',
18+
'syncing',
19+
'failed'
20+
]
21+
22+
23+
class Connection(TypedDict):
24+
id: str
25+
entity_id: str
26+
accounts: List[str]
27+
source: ConnectionSourcesLiterals
28+
status: ConnectionStatusesLiterals
29+
error: Optional[ResourceError]
30+
created_at: str
31+
updated_at: str
32+
last_synced_at: str
33+
34+
35+
class ConnectionUpdateOpts(TypedDict):
36+
status: Literal['syncing']
37+
38+
39+
class ConnectionResource(Resource):
40+
def __init__(self, config: Configuration):
41+
super(ConnectionResource, self).__init__(config.add_path('connections'))
42+
43+
def get(self, _id: str) -> Connection:
44+
return super(ConnectionResource, self)._get_with_id(_id)
45+
46+
def list(self) -> List[Connection]:
47+
return super(ConnectionResource, self)._list(None)
48+
49+
def update(self, _id: str, opts: ConnectionUpdateOpts) -> Connection:
50+
return super(ConnectionResource, self)._update_with_id(_id, opts)
51+
52+
def get_accounts(self, _id: str) -> List[Account]:
53+
return super(ConnectionResource, self)._get_with_sub_path('{_id}/accounts'.format(_id=_id))
54+
55+
def get_public_account_tokens(self, _id: str) -> List[str]:
56+
return super(ConnectionResource, self)._get_with_sub_path('{_id}/public_account_tokens'.format(_id=_id))

method/resources/Element.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict, Optional, Literal
1+
from typing import TypedDict, Optional, Literal, List
22

33
from method.resource import Resource
44
from method.configuration import Configuration
@@ -25,7 +25,8 @@ class Element(TypedDict):
2525

2626

2727
class ElementExchangePublicAccountOpts(TypedDict):
28-
public_account_token: str
28+
public_account_token: Optional[str]
29+
public_account_tokens: Optional[List[str]]
2930

3031

3132
class ElementResource(Resource):
@@ -37,3 +38,6 @@ def create_token(self, opts: ElementTokenCreateOpts) -> Element:
3738

3839
def exchange_public_account_token(self, opts: ElementExchangePublicAccountOpts) -> Account:
3940
return super(ElementResource, self)._create_with_sub_path('/accounts/exchange', opts)
41+
42+
def exchange_public_account_tokens(self, opts: ElementExchangePublicAccountOpts) -> Account:
43+
return super(ElementResource, self)._create_with_sub_path('/accounts/exchange', opts)

method/resources/Webhook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
'account.update',
1212
'entity.update',
1313
'entity.create',
14+
'payment_reversal.create',
15+
'payment_reversal.update',
16+
'connection.create',
17+
'connection.update',
1418
'account_verification.create',
1519
'account_verification.update',
1620
'account_verification.sent',

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.15',
5+
version='0.0.16',
66
description='Python library for the Method API',
77
author='Marco del Carmen',
88
author_email='marco@mdelcarmen.me',

0 commit comments

Comments
 (0)