Download the PHP package eidolex/e-wallet without Composer
On this page you can find all versions of the php package eidolex/e-wallet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eidolex/e-wallet
More information about eidolex/e-wallet
Files in eidolex/e-wallet
Package e-wallet
Short Description E-Wallet package for managing wallets, transfers, and transactions.
License MIT
Informations about the package e-wallet
Eidolex E-Wallet
A Laravel package for managing wallets, transfers, and transactions. Attach a wallet to any Eloquent model with a simple trait and start processing top-ups, withdrawals, and peer-to-peer transfers.
Requirements
- PHP ^8.1
- Laravel ^9.0 | ^10.0 | ^11.0 | ^12.0
- spatie/laravel-data ^3.0 | ^4.0 (v3 for Laravel 9, v4 for Laravel 10+)
Installation
Add the package to your composer.json repositories (local path or VCS), then require it:
The service provider is auto-discovered via composer.json extra config.
Run the migrations:
Optionally publish the config and migrations:
Setup
Add the HasWallet trait and HasWalletContract interface to any Eloquent model:
This gives the model access to wallet(), transactions(), deposit), withdraw(), and transfer(). To use your own Wallet, Transaction, or Transfer models, see Custom models.
Usage
Top Up
Add funds to a wallet. The wallet is automatically created on first use.
You can pass a custom DTO that extends DepositData (e.g. to add fees, computed metadata, or opening/closing balance). See Custom DepositData for an example.
Withdraw
Deduct funds from a wallet.
You can pass a custom DTO that extends WithdrawData and overrides fields(Wallet $wallet). See Custom DepositData for the same pattern.
Transfer
Move funds between two wallet holders. Creates a withdrawal transaction for the sender and a deposit transaction for the receiver, linked by a Transfer record.
You can pass a custom DTO that extends TransferData and overrides fromFields(Wallet $wallet) and toFields(Wallet $wallet). See Custom DepositData for the same pattern.
Accessing the Wallet & Transactions
Transaction Statuses
Balance is only updated when a transaction's status is Completed. Use Pending to record a transaction without affecting the balance.
Data Transfer Objects
All operations use Spatie Laravel Data DTOs. The name parameter accepts any UnitEnum, so you can use the built-in TransactionName or your own enum. Transaction attributes are built from each DTO: DepositData and WithdrawData expose fields(Wallet $wallet), and TransferData exposes fromFields(Wallet $wallet) and toFields(Wallet $wallet). Extend the DTO classes and override these methods if you need custom transaction data (e.g. computed metadata or balances).
| DTO | Parameters |
|---|---|
DepositData |
name (UnitEnum), amount (int), status (TransactionStatus = Completed), metadata (?array) |
WithdrawData |
name (UnitEnum), amount (int), status (TransactionStatus = Completed), metadata (?array) |
TransferData |
to (HasWalletContract), name (UnitEnum), amount (int), fromMetadata (?array), toMetadata (?array) |
Customization
Custom Transaction Name Enum
By default, transaction names use Eidolex\EWallet\Enums\TransactionName which provides: TopUp, Withdraw, Gift, and Purchase.
To use your own enum, create it and update the config:
Then pass your enum when creating transactions:
Custom Transaction Status Enum
Similarly, you can replace the default TransactionStatus enum:
Custom Metadata Cast
The metadata column is cast to array by default. You can change this in the config:
Custom DepositData
Extend DepositData and override fields(Wallet $wallet) when you need custom transaction attributes (e.g. computed metadata, fees, or opening/closing balance).
Usage:
The same pattern applies to WithdrawData (override fields(Wallet $wallet)) and TransferData (override fromFields(Wallet $wallet) and toFields(Wallet $wallet)).
Configuration Reference
Custom Models
You can swap the package models with your own by extending the base classes and registering them in config. Use this when you need a custom table, extra attributes, or app-specific methods.
1. Extend the package model (e.g. custom Wallet):
2. Register in config:
3. Add the trait with matching generics so static analysis and IDE know the correct types:
Trait generic order: TName, WalletModel, TransactionModel, TransferModel. Omit or keep defaults for models you do not customize. If you only use a custom Wallet:
Database Schema
The package creates three tables:
wallets — One wallet per owner (polymorphic). Unique on (owner_type, owner_id).
| Column | Type |
|---|---|
id |
UUID (primary) |
owner_type |
string |
owner_id |
string |
balance |
unsigned big integer (default: 0) |
created_at |
timestamp |
updated_at |
timestamp |
transactions — Individual debit/credit records.
| Column | Type |
|---|---|
id |
UUID (primary) |
wallet_id |
UUID (foreign key) |
type |
unsigned tiny integer (enum: 0 = Withdraw, 1 = Deposit) |
name |
string (configurable enum) |
amount |
unsigned big integer |
status |
unsigned tiny integer (enum: Pending, Completed, Cancelled, Failed, Refunded) |
opening_balance |
unsigned big integer (nullable) |
closing_balance |
unsigned big integer (nullable) |
metadata |
JSON (nullable) |
created_at |
timestamp |
updated_at |
timestamp |
transfers — Links two transactions (sender and receiver).
| Column | Type |
|---|---|
id |
UUID (primary) |
from_transaction_id |
UUID (foreign key, cascade delete) |
to_transaction_id |
UUID (foreign key, cascade delete) |
amount |
unsigned big integer |
metadata |
JSON (nullable) |
created_at |
timestamp |
updated_at |
timestamp |
Transaction Safety
All wallet operations (topUp, withdraw, transfer) are wrapped in DB::transaction() so each operation is atomic.
License
MIT
All versions of e-wallet with dependencies
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
spatie/laravel-data Version ^3.0|^4.0