Skip to content

Commit 8b21167

Browse files
authored
support for events (#42)
* support for events * fixed tests + other bugs * fixed entity test * fixed event test * version bump
1 parent 89e5040 commit 8b21167

12 files changed

Lines changed: 197 additions & 16 deletions

File tree

method/method.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
from method.resources.Webhook import WebhookResource
1010
from method.resources.HealthCheck import PingResponse, HealthCheckResource
1111
from method.resources.Simulate import SimulateResource
12-
12+
from method.resources.Events import EventResource
1313

1414
class Method:
1515
accounts: AccountResource
1616
entities: EntityResource
1717
elements: ElementResource
18+
events: EventResource
1819
merchants: MerchantResource
1920
payments: PaymentResource
2021
reports: ReportResource
@@ -29,6 +30,7 @@ def __init__(self, opts: ConfigurationOpts = None, **kwargs: ConfigurationOpts):
2930
self.accounts = AccountResource(config)
3031
self.entities = EntityResource(config)
3132
self.elements = ElementResource(config)
33+
self.events = EventResource(config)
3234
self.merchants = MerchantResource(config)
3335
self.payments = PaymentResource(config)
3436
self.reports = ReportResource(config)

method/resources/Events/Event.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import TypedDict, Optional, Dict, Any, List, Literal
2+
from method.resource import MethodResponse, Resource, ResourceListOpts
3+
from method.configuration import Configuration
4+
from method.resources.Webhook import WebhookTypesLiterals
5+
6+
EventResourceTypesLiterals = Literal[
7+
'account',
8+
'credit_score',
9+
'attribute',
10+
'connect'
11+
]
12+
13+
class EventDiff(TypedDict):
14+
before: Optional[Dict[str, Any]]
15+
after: Optional[Dict[str, Any]]
16+
17+
class Event(TypedDict):
18+
id: str
19+
type: WebhookTypesLiterals
20+
resource_id: str
21+
resource_type: EventResourceTypesLiterals
22+
data: Dict[str, Any]
23+
diff: EventDiff
24+
updated_at: str
25+
created_at: str
26+
27+
class EventListOpts(ResourceListOpts):
28+
resource_id: Optional[str]
29+
resource_type: Optional[EventResourceTypesLiterals]
30+
type: Optional[WebhookTypesLiterals]
31+
32+
class EventResource(Resource):
33+
def __init__(self, config: Configuration):
34+
super(EventResource, self).__init__(config.add_path('events'))
35+
36+
def retrieve(self, evt_id: str) -> MethodResponse[Event]:
37+
return super(EventResource, self)._get_with_id(evt_id)
38+
39+
def list(self, params: Optional[EventListOpts] = None) -> MethodResponse[List[Event]]:
40+
return super(EventResource, self)._list(params)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from method.resources.Events.Event import Event, EventResource
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import Dict, TypedDict, Optional
2+
from method.resource import MethodResponse, Resource
3+
from method.configuration import Configuration
4+
from method.resources.Webhook import WebhookTypesLiterals
5+
6+
class SimulateEventsOpts(TypedDict):
7+
type: WebhookTypesLiterals
8+
entity_id: Optional[str]
9+
account_id: Optional[str]
10+
11+
class SimulateEventsResource(Resource):
12+
def __init__(self, config: Configuration):
13+
super(SimulateEventsResource, self).__init__(config.add_path('events'))
14+
15+
def create(self, opts: SimulateEventsOpts) -> MethodResponse[Dict]:
16+
return super(SimulateEventsResource, self)._create(opts)

method/resources/Simulate/Simulate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
from method.configuration import Configuration
33
from method.resources.Simulate.Payments import SimulatePaymentResource
44
from method.resources.Simulate.Accounts import SimulateAccountResource
5-
5+
from method.resources.Simulate.Events import SimulateEventsResource
66

77
class SimulateResource(Resource):
88
payments: SimulatePaymentResource
99
accounts: SimulateAccountResource
10+
events: SimulateEventsResource
1011

1112
def __init__(self, config: Configuration):
1213
_config = config.add_path('simulate')
1314
super(SimulateResource, self).__init__(_config)
1415
self.payments = SimulatePaymentResource(_config)
1516
self.accounts = SimulateAccountResource(_config)
17+
self.events = SimulateEventsResource(_config)

method/resources/Webhook.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,58 @@
1111
'account.update',
1212
'entity.update',
1313
'entity.create',
14+
'account_verification.create',
15+
'account_verification.update',
1416
'payment_reversal.create',
1517
'payment_reversal.update',
1618
'connection.create',
1719
'connection.update',
18-
'account_verification.create',
19-
'account_verification.update',
2020
'transaction.create',
2121
'transaction.update',
2222
'report.create',
2323
'report.update',
24+
'product.create',
25+
'product.update',
26+
'subscription.create',
27+
'subscription.update',
2428
'credit_score.create',
2529
'credit_score.update',
26-
27-
# Deprecated
28-
'account_verification.sent',
29-
'account_verification.returned'
30+
'payoff.create',
31+
'payoff.update',
32+
'entity_verification_session.create',
33+
'entity_verification_session.update',
34+
'connect.create',
35+
'connect.update',
36+
'balance.create',
37+
'balance.update',
38+
'identity.create',
39+
'identity.update',
40+
'account_verification_session.create',
41+
'account_verification_session.update',
42+
'card_brand.create',
43+
'card_brand.update',
44+
'sensitive.create',
45+
'sensitive.update',
46+
'update.create',
47+
'update.update',
48+
'attribute.create',
49+
'attribute.update',
50+
'account.opened',
51+
'account.closed',
52+
'credit_score.increased',
53+
'credit_score.decreased',
54+
'attribute.credit_health_credit_card_usage.increased',
55+
'attribute.credit_health_credit_card_usage.decreased',
56+
'attribute.credit_health_derogatory_marks.increased',
57+
'attribute.credit_health_derogatory_marks.decreased',
58+
'attribute.credit_health_hard_inquiries.increased',
59+
'attribute.credit_health_hard_inquiries.decreased',
60+
'attribute.credit_health_total_accounts.increased',
61+
'attribute.credit_health_total_accounts.decreased',
62+
'attribute.credit_health_credit_age.increased',
63+
'attribute.credit_health_credit_age.decreased',
64+
'attribute.credit_health_payment_history.increased',
65+
'attribute.credit_health_payment_history.decreased'
3066
]
3167

