Skip to content

Commit a41139c

Browse files
authored
Bilal/mthd-8679 (#52)
* support for transactions, payment instruments & simulating credit scores + tests * bump version
1 parent 70ee676 commit a41139c

14 files changed

Lines changed: 249 additions & 92 deletions

File tree

method/resources/Accounts/Account.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from method.resources.Accounts.VerificationSessions import AccountVerificationSession, AccountVerificationSessionResource
1616
from method.resources.Accounts.Products import AccountProduct, AccountProductResource
1717
from method.resources.Accounts.Attributes import AccountAttributes, AccountAttributesResource
18+
from method.resources.Accounts.PaymentInstruments import AccountPaymentInstrument, AccountPaymentInstrumentsResource
19+
1820
class AccountCreateOpts(TypedDict):
1921
holder_id: str
2022
metadata: Optional[Dict[str, Any]]
@@ -67,6 +69,7 @@ class Account(TypedDict):
6769
card_brand: Optional[Union[str, AccountCardBrand]]
6870
payoff: Optional[Union[str, AccountPayoff]]
6971
transaction: Optional[Union[str, AccountTransaction]]
72+
payment_instrument: Optional[Union[str, AccountPaymentInstrument]]
7073
update: Optional[Union[str, AccountUpdate]]
7174
latest_verification_session: Optional[Union[str, AccountVerificationSession]]
7275
error: Optional[ResourceError]
@@ -94,7 +97,7 @@ class AccountSubResources:
9497
verification_sessions: AccountVerificationSessionResource
9598
products: AccountProductResource
9699
attributes: AccountAttributesResource
97-
100+
payment_instruments: AccountPaymentInstrumentsResource
98101

99102
def __init__(self, _id: str, config: Configuration):
100103
self.balances = AccountBalancesResource(config.add_path(_id))
@@ -103,6 +106,7 @@ def __init__(self, _id: str, config: Configuration):
103106
self.sensitive = AccountSensitiveResource(config.add_path(_id))
104107
self.subscriptions = AccountSubscriptionsResource(config.add_path(_id))
105108
self.transactions = AccountTransactionsResource(config.add_path(_id))
109+
self.payment_instruments = AccountPaymentInstrumentsResource(config.add_path(_id))
106110
self.updates = AccountUpdatesResource(config.add_path(_id))
107111
self.verification_sessions = AccountVerificationSessionResource(config.add_path(_id))
108112
self.products = AccountProductResource(config.add_path(_id))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from typing import TypedDict, Optional, Literal, List, Any
2+
3+
from method.resource import MethodResponse, Resource, ResourceListOpts
4+
from method.configuration import Configuration
5+
from method.errors import ResourceError
6+
7+
AccountPaymentInstrumentTypesLiterals = Literal[
8+
'card',
9+
'network_token'
10+
]
11+
12+
class AccountPaymentInstrumentCreateOpts(TypedDict):
13+
type: AccountPaymentInstrumentTypesLiterals
14+
15+
class AccountPaymentInstrumentNetworkToken(TypedDict):
16+
token: str
17+
18+
class AccountPaymentInstrumentCard(TypedDict):
19+
number: str
20+
exp_month: int
21+
exp_year: int
22+
23+
AccountPaymentInstrumentStatusesLiterals = Literal[
24+
'completed',
25+
'in_progress',
26+
'pending',
27+
'failed'
28+
]
29+
30+
class AccountPaymentInstrument(TypedDict):
31+
id: str
32+
account_id: str
33+
type: AccountPaymentInstrumentTypesLiterals
34+
network_token: Optional[AccountPaymentInstrumentNetworkToken]
35+
card: Optional[AccountPaymentInstrumentCard]
36+
chargeable: bool
37+
status: AccountPaymentInstrumentStatusesLiterals
38+
error: Optional[ResourceError]
39+
created_at: str
40+
updated_at: str
41+
42+
43+
class AccountPaymentInstrumentsResource(Resource):
44+
def __init__(self, config: Configuration):
45+
super(AccountPaymentInstrumentsResource, self).__init__(config.add_path('payment_instruments'))
46+
47+
def retrieve(self, pmt_inst_id: str) -> MethodResponse[AccountPaymentInstrument]:
48+
return super(AccountPaymentInstrumentsResource, self)._get_with_id(pmt_inst_id)
49+
50+
def list(self, params: Optional[ResourceListOpts] = None) -> MethodResponse[List[AccountPaymentInstrument]]:
51+
return super(AccountPaymentInstrumentsResource, self)._list(params)
52+
53+
def create(self, data: AccountPaymentInstrumentCreateOpts) -> MethodResponse[AccountPaymentInstrument]:
54+
return super(AccountPaymentInstrumentsResource, self)._create(data)

method/resources/Accounts/Products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AccountProductListResponse(TypedDict):
3232
transactions: Optional[AccountProduct]
3333
payoff: Optional[AccountProduct]
3434
card_brand: Optional[AccountProduct]
35+
payment_instruments: Optional[AccountProduct]
3536

3637
class AccountProductResource(Resource):
3738
def __init__(self, config: Configuration):

method/resources/Accounts/Subscriptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
AccountSubscriptionTypesLiterals = Literal[
8-
'transactions',
8+
'transaction',
99
'update',
1010
'update.snapshot'
1111
]
@@ -21,7 +21,7 @@ class AccountSubscription(TypedDict):
2121

2222

2323
AccountSubscriptionsResponse = TypedDict('AccountSubscriptionsResponse', {
24-
'transactions': Optional[AccountSubscription],
24+
'transaction': Optional[AccountSubscription],
2525
'update': Optional[AccountSubscription],
2626
'update.snapshot': Optional[AccountSubscription]
2727
})

method/resources/Accounts/Transactions.py

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,33 @@
22

33
from method.resource import MethodResponse, Resource, ResourceListOpts
44
from method.configuration import Configuration
5-
from method.errors import ResourceError
6-
7-
8-
AccountCurrencyTypesLiterals = Literal[
9-
'USD'
10-
]
11-
125

136
AccountTransactionStatusLiterals = Literal[
14-
'cleared',
15-
'auth',
16-
'refund',
17-
'unknown'
7+
'pending',
8+
'posted',
9+
'voided',
1810
]
1911

20-
21-
class AccountTransactionMerchant(TypedDict):
22-
name: str
23-
category_code: str
24-
city: str
25-
state: str
26-
country: str
27-
acquirer_bin: str
28-
acquirer_card_acceptor_id: str
29-
30-
31-
class AccountTransactionNetworkData(TypedDict):
32-
visa_merchant_id: Optional[str]
33-
visa_merchant_name: Optional[str]
34-
visa_store_id: Optional[str]
35-
visa_store_name: Optional[str]
36-
37-
3812
class AccountTransaction(TypedDict):
3913
id: str
4014
account_id: str
41-
merchant: AccountTransactionMerchant
42-
network: str
43-
network_data: AccountTransactionNetworkData
15+
descriptor: str
4416
amount: int
45-
currency: AccountCurrencyTypesLiterals
46-
billing_amount: int
47-
billing_currency: AccountCurrencyTypesLiterals
17+
auth_amount: int
18+
currency_code: str
19+
transaction_amount: int
20+
transaction_auth_amount: int
21+
transaction_currency_code: str
22+
merchant_category_code: str
4823
status: AccountTransactionStatusLiterals
49-
error: Optional[ResourceError]
24+
transacted_at: str
25+
posted_at: Optional[str]
26+
voided_at: Optional[str]
27+
original_txn_id: Optional[str]
5028
created_at: str
5129
updated_at: str
30+
31+
5232

5333

5434
class AccountTransactionsResource(Resource):

method/resources/Accounts/Types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'payoff',
2323
'update',
2424
'attribute',
25-
'transactions'
25+
'transactions',
26+
'payment_instruments'
2627
]
2728

