- 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)
Customize the canWithdraw in the model (Optional)
public function canWithdraw(float $amount, bool $forceBalanceCalculation): bool
{
//EX : Set to true because the account is debited only when the service is consumed
return true;
}
Set model currency by adding this method in the model
public function getCurrency()
{
// Implement your logic to get currency here the default value is set in the finance config file
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