3268

@@ -37,13 +73,15 @@ class Webhook(TypedDict):
3773
metadata: Optional[Dict[str, Any]]
3874
created_at: str
3975
updated_at: str
76+
expand_event: bool
4077

4178

4279
class WebhookCreateOpts(TypedDict):
4380
type: WebhookTypesLiterals
4481
url: str
4582
auth_token: Optional[str]
4683
metadata: Optional[Dict[str, Any]]
84+
expand_event: Optional[bool]
4785

4886

4987
class WebhookResource(Resource):

method/resources/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
from method.resources.HealthCheck import PingResponse, HealthCheckResource
1111
from method.resources.Merchant import Merchant, MerchantProviderIds, MerchantResource
1212
from method.resources.Report import Report, ReportCreateOpts, ReportResource
13-
from method.resources.Webhook import Webhook, WebhookCreateOpts, WebhookResource
13+
from method.resources.Webhook import Webhook, WebhookCreateOpts, WebhookResource
14+
from method.resources.Events.Event import Event, EventResource

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='1.1.1',
5+
version='1.1.2',
66
description='Python library for the Method API',
77
long_description='Python library for the Method API',
88
long_description_content_type='text/x-rst',

test/resources/Account_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_create_card_brands(setup):
267267
'account_id': test_credit_card_account['id'],
268268
'network': 'visa',
269269
'status': 'completed',
270-
'issuer': None,
270+
'issuer': card_brand_create_response['issuer'],
271271
'last4': '1580',
272272
'brands': card_brand_create_response['brands'],
273273
'shared': False,
@@ -288,7 +288,7 @@ def test_retrieve_card_brands(setup):
288288
'account_id': test_credit_card_account['id'],
289289
'network': 'visa',
290290
'status': 'completed',
291-
'issuer': None,
291+
'issuer': card_brand_create_response['issuer'],
292292
'last4': '1580',
293293
'brands': card_brand_create_response['brands'],
294294
'shared': False,

test/resources/Entity_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timedelta
12
import os
23
from method.resources.Entities.Attributes import EntityAttributes
34
import pytest
@@ -239,7 +240,8 @@ def test_update_entity():
239240

240241
def test_list_entities():
241242
global entities_list_response
242-
entities_list_response = method.entities.list()
243+
# list only those entities created in past day, in the format of YYYY-MM-DD
244+
entities_list_response = method.entities.list( {'from_date': (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')} )
243245
entities_list_response = [entity['id'] for entity in entities_list_response]
244246

245247
assert entities_create_response['id'] in entities_list_response
@@ -371,7 +373,7 @@ def get_credit_score():
371373
{
372374
'score': credit_score_retrieve_response['scores'][0]['score'],
373375
'source': 'equifax',
374-
'model': 'vantage_3',
376+
'model': 'vantage_4',
375377
'factors': credit_score_retrieve_response['scores'][0]['factors'],
376378
'created_at': credit_score_retrieve_response['scores'][0]['created_at']
377379
}

0 commit comments

Comments
 (0)