2829

method/resources/Accounts/VerificationSessions.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
'teller',
2222
'standard',
2323
'instant',
24-
'pre_auth'
24+
'pre_auth',
25+
'network'
2526
]
2627

2728

@@ -85,6 +86,13 @@ class AccountVerificationSessionPreAuth(AccountVerificationSessionInstant):
8586
pre_auth_check: Optional[AccountVerificationPassFailLiterals]
8687

8788

89+
class AccountVerificationSessionNetwork(AccountVerificationSessionInstant):
90+
cvv: str
91+
cvv_check: Optional[AccountVerificationPassFailLiterals]
92+
billing_zip_code: str
93+
billing_zip_code_check: Optional[AccountVerificationPassFailLiterals]
94+
network_check: Optional[AccountVerificationPassFailLiterals]
95+
8896
class AccountVerificationSessionCreateOpts(TypedDict):
8997
type: AccountVerificationSessionTypesLiterals
9098

@@ -117,14 +125,19 @@ class AccountVerificationSessionPreAuthUpdateOpts(TypedDict):
117125
pre_auth: AccountVerificationSessionPreAuth
118126

119127

128+
class AccountVerificationSessionNetworkUpdateOpts(TypedDict):
129+
network: AccountVerificationSessionNetwork
130+
131+
120132
AccountVerificationSessionUpdateOpts = Union[
121133
AccountVerificationSessionMicroDepositsUpdateOpts,
122134
AccountVerificationSessionPlaidUpdateOpts,
123135
AccountVerificationSessionMXUpdateOpts,
124136
AccountVerificationSessionTellerUpdateOpts,
125137
AccountVerificationSessionStandardUpdateOpts,
126138
AccountVerificationSessionInstantUpdateOpts,
127-
AccountVerificationSessionPreAuthUpdateOpts
139+
AccountVerificationSessionPreAuthUpdateOpts,
140+
AccountVerificationSessionNetworkUpdateOpts
128141
]
129142

