Ruby on Rails Background Jobs with Sidekiq: making PaymentsServiceWrapper idempotent (p34)

I’ve looked at PaymentsServiceWrapper and can’t see support for an idempotency key nor a third party API call to see if the charge_id has already been used. So how do you make it idempotent?

The fake payments service doesn’t support either of those. I added idempotency to the fulfillment service and ability to check past action to the email service to demonstrate, but didn’t do that for the payments one.

If you wanted to try to do that, the code for the server is available and you could replicate what email or fulfillment are doing for payments.

For a real world example, Stripe’s API supports both.

If you had a real world third party where you could not do either of these, you are in for a bad time, but the book recommends you not retry those jobs because you will have to check to see what happened when there is a failure.