Adyen Python API Library
The Adyen Python API Library provides a comprehensive client for integrating with Adyen's various APIs, including Checkout, Management, Recurring, and more. It is currently at version 15.0.1 and receives frequent updates, often with minor or patch releases, and occasional major versions that align with Adyen's OpenAPI specification updates.
Warnings
- breaking Version 15.0.0 raised the minimum Python requirement to 3.8. Support for Python 2.7 and 3.6 has been dropped. Integrations on older Python versions must upgrade before migrating to this release.
- breaking In version 15.0.0, the base URL for the Recurring API changed from `pal-{env}.adyen.com/pal/servlet/Recurring/v68` to `paltokenization-{env}.adyen.com/paltokenization/servlet/Recurring/v68`. Any hard-coded environment-specific URL overrides for `RecurringApi` must be updated.
- breaking Version 14.0.0 introduced a significant refactoring of the service layer and corrected auto-generated method signatures. This may require adjustments to how API methods are called, particularly if relying on specific method names or structures from prior versions.
- deprecated As of v13.5.0, `AdyenBalanceControlApi`, `AdyenRecurringApi` (prefer `Checkout API recurring endpoints`), and the POS Terminal Management API (prefer `Management API`) methods have been deprecated.
- deprecated In version 13.3.0, methods within the `Terminal` service, such as `assign_terminals`, `find_terminal`, `get_stores_under_account`, `get_terminal_details`, and `get_terminals_under_account`, were deprecated.
- gotcha Incorrect API key, environment (`test` vs `live`), or live endpoint prefix (`ADYEN_LIVE_ENDPOINT_PREFIX`) are common causes of authentication or routing errors. For live environments, ensure the correct unique prefix is included in the endpoint configuration.
Install
-
pip install Adyen
Imports
- Adyen
import Adyen
- AdyenClient
from Adyen import AdyenClient
Quickstart
import Adyen
import os
# Set your API Key and Merchant Account from environment variables
ADYEN_API_KEY = os.environ.get('ADYEN_API_KEY', 'YOUR_ADYEN_API_KEY')
ADYEN_MERCHANT_ACCOUNT = os.environ.get('ADYEN_MERCHANT_ACCOUNT', 'YOUR_MERCHANT_ACCOUNT')
# Initialize Adyen client
adyen = Adyen.Adyen()
adyen.client.xapikey = ADYEN_API_KEY
adyen.client.platform = 'test' # Use 'live' for production
try:
# Example: Make a test payment request
request = {
"merchantAccount": ADYEN_MERCHANT_ACCOUNT,
"amount": {"currency": "EUR", "value": 1000}, # Value in minor units (e.g., 10 EUR)
"reference": "my-test-payment-ref-123",
"paymentMethod": {"type": "scheme", "number": "4921960000000000", "expiryMonth": "12", "expiryYear": "2030", "cvc": "123"}
}
print("Initiating payment request...")
response = adyen.checkout.payments_api.payments(request)
print("Payment response:", response)
if response.status_code == 200 and response.message.get('resultCode') == 'Authorised':
print("Payment successful!")
else:
print("Payment failed or pending.")
print(f"Result Code: {response.message.get('resultCode')}, Refusal Reason: {response.message.get('refusalReason')}")
except Adyen.exceptions.AdyenError as e:
print(f"Adyen API Error: {e.debug()}")
except Exception as e:
print(f"An unexpected error occurred: {e}")