66from gr4vy .types import OptionalNullable , UNSET
77from gr4vy .utils import get_security_from_env
88from gr4vy .utils .unmarshal_json_response import unmarshal_json_response
9- from typing import Any , Mapping , Optional
9+ from jsonpath import JSONPath
10+ from typing import Any , Dict , List , Mapping , Optional , Union
1011
1112
1213class Events (BaseSDK ):
@@ -21,7 +22,7 @@ def list(
2122 server_url : Optional [str ] = None ,
2223 timeout_ms : Optional [int ] = None ,
2324 http_headers : Optional [Mapping [str , str ]] = None ,
24- ) -> models .TransactionEvents :
25+ ) -> Optional [ models .ListTransactionEventsResponse ] :
2526 r"""List transaction events
2627
2728 Retrieve a paginated list of events related to processing a transaction, including status changes, API requests, and webhook delivery attempts. Events are listed in chronological order, with the most recent events first.
@@ -113,9 +114,31 @@ def list(
113114 retry_config = retry_config ,
114115 )
115116
117+ def next_func () -> Optional [models .ListTransactionEventsResponse ]:
118+ body = utils .unmarshal_json (http_res .text , Union [Dict [Any , Any ], List [Any ]])
119+ next_cursor = JSONPath ("$.next_cursor" ).parse (body )
120+
121+ if len (next_cursor ) == 0 :
122+ return None
123+
124+ next_cursor = next_cursor [0 ]
125+ if next_cursor is None or str (next_cursor ).strip () == "" :
126+ return None
127+
128+ return self .list (
129+ transaction_id = transaction_id ,
130+ cursor = next_cursor ,
131+ limit = limit ,
132+ merchant_account_id = merchant_account_id ,
133+ retries = retries ,
134+ )
135+
116136 response_data : Any = None
117137 if utils .match_response (http_res , "200" , "application/json" ):
118- return unmarshal_json_response (models .TransactionEvents , http_res )
138+ return models .ListTransactionEventsResponse (
139+ result = unmarshal_json_response (models .TransactionEvents , http_res ),
140+ next = next_func ,
141+ )
119142 if utils .match_response (http_res , "400" , "application/json" ):
120143 response_data = unmarshal_json_response (errors .Error400Data , http_res )
121144 raise errors .Error400 (response_data , http_res )
@@ -174,7 +197,7 @@ async def list_async(
174197 server_url : Optional [str ] = None ,
175198 timeout_ms : Optional [int ] = None ,
176199 http_headers : Optional [Mapping [str , str ]] = None ,
177- ) -> models .TransactionEvents :
200+ ) -> Optional [ models .ListTransactionEventsResponse ] :
178201 r"""List transaction events
179202
180203 Retrieve a paginated list of events related to processing a transaction, including status changes, API requests, and webhook delivery attempts. Events are listed in chronological order, with the most recent events first.
@@ -266,9 +289,31 @@ async def list_async(
266289 retry_config = retry_config ,
267290 )
268291
292+ def next_func () -> Optional [models .ListTransactionEventsResponse ]:
293+ body = utils .unmarshal_json (http_res .text , Union [Dict [Any , Any ], List [Any ]])
294+ next_cursor = JSONPath ("$.next_cursor" ).parse (body )
295+
296+ if len (next_cursor ) == 0 :
297+ return None
298+
299+ next_cursor = next_cursor [0 ]
300+ if next_cursor is None or str (next_cursor ).strip () == "" :
301+ return None
302+
303+ return self .list (
304+ transaction_id = transaction_id ,
305+ cursor = next_cursor ,
306+ limit = limit ,
307+ merchant_account_id = merchant_account_id ,
308+ retries = retries ,
309+ )
310+
269311 response_data : Any = None
270312 if utils .match_response (http_res , "200" , "application/json" ):
271- return unmarshal_json_response (models .TransactionEvents , http_res )
313+ return models .ListTransactionEventsResponse (
314+ result = unmarshal_json_response (models .TransactionEvents , http_res ),
315+ next = next_func ,
316+ )
272317 if utils .match_response (http_res , "400" , "application/json" ):
273318 response_data = unmarshal_json_response (errors .Error400Data , http_res )
274319 raise errors .Error400 (response_data , http_res )
0 commit comments