Download the PHP package hpwebdeveloper/laravel-pay-pocket without Composer
On this page you can find all versions of the php package hpwebdeveloper/laravel-pay-pocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hpwebdeveloper/laravel-pay-pocket
More information about hpwebdeveloper/laravel-pay-pocket
Files in hpwebdeveloper/laravel-pay-pocket
Package laravel-pay-pocket
Short Description Laravel Pay Pocket
License MIT
Homepage https://github.com/hpwebdeveloper/laravel-pay-pocket
Informations about the package laravel-pay-pocket
Laravel Pay Pocket
Laravel Pay Pocket is a package designed for Laravel applications, offering the flexibility to manage multiple wallet types within two dedicated database tables, wallets and wallets_logs.
Demo: Link to the demo in Laravel 12
Videos:
- Laravel Pay Pocket Package: Virtual Wallets in Your Project
- Laravel Exceptions: Why and How to Use? Practical Example.
- PHP Enums in Laravel: Practical Example from Package
Note: This package does not handle payments from payment platforms, but instead offers the concept of virtual money, deposit, and withdrawal.
📚 Table of Contents
- Version Compatibility
- Installation
- Updating
- Preparation
- Prepare User Model
- Prepare Wallets
- Usage, APIs and Operations
- Deposit
- Pay
- Balance
- Exceptions
- Log
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
- Author: Hamed Panjeh
- Vendor: hpwebdeveloper
- Package: laravel-pay-pocket
- Version:
2.x - Composer:
composer require hpwebdeveloper/laravel-pay-pocket
Version Compatibility
| Package Version | Laravel Versions | PHP Versions | Status |
|---|---|---|---|
| 1.x | 10.x | 8.1+ | Security fixes only |
| 2.x | 10.x, 11.x, 12.x | 8.1+ | Active support |
Note: The package follows Laravel's philosophy of being as permissive as possible with PHP versions. Your application's composer.json will enforce the minimum PHP version required by your Laravel version (10.x requires PHP 8.1+, 11.x and 12.x require PHP 8.2+).
Installation
-
Step 1: You can install the package via composer:
- Step 2: Publish and run the migrations with:
You have successfully added two dedicated database tables, wallets and wallets_logs, without making any modifications to the users table.
- Step 3: Publish the wallet types using:
This command will automatically publish the pay-pocket.php config file and also WalletEnums.php file into your application's config and app/Enums directories respectively.
Updating
If updating to version ^2.0.0, new migration and config files have been added to support the new Transaction Notes Feature
Run the following commands to publish the updated migrations and config:
Preparation
Prepare User Model
To use this package you need to implement the WalletOperations into User model and utilize the ManagesWallet trait.
Prepare Wallets
In Laravel Pay Pocket, you have the flexibility to define the order in which wallets are prioritized for payments through the use of Enums. The order of wallets in the Enum file determines their priority level. The first wallet listed has the highest priority and will be used first for deducting order values.
For example, consider the following wallet types defined in the Enum class (published in step 3 of installation):
You have complete freedom to name your wallets as per your requirements and even add more wallet types to the Enum list.
In this particular setup, wallet_1 (WALLET1) is given the highest priority. When an order payment is processed, the system will first attempt to use wallet_1 to cover the cost. If wallet_1 does not have sufficient funds, wallet_2 (WALLET2) will be used next.
Example:
If the balance in wallet_1 is 10 and the balance in wallet_2 is 20, and you need to pay an order value of 15, the payment process will first utilize the entire balance of wallet_1. Since wallet_1's balance is insufficient to cover the full amount, the remaining 5 will be deducted from wallet_2. After the payment, wallet_2 will have a remaining balance of 15."
Usage, APIs and Operations:
Deposit
Deposit funds into wallet_1
Deposit funds into wallet_2
Or using provided facade
Note: wallet_1 and wallet_2 must already be defined in the WalletEnums.
Transaction Notes (#8)
When you need to add descriptions for a specific transaction, the $notes parameter enables you to provide details explaining the reason behind the transaction.
Pay
Pay the value using the total combined balance available across all allowed wallets
Or using provided facade
Payment Transaction Logs
The pay() method returns a collection of WalletsLog instances representing all wallet transactions that occurred during the payment. This enables you to track exactly which wallets were used and access detailed transaction information.
Return Value:
Basic Usage:
Practical Examples:
Use Cases:
- Receipt Generation: Display detailed payment breakdown showing amounts from each wallet
- Audit Trail: Maintain comprehensive records of payment sources
- Transaction Verification: Confirm the exact amount deducted from each wallet
- Analytics: Track wallet usage patterns across payments
Example: Multi-Wallet Payment
Note: This feature is backward compatible. Existing code that doesn't capture the return value will continue to work without any modifications.
Balance
-
Wallets
- Particular Wallet
Exceptions
Upon examining the src/Exceptions directory within the source code,
you will discover a variety of exceptions tailored to address each scenario of invalid entry. Review the demo that accounts for some of the exceptions.
Log
A typical wallets_logs table.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Hamed Panjeh
- All Contributors
- Icon in the above image: pocket by Creative Mahira from Noun Project (CC BY 3.0)
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-pay-pocket with dependencies
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0