Nowadays in digital life, Virtual wallets are very important for everyone
You all might know about Paytm, PhonePe, AmazonPay and might have an account on their respective applications. Today I will share with you an easy method through which you can create a virtual wallet in Laravel Framework.
What is Virtual Wallet ?
The basic idea is really simple - a virtual wallet just serves as a place to hold some of your money online. You can pay from that wallet directly or you can redeem/ transfer money from the wallet to your bank account. You might have seen that most online shopping applications have wallet integration in website and they will provide cashback on your purchase. ecommerce wallet is another good example in which user gets cashback as on purchase of goods from website which and this feature adds value addition to website functionality. This idea of virtual wallet created a change in online shopping methodology and there are multiple benefits to both consumer and provider. As mentioned in title, I will share code with you to create e-wallet in Laravel Framework which is one of the top notch framework in recent times and used all over the world in complex applications. Laravel development employs a fast approach for developing high-quality web applications with modular programming and stress-free coding. Well, let’s now go to the technical part to integrate the wallet in Laravel Application .
Create new Laravel Project
composer create-project --prefer-dist laravel/laravel virtual-wallet
Execute above command with help of command line tool and new project will be created named “virtual-wallet”
Setup DB Connection in .env file
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=databasename DB_USERNAME=databaseuser DB_PASSWORD=databasepassword
Generate Laravel Authentication
php artisan make:auth
This command will install a layout view, registration and login views as well as routes for authentication process
Run Database Migration
Php artisan migrate
This command will generate users and other tables in your database. You can change migrations if you need to change the database schema. For more information on migrations you can go to Laravel official Documentation.
Now I will suggest one package and provide you it’s integration details with Laravel, with which you can easily manage Virtual Wallet. The supported laravel versions for this wallet are 5.5 and above.
Install bavex/laravel-wallet Package
composer req bavix/laravel-wallet
Publish the migrations of the package with below command
php artisan vendor:publish --tag=laravel-wallet-migrations
Publish the config file with help of below command
php artisan vendor:publish --tag=laravel-wallet-config
Add Interface to User Model
use Bavix\Wallet\Traits\HasWallet; use Bavix\Wallet\Interfaces\Wallet; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements Wallet{ use HasWallet; }
As you can check the above code, User Model now implements the Wallet interface of Package and uses Has Wallet trait.
Now I will guide you with Checking your Virtual Wallet Balance & how to deposit, withdraw and transfer money from the Wallet
$user = User::first(); // This will fetch one User $user->deposit(10); // This will deposit Rs.10 in User’s Wallet $user->deposit(10, [‘payable for’=>’Shoes Order’]) // This will deposit Rs.10 in User’s Wallet with json stored in meta field in transaction table. This will help you to store any extra information related to deposit. $user->deposit(10,0) // This will deposit Rs.10 in User’s Wallet in Unconfirmed stage. This money will not be considered in the User's Wallet balance until confirmed. $user->withdraw(10); // This will withdraw Rs.10 from User’s Wallet. $user->balance; // This will check user balance and return the confirmed balance amount $user->wallet->refreshBalance(); // This command is used for refreshing user account balance. In case you have updated amount in database directly, than to display that change in main balance you need to refresh balance once Sometimes you need to create an credit to account and confirm it later on after some verification. Below code will be useful for the same $transaction = $user->deposit(100, null, false); // not confirm $transaction->confirmed; // bool(false) $user->balance; // int(0) $user->confirm($transaction); // bool(true) $transaction->confirmed; // bool(true)
Other technical points to make a complete eWallet Application
1) As in above example we have bind Laravel wallet package with User model. So each user of App will have wallet feature extended
2) Fetch transactions from table and display in user panel so, customers can have a look at their report. You can provide details with filter such as current week, month or year. In this way you eWallet passbook is ready
3) E-mail user everytime amount is credited in wallet, so that they can be more informed about wallet status
4) Show Wallet balance on home page after user is logged In to the App.
That's it !! You are ready with you eWallet Application.
Conclusion
eWallets are no more a trend; instead, they are need of the hour. However, you need to be sure about the implementation flow and data calculation as financial domain applications needs to be flawless and have interactive user experience. We at Elitech Sytems, an Laravel Development Company have a team of best Laravel Developers with strong knowledge and techie minds for developing e-wallets and other Laravel Mobile and Web applications with quality coding. You can Hire Laravel Developers or Feel Free to contact us for more details
Do you plan to develop a eWallet Application based on Laravel framework or want to start eWallet business ?
Our Laravel development team will be ready to roll out your plan into reality. We develop Laravel web applications with strong database structure . Feel free to bring us your idea and get a free quote
Sahil is a highly skilled and dedicated Salesforce Certified Platform Developer with a passion for creating efficient and innovative solutions within the Salesforce ecosystem. With an insatiable curiosity and a relentless drive for excellence, he has become a go-to expert in developing custom applications and functionalities on the Salesforce platform.
Comments are closed.