What do you consider as e-wallet because PayPal itself is an e-wallet?
How does e-wallet works?
Hello,
I am having a bit of confusion regarding how does money coming from PayPal or credit card be converted to an e-wallet balance and use that balance as payment to the merchant?
Say, I cash in $100 to my e-wallet account using PayPal. That transaction should be saved on my database, right? Then, I'll update the user's e-wallet balance to $100. Now, I'm going to purchase an item from a merchant using my e-wallet balance, how then can the e-wallet balance be validated and transferred to the merchant as money?
I am maybe missing a step here, could you please help me clarify this flow?
Thank you!
@helloejsulit I don’t really understand your question. Are you building an “e-wallet” or are you just wanting to know how PayPal works?
Either way, a wallet is just a ledger. Same as any bank account. A user has an account, and they can they make debits and credits to that account. All transactions are recorded on a separate line. If a user adds funds to an e-wallet, that’s recorded as a credit on the account. If a user uses their e-wallet balance to pay for something, then that’s recorded as a debit. You can then calculate a user’s balance by summing the transaction amounts (all credits minus all debits):
$userBalance = Transaction::where('user_id', '=', $user->getKey())->sum('amount');
You may then be thinking, “But won’t this be heavy on the database?” and the answer is, well, it depends on the number of users you have and transactions you’re handling. Databases are pretty good at handling large amounts of data (so long as you have efficient indexes), but at PayPal scale they’ll probably be using some form of event sourcing architecture where they’ll create snapshots, and then calculate balances from a specific point in time instead of summing transactions all the way back to 1998 or whenever it was PayPal was established.
Please or to participate in this conversation.