Laravel Virtual Wallet

Laravel Virtual Wallet stats

Downloads
20
Stars
13
Open Issues
0
Forks
2

View on GitHub →

Laravel Virtual Wallet Package

πŸ’³ Laravel Virtual Wallet Documentation

Laravel Virtual Wallet Logo

A lightweight, plug-and-play Laravel package for managing virtual wallets, supporting multiple wallet types, transaction logs, and seamless integration with any model like User.


πŸš€ Features

πŸ’Ό Multi-Wallet Support β€” Create and manage multiple wallet types per user.
πŸ“œ Transaction Management β€” All wallet operations are recorded for full traceability.
πŸ’³ Payment Processing β€” Seamlessly handle payments between wallets or external systems.
🏦 Deposit Handling β€” Accept and log deposits from users or third-party services.
🌍 Multiple Currency Support β€” Manage wallet balances in different currencies with ease.
πŸ“Ά Wallet Status Tracking β€” Monitor and update wallet statuses like active, frozen, or closed.
πŸ” Secure & Reliable β€” Built using Laravel's Eloquent, enums, morphs & policy-friendly structure.
βš™οΈ Highly Configurable β€” Override models, table names, and more via config.
🧩 Easy Integration β€” Just use a trait on your model and you're ready to go.
πŸ’Έ Balance Management β€” Simple credit, debit, transfer, and balance APIs.


πŸ“¦ Installation

composer require haxneeraj/laravel-virtual-wallet
php artisan vendor:publish --provider="Haxneeraj\LaravelVirtualWallet\LaravelVirtualWalletServiceProvider"
php artisan migrate

πŸ”§ Configuration

After publishing the config file, you can modify config/laravel-virtual-wallet.php to override models, table names, and enums if needed.


πŸ“₯ Setup in Your Model

Add the trait and implement the interface in your User (or any Eloquent model):

use Haxneeraj\LaravelVirtualWallet\Interfaces\WalletInterface;
use Haxneeraj\LaravelVirtualWallet\Traits\HasVirtualWallet;
 
class User extends Authenticatable implements WalletInterface
{
use HasVirtualWallet;
}

πŸ’‘ Usage

Create Wallets

$user->wallets()->create([
'wallet_type' => 'main', // Type of wallet (e.g., 'main', 'bonus', 'savings'). Define these in your WalletType enum.
'currency' => 'usd', // ISO currency code. Ensure 'usd' or your required currencies are defined in your Currency enum.
'balance' => 100, // Initial wallet balance. Usually set to 0 or default starting value.
'currency_type' => 'fiat_currency', // Define whether the currency is fiat, crypto, token, etc. Set values in CurrencyType enum.
'status' => 'active' // Current status of wallet (e.g., 'active', 'frozen', 'closed'). Defined in WalletStatus enum.
]);

Deposit

$paymentData = new PaymentData([
'owner_type' => User::class,
'owner_id' => $this->user->id,
'txid' => 'test-txid',
'amount' => 100,
'description' => 'Test deposit',
'wallet_type' => 'wallet1',
'method' => 'automatic',
'transaction_type' => 'deposit',
'status' => 'approved',
'currency' => 'usd',
'currency_type' => 'fiat_currency'
]);
$user->deposit($paymentData);

Withdraw

$paymentData = new PaymentData([
'owner_type' => User::class,
'owner_id' => $this->user->id,
'txid' => 'test-txid-withdraw1',
'amount' => 50,
'description' => 'Test withdrawal',
'wallet_type' => 'wallet1',
'method' => 'automatic',
'transaction_type' => 'withdraw',
'status' => 'approved',
'currency' => 'usd',
'currency_type' => 'fiat_currency'
]);
$user->pay($paymentData);

Get Balance

$balance = $user->getBalance('main');

Check Balance

$user->hasSufficientBalance(50, 'main');

Available Methods

Wallet Management

Method Parameters Returns Description
wallets() string $walletType = null MorphMany Get all wallets or filter by type
getBalance() string $walletType = null int OR float Get wallet balance
hasBalance() string $walletType = null bool Check if wallet has positive balance
hasSufficientBalance() int OR float $amount, string $walletType = null bool Check if wallet has sufficient balance

Payment Processing

Method Parameters Returns Description
pay() PaymentData $paymentData void Process payment from wallet(s)

Deposit Handling

Method Parameters Returns Description
deposit() PaymentData $paymentData void Deposit funds into wallet

Data Objects

PaymentData

The PaymentData object is used for both payments and deposits. It accepts the following parameters:

  • owner_type: Owner model type
  • owner_id: Owner model ID
  • amount: The amount to process
  • wallet_type: Type of wallet (optional)
  • description: Transaction description
  • status: Transaction status
  • method: Payment method
  • transaction_type: Type of transaction
  • txid: Transaction ID

Exceptions

The package throws the following exceptions:

  • InvalidWalletException: When wallet type is invalid or wallet not found
  • InsufficientBalanceException: When wallet balance is insufficient

βš™οΈ Testing

This package comes with feature and unit tests to ensure everything works smoothly.

πŸƒ Run Tests

composer test

🀝 Contributing

Contributions, issues and feature requests are welcome!

  1. Fork it
  2. Create your feature branch (git checkout -b feature/awesome)
  3. Commit your changes (git commit -am 'Add something awesome')
  4. Push to the branch (git push origin feature/awesome)
  5. Create a new Pull Request

🧠 Author

Neeraj Saini
πŸ“§ hax-neeraj@outlook.com
🌐 https://github.com/haxneeraj/laravel-virtual-wallet


πŸ“„ License

Licensed under the MIT License.

haxneeraj photo

Senior Software Developer | 6+ Years Experience | Building Scalable Web Applications

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Haxneeraj Laravel Virtual Wallet Related Articles

Laravel Virtual Wallet image

Laravel Virtual Wallet

Read article
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell