PHP Classes

How to Use a PHP Wallet System to Perform Financial Operations with User Money Using the Package Laravel Virtual Wallet: Manage money amounts stored in a wallet

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-04-24 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
laravel-virtual-wall 1.0.0Custom (specified...7Finances, PHP 7
Description 

Author

This package can manage money amounts stored in a wallet.

It provides classes that associated users with records stored using a Laravel model to wallets, supporting several types of wallets and transaction logs.

Currently, the wallet class can perform several types of financial operations:

- Deposit money amounts

- Withdraw

- Check balance

- Get balance

Picture of Neeraj Saini
  Performance   Level  
Name: Neeraj Saini <contact>
Classes: 3 packages by
Country: India India
Innovation award
Innovation award
Nominee: 2x

Instructions

Please read this documentation with usage instructions to learn [how to use PHP to manage money amounts stored in wallets] using this package.(https://www.phpclasses.org/browse/file/399447.html).

Documentation

<h1 align="center">? Laravel Virtual Wallet Documentation</h1>

<p align="center">

<img src="laravel-virtual-wallet-logo.png" alt="Laravel Virtual Wallet Logo" style="width: 100%; max-width: 800px;" />

</p>

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.


  Files folder image Files (50)  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedatabase (1 directory)
Files folder imageenums (7 files)
Files folder imageresources (1 directory)
Files folder imagesrc (2 files, 5 directories)
Files folder imagetests (1 file, 5 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Image file laravel-virtual-wallet-logo.png Icon Icon image
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (50)  /  config  
File Role Description
  Plain text file laravel-virtual-wallet.php Class Class source

  Files folder image Files (50)  /  database  
File Role Description
Files folder imagemigrations (2 files)

  Files folder image Files (50)  /  database  /  migrations  
File Role Description
  Plain text file 2024_09_06_122835_...nsactions_table.php Class Class source
  Plain text file 2024_09_06_122836_...e_wallets_table.php Class Class source

  Files folder image Files (50)  /  enums  
File Role Description
  Accessible without login Plain text file CurrencyEnum.php Aux. Configuration script
  Accessible without login Plain text file CurrencyTypeEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionMethodEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionStatusEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionTypeEnum.php Aux. Configuration script
  Accessible without login Plain text file WalletStatusEnum.php Aux. Configuration script
  Accessible without login Plain text file WalletTypeEnum.php Aux. Configuration script

  Files folder image Files (50)  /  resources  
File Role Description
Files folder imagelang (1 directory)

  Files folder image Files (50)  /  resources  /  lang  
File Role Description
Files folder imageen (1 file)

  Files folder image Files (50)  /  resources  /  lang  /  en  
File Role Description
  Accessible without login Plain text file message.php Aux. Configuration script

  Files folder image Files (50)  /  src  
File Role Description
Files folder imageDataObjects (1 file)
Files folder imageExceptions (7 files)
Files folder imageInterfaces (1 file)
Files folder imageModels (2 files)
Files folder imageTraits (7 files)
  Accessible without login Plain text file helper.php Example Example script
  Plain text file LaravelVirtualWalletServiceProvider.php Class Class source

  Files folder image Files (50)  /  src  /  DataObjects  
File Role Description
  Plain text file PaymentData.php Class Class source

  Files folder image Files (50)  /  src  /  Exceptions  
File Role Description
  Plain text file InsufficientBalanceException.php Class Class source
  Plain text file InvalidCurrencyException.php Class Class source
  Plain text file InvalidCurrencyTypeException.php Class Class source
  Plain text file InvalidDepositException.php Class Class source
  Plain text file InvalidStatusException.php Class Class source
  Plain text file InvalidValueException.php Class Class source
  Plain text file InvalidWalletException.php Class Class source

  Files folder image Files (50)  /  src  /  Interfaces  
File Role Description
  Plain text file WalletInterface.php Class Class source

  Files folder image Files (50)  /  src  /  Models  
File Role Description
  Plain text file Wallet.php Class Class source
  Plain text file WalletTransaction.php Class Class source

  Files folder image Files (50)  /  src  /  Traits  
File Role Description
  Plain text file DepositTrait.php Class Class source
  Plain text file EnumTrait.php Class Class source
  Plain text file HasVirtualWallet.php Class Class source
  Plain text file ModelTrait.php Class Class source
  Plain text file PayTrait.php Class Class source
  Plain text file VirtualWalletTrait.php Class Class source
  Plain text file WalletTransactionTrait.php Class Class source

  Files folder image Files (50)  /  tests  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedatabase (2 directories)
Files folder imageenums (7 files)
Files folder imageFeature (2 files)
Files folder imageModels (1 file)
  Plain text file TestCase.php Class Class source

  Files folder image Files (50)  /  tests  /  config  
File Role Description
  Plain text file laravel-virtual-wallet.php Class Class source

  Files folder image Files (50)  /  tests  /  database  
File Role Description
Files folder imagefactories (1 file)
Files folder imagemigrations (1 file)

  Files folder image Files (50)  /  tests  /  database  /  factories  
File Role Description
  Plain text file UserFactory.php Class Class source

  Files folder image Files (50)  /  tests  /  database  /  migrations  
File Role Description
  Plain text file create_users_table.php Class Class source

  Files folder image Files (50)  /  tests  /  enums  
File Role Description
  Accessible without login Plain text file CurrencyEnum.php Aux. Configuration script
  Accessible without login Plain text file CurrencyTypeEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionMethodEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionStatusEnum.php Aux. Configuration script
  Accessible without login Plain text file TransactionTypeEnum.php Aux. Configuration script
  Accessible without login Plain text file WalletStatusEnum.php Aux. Configuration script
  Accessible without login Plain text file WalletTypeEnum.php Aux. Configuration script

  Files folder image Files (50)  /  tests  /  Feature  
File Role Description
  Plain text file DatabaseSetupTest.php Class Class source
  Plain text file LaravelVirtualWalletTest.php Class Class source

  Files folder image Files (50)  /  tests  /  Models  
File Role Description
  Plain text file User.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0