130143

@@ -144,6 +157,7 @@ class AccountVerificationSession(TypedDict):
144157
pre_auth: Optional[AccountVerificationSessionPreAuth]
145158
three_ds: Optional[AccountVerificationSessionThreeDS]
146159
issuer: Optional[AccountVerificationSessionIssuer]
160+
network: Optional[AccountVerificationSessionNetwork]
147161
created_at: str
148162
updated_at: str
149163

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from method.resource import MethodResponse, Resource
2+
from method.configuration import Configuration
3+
from typing import List, Dict, Any
4+
from method.resources.Entities.CreditScores import EntityCreditScoresType, EntityCreditScores
5+
6+
7+
class SimulateCreditScoresInstance(Resource):
8+
def __init__(self, crs_id: str, config: Configuration):
9+
super(SimulateCreditScoresInstance, self).__init__(config.add_path(crs_id))
10+
11+
def create(self, scores: List[EntityCreditScoresType]) -> MethodResponse[EntityCreditScores]:
12+
return super(SimulateCreditScoresInstance, self)._create({"scores": scores})
13+
14+
15+
class SimulateCreditScoresResource(Resource):
16+
def __init__(self, config: Configuration):
17+
super(SimulateCreditScoresResource, self).__init__(config.add_path('credit_scores'))
18+
19+
def __call__(self, crs_id: str) -> SimulateCreditScoresInstance:
20+
return SimulateCreditScoresInstance(crs_id, self.config)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from method.resource import Resource
2+
from method.configuration import Configuration
3+
from method.resources.Simulate.CreditScores import SimulateCreditScoresResource
4+
5+
6+
class SimulateEntitySubResources:
7+
credit_scores: SimulateCreditScoresResource
8+
9+
def __init__(self, _id: str, config: Configuration):
10+
self.credit_scores = SimulateCreditScoresResource(config.add_path(_id))
11+
12+
13+
class SimulateEntityResource(Resource):
14+
def __init__(self, config: Configuration):
15+
super(SimulateEntityResource, self).__init__(config.add_path('entities'))
16+
17+
def __call__(self, ent_id) -> SimulateEntitySubResources:
18+
return SimulateEntitySubResources(ent_id, self.config)

method/resources/Simulate/Simulate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
from method.resources.Simulate.Payments import SimulatePaymentResource
44
from method.resources.Simulate.Accounts import SimulateAccountResource
55
from method.resources.Simulate.Events import SimulateEventsResource
6+
from method.resources.Simulate.Entities import SimulateEntityResource
67

78
class SimulateResource(Resource):
89
payments: SimulatePaymentResource
910
accounts: SimulateAccountResource
1011
events: SimulateEventsResource
12+
entities: SimulateEntityResource
1113

1214
def __init__(self, config: Configuration):
1315
_config = config.add_path('simulate')
1416
super(SimulateResource, self).__init__(_config)
1517
self.payments = SimulatePaymentResource(_config)
1618
self.accounts = SimulateAccountResource(_config)
1719
self.events = SimulateEventsResource(_config)
20+
self.entities = SimulateEntityResource(_config)
21+

0 commit comments

Comments
 (0)