- make deposit
- make withdrawal
- Set account threshold
composer require nycorp/finance
Publish migration file and config
php artisan vendor:publish --provider="NYCorp\Finance\FinanceServiceProvider"
Run migration
php artisan migrate
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