N
N
nioterzor2018-07-24 10:13:29
Stripes
nioterzor, 2018-07-24 10:13:29

Correct error handling in financial transactions?

Scenario.
1. The user enters card details into the Stripe form on the website.
2. The backend "billits" it and enters data into the database that the payment has passed.
Pseudocode

$result = Stripe::charge($customerId, $amount);
if ($result->paid) {
    Billing::create($customerId, $amount);
}

Error options.
1. charge occurred, but the network connection was interrupted during the delivery process, and we did not receive information about it
2. charge occurred, we received information, but at that moment the base decided to fall / the power went out / the UPS battery ran out
In both cases, the user has money no longer, and we have no information about it either.
Solution: a script that once every N minutes receives a list of the last successful transactions from Stripe and compares them with those that we don't have yet.
Am I trying to reinvent the wheel? Is there a best practice for such cases? This is not only about Stripe, but about any payment system where information about the fact of payment is delivered once and synchronously, and not in the form of callbacks, which are usually tried to be delivered several times.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Doc44, 2018-07-24
@Doc44

Provided:
https://stripe.com/docs/webhooks

D
Dmitry, 2018-07-24
@dmtrrr

Solution: a script that once every N minutes receives a list of the last successful transactions from Stripe and compares them with those that we do not have yet.

Normal option.

B
boss_lexa, 2018-07-24
@boss_lexa

for each new transaction, set a timeout for waiting for payment, for example, 20 minutes,
and then every N minutes send a request to the payment server about the status of transactions that have not yet expired

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question