Manage Virtual Wallets in Laravel with Pay Pocket
Published on by Paul Redmond
The Pay Pocket package for Laravel offers payment capabilities and logging. It does not handle payments from payment platforms, but instead offers the concept of virtual money.
Let's say that you want to allow users to earn virtual money in their wallet, or add a balance to their account after completing a payment via a processor. For example, Fortnite's V-Bucks is an example of exchanging real currency in a virtual wallet that you can spend in the game's store.
You can track wallets via models using the package's ManagesWallet
trait:
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;use HPWebdeveloper\LaravelPayPocket\Traits\ManagesWallet; class User extends Authenticatable implements WalletOperations{ use ManagesWallet;} // Deposit funds into 'wallet_1'$user->deposit('wallet_1', 123.45); // Deposit funds into 'wallet_2'$user->deposit('wallet_2', 67.89); // Pay the value using the combined balance available across all wallets$user->pay(12.34);
This package supports creating and depositing currency into multiple wallets. It also tracks all transactions in and out of a user's wallet via the wallet_logs
database table.
Lastly, you can also get the individual balances of each wallet:
// Balance available in wallet_1$user->getWalletBalanceByType('wallet_1'); // Balance available in wallet_2$user->getWalletBalanceByType('wallet_2');
You can learn more about this package, get full installation instructions, and view the source code on GitHub.