Each user can buy credits at different prices to get discounts when they buy services.
But when they buy products the price they pay should be the same as the value of the product.
(Eg. The customer buys 10 credits for $1 each. The customer buys 10 credits for 5$ each. In total customer has 20 credits but the value is $60)
So I’ve built a wallet system with the price per credit the number of credits and who bought them.
But my question is, how do I build a workflow that takes money from one of the wallets based on the price per credit and the value of the product, and then that wallet is empty it takes money from the next wallet?
It would be something like:
When buy is clicked: Make changes to the oldest wallet: Credits minus product’s cost. If the wallet is empty search for the next oldest wallet. Until the value of the product has been subtracted from wallets.