Adyen / Adyen/adyen-python-api-library

[Feature]: Refactor `_determine_api_url` method in `Adyen/client.py`

Open
#395 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

do not stale Feature
Dominant language
Python
Stars
68
Forks
49
Avg merge
2h 3m
Merged PRs (30d)
2

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/elif statements with in checks 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:

  1. Service-level mapping: The service calling the client should be responsible for providing the correct and complete URL. The _determine_api_url method would then become a simple pass-through or perform minimal validation.
  2. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Adyen/client.py by reading _determine_api_url and tracing the existing API calls that depend on it. Compare the proposed service-level and method-name-based approaches before choosing a centralized mapping. Done means string-based checks are removed, URL determination is easier to extend, and all existing API calls continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design, payments
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.