mahbodhastam/laravel-user-wallet

This package allows you to create wallet for the users

v1.1.1 2021-08-16 14:42 UTC

This package is auto-updated.

Last update: 2024-03-16 20:58:29 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

With this package you can create wallet for the users.

Note: Make sure you've already installed php ^8

Installation

Install the package via composer:

composer require mahbodhastam/laravel-user-wallet

Usage

  • Create New Wallet

use MahbodHastam\UserWallet\UserWallet;

$wallet = UserWallet::createNewWallet(user_id: 1);

$amount = $wallet->amount;
$token = $wallet->token;
  • Get wallet with the token/id

$wallet = UserWallet::getWallet('abc');
  • Get wallet's balance

$balance = UserWallet::balance($wallet)['total'];
  • Change wallet's amount

UserWallet::fill($wallet, 100);
  • Charge the wallet

UserWallet::charge($wallet, 500);
  • Send

UserWallet::send(
    sender: $wallet1,
    receiver: $wallet2,
    value: 50
);
  • Open a request

$transaction = UserWallet::makeRequest(
    value: 300,
    receiver: $wallet
);

// Keep it
$hash = $transaction->transaction_hash;

UserWallet::closeRequest(
    sender: $wallet,
    transaction_hash: $hash
);
  • Get the balance in blade

@userWalletBalance($wallet)

{{-- $wallet can be wallet's `id`, `token` or an instance from UserWalletModel --}}

See the Tests for more examples.

Testing

composer test

Todos

  • Blade Directives

Changelog

See CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

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