Download the PHP package vandarpay/cashier without Composer
On this page you can find all versions of the php package vandarpay/cashier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vandarpay/cashier
More information about vandarpay/cashier
Files in vandarpay/cashier
Package cashier
Short Description Official Vander package for easier access to Vander documents
License MIT
Informations about the package cashier
Vandar Cashier
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
To use Vandar Cashier, you need to install it through Composer first:
Then, you will need to publish the package's assets and migrate your project's database to add Vandar Cashier's tables:
After that, open your User model (located in app/User.php
or app/Models/User.php
in most projects) and add
the Billable
trait:
You will need to add the necessary configuration to your .env
file:
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
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
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.
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:
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:
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
When setting up direct-debit, you have two main steps to take.
- Get user to allow for access to their account (also known as a Mandate)
- Request a withdrawal from a user's account
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:
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:
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:
You can also revoke any mandates through the Mandate model's revoke function:
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
Once the mandate has been created successfully, you may create a withdrawal through the mandate:
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:
Settlement
Vandar Cashier provides the ability to make requests for settlements:
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:
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
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:
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
All material in this project (unless otherwise noted) are available under the MIT License. See LICENSE for more information.
All versions of cashier with dependencies
guzzlehttp/guzzle Version ^6.3.1|^7.0.1
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/database Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/routing Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/http Version ^6.0|^7.0|^8.0|^9.0|^10.0
ext-json Version *