Adyen Python API Library

15.0.1 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Adyen client, set your API key and merchant account, and make a simple credit card payment request using the `payments_api` service. Replace placeholder values with your actual Adyen credentials and test card details.

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}")

view raw JSON →