Skip to content

Commit 56078aa

Browse files
Idempotency Key Guide (Update)
1 parent 077f59c commit 56078aa

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

README.md

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ This documentation is for the new Mollie's SDK. You can find more details on how
2727
* [IDE Support](#ide-support)
2828
* [SDK Example Usage](#sdk-example-usage)
2929
* [Authentication](#authentication)
30+
* [Idempotency Key](#idempotency-key)
3031
* [Available Resources and Operations](#available-resources-and-operations)
3132
* [Retries](#retries)
3233
* [Error Handling](#error-handling)
3334
* [Server Selection](#server-selection)
3435
* [Custom HTTP Client](#custom-http-client)
3536
* [Resource Management](#resource-management)
3637
* [Debugging](#debugging)
37-
* [Idempotency Key](#idempotency-key)
3838
* [Development](#development)
3939
* [Maturity](#maturity)
4040
* [Contributions](#contributions)
@@ -201,6 +201,46 @@ with ClientSDK(
201201
```
202202
<!-- End Authentication [security] -->
203203

204+
<!-- Start Idempotency Key -->
205+
## Idempotency Key
206+
207+
This SDK supports the usage of Idempotency Keys. See our [documentation](https://docs.mollie.com/reference/api-idempotency) on how to use it.
208+
209+
```python
210+
import os
211+
from mollie import ClientSDK, Security
212+
213+
client = ClientSDK(
214+
security = Security(
215+
api_key = os.getenv("CLIENT_API_KEY", "test_..."),
216+
)
217+
)
218+
219+
payload = {
220+
"description": "Description",
221+
"amount": {
222+
"currency": "EUR",
223+
"value": "5.00",
224+
},
225+
"redirect_url": "https://example.org/redirect",
226+
}
227+
228+
idempotency_key = "<some-idempotency-key>"
229+
payment1 = client.payments.create(
230+
payment_request=payload,
231+
idempotency_key=idempotency_key
232+
)
233+
234+
payment2 = client.payments.create(
235+
payment_request=payload,
236+
idempotency_key=idempotency_key
237+
)
238+
print(f"Payment created with ID: {payment1.id}")
239+
print(f"Payment created with ID: {payment2.id}")
240+
print("Payments are the same" if payment1.id == payment2.id else "Payments are different")
241+
```
242+
<!-- End Idempotency Key -->
243+
204244
<!-- Start Available Resources and Operations [operations] -->
205245
## Available Resources and Operations
206246

@@ -664,48 +704,6 @@ You can also enable a default debug logger by setting an environment variable `C
664704

665705
<!-- Placeholder for Future Speakeasy SDK Sections -->
666706

667-
## Idempotency Key
668-
669-
You can setup an Idempotency Key.
670-
671-
```
672-
import os
673-
from mollie import ClientSDK, Security
674-
675-
client = ClientSDK(
676-
security = Security(
677-
api_key = os.getenv("MOLLIE_API_KEY", "test_..."),
678-
)
679-
)
680-
681-
payload = {
682-
"description": "Some Description",
683-
"amount": {
684-
"currency": "EUR",
685-
"value": "0.01",
686-
},
687-
"redirect_url": "https://example.org/redirect",
688-
}
689-
690-
idempotency_key = "unique-idempotency-key-12345"
691-
payment1 = client.payments.create(
692-
request_body=payload,
693-
http_headers={
694-
"Idempotency-Key": idempotency_key
695-
}
696-
)
697-
698-
payment2 = client.payments.create(
699-
request_body=payload,
700-
http_headers={
701-
"Idempotency-Key": idempotency_key
702-
}
703-
)
704-
print(f"Payment created with ID: {payment1.id}")
705-
print(f"Payment created with ID: {payment2.id}")
706-
print("Payments are the same" if payment1.id == payment2.id else "Payments are different")
707-
```
708-
709707
# Development
710708

711709
## Maturity

0 commit comments

Comments
 (0)