silali/laravel-wallet

为您的应用提供的易于使用的虚拟钱包

v1.0.9 2020-03-22 09:13 UTC

This package is auto-updated.

Last update: 2024-09-13 17:10:15 UTC


README

在几个项目中,我必须实现虚拟货币。用户会使用Stripe购买积分包,然后在应用中使用这些积分兑换服务或商品。本包是这个概念的简单实现,并留有自定义空间。

安装

使用composer安装此包

composer require depsimon/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配置文件,您可以在其中指定自定义的用户、钱包和交易类。

使用方法

HasWallet特性添加到您的用户模型中。

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)。有关更多信息,请参阅许可证文件