PHPackages                             nycorp/finance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nycorp/finance

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nycorp/finance
==============

to handle wallet

1.4.8(1mo ago)72031MITPHP

Since Nov 26Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/yann-yvan/finance)[ Packagist](https://packagist.org/packages/nycorp/finance)[ RSS](/packages/nycorp-finance/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (6)Versions (51)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c5104cf9d1476fd5c7303d19e9dcabab7a43b5d0ac0c479a16226ddf97055866/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e79636f72702f66696e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nycorp/finance)[![Total Downloads](https://camo.githubusercontent.com/44d27d1534832244196fc738e5cf98ec55af4d37b9eb56e76103ba66d0b4f701/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e79636f72702f66696e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nycorp/finance)

Features
--------

[](#features)

1. make deposit
2. make withdrawal
3. Set account threshold
4. Listen to success transaction
5. Custom payment provider

#### Installation (with Composer)

[](#installation-with-composer)

```
composer require nycorp/finance
```

Then

```
composer require nycorp/lite-api
```

#### Configuration

[](#configuration)

Publish migration file and config

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

Run migration

```
php artisan migrate
```

Get exchange rate API KEY of  and set in .env

```
EXCHANGE_RATE_API_KEY=
```

Usage
-----

[](#usage)

### Add Finance Account Trait to any model

[](#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)
```

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';
```

To listen to success transaction
--------------------------------

[](#to-listen-to-success-transaction)

```
php artisan make:listener SuccessFinanceTransactionListener --event=FinanceTransactionSuccessEvent
```

```
 /**
     * Handle the event.
     */
    public function handle(FinanceTransactionSuccessEvent $event): void
    {
        # In case you handle multiple model
        match (get_class($event->model)) {
            Model1::class => $this->handleModel1($event),
            Model2::class => $this->hanleModel2($event),
            default => static fn() => Log::warning("FinanceTransactionSuccessEvent Model not handle")
        };
    }
```

Custom Provider
---------------

[](#custom-provider)

```
use NYCorp\Finance\Http\Payment\PaymentProviderGateway;

class CustomPaymentProvider extends PaymentProviderGateway
{

    public static function getName(): string
    {
        return 'CustomProvider';
    }

    public function deposit(FinanceTransaction $transaction): PaymentProviderGateway
    {
        #Your custom logic here

        //use this url for callback
        $callbackUrl = self::depositNotificationUrl();

        $amountToPay = $transaction->getConvertedAmount();

        $response = Http::post('https://api-checkout/v2/payment', $formData);
        $this->successful = $response->successful();
        $this->message = $response->json('description');
        $this->response = new FinanceProviderGatewayResponse($transaction, $this->getWallet($transaction)->id, $response->body(), false, $response->json('data.payment_url'));
        return $this;
    }

    public static function getId(): string
    {
        return 'MY_PROVIDER_ID';
    }

    public function withdrawal(FinanceTransaction $transaction): PaymentProviderGateway
    {
        #Your custom logic here

        //use this url for callback
        $callbackUrl = self::withdrawalNotificationUrl();

        $response = Http::post('https://api-checkout/v2/payment', $formData);
        $this->successful = $response->successful();
        $this->message = $response->json('description');
        $this->response = new FinanceProviderGatewayResponse($transaction, $this->getWallet($transaction)->id, $response->body(), false, $response->json('data.payment_url'));
        return $this;
    }

    public function onDepositSuccess(Request $request): PaymentProviderGateway
    {
        Log::debug("**Payment** | " . self::getId() . ": callback " . $request->cpm_trans_id, $request->all());

        # For example here the transaction id is inside the cpm_trans_id in your case it maybe another value
        if ($this->findTransaction($request, 'cpm_trans_id') === null) {
            return $this;
        }

        return $this;
    }

    public function onWithdrawalSuccess(Request $request): PaymentProviderGateway
    {
        return $this;
    }

    protected function findTransaction(Request $request, string $key): ?FinanceTransaction
    {
        $transactionId = Arr::get($request->all(), $key);
        $this->transaction = FinanceTransaction::find($transactionId);
        if (empty($this->transaction)) {
            $id = self::getId();
            Log::error("**Payment** | $id : order not found $transactionId");
            $this->message = "Order not found !";
            $this->successful = false;
            $this->response = new FinanceProviderGatewayResponse(null, null, $request->all());
        }
        return $this->transaction;
    }
}
```

Register provider in config
---------------------------

[](#register-provider-in-config)

```
return [
    'default_payment_provider_id' => 'LOCAL_PROVIDER',
    'default_payment_provider_name' => env('APP_NAME')."'s Local Provider",
    'default_threshold' => 0, #minimum account balance applied to all model
    'default_currency' => 'USD',
    'refresh_account_ttl' => 60, #in minute
    'payment_providers' => [
        \NYCorp\Finance\Http\Payment\DefaultPaymentProvider::class,
        \NYCorp\Finance\Http\Payment\CustomPaymentProvider::class,
    ],

    'force_balance_check_min_amount' => 5000,
    'prefix' => 'finance',
    'middleware' => ['api'],

    'user_email_field' => "email",
    'finance_account_id_parameter' => "finance_account_id",
];
```

Response handle
---------------

[](#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
```

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance90

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity63

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Total

50

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d46eefacf6eb9db2a88486e899e9b9310b593b660860d96bbf777cf1780ab7eb?d=identicon)[Yann-Yvan](/maintainers/Yann-Yvan)

### Embed Badge

![Health badge](/badges/nycorp-finance/health.svg)

```
[![Health](https://phpackages.com/badges/nycorp-finance/health.svg)](https://phpackages.com/packages/nycorp-finance)
```

###  Alternatives

[websharks/html-compressor

Combines &amp; compresses CSS/JS/HTML code.

407.1k1](/packages/websharks-html-compressor)[limewell/laravel-make-extender

This package helps to generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory.

366.8k](/packages/limewell-laravel-make-extender)[linkorb/autotune

Tune your autoloader

177.0k17](/packages/linkorb-autotune)[jayanka/patch-manager

A magento extension to maintain data patches

232.4k](/packages/jayanka-patch-manager)[tapp/filament-progress-bar-column

Add beautiful, color-coded progress bars to your Filament table columns. Perfect for inventory, tasks, storage, and any progress metrics without writing custom views.

124.5k](/packages/tapp-filament-progress-bar-column)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
