PHPackages                             hpwebdeveloper/laravel-pay-pocket - 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. hpwebdeveloper/laravel-pay-pocket

ActiveLibrary[Payment Processing](/categories/payments)

hpwebdeveloper/laravel-pay-pocket
=================================

Laravel Pay Pocket

2.3.3(5mo ago)31618.2k↓10.5%34[3 PRs](https://github.com/HPWebdeveloper/laravel-pay-pocket/pulls)MITPHPPHP ^8.1CI passing

Since Dec 1Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/HPWebdeveloper/laravel-pay-pocket)[ Packagist](https://packagist.org/packages/hpwebdeveloper/laravel-pay-pocket)[ Docs](https://github.com/hpwebdeveloper/laravel-pay-pocket)[ RSS](/packages/hpwebdeveloper-laravel-pay-pocket/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (20)Used By (0)

[![Laravel Pay Pocket](https://private-user-images.githubusercontent.com/16323354/288179812-8e8ebcf6-f8d4-4811-b97c-fb6362e3f019.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzODE1NDksIm5iZiI6MTc3NDM4MTI0OSwicGF0aCI6Ii8xNjMyMzM1NC8yODgxNzk4MTItOGU4ZWJjZjYtZjhkNC00ODExLWI5N2MtZmI2MzYyZTNmMDE5LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE5NDA0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBjNDkxMzliNDI5YzYyNDE5Mjk1NmRlMWU1MDZjOWVmNDZkNjBmMGYzM2NlMmNiZDM1YzVmNTZmMDczN2IyMjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KVZNJSvEJWV61oFdxump-c3rHabmoyvyFLvTjxLP_rQ)](https://private-user-images.githubusercontent.com/16323354/288179812-8e8ebcf6-f8d4-4811-b97c-fb6362e3f019.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzODE1NDksIm5iZiI6MTc3NDM4MTI0OSwicGF0aCI6Ii8xNjMyMzM1NC8yODgxNzk4MTItOGU4ZWJjZjYtZjhkNC00ODExLWI5N2MtZmI2MzYyZTNmMDE5LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE5NDA0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBjNDkxMzliNDI5YzYyNDE5Mjk1NmRlMWU1MDZjOWVmNDZkNjBmMGYzM2NlMmNiZDM1YzVmNTZmMDczN2IyMjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KVZNJSvEJWV61oFdxump-c3rHabmoyvyFLvTjxLP_rQ)

Laravel Pay Pocket
==================

[](#laravel-pay-pocket)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1fc36e2e50599e76f0d142f84287f3047d1016302d4227b5e8d1334d191bf254/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6870776562646576656c6f7065722f6c61726176656c2d7061792d706f636b65742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hpwebdeveloper/laravel-pay-pocket)[![GitHub Tests Action Status](https://camo.githubusercontent.com/fa45c695753e2402a656333284db8120ac6040ed7070947a45bdbd71da01d73c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6870776562646576656c6f7065722f6c61726176656c2d7061792d706f636b65742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/hpwebdeveloper/laravel-pay-pocket/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/9d7f0159b2aeae13265e0813a583c9d419097f02470dc64c3f8e7fd467f40c33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6870776562646576656c6f7065722f6c61726176656c2d7061792d706f636b65742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/hpwebdeveloper/laravel-pay-pocket/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Imports](https://github.com/HPWebdeveloper/laravel-pay-pocket/actions/workflows/check_imports.yml/badge.svg?branch=main)](https://github.com/HPWebdeveloper/laravel-pay-pocket/actions/workflows/check_imports.yml)

**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](https://github.com/HPWebdeveloper/demo-pay-pocket-laravel-12)

**Videos:**

- [Laravel Pay Pocket Package: Virtual Wallets in Your Project](https://www.youtube.com/watch?v=KoQyURiwsA4)
- [Laravel Exceptions: Why and How to Use? Practical Example.](https://www.youtube.com/watch?v=-Sr18w91v8Q)
- [PHP Enums in Laravel: Practical Example from Package](https://www.youtube.com/watch?v=iUOb-3HQtK8)

**Note:** This package does not handle payments from payment platforms, but instead offers the concept of virtual money, deposit, and withdrawal.

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

[](#-table-of-contents)

- [Version Compatibility](#version-compatibility)
- [Installation](#installation)
- [Updating](#updating)
- [Preparation](#preparation)
    - [Prepare User Model](#prepare-user-model)
    - [Prepare Wallets](#prepare-wallets)
- [Usage, APIs and Operations](#usage-apis-and-operations)
    - [Deposit](#deposit)
    - [Pay](#pay)
    - [Balance](#balance)
    - [Exceptions](#exceptions)
    - [Log](#log)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

---

- **Author**: Hamed Panjeh
- **Vendor**: hpwebdeveloper
- **Package**: laravel-pay-pocket
- **Version**: `2.x`
- **[Composer](https://getcomposer.org/):** `composer require hpwebdeveloper/laravel-pay-pocket`

Version Compatibility
---------------------

[](#version-compatibility)

Package VersionLaravel VersionsPHP VersionsStatus1.x10.x8.1+Security fixes only2.x10.x, 11.x, 12.x8.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
------------

[](#installation)

- **Step 1:** You can install the package via composer:

```
composer require hpwebdeveloper/laravel-pay-pocket
```

- **Step 2:** Publish and run the migrations with:

```
php artisan vendor:publish --tag="pay-pocket-migrations"
php artisan migrate
```

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:

```
php artisan vendor:publish --tag="pay-pocket-wallets"
php artisan vendor:publish --tag="config"
```

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
--------

[](#updating)

If updating to version `^2.0.0`, new migration and config files have been added to support the new [Transaction Notes Feature](#transaction-notes-8)

Run the following commands to publish the updated migrations and config:

```
php artisan vendor:publish --tag="pay-pocket-migrations"
php artisan migrate
php artisan vendor:publish --tag="pay-pocket-wallets"
php artisan vendor:publish --tag="config"
```

Preparation
-----------

[](#preparation)

### Prepare User Model

[](#prepare-user-model)

To use this package you need to implement the `WalletOperations` into `User` model and utilize the `ManagesWallet` trait.

```
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
use HPWebdeveloper\LaravelPayPocket\Traits\ManagesWallet;

class User extends Authenticatable implements WalletOperations
{
    use ManagesWallet;
}
```

### Prepare Wallets

[](#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):

```
namespace App\Enums;

enum WalletEnums: string
{
    case WALLET1 = 'wallet_1';
    case WALLET2 = 'wallet_2';
}
```

**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:

[](#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:
---------------------------

[](#usage-apis-and-operations)

### Deposit

[](#deposit)

```
deposit(type: 'wallet_1', amount: 123.45, notes: null)
```

Deposit funds into `wallet_1`

```
$user = auth()->user();
$user->deposit('wallet_1', 123.45);
```

Deposit funds into `wallet_2`

```
$user = auth()->user();
$user->deposit('wallet_2', 67.89);
```

Or using provided facade

```
use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;

$user = auth()->user();
LaravelPayPocket::deposit($user, 'wallet_1', 123.45);
```

Note: `wallet_1` and `wallet_2` must already be defined in the `WalletEnums`.

#### Transaction Notes ([\#8](https://github.com/HPWebdeveloper/laravel-pay-pocket/releases/tag/2.0.0))

[](#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.

```
$user = auth()->user();
$user->deposit('wallet_1', 67.89, 'You ordered pizza.');
```

### Pay

[](#pay)

```
pay(amount: 12.34, notes: null)
```

Pay the value using the total combined balance available across all allowed wallets

```
$user = auth()->user();
$user->pay(12.34);
```

Or using provided facade

```
use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;

$user = auth()->user();
LaravelPayPocket::pay($user, 12.34);
```

#### Payment Transaction Logs

[](#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:**

```
@return \Illuminate\Database\Eloquent\Collection
```

**Basic Usage:**

```
$user = auth()->user();
$logs = $user->pay(120.00, 'Order #1234');

// Access transaction details
foreach ($logs as $log) {
    echo "Wallet: {$log->wallet_name}, Amount: {$log->value}";
}
```

**Practical Examples:**

```
// Get the number of wallets used in the payment
$walletCount = $logs->count();

// Calculate total amount deducted (verification)
$totalDeducted = $logs->sum('value');

// Get all wallet names used in the transaction
$walletsUsed = $logs->pluck('wallet_name');

// Access specific log details
$firstLog = $logs->first();
echo "From: {$firstLog->from}, To: {$firstLog->to}";
echo "Reference: {$firstLog->reference}";
```

**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**

```
$user = auth()->user();

// User has: wallet_1 = $100, wallet_2 = $50
$logs = $user->pay(120.00, 'Premium subscription');

// Returns collection with 2 logs:
// Log 1: wallet_1 deducted $100 (100.00 -> 0.00)
// Log 2: wallet_2 deducted $20 (50.00 -> 30.00)

echo "Payment completed using {$logs->count()} wallet(s)";
// Output: Payment completed using 2 wallet(s)
```

**Note:** This feature is backward compatible. Existing code that doesn't capture the return value will continue to work without any modifications.

### Balance

[](#balance)

- **Wallets**

```
$user->walletBalance // Total combined balance available across all wallets

// Or using provided facade

LaravelPayPocket::checkBalance($user);
```

- **Particular Wallet**

```
$user->getWalletBalanceByType('wallet_1') // Balance available in wallet_1
$user->getWalletBalanceByType('wallet_2') // Balance available in wallet_2

// Or using provided facade

LaravelPayPocket::walletBalanceByType($user, 'wallet_1');
```

### Exceptions

[](#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](https://github.com/HPWebdeveloper/demo-pay-pocket-laravel-12) that accounts for some of the exceptions.

### Log

[](#log)

A typical `wallets_logs` table. [![Laravel Pay Pocket Log](https://private-user-images.githubusercontent.com/16323354/344209949-0d7f2237-88e1-4ac0-a4f2-ac200bad9273.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzODE1NDksIm5iZiI6MTc3NDM4MTI0OSwicGF0aCI6Ii8xNjMyMzM1NC8zNDQyMDk5NDktMGQ3ZjIyMzctODhlMS00YWMwLWE0ZjItYWMyMDBiYWQ5MjczLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE5NDA0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1YTgzNWUxMzM2ODIzZDNhYzEzMTBlNzQ5NzllZWFmMGQ3MzVhMzkzM2ZlZjI0MDRmNGZlNzYwMWM1NjA4MjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.R2gsoV6jzsyY8RKXS7KnDMPs4rik8po64Tz8b3d1i_Q)](https://private-user-images.githubusercontent.com/16323354/344209949-0d7f2237-88e1-4ac0-a4f2-ac200bad9273.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzODE1NDksIm5iZiI6MTc3NDM4MTI0OSwicGF0aCI6Ii8xNjMyMzM1NC8zNDQyMDk5NDktMGQ3ZjIyMzctODhlMS00YWMwLWE0ZjItYWMyMDBiYWQ5MjczLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE5NDA0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1YTgzNWUxMzM2ODIzZDNhYzEzMTBlNzQ5NzllZWFmMGQ3MzVhMzkzM2ZlZjI0MDRmNGZlNzYwMWM1NjA4MjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.R2gsoV6jzsyY8RKXS7KnDMPs4rik8po64Tz8b3d1i_Q)

Testing
-------

[](#testing)

```
composer install

composer test

# Or

./vendor/bin/pest
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Hamed Panjeh](https://github.com/HPWebdeveloper)
- [All Contributors](../../contributors)
- Icon in the above image: pocket by Creative Mahira from [Noun Project](https://thenounproject.com/browse/icons/term/pocket/) (CC BY 3.0)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance80

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 54.3% 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 ~56 days

Recently: every ~131 days

Total

14

Last Release

166d ago

Major Versions

1.0.3 → 2.0.02024-01-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc1b18dc5a22ae254c91a5f3a247951d882ba99594b59a746dfd9f68901babd8?d=identicon)[panjeh](/maintainers/panjeh)

---

Top Contributors

[![HPWebdeveloper](https://avatars.githubusercontent.com/u/16323354?v=4)](https://github.com/HPWebdeveloper "HPWebdeveloper (82 commits)")[![3m1n3nc3](https://avatars.githubusercontent.com/u/52163001?v=4)](https://github.com/3m1n3nc3 "3m1n3nc3 (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![SSEsmaeeli](https://avatars.githubusercontent.com/u/30143856?v=4)](https://github.com/SSEsmaeeli "SSEsmaeeli (12 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (6 commits)")[![josecarpio99](https://avatars.githubusercontent.com/u/86316300?v=4)](https://github.com/josecarpio99 "josecarpio99 (1 commits)")[![samehdoush](https://avatars.githubusercontent.com/u/48515888?v=4)](https://github.com/samehdoush "samehdoush (1 commits)")

---

Tags

balancedepositlaravellaravel-walletmulti-walletpaypaymentphppocketpurchasewalletwithdrawlaravelHamed Panjehlaravel-pay-pocket

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/hpwebdeveloper-laravel-pay-pocket/health.svg)

```
[![Health](https://phpackages.com/badges/hpwebdeveloper-laravel-pay-pocket/health.svg)](https://phpackages.com/packages/hpwebdeveloper-laravel-pay-pocket)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[danestves/laravel-polar

A package to easily integrate your Laravel application with Polar.sh

7812.3k](/packages/danestves-laravel-polar)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[creagia/laravel-redsys

Laravel Redsys Payments Gateway

2013.6k](/packages/creagia-laravel-redsys)

PHPackages © 2026

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