So, I have a most basic handy crafted eCommerce application which was running smooth times ago. And now I would like to implement an eWallet feature for the site. As we are mostly saw it before, for example the billing in Digital Ocean: you deposit some funds as credit, and use it to create Droplets. So, the eWallet is what it has been named, it is an wallet which can provide features like these:
- User can deposit funds into their own account
- User can make purchases using the wallet balance
- User can withdraw their funds
- User can view all transaction history in their account
- ...etc
However, there is not much information about development of this feature, and I was also unable to find any normalized business model (or maybe I was just not googled enough?). So I think i will have to implemented it by myself. And while googling for the development process I see a lot of people are also want to create this feature so I think I should create a discussion here, and we can together build the feature. So may we begin?
Model
I am consider between 2 options to provision the model. First is group all the deposit, withdraw... in to the Transaction, and secondly is separate them into some Model itself.
OPTION 1:
-
Wallet model:
- user_id: foreign key to the users
- balance: holding information of current wallet balance
-
Transaction model:
- wallet_id: foreign key to the wallet
- amount: the value of funds
- type: array('deposit', 'withdrawal'...)
OPTION 2:
-
Wallet model:
- user_id: foreign key to the users
- balance: holding information of current wallet balance
-
Deposit model:
- wallet_id: foreign key to the wallet
- amount: the value of funds
-
Withdrawal model:
- wallet_id: foreign key to the wallet
- amount: the value of funds
Okay, it what i am thinking right now, and let me explain about the balance. I will have a balance field which holding information of current wallet balance which I can calculate it dynamically, on the fly. But imagine if you have about thousands of transactions, and whenever you want to access the balance it will need to calculate again, and again. And it will slow your application down to the hell.
Okay, this is enough for now, I will need your idea and suggestion of which model option should i use before continue.
Thank you for your time!