Processing successful payment processing but database update failed

I am trying to implement a strip checking process in one of my express.js routes. For this I have:

  • Official Node.js Stripe Module
  • Official Strip Client Side Module
  • Json logger I use things like javascript errors, incoming requests and responses from external services like stripe, mongodb, etc. to log.
  • Order model defined using mongoose - ODM MongoDB

My steps are as follows:

Customer:

  • Send order details that include a bandwidth token

Server:

  • Create an unpaid order and save it in the database ( order.status is created )
  • Use a stripe client to pay for a user's credit / debit card.
  • The update order and storage in the database ( order.status is accepted or failed depending on the response from Stripe)

Question If the payment was successful after step 2, but there is an error updating the order in step 3 (due to a database server error, disconnection, or the like), what are some suitable ways to fix this error and potentially recover from it?

+8
source share
1 answer

With payment systems, you always need a consolidation process (hourly, daily, monthly) based on sound accounting principles that will check the consistency of each cash flow.

In your case, I suggest that each external asynchronous call record the parameters sent and the response received. If you do not have an answer for a certain time, you know that something went wrong in the external system (Stripe, in your case) or on the way back from the external system (you mention a database failure on your side)

Basically, for every asynchronous "transaction" you create, you know when you start it, and you need to decide a reasonable amount of time before it ends. Thus, the database has the expected_END_ts.

If you did not receive a response after expect_end_ts, you know that something is wrong. You can then request the status of Stripe or another PSP. We hope that the API will give you a reasonable answer about whether the payment passed or not.

Also note that you must add a step between 1. and 2: re-read the database. You want to make sure that every payment request that you make is really in the database, saved just like you are going to send it.

+4
source

Source: https://habr.com/ru/post/974103/


All Articles