Download the PHP package nishant/wallet without Composer
On this page you can find all versions of the php package nishant/wallet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nishant/wallet
More information about nishant/wallet
Files in nishant/wallet
Package wallet
Short Description A Laravel package for managing multiple wallets per user with deposit, withdraw, and transaction tracking
License MIT
Informations about the package wallet
Nishant Wallet - Multi-Wallet Management Package for Laravel 11
A comprehensive Laravel package for managing multiple wallets per user with deposit, withdraw, and transaction tracking capabilities. Built for Laravel 11 and PHP 8.0+.
Features
- ✅ Multiple wallets per user
- ✅ Deposit and withdraw functionality
- ✅ Pending transactions with confirmation support
- ✅ Transaction history tracking
- ✅ Get transactions by wallet name
- ✅ Interface-based architecture
- ✅ Trait-based implementation
- ✅ RESTful API endpoints
- ✅ Soft deletes support
- ✅ Balance validation
Requirements
- PHP >= 8.0
- Laravel >= 11.0
Installation
Step 1: Install the Package
Option A: Install from Packagist (Production)
If the package is published to Packagist, use:
Note: If you get a stability error, make sure the package has a stable version tag (v1.0.0) in the Git repository. You can also install a specific version:
Or if you need to allow dev stability temporarily:
Option B: Local Development Setup
If you're developing the package locally or testing it before publishing, add it to your Laravel project's composer.json:
Important Notes for Local Development:
- The package folder (
nishant-wallet-laravel) should be in the same directory as your Laravel project - After adding this, run
composer updateto link the package - Changes in the package will be immediately available (no need to reinstall)
- The package will be symlinked, so you can edit it directly
- For production, remove the
repositoriessection and usecomposer require nishant/walletinstead
Project Structure:
After adding the repository configuration, run:
Step 2: Publish Configuration and Migrations
Publish the configuration file:
Publish the migrations:
Step 3: Run Migrations
Run the database migrations:
Step 4: Add Trait to User Model
Add the HasWallets trait to your User model:
Configuration
The configuration file is located at config/wallet.php. You can customize:
- user_model: The User model class (default:
App\Models\User) - route_prefix: API route prefix (default:
api/wallet) - middleware: Route middleware (default:
['api']) - decimal_places: Number of decimal places for balances (default:
2)
Usage
Creating Wallets
Using the Trait (Recommended)
Using the Service
Depositing Amount
Using the Wallet Model
Using the Service
Withdrawing Amount
Using the Wallet Model
Using the Service
Getting Transactions
Get All Transactions for a Wallet
Get Transactions by Wallet Name
Get Transactions by Type
Confirming Pending Transactions
When you create a transaction with confirmed: false, the wallet balance is not affected. You can confirm the transaction later to apply the balance change.
Using the Service
Check Transaction Status
Getting Wallet Information
API Endpoints
The package provides RESTful API endpoints. Make sure you have authentication middleware configured.
Wallet Endpoints
GET /api/wallets- Get all wallets for authenticated userPOST /api/wallets- Create a new walletGET /api/wallets/{id}- Get a specific wallet with transactionsPOST /api/wallets/{id}/deposit- Deposit amount to walletPOST /api/wallets/{id}/withdraw- Withdraw amount from walletGET /api/wallets/{id}/transactions- Get transactions for a walletPOST /api/wallets/transactions/{transactionId}/confirm- Confirm a pending transaction
Transaction Endpoints
GET /api/transactions/by-wallet-name?wallet_name=Main Wallet- Get transactions by wallet namePOST /api/transactions/deposit-by-name- Deposit to wallet by namePOST /api/transactions/withdraw-by-name- Withdraw from wallet by name
API Request Examples
Create Wallet
Deposit Amount
Deposit Amount (Pending)
Withdraw Amount
Withdraw Amount (Pending)
Confirm Pending Transaction
Response:
Get Transactions by Wallet Name
Interfaces
The package uses interfaces for better code organization:
WalletInterface
TransactionInterface
Traits
HasWallets Trait
Add this trait to your User model to enable wallet functionality:
This trait provides methods like:
wallets()- Relationship to walletscreateWallet()- Create a new walletgetWalletByName()- Get wallet by namegetTransactionsByWalletName()- Get transactions by wallet namegetTotalBalance()- Get total balance across all wallets
Walletable Trait
This trait is automatically used by the Wallet model and provides:
deposit()- Deposit amount (with optionalconfirmedparameter)withdraw()- Withdraw amount (with optionalconfirmedparameter)hasBalance()- Check balancegetBalance()- Get current balance
Database Schema
Wallets Table
id- Primary keyuser_id- Foreign key to users tablename- Wallet namebalance- Current balance (decimal 15,2)is_active- Active statusdescription- Optional descriptiontimestamps- Created/updated timestampsdeleted_at- Soft delete timestamp
Wallet Transactions Table
id- Primary keywallet_id- Foreign key to wallets tabletype- Transaction type (deposit/withdraw)amount- Transaction amountbalance_before- Balance before transactionbalance_after- Balance after transactionreference- Optional reference numberdescription- Optional descriptionmeta- JSON metadataconfirmed- Boolean flag indicating if transaction is confirmed (default: true)timestamps- Created/updated timestamps
Note: When confirmed is false, the transaction is created but the wallet balance is not updated. The balance will only be updated when the transaction is confirmed using the confirmTransaction() method.
Error Handling
The package throws exceptions for various scenarios:
- Insufficient Balance: When trying to withdraw more than available balance (or when confirming a withdrawal)
- Inactive Wallet: When trying to deposit/withdraw from inactive wallet
- Invalid Amount: When amount is zero or negative
- Wallet Not Found: When wallet doesn't exist
- Transaction Already Confirmed: When trying to confirm an already confirmed transaction
- Transaction Not Found: When trying to confirm a non-existent transaction
Always wrap wallet operations in try-catch blocks:
Testing
To test the package, you can use Laravel's testing features:
License
This package is open-sourced software licensed under the MIT license.
Support
For issues, questions, or contributions, please open an issue on the GitHub repository.
Changelog
Version 1.1.0
- Added pending transaction support with
confirmedcolumn - Transactions can now be created with
confirmed: falseto prevent immediate balance changes - Added
confirmTransaction()method to confirm pending transactions - Added API endpoint for confirming transactions
- Updated interfaces to support confirmed parameter
- Balance is only updated when transactions are confirmed
Version 1.0.0
- Initial release
- Multiple wallets per user
- Deposit and withdraw functionality
- Transaction tracking
- Get transactions by wallet name
- Interface and trait implementation
- RESTful API endpoints