webafra/laravel-user-wallet
Composer 安装命令:
composer require webafra/laravel-user-wallet
包简介
laravel user wallet manager
README 文档
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require webafra/laravel-user-wallet
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-user-wallet-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-user-wallet-config"
Prepare User Model
To use this package you need to implement the WalletOperations into User model and utilize the ManagesWallet trait.
use Webafra\LaravelUserWallet\Interfaces\WalletOperations; use Webafra\LaravelUserWallet\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 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:
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(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 Webafra\LaravelUserWallet\Facades\LaravelUserWallet; $user = auth()->user(); LaravelUserWallet::deposit($user, 'wallet_1', 123.45);
Note: wallet_1 and wallet_2 must already be defined in the WalletEnums.
Transaction Info ([#8][i8])
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(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 Webafra\LaravelUserWallet\Facades\LaravelUserWallet; $user = auth()->user(); LaravelUserWallet::pay($user, 12.34); # decrease from all wallets LaravelUserWallet::pay($user, 12.34, type: 'wallet_1'); LaravelUserWallet::pay($user, 12.34, type: 'wallet_1', notes: 'payment notes');
Balance
- Wallets
$user->walletBalance // Total combined balance available across all wallets // Or using provided facade LaravelUserWallet::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 LaravelUserWallet::walletBalanceByType($user, 'wallet_1');
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.
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.
webafra/laravel-user-wallet 适用场景与选型建议
webafra/laravel-user-wallet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 135 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-user-wallet」 「webafra」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webafra/laravel-user-wallet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webafra/laravel-user-wallet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webafra/laravel-user-wallet 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 135
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-25