-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add idempotency support #639
Add idempotency support #639
Conversation
Thanks Sander! I like the implementation, however we do not currently want to offer idempotency out-of-the-box. It's a feature that should remain optional for now for two reasons. Firstly, it's a beta feature that we have yet to test at full scale (and adding library support is a critical part of even being able to test it at scale). Secondly, the feature will change the behavior of the API for the user in subtle ways. This may not be what the user expects. As such, I suggest we launch it as optional first, and then review after a while. |
Hi @mollierobbert , Thanks for the ❤️ . This is exactly why it was prepared for a separate |
Hi @sandervanhooft, We've implemented this same functionality in the Node.js client, and had a question. In this PR, idempotency keys are added to |
Hi @Pimm ! Good question. As far as I know all PATCH endpoints are idempotent, but best to double check with @mollierobbert . What do you think Robbert? |
I silently launched the documentation with a 'beta' flag, since the closed beta was a bit hard to test without coverage by the PHP/Node/etc. packages anyway. https://docs.mollie.com/overview/api-idempotency As stated in the docs, we will ignore keys for
Hope this helps! One more thing Sander — in Pimm's package we now decided to allow configuring a key per request. Do you think we can do something similar for PHP? It makes a bit more sense to me than configuring it on client-level, since each request should have its own key. (Perhaps I'm misinterpreting the interface though — correct me if I'm wrong.) |
This is getting a little off-topic, as it concerns not just the PHP client.
In the Node.js client, we're adding idempotency keys to Deleting an existing customer causes Mollie core to respond 204; deleting an already deleted customer causes it to respond 410. Consequently, if a client (PHP, Node.js, or otherwise) re-attempts a deletion, it may receive the 410 on the second attempt and report that, which is not ideal. With the idempotency key, Mollie core could replay the initial 204, causing that to be reported instead. In other words: Do you have any thoughts on this @mollierobbert? |
Agreeing with @Pimm here on the DELETE idempotency keys. |
It's already here! mollie-api-php/src/MollieApiClient.php Lines 506 to 519 in 195391d
|
I reasoned that since I don't have a strong preference to include or exclude it though. But, I'm a bit hesitant to further increase scope for now, since we're not entirely sure how big of a storage footprint the |
For clarity:
|
Fair enough! We just added support to |
This PR adds idempotency support to the MollieApiClient.
Using a (Default)IdempotencyKeyGenerator, an idempotency key is automatically added to the request headers on each mutating action (POST, PATCH, DELETE).
On retries, the same key is reused.
New methods:
$mollieApiClient->setIdempotencyKey(string $key): MollieApiClient
$mollieApiClient->getIdempotencyKey(): string
$mollieApiClient->resetIdempotencyKey(): MollieApiClient
$mollieApiClient->setIdempotencyKeyGenerator(IdempotencyKeyGeneratorContract $generator): MollieApiClient
$mollieApiClient->clearIdempotencyKeyGenerator(IdempotencyKeyGeneratorContract $generator): MollieApiClient
Note that it's now possible to inject the
IdempotencyKeyGenerator
when instantiating theMollieApiClient
.