Skip to content

yann-yvan/finance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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(DefaultPaymentProvider::getId(), 12, $description)

Get balance

return User::first()->balance

For withdrawal

return User::first()->withdrawal(DefaultPaymentProvider::getId(), 12, $description)

Set model currency by adding this method

public function getCurrency()
    {
        // Implement your logic to get currency here
        return \NYCorp\Finance\Http\Core\ConfigReader::getDefaultCurrency();
    }

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

return Company::first()->canMakeTransaction() ? Company::first()->withdrawal(DefaultPaymentProvider::getId(), 12, $description) : '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(DefaultPaymentProvider::getId(), 12, $description) : 'Insufficient balance';

Response handle

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages