I have an app + website that uses an API where you can purchase goods for virtual currency.
When you've bought an item you can do a refund and get your money back.
Below is some pseudo code to explain.
api/order/refund/{orderid}
if(order.status == accepted)
{
order.status = refunded;
user.AddMoney(order.Amount);
dbcontext.saveChanges();
}
the problem is, if the API gets called like api/order/refund/21 multiple times quite fast, it will run before saveChanges(); is successful and will AddMoney(); to the user more than once for the same order.
Does anybody know a solution for this?
Thanks