Laravel Pay Pocket

hpwebdeveloper/laravel-pay-pocket image

Laravel Pay Pocket stats

Downloads
2
Stars
18
Open Issues
0
Forks
0

View on GitHub →

Laravel Pay Pocket

Laravel Pay Pocket

Laravel Pay Pocket is a simple package designed for Laravel applications, offering the flexibility to manage multiple wallet types within two dedicated database tables, wallets and wallets_logs.

  • Author: Hamed Panjeh
  • Vendor: hpwebdeveloper
  • Package: laravel-pay-pocket
  • Version: 1.x
  • PHP Version: 8.1+
  • Laravel Version: 10.x
  • Composer: composer require hpwebdeveloper/laravel-pay-pocket

Support Policy

Version Laravel PHP Release date End of improvements End of support
1.x ^10.0 8.1 Nov 30, 2023 Mar 1, 2024
x.x

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
  • Step 3: Publish the wallet types using
php artisan vendor:publish --tag="pay-pocket-wallets"

This command will automatically publish the WalletEnums.php file into your application's app/Enums directory.

Usage

Prepare User Model

To use this package you need to implements the WalletOperations into User model and utlize the ManagesWallet trait.

 
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
use HPWebdeveloper\LaravelPayPocket\Traits\ManagesWallet;
 
class User extends Authenticatable implements WalletOperations
{
use ManagesWallet;
}

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

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

Deposit

$user = auth()->user();
 
$user->deposit('wallet_1', 123.45); // Deposit funds into 'wallet_1'
 
$user->deposit('wallet_2', 67.89); // Deposit funds into 'wallet_2'
 
// Or using provided facade
 
use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;
 
LaravelPayPocket::deposit($user, 'wallet_1', 123.45);

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

Pay

$user->pay(12.34); // Pay the value using the total combined balance available across all wallets
 
// Or using provided facade
 
use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;
 
LaravelPayPocket::pay($user, 12.34);

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');

Testing

composer install
 
composer test
 
 
// Or
 
./vender/bin/pest

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

License

The MIT License (MIT). Please see License File for more information.

HPWebdeveloper photo

Developer Laravel, Vue, React, Tailwind

Email: panjeh@gmail.com

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Hpwebdeveloper Laravel Pay Pocket Related Articles

Manage Virtual Wallets in Laravel with Pay Pocket image

Manage Virtual Wallets in Laravel with Pay Pocket

Read article
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm