Skip to content

Commit 7cd4d29

Browse files
authored
Merge pull request #383 from galesky-a/fix-readme-clients
FIX: explicitly callout how to initialize individual api clients
2 parents f702eae + ac7a755 commit 7cd4d29

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

README.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,28 @@ pip install Adyen
5454
~~~~
5555

5656
## Using the library
57-
58-
### General use with API key
59-
60-
~~~~ python
61-
import Adyen
62-
63-
adyen = Adyen.Adyen()
64-
65-
adyen.payment.client.xapikey = "YourXapikey"
66-
adyen.payment.client.hmac = "YourHMACkey"
67-
adyen.payment.client.platform = "test" # Environment to use the library in.
68-
~~~~
69-
70-
### Consuming Services
7157

7258
Every API the library supports is represented by a service object. The name of the service matching the corresponding API is listed in the [Integrations](#supported-api-versions) section of this document.
7359

60+
This library offers two ways to initialize and use the Adyen API services.
61+
7462
#### Using all services
7563

64+
For simple scripts or applications that only use a single set of API credentials, you can use the main `Adyen` object. This creates a convenient "facade" that loads and provides easy access to all available APIs. Keep in mind that different API keys will have different scopes so you may still need need more than one instance.
65+
7666
~~~~python
7767
import Adyen
7868

69+
# Create the all-in-one client
7970
adyen = Adyen.Adyen()
80-
adyen.payment.client.xapikey = "YourXapikey"
81-
adyen.payment.client.platform = "test" # change to live for production
71+
72+
# Configure the client
73+
adyen.client.xapikey = "YourXapikey"
74+
adyen.client.platform = "test" # change to "live" for production
75+
76+
# Prepare the request
8277
request = {
78+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
8379
"amount": {
8480
"currency": "USD",
8581
"value": 1000 # value in minor units
@@ -92,38 +88,42 @@ request = {
9288
"encryptedExpiryYear": "test_2030",
9389
"encryptedSecurityCode": "test_737"
9490
},
95-
"shopperReference": "YOUR_UNIQUE_SHOPPER_ID_IOfW3k9G2PvXFu2j",
96-
"returnUrl": "https://your-company.com/...",
97-
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
91+
"returnUrl": "https://your-company.com/..."
9892
}
93+
94+
# Make the API call through the long-form path
9995
result = adyen.checkout.payments_api.payments(request)
10096
~~~~
10197

102-
#### Using one of the services
98+
#### Using Individual Service Clients
99+
100+
For some web applications (e.g., using Flask or Django), multi-threaded environments, or any use case where you might need to manage multiple API credentials (for different merchant accounts, ECOM vs. POS, etc.), it is recommended to instantiate API clients directly.
103101

104102
~~~~python
105-
from Adyen import checkout
103+
# Import the core client and the service-level API class
104+
from Adyen.client import AdyenClient
105+
from Adyen.services import AdyenCheckoutApi
106+
107+
# Create and configure the core AdyenClient
108+
adyen_client = AdyenClient()
109+
adyen_client.xapikey = "YourXapikey"
110+
adyen_client.platform = "test"
111+
112+
# Instantiate the AdyenCheckoutApi service
113+
checkout_service = AdyenCheckoutApi(client=adyen_client)
114+
115+
# Make API calls using the sub-clients within the service
116+
request = {"merchantAccount": "YOUR_MERCHANT_ACCOUNT", ...}
117+
payment_result = checkout_service.payments_api.payments(request)
118+
order_result = checkout_service.orders_api.orders(request)
119+
~~~~
106120

107-
checkout.client.xapikey = "YourXapikey"
108-
checkout.client.platform = "test" # change to live for production
109-
request = {
110-
"amount": {
111-
"currency": "USD",
112-
"value": 1000 # value in minor units
113-
},
114-
"reference": "Your order number",
115-
"paymentMethod": {
116-
"type": "visa",
117-
"encryptedCardNumber": "test_4111111111111111",
118-
"encryptedExpiryMonth": "test_03",
119-
"encryptedExpiryYear": "test_2030",
120-
"encryptedSecurityCode": "test_737"
121-
},
122-
"shopperReference": "YOUR_UNIQUE_SHOPPER_ID_IOfW3k9G2PvXFu2j",
123-
"returnUrl": "https://your-company.com/...",
124-
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
125-
}
126-
result = checkout.payments_api.payments(request)
121+
Similarly you can instantiate a separate client for services that required different API keys
122+
123+
~~~~python
124+
adyen_lem_client = AdyenClient()
125+
adyen_lem_client.xapikey = "YourLEMXapikey"
126+
adyen_lem_client.platform = "test"
127127
~~~~
128128

129129
#### Force HTTP library

0 commit comments

Comments
 (0)