anexponent / tgr-laravel-wallet
易于使用的应用程序虚拟钱包
dev-main
2023-09-02 10:02 UTC
Requires
- php: ^7.0 || ^8.0
- illuminate/database: ~5.6|^6.0|^7.0|^8.0|^9.7.0|^10.0.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-01 00:08:14 UTC
README
在我实施虚拟货币的几个项目中,用户会用Stripe购买积分包,然后在应用中使用这些积分来交换服务或商品。这个包是这个概念的小型简单实现,并留有自定义空间。
安装
使用composer安装此包
composer require anexponent/tgr-laravel-wallet
运行迁移
使用以下 artisan 命令发布迁移
php artisan vendor:publish --provider="Depsimon\Wallet\WalletServiceProvider" --tag=migrations
配置
您可以使用以下 artisan 命令发布配置文件
php artisan vendor:publish --provider="Depsimon\Wallet\WalletServiceProvider" --tag=config
这将合并 wallet.php 配置文件,您可以在此指定自定义的 Users、Wallets & Transactions 类。
用法
将 HasWallet 特性添加到您的 User 模型中。
use Depsimon\Wallet\HasWallet; class User extends Model { use HasWallet; ... }
在执行交易之前,创建用户的钱包。
$user->wallet()->create();
然后您可以从用户模型中轻松执行交易。
$user = User::find(1); $user->balance; // 0 $user->deposit(100); $user->balance; // 100 $user->withdraw(50); $user->balance; // 50 $user->forceWithdraw(200); $user->balance; // -150
您可以为交易轻松添加元信息以满足您的需求。
$user = User::find(1); $user->deposit(100, 'deposit', ['stripe_source' => 'ch_BEV2Iih1yzbf4G3HNsfOQ07h', 'description' => 'Deposit of 100 credits from Stripe Payment']); $user->withdraw(10, 'withdraw', ['description' => 'Purchase of Item #1234']);
安全
如果您发现任何与安全相关的问题,请通过电子邮件simon@webartisan.be联系,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。