-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
Feature summary
No response
Problem statement
The _determine_api_url method in Adyen/client.py is fragile and difficult to maintain. It relies on string manipulation and hardcoded values to determine the correct API endpoint URL. This makes it prone to errors and difficult to extend.
Problem:
- The current implementation uses a series of
if/elifstatements withinchecks on the endpoint string. This is not robust and can break if endpoint names change. - It has special logic for "pal-" and "checkout-" prefixes, including hardcoded URLs.
Proposed solution
The logic for determining the correct endpoint URL should be more robust and centralized. Here are two potential approaches:
- Service-level mapping: The service calling the client should be responsible for providing the correct and complete URL. The
_determine_api_urlmethod would then become a simple pass-through or perform minimal validation. - Method-name-based mapping: Instead of relying on URL substrings, the client could use the service and method names to look up the correct endpoint from a structured configuration or map. This would decouple the logic from the specific URL structure.
Alternatives considered
Another alternative is to rely on the "servers" field of OpenAPI specs, but currently those don't contain mappings for all environments
Additional context
Acceptance Criteria:
- Remove the string-based checks in
_determine_api_url. - Implement a more robust mechanism for URL determination.
- Ensure all existing API calls continue to work correctly.
- The new implementation should be easier to read, maintain, and extend for future services.