PHPackages                             mdhesari/cashier - 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. mdhesari/cashier

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

mdhesari/cashier
================

Official Vander package for easier access to Vander documents

05PHP

Since Jul 24Pushed 2y agoCompare

[ Source](https://github.com/Mdhesari/cashier)[ Packagist](https://packagist.org/packages/mdhesari/cashier)[ RSS](/packages/mdhesari-cashier/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Vandar Cashier
==============

[](#vandar-cashier)

[![GitHub license](https://camo.githubusercontent.com/e425d2c79d003bf68eee7356bbf941824a06dbe0d3a219928670f9a627c4767d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f76616e6461727061792f636173686965723f7374796c653d666c61742d737175617265)](https://github.com/vandarpay/cashier/blob/master/LICENSE)[![GitHub Workflow Status](https://camo.githubusercontent.com/a946b7fffb6493ca989ff11d18d4357f2c0b337d1ef92fafb7600b5482c6143c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f76616e6461727061792f636173686965722f74657374733f7374796c653d666c61742d737175617265)](https://github.com/vandarpay/cashier/actions/workflows/tests.yml)[![Packagist Downloads](https://camo.githubusercontent.com/eefe4c4d3d3ef03e477bc8625e1056b943cae5283b497e4523224e39ab82bac7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76616e6461727061792f636173686965723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vandarpay/cashier)[![Packagist PHP Version Support](https://camo.githubusercontent.com/879b9470d606eeb8c724729c2a8837d8413e01a589e8ccc0b05e55a402147010/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76616e6461727061792f636173686965723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/879b9470d606eeb8c724729c2a8837d8413e01a589e8ccc0b05e55a402147010/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76616e6461727061792f636173686965723f7374796c653d666c61742d737175617265)[![Laravel Version Support](https://camo.githubusercontent.com/2e239443486f6d88ca718c237dffc1b18c32aff5ebd829fc00090fd21c5f20f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362e30253243253230372e30253243253230382e30253243253230392e302d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/2e239443486f6d88ca718c237dffc1b18c32aff5ebd829fc00090fd21c5f20f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d362e30253243253230372e30253243253230382e30253243253230392e302d627269676874677265656e3f7374796c653d666c61742d737175617265)

Vandar Cashier is a Laravel package that provides you with a seamless integration with Vandar services. Take a look at Vandar Documentation for more information on the services we provide.

Setup
=====

[](#setup)

To use Vandar Cashier, you need to install it through Composer first:

```
composer require vandarpay/cashier
```

Then, you will need to publish the package's assets and migrate your project's database to add Vandar Cashier's tables:

```
php artisan vendor:publish --provider="Vandar\\Cashier\\VandarCashierServiceProvider"
php artisan migrate
```

After that, open your User model (located in `app/User.php` or `app/Models/User.php` in most projects) and add the `Billable` trait:

```
use Vandar\Cashier\Traits\Billable;
// ...
class User extends Authenticatable
{
    use Billable;
// ...
```

You will need to add the necessary configuration to your `.env` file:

```
VANDAR_MOBILE=
VANDAR_PASSWORD=
VANDAR_BUSINESS_SLUG=
VANDAR_API_KEY=
```

`VANDAR_MOBILE` and `VANDAR_PASSWORD` are your login credentials to Vandar dashboard, the `VANDAR_BUSINESS_SLUG` is set by you when you add a business in Vandar and `VANDAR_API_KEY` is obtained through your business dashboard.

Usage
=====

[](#usage)

Currently, Vandar Cashier supports three of Vandar services: **IPG**, **Direct Debit**, and **Settlement**. IPG is the more common method used which provides you with a link that the user can use to pay for a service. The direct debit service works by requesting access from a user's bank account and withdrawing from their accounts periodically without a need for user interaction.

IPG
---

[](#ipg)

### Independent

[](#independent)

if you're creating a donation form, or you don't really need a logged-in user to make payments, you will need two paths. The first path is going to be initiating the payment and sending it to payment gateway. The second path (also known as callback url) will verify the transaction once your user has returned.

```
use Vandar\Cashier\Models\Payment;
Route::get('/initiate-payment', function(Request $request) {
    // Amounts are in IRR
    // For more values, see Payment or https://vandarpay.github.io/docs/ipg/#step-1
    $payment = Payment::create(['amount' => 10000]);
    return redirect($payment->url);
});
```

### User-Dependent

[](#user-dependent)

In a user-dependant scenario, we are assuming that anyone making a payment is already logged-in to your system, therefore, you can create a payment link for them to redirect them to through their user model:

```
Route::get('/initiate-payment', function(Request $request){
    $user = auth()->user(); // Added as a separate variable for clarity
    // Amounts are in IRR
    // For more values, see Payment or https://vandarpay.github.io/docs/ipg/#step-1
    $payment = $user->payments()->create(['amount' => 10000]);
    return redirect($payment->url); // See documentation for info on payload and callback
});
```

### Callback URL

[](#callback-url)

Once the transaction finishes (successfully or not), they will be redirect back to the path you defined in callback, you may define a controller or a route to verify the payment using the `Payment::verify($request)` method:

```
use Vandar\Cashier\Models\Payment;
Route::get('/callback', function(Request $request){
    if(Payment::verifyFromRequest($request)){
        return 'Success!';
    }
    else {
        return 'Failed!';
    }
});
```

The verify method automatically updates the transaction status in your database.

Also, for IPG, you're going to need to define a callback url for when users are returning from Vandar to your application, you can either set the `VANDAR_CALLBACK_URL` environment variable or modify `config/vandar.php`. You will also need to add the callback URL in your Business Dashboard in Vandar or otherwise it will lead into an error.

Direct-Debit
------------

[](#direct-debit)

When setting up direct-debit, you have two main steps to take.

1. Get user to allow for access to their account (also known as a Mandate)
2. Request a withdrawal from a user's account

### Mandate

[](#mandate)

A mandate is basically a permission that a customer gives us to access their accounts. in Vandar, a customer is defined by their phone number and that's considered the primary key when it comes to customers. if you're planning to use subscription services in your project, you will need a `mobile_number` column in your users table. This code can be used as a migration that will add such a column:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddMobileNumbersColumnToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('mobile_number')->nullable();
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
           $table->dropColumn('mobile_number');
        });
    }
}
```

You may also pass the `mobile_number` key in the array passed to authorizeMandate manually.

You can then create a mandate and redirect the user to the bank for authorizing the mandate:

```
Route::get('/initiate-mandate', function(){
    $user = auth()->user();
    if(! $user->hasValidMandate()){ // You may use the hasValidMandate method if your design requires each user to have only one active mandate
    return redirect($user->authorizeMandate(['bank_code' => '062', 'count' => 3, 'limit' => '10000', 'expiration_date' => '2021-01-01']));
    }
})
```

You are also going to need a callback url for the user to return to after they're finished with the mandate process, this path should be set as an absolute url through `VANDAR_MANDATE_CALLBACK_URL` or editing the config file.

You can verify whether the mandate was successfully made and update the mandate accordingly using the `Mandate::verifyFromRequest` method:

```
use Vandar\Cashier\Models\Mandate;
Route::get('/mandate-callback', function(Request $request){
    if(Mandate::verifyFromRequest($request)){
        return 'Success!';
    } else {
        return 'Failed!';
    }
})
```

You can also revoke any mandates through the Mandate model's revoke function:

```
use Vandar\Cashier\Models\Mandate

$mandate = Mandate::find(1);
$mandate->revoke(); // true if mandate was revoked successfully
```

Since the only way for a user to cancel a mandate is through your platform, it is standard to provide a way for users to do so in a convenient way.

### Withdrawal

[](#withdrawal)

Once the mandate has been created successfully, you may create a withdrawal through the mandate:

```
$user->mandates()->active()->first()->createWithdrawal(['amount' => 10000, 'is_instant' => true, 'description' => 'Subscription renewal', 'max_retry_count' => 16]);
```

Please note that you may use any method you like to find your current mandate, for example if you have more than one mandate per user, you may use different queries to find that particular mandate.

When creating a new withdrawal, passing `authorization_id` and `notify_url` is not necessary as Cashier automatically sets these values.

Note: if not provided, Vandar Cashier automatically sets `withdrawal_date` to now. (`date('Y-m-d')`)

if you're not creating an instant withdrawal (`is_instant = false`) you can also cancel the withdrawal before it is run:

```
$status = $withdrawal->cancel(); // Returns 'CANCELED' on success, any other status (DONE, PENDING, INIT, FAILED) on failure.
```

Settlement
----------

[](#settlement)

Vandar Cashier provides the ability to make requests for settlements:

```
$settlement = Settlement::create(['amount' => 5000, 'iban' => 'IR000000000000000000000000']) // amount is in Toman
```

Once a settlement is created successfully, Vandar will queue the settlement and send it to bank. When the settlement is finalized, a notification will be sent to the URL specified in `settlement_notify_url` in vandar config.

Vandar Cashier provides a route that automatically handles settlement updates and updates your databases accordingly, so you don't need to update the `settlement_notify_url` unless you need to implement your own solution.

You may also cancel a settlement through the cancel method before it is done, if successful, `CANCELED` will be returned. if the cancel attempt fails, the last known settlement status is returned from the database:

```
$settlement->cancel(); // Returns `CANCELED` on success.
```

Utilities
---------

[](#utilities)

You may use the `Vandar::getBanksHealth()` method to get an array containing a list of all banks and whether they're healthy.

Error Handling
--------------

[](#error-handling)

When making contact with Vandar APIs, a series of exceptions may be raised due to errors while processing your requests in the APIs. All of these errors can be caught and processed through `Vandar\Exceptions\ResponseException` exception. This means that all exceptions raised by Cashier have the following methods:

```
try {
    ...
} catch (\Vandar\Cashier\Exceptions\ResponseException $exception) {
    dump($exception->context()) // Dumps all the information passed into Guzzle, including headers and configuration
    dump($exception->getUrl()) // Dumps the url the request was sent to
    dump($exception->getPayload()) // Dumps the payload that was sent to Vandar APIs
    dump($exception->getResponse()) // Dumps the response object returned by Guzzle
    dump($exception->getResponse()->json()) // Returns an associative array of json response.
    dump($exception->errors()) // Useful especially in InvalidPayloadException, returns the "errors" key in the json response
}
```

You may also attempt to differentiate between the errors based on the exception that was raised:

- **ExternalAPIException** is raised when any 5xx error occurs
- **AuthenticationException** is raised when there's an HTTP 401 error, this may only happen if you forgot to set your env or if your information is invalid, if this occurs in any other case, do let us know!
- **DeprecatedAPIException** is raised when there's either an HTTP 404, 405 or 410 error, this probably means that the version of Vandar Cashier (and the APIs behind it) used is no longer supported by Vandar, run `composer update`!
- **InvalidPayloadException** is raised when the attempted action was in any way invalid on Vandar's side raising an HTTP 422. (e.g. you're authorized to withdraw 1000 Toman and you attempt to withdraw more), We aim to break this down into more specific exceptions in the future.
- **TooManyRequestsException** is raised if you attempt to send a very large sum of requests to Vandar in a short period of time, causing an HTTP 429 error.
- **UnexpectedAPIErrorException** is raised when any other 4xx series error not in the scope of Vandar Cashier is returned. if this happens, consider updating Cashier or filing a bug with the full context of the exception you got.

License
=======

[](#license)

All material in this project (unless otherwise noted) are available under the MIT License. See LICENSE for more information.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7504d2dd62302fe03079daa3b37a7cb007d7d67d9aacdf8f5128282d4ab15fcc?d=identicon)[mdhesari](/maintainers/mdhesari)

---

Top Contributors

[![MikeMazalahi](https://avatars.githubusercontent.com/u/21097871?v=4)](https://github.com/MikeMazalahi "MikeMazalahi (4 commits)")[![Mdhesari](https://avatars.githubusercontent.com/u/28428724?v=4)](https://github.com/Mdhesari "Mdhesari (3 commits)")[![msalehipro](https://avatars.githubusercontent.com/u/5165298?v=4)](https://github.com/msalehipro "msalehipro (3 commits)")[![Mahdiazadbar](https://avatars.githubusercontent.com/u/11613106?v=4)](https://github.com/Mahdiazadbar "Mahdiazadbar (2 commits)")

### Embed Badge

![Health badge](/badges/mdhesari-cashier/health.svg)

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

###  Alternatives

[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-bundle)[xethron/laravel-4-generators

Rapidly generate resources, migrations, models, and much more.

972.8M10](/packages/xethron-laravel-4-generators)[timacdonald/has-parameters

A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.

228271.7k2](/packages/timacdonald-has-parameters)[cornernote/gii-modeldoc-generator

Gii ModelDoc Generator for Yii framework

13109.1k](/packages/cornernote-gii-modeldoc-generator)[vanthao03596/laravel-hanhchinhvn

hành chính việt nam laravel

406.3k](/packages/vanthao03596-laravel-hanhchinhvn)

PHPackages © 2026

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