Increment value in database from backend workflow

So my user has a credits property that is a number. The user can buy extra credits.

Using the Stripe API I fetch the price_id from the product purchased and also the client reference id which maps to the user’s unique ID.

I have another table to map the price_id to the amount of credits. These credits I want to add to the credits the user already has in my backend workflow.

However, currently it does not add the credits, but replaces it. E.g. customer has 2 credits and buys 10. He then has 10 credits instead of 12.

So all my connections really work, the only thing that doesn’t work is to increment the value in the database.

Screenshot 2023-01-27 124032

1 Like

How are you doing these searches?

image

Did you already checked your server log to see what is happening?

Both of those searches appear identical to me.
Thing to change:

credits:

Here are the logs for when I had 10 credits and bought 100 additional credits. In the end I had 100, instead of 110.
Screenshot 2023-01-27 181721

Updated my code to use “This user” instead of doing the same search twice, but have the exact same problem.

I’ve actually found a workaround to still get my desired functionality. I record each time a user spends a credit and I have a table containing all the purchases and their credits linked to a user. So now to get the amount of credits a user has. I add all off the credits of a user’s purchases and subtract the amount of credits spend. It’s a ridiculous way of working, so if anyone knows a better way, please le met know.