Skip to content

Commit 41e0d4a

Browse files
authored
Merge pull request #12 from paywithextend/use-correct-transactions-endpoint
use correct transactions endpoint
2 parents c326e13 + f9661f2 commit 41e0d4a

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def main():
5454

5555
# Get all transactions
5656
response = await client.transactions.get_transactions()
57-
print("Transactions:", response["transactions"])
57+
print("Transactions:", response["report"]["transactions"])
5858

5959

6060
# Run the async function

extend/resources/resource.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,28 @@ async def _request(
2323
params: Optional[Dict] = None,
2424
data: Optional[Dict[str, Any]] = None,
2525
files: Optional[Dict[str, Any]] = None,
26+
base_url_override: Optional[str] = None,
2627
) -> Any:
2728
if params is not None:
2829
params = {k: v for k, v in params.items() if v is not None}
2930
match method:
3031
case "get":
31-
return await self._api_client.get(self.build_full_path(path), params)
32+
return await self._api_client.get(self.build_full_path(path, base_url_override), params)
3233
case "post":
33-
return await self._api_client.post(self.build_full_path(path), params)
34+
return await self._api_client.post(self.build_full_path(path, base_url_override), params)
3435
case "put":
35-
return await self._api_client.put(self.build_full_path(path), params)
36+
return await self._api_client.put(self.build_full_path(path, base_url_override), params)
3637
case "patch":
37-
return await self._api_client.patch(self.build_full_path(path), params)
38+
return await self._api_client.patch(self.build_full_path(path, base_url_override), params)
3839
case "post_multipart":
3940
return await self._api_client.post_multipart(
40-
self.build_full_path(path),
41+
self.build_full_path(path, base_url_override),
4142
data=data,
4243
files=files
4344
)
4445
case _:
4546
raise ValueError(f"Unsupported HTTP method: {method}")
4647

47-
def build_full_path(self, path):
48-
return f"{self._base_url}{path or ''}"
48+
def build_full_path(self, path, base_url_override):
49+
base = base_url_override if base_url_override is not None else self._base_url
50+
return f"{base}{path or ''}"

extend/resources/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def get_transactions(
7171
"sort": sort_field,
7272
}
7373

74-
return await self._request(method="get", params=params)
74+
return await self._request(method="get", params=params, base_url_override='/reports/transactions/v2')
7575

7676
async def get_transaction(self, transaction_id: str) -> Dict:
7777
"""Get detailed information about a specific transaction.

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ async def test_cancel_and_close_virtual_card(extend, mocker, mock_virtual_card):
250250
@pytest.mark.asyncio
251251
async def test_get_transactions(extend, mocker, mock_transaction):
252252
mock_response: Any = {
253-
"transactions": [mock_transaction, mock_transaction]
253+
"report": {"transactions": [mock_transaction, mock_transaction]}
254254
}
255255

256256
mocker.patch.object(extend._api_client, 'get', return_value=mock_response)
257257

258258
response = await extend.transactions.get_transactions()
259-
assert len(response["transactions"]) == 2
259+
assert len(response["report"]["transactions"]) == 2
260260

261261

262262
# Additional recurrence validation tests

tests/test_integration.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ async def test_list_transactions(self, extend):
184184

185185
# Verify response structure
186186
assert isinstance(response, dict), "Response should be a dictionary"
187-
assert "transactions" in response, "Response should contain 'transactions' key"
188-
assert isinstance(response["transactions"], list), "Transactions should be a list"
187+
assert "transactions" in response["report"], "Response should contain 'report' key"
188+
assert isinstance(response["report"]["transactions"], list), "Transactions should be a list"
189189

190190
# If there are transactions, verify their structure
191-
if response["transactions"]:
192-
transaction = response["transactions"][0]
191+
if response["report"] and response["report"]['transactions']:
192+
transactions = response["report"]['transactions']
193+
transaction = transactions[0]
193194
required_fields = ["id", "status", "virtualCardId", "merchantName", "type", "authBillingAmountCents"]
194195
for field in required_fields:
195196
assert field in transaction, f"Transaction should contain '{field}' field"
@@ -216,10 +217,11 @@ async def test_list_transactions_with_sorting(self, extend):
216217

217218
# Verify response contains transactions and basic structure
218219
assert isinstance(response, dict), f"Response for sort {sort_field} should be a dictionary"
219-
assert "transactions" in response, f"Response for sort {sort_field} should contain 'transactions' key"
220+
assert "report" in response, f"Response for sort {sort_field} should contain 'report' key"
221+
assert "transactions" in response["report"], f"Report should contain 'transactions' key"
220222

221223
# If we have enough data, test opposite sort direction for comparison
222-
if len(response["transactions"]) > 1:
224+
if len(response["report"]["transactions"]) > 1:
223225
# Determine the field name and opposite sort field
224226
is_desc = sort_field.startswith("-")
225227
field_name = sort_field[1:] if is_desc else sort_field
@@ -232,8 +234,8 @@ async def test_list_transactions_with_sorting(self, extend):
232234
)
233235

234236
# Get IDs in both sort orders for comparison
235-
sorted_ids = [tx["id"] for tx in response["transactions"]]
236-
opposite_sorted_ids = [tx["id"] for tx in opposite_response["transactions"]]
237+
sorted_ids = [tx["id"] for tx in response["report"]["transactions"]]
238+
opposite_sorted_ids = [tx["id"] for tx in opposite_response["report"]["transactions"]]
237239

238240
# If we have the same set of transactions in both responses,
239241
# verify that different sort directions produce different orders
@@ -469,8 +471,9 @@ async def test_create_receipt_attachment(self, extend):
469471

470472
# Retrieve a valid transaction id from existing transactions
471473
transactions_response = await extend.transactions.get_transactions(page=0, per_page=1)
472-
assert transactions_response.get("transactions"), "No transactions available for testing receipt attachment"
473-
transaction_id = transactions_response["transactions"][0]["id"]
474+
assert transactions_response["report"][
475+
"transactions"], "No transactions available for testing receipt attachment"
476+
transaction_id = transactions_response["report"]["transactions"][0]["id"]
474477

475478
# Call the receipt attachment upload method
476479
response = await extend.receipt_attachments.create_receipt_attachment(

0 commit comments

Comments
 (0)