Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
174 stars 69 forks source link

Use idempotency key to prevent duplicate requests #3352

Open chickenn00dle opened 2 years ago

chickenn00dle commented 2 years ago

Description

In https://github.com/Automattic/woocommerce-payments/pull/3303, we added the Idempotency-Key header to all post requests and added these to request logs.

This is useful for debugging, but it would be nice to also utilize these keys to prevent duplicate requests.

Acceptance criteria

Testing instructions

  1. Once https://github.com/Automattic/woocommerce-payments/pull/3303 is merged, initialize a POST request by doing something like purchasing a product with WCPay.
  2. View the logs for this request and find the Idempotency-Key header

Right now a new key is generated for each request, making this only useful for debugging.

Related to https://github.com/Automattic/woocommerce-payments/issues/530

dechov commented 2 years ago

FYI we had dealt with some duplicate onboarding requests with a bespoke solution in https://github.com/Automattic/woocommerce-payments/pull/2867 – in the event the solution here makes that one redundant, it can be removed.

Also FYI in case it makes a difference, @ricardo and I found out that if the original request is still in progress, subsequent requests with the same key will fail (not wait to return the same response).

RadoslavGeorgiev commented 2 years ago

https://github.com/Automattic/woocommerce-payments/issues/3998 is likely a duplicate of this issue.

zmaglica commented 1 year ago

@diegocurbelo Moving this issue from the Engineering review queue to the Other teams queue since you added it to the Fractal team backlog.