After a recent PR, the refund handler started behaving inconsistently when the same request is retried. A review of the code and the API contract is needed to find defects in the implementation.
POST /refunds accepts JSON of the form {"payment_id":"p-1","amount":120}.Idempotency-Key header with a non-empty value.201 Created and JSON with the fields refund_id, payment_id, amount.Idempotency-Key and the same request body, the handler must:
Idempotency-Key but a different request body, the handler must return 409 Conflict.400 Bad Request.go test ./...
Pay attention to changes in the Idempotency-Key logic and persistence of the processing result.
For manual verification, the following scenarios are useful:
Idempotency-Key but different amount values;1.24Store must be safe for concurrent calls from multiple net/http goroutinesgo test ./...Use line comments to explain the problem, its impact, the fix and how to test it.