diff --git a/test/CheckoutTest.py b/test/CheckoutTest.py index a781aa6c..2c387d2b 100644 --- a/test/CheckoutTest.py +++ b/test/CheckoutTest.py @@ -19,6 +19,21 @@ class TestCheckout(unittest.TestCase): baseUrl = adyen.checkout.payments_api.baseUrl lib_version = settings.LIB_VERSION + def test_checkout_api_version(self): + checkout_apis = ( + self.adyen.checkout.donations_api, + self.adyen.checkout.modifications_api, + self.adyen.checkout.orders_api, + self.adyen.checkout.payment_links_api, + self.adyen.checkout.payments_api, + self.adyen.checkout.recurring_api, + self.adyen.checkout.utility_api, + ) + + for checkout_api in checkout_apis: + with self.subTest(api=checkout_api.__class__.__name__): + self.assertEqual("https://checkout-test.adyen.com/v72", checkout_api.baseUrl) + def test_payment_methods_success_mocked(self): request = {"merchantAccount": "YourMerchantAccount"} self.adyen.client = self.test.create_client_from_file( @@ -438,6 +453,25 @@ def test_sessions_error(self): self.assertEqual("130", result.message["errorCode"]) self.assertEqual("validation", result.message["errorType"]) + def test_update_session(self): + request = {"amount": {"currency": "EUR", "value": 1000}} + session_id = "YOUR_SESSION_ID" + self.adyen.client = self.test.create_client_from_file(200, request) + + self.adyen.checkout.payments_api.update_session(request, session_id) + + self.adyen.client.http_client.request.assert_called_once_with( + "PATCH", + f"{self.baseUrl}/sessions/{session_id}", + headers={ + "adyen-library-name": "adyen-python-api-library", + "adyen-library-version": settings.LIB_VERSION, + "User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION, + }, + json=request, + xapikey="YourXapikey", + ) + def test_payment_link(self): request = { "reference": "YOUR_ORDER_NUMBER", diff --git a/test/TransfersTest.py b/test/TransfersTest.py index 28cd1c30..1dc26a2a 100644 --- a/test/TransfersTest.py +++ b/test/TransfersTest.py @@ -103,3 +103,62 @@ def test_get_transaction(self): json=None, xapikey="YourXapikey", ) + + def test_initiate_cashout(self): + request = { + "instructingBalanceAccountId": "BA00000000000000000000001", + "amount": {"currency": "EUR", "value": 50000}, + "counterparty": {"transferInstrumentId": "SE00000000000000000000001"}, + "description": "Cashout to bank account", + "referenceForBeneficiary": "CASHOUT-REF-001", + "fee": {"amount": {"currency": "EUR", "value": 500}}, + } + self.adyen.client = self.test.create_client_from_file( + 200, request, "test/mocks/transfers/initiate-cashout.json" + ) + result = self.adyen.transfers.cash_out_api.initiate_cashout(request) + self.assertIsNotNone(result) + self.assertEqual("CO00000000000000000000001", result.message["id"]) + self.assertEqual(50000, result.message["amount"]["value"]) + self.assertEqual( + ["cashoutRepayment", "cashoutFee"], + [transfer["type"] for transfer in result.message["transfers"]], + ) + + self.adyen.client.http_client.request.assert_called_once_with( + "POST", + f"{self.transfers_url}/cashouts", + headers={ + "adyen-library-name": "adyen-python-api-library", + "adyen-library-version": settings.LIB_VERSION, + "User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION, + }, + json=request, + xapikey="YourXapikey", + ) + + def test_initiate_cashout_idempotency_key(self): + request = { + "instructingBalanceAccountId": "BA00000000000000000000001", + "amount": {"currency": "EUR", "value": 50000}, + "counterparty": {"transferInstrumentId": "SE00000000000000000000001"}, + } + self.adyen.client = self.test.create_client_from_file( + 200, request, "test/mocks/transfers/initiate-cashout.json" + ) + self.adyen.transfers.cash_out_api.initiate_cashout( + request, idempotency_key="test-idempotency-key-001" + ) + + self.adyen.client.http_client.request.assert_called_once_with( + "POST", + f"{self.transfers_url}/cashouts", + headers={ + "adyen-library-name": "adyen-python-api-library", + "adyen-library-version": settings.LIB_VERSION, + "User-Agent": "adyen-python-api-library/" + settings.LIB_VERSION, + "Idempotency-Key": "test-idempotency-key-001", + }, + json=request, + xapikey="YourXapikey", + ) diff --git a/test/mocks/transfers/initiate-cashout.json b/test/mocks/transfers/initiate-cashout.json new file mode 100644 index 00000000..6345d895 --- /dev/null +++ b/test/mocks/transfers/initiate-cashout.json @@ -0,0 +1,37 @@ +{ + "id": "CO00000000000000000000001", + "instructingBalanceAccountId": "BA00000000000000000000001", + "amount": { + "currency": "EUR", + "value": 50000 + }, + "counterparty": { + "transferInstrumentId": "SE00000000000000000000001" + }, + "description": "Cashout to bank account", + "referenceForBeneficiary": "CASHOUT-REF-001", + "fee": { + "amount": { + "currency": "EUR", + "value": 500 + } + }, + "transfers": [ + { + "id": "400F6060JMB1I0AB", + "type": "cashoutRepayment", + "amount": { + "currency": "EUR", + "value": 50500 + } + }, + { + "id": "400F6060JMB1I0AA", + "type": "cashoutFee", + "amount": { + "currency": "EUR", + "value": 500 + } + } + ] +}