From 957dae344516e64f478e09969f61b93b4f85ee86 Mon Sep 17 00:00:00 2001 From: "Dev.Mubarak" Date: Wed, 7 Oct 2026 10:16:54 +0100 Subject: [PATCH] fix(transactions): resolve order URI via connection in create In Transactions.create(), calling Orders.get_resource_uri_from_id(order_id) unbound on the class passed order_id as self, leaving resource_id unfilled and raising TypeError. Resolve the order URI via self.connection.get_resource_uri_from_id with Orders.resource_name, and update the test to assert payload dispatch. Fixes #16 --- actionkit/transactions.py | 4 +++- tests/test_transactions.py | 41 +++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/actionkit/transactions.py b/actionkit/transactions.py index 1d4dc4c..e6f0a19 100644 --- a/actionkit/transactions.py +++ b/actionkit/transactions.py @@ -94,7 +94,9 @@ def create( if not type in TRANSACTION_TYPES: raise ValueError('Transaction type must be one of sale, refund, or credit') - order_uri = order_uri or Orders.get_resource_uri_from_id(order_id) + order_uri = order_uri or self.connection.get_resource_uri_from_id( + order_id, Orders.resource_name + ) payload = dict( account=account, diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 9f40fba..86d1508 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -57,24 +57,29 @@ def test_create_rejects_invalid_type(transactions): ) -def test_create_with_order_id_is_broken(transactions): - """ - Pins a real bug, does not fix it: Transactions.create (transactions.py:97) - calls `Orders.get_resource_uri_from_id(order_id)` UNBOUND on the Orders - class rather than on an instance. HttpMethods.get_resource_uri_from_id is - `def get_resource_uri_from_id(self, resource_id)`, so this call binds - order_id to `self` and leaves the real `resource_id` parameter unfilled. - Transactions.create(order_id=...) (without order_uri) currently always - raises TypeError, never reaching the network. Contrast with the correct - `self.get_resource_uri_from_id(resource_id)` pattern in orders.py:23. - """ - with pytest.raises(TypeError): - transactions.create( - account="WM-Card", - amount=Decimal("5.00"), - currency="EUR", - order_id="123", - ) +@responses.activate +def test_create_with_order_id_sends_expected_payload(transactions): + responses.add( + responses.POST, + rest("transaction"), + status=201, + headers={"Location": rest("transaction/1/")}, + ) + result = transactions.create( + account="WM-Card", + amount=Decimal("5.00"), + currency="EUR", + order_id="123", + ) + assert result == rest("transaction/1/") + body = json_module.loads(responses.calls[0].request.body) + assert body == { + "account": "WM-Card", + "amount": "5.00", + "currency": "EUR", + "type": "sale", + "order": "/rest/v1/order/123/", + } # --- reverse() ---------------------------------------------------------