I am working with REST API and have the following scenario for processing request to make a payment:
- A client sends the request (payment information) to my own API.
- My API calls third-party REST API, passes it payment information, and receives a payment ID from it. If third-party API call fails for any reason, the error is returned to the client immediately.
- My API stores the resulting payment ID from step 2 and some extra info to its own database.
I want the data to be consistent between third-party API and my own database. However, if for some reason the database is not accessible on step 3, I will end up with inconsistent data — the payment will exist in third-party API, but not in my own API's database.
What's the best way of handling this consistency issue?