nycorp/finance

to handle wallet

1.2.1 2024-11-20 07:46 UTC

This package is auto-updated.

Last update: 2024-11-20 07:51:41 UTC


README

Latest Version on Packagist Total Downloads

Features

  1. make deposit
  2. make withdrawal
  3. Set account threshold

Installation (with Composer)

composer require nycorp/finance

Configuration

Publish migration file and config

php artisan vendor:publish --provider="NYCorp\Finance\FinanceServiceProvider"

Run migration

php artisan migrate

Usage

Add Finance Account Trait to any model

use FinanceAccountTrait;

(Optional) Set Threshold the min balance for an account

return User::first()->setThreshold(100) 

For deposit

return User::first()->deposit($request)

Get balance

return User::first()->balance

For withdrawal

return User::first()->withdrawal($request)

Check if user can make transaction if his finance account is not disabled

return Company::first()->canMakeTransaction() ? Company::first()->withdrawal($request) : 'Your account is disabled';

Check if user can make transaction if his finance account has enough balance base on threshold use true to force balance calculation

return Company::first()->canWithdraw(100,true) ? Company::first()->withdrawal($request) : 'Insufficient balance';

Response handle

$response = \Nycorp\LiteApi\Response\DefResponse::parse(User::first()->withdrawal($request));
$response->getBody(); // get the body of the response
$response->isSuccess(); // get the success state as boolean
$response->getMessage(); // get response message