PHPackages                             towoju5/laravel-wallet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. towoju5/laravel-wallet

ActiveLibrary[Payment Processing](/categories/payments)

towoju5/laravel-wallet
======================

A multi-wallet package for Laravel with support for user roles.

v1.1(1y ago)1878MITPHPPHP ^7.4|^8.0

Since Oct 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/towoju5/adv_laravel_wallet)[ Packagist](https://packagist.org/packages/towoju5/laravel-wallet)[ RSS](/packages/towoju5-laravel-wallet/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Laravel Multi-Wallet Package
============================

[](#laravel-multi-wallet-package)

**Package Name**: `towoju5/laravel-wallet`
**Description**: A multi-wallet package for Laravel applications, with support for user roles, currency-based wallets, and transaction logging.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
    - [Step 1: Install the Package via Composer](#step-1-install-the-package-via-composer)
    - [Step 2: Publish Configuration and Migrations](#step-2-publish-configuration-and-migrations)
    - [Step 3: Run Migrations](#step-3-run-migrations)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Creating and Accessing Wallets](#creating-and-accessing-wallets)
    - [Depositing Funds](#depositing-funds)
    - [Withdrawing Funds](#withdrawing-funds)
    - [Viewing Balance](#viewing-balance)
    - [Transaction Logs](#transaction-logs)
    - [Example Usage in Code](#example-usage-in-code)
- [Database Structure](#database-structure)

Features
--------

[](#features)

- **Multiple Wallets per User**: Each user can have multiple wallets, such as for different currencies or purposes.
- **Role-Based Wallets**: Wallets are tied to user roles, allowing users to manage funds based on their active role.
- **Transaction Tracking**: Full tracking of deposits, withdrawals, and balances, with detailed transaction logs.
- **Flexible Balance Storage**: Balances are stored as integers in the database (in "cents" format) to avoid floating-point inaccuracies.

Features
--------

[](#features-1)

- **Multiple Wallets per User**: Each user can have multiple wallets, such as for different currencies or purposes.
- **Role-Based Wallets**: Wallets are tied to user roles, allowing users to manage funds based on their active role.
- **Transaction Tracking**: Full tracking of deposits, withdrawals, and balances, with detailed transaction logs.
- **Flexible Balance Storage**: Balances are stored as integers in the database (in "cents" format) to avoid floating-point inaccuracies.

Installation
------------

[](#installation)

### Step 1: Install the Package via Composer

[](#step-1-install-the-package-via-composer)

```
composer require towoju5/laravel-wallet
```

### Step 2: Publish Configuration and Migrations

[](#step-2-publish-configuration-and-migrations)

After installation, publish the configuration file and migrations:

```
php artisan vendor:publish --provider="Towoju5\\Wallet\\Providers\\WalletServiceProvider"
```

### Step 3: Run Migrations

[](#step-3-run-migrations)

Run the migrations to create the `wallets` and `_transaction` tables.

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

The default currency for wallets can be set in the configuration file:

```
// config/wallet.php
return [
    'default_currency' => 'usd',
];
```

Usage
-----

[](#usage)

### Creating and Accessing Wallets

[](#creating-and-accessing-wallets)

Each user can have multiple wallets based on currency or other criteria. Use the `getWallet()` method to create or retrieve a wallet for the user:

```
$user = User::find(1); // Retrieve a user instance
$wallet = $user->getWallet('usd'); // Retrieve or create a wallet for USD currency
```

### Depositing Funds

[](#depositing-funds)

Add funds to the wallet with the `deposit()` method. Optionally, you can include metadata or descriptions for the transaction:

```
$wallet->deposit(100, ['description' => 'Task completed', 'meta' => ['task_id' => 123]]);
```

### Withdrawing Funds

[](#withdrawing-funds)

Withdraw funds from the wallet with the `withdraw()` method, similarly passing metadata as needed:

```
$wallet->withdraw(50, ['description' => 'Purchase of domain', 'meta' => ['order_id' => 456]]);
```

### Viewing Balance

[](#viewing-balance)

Retrieve the wallet’s balance, automatically converted from stored format:

```
echo $wallet->balance; // E.g., "10.50" for 1050 stored in cents
```

### Transaction Logs

[](#transaction-logs)

Each transaction is logged in the `_transaction` table with the following attributes:

- `type`: Transaction type (`deposit` or `withdrawal`).
- `amount`: The amount involved in the transaction.
- `balance_before` and `balance_after`: Track balance changes.
- `description`: Additional context or notes on the transaction.
- `_account_type`: Indicates the role-based context for the transaction.

### Example Usage in Code

[](#example-usage-in-code)

```
$user = User::find(1);
$wallet = $user->getWallet('usd');

$wallet->deposit(1000, ['description' => 'Initial deposit']); // Adds $10.00 in USD
$wallet->withdraw(250, ['description' => 'Payment for service']); // Deducts $2.50

echo "Current Balance: " . $wallet->balance; // Output balance as a decimal value

// For currency swap or conversion

use Towoju5\LaravelWallet\Models\Wallet;
use Towoju5\LaravelWallet\Services\WalletService;
use Towoju5\LaravelWallet\Services\CurrencyExchangeService;

// Assuming dependency injection or manual instantiation
$walletService = new WalletService(new CurrencyExchangeService());

// Create wallets
$usdWallet = Wallet::create(['user_id' => $user->id, 'currency' => 'usd']);
$eurWallet = Wallet::create(['user_id' => $user->id, 'currency' => 'eur']);

// Deposit in USD wallet
$usdWallet->deposit(1000, ['description' => 'Initial deposit in USD']);

// Transfer funds from USD wallet to EUR wallet
$walletService->transferBetweenCurrencies($usdWallet, $eurWallet, 500);
```

Database Structure
------------------

[](#database-structure)

1. **`wallets`**: Stores wallet information for each user and role combination.

    - `user_id`: User who owns the wallet.
    - `role`: User role associated with the wallet (e.g., 'admin', 'general').
    - `currency`: Wallet currency (e.g., 'usd', 'eur').
    - `balance`: Stored in integer format (cents) for precision.
2. **`_transaction`**: Logs all wallet transactions with relevant details.

    - `type`: Transaction type (`deposit` or `withdrawal`).
    - `balance_before`: Balance before transaction.
    - `balance_after`: Balance after transaction.
    - `meta`: Additional data (JSON format).
    - `_account_type`: Active user role when the transaction occurred.

---

Add screenshots of the following to demonstrate:

1. Database tables (`wallets` and `_transaction`) with example data.
2. Example code execution and output showing wallet creation, deposits, and withdrawals.

---

This setup should help you create a seamless, multi-currency, role-based wallet system in your Laravel application. Let me know if you'd like more specific guidance on adding the screenshots or other package improvements!

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance42

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~85 days

Total

2

Last Release

472d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10d0b6560e7895f8e4b30e120cc5fca9e6a6472ce741a9c54779ba6f1ac6b158?d=identicon)[Towoju5](/maintainers/Towoju5)

---

Top Contributors

[![towoju5](https://avatars.githubusercontent.com/u/40261626?v=4)](https://github.com/towoju5 "towoju5 (2 commits)")

### Embed Badge

![Health badge](/badges/towoju5-laravel-wallet/health.svg)

```
[![Health](https://phpackages.com/badges/towoju5-laravel-wallet/health.svg)](https://phpackages.com/packages/towoju5-laravel-wallet)
```

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
