laravel zibal - transaction request package for zibal

Overview


Logo Logo

laravel zibal

transaction request package for zibal

Getting Started

To get a local copy up and running follow these simple steps.

Installation

  1. You can install the package via composer:
    composer require llabbasmkhll/laravel-zibal 

note that you only need to do following steps if you want to change merchant id . if you only want to test the webservice , no need to do these steps

  1. publish config file to your project
    php artisan vendor:publish
  2. change merchant value to your merchant id in config/zibal.php ( use zibal for testing )
    return [
          'merchant' => 'zibal',
    ];


Usage

first include package facade into your file by :

use Llabbasmkhll\LaravelZibal\Facades\Zibal;

according to zibals official documentation there is 3 steps to issue a transaction in zibal

1 . Request :

in this step zibal gets basic information about the transaction and returns trackId that is needed for next step

use this to init the transaction request :

Zibal::init(
    1000000,            //required amount          - in rial
    'redirect',         //required callback        - can be either route name or a valid url starting with http or https
    ['key' => 'value'], //optional callback_params - will be passed to callback as query params , works only when route name passed to callback
    'description',      //optional description     - additional data , good for various reports
    123,                //optional orderId         - id of clients order (eg $invoice->id) , will be passed back to callback
    '09366217515',      //optional mobile          - clients mobile number
    ['000000000000']    //optional allowedCards    - array of allowed card numbers
)->getResponse();

this will return an array consist of result , message and trackId

result represents the request status as below.

status meaning
100 successful operation
102 merchant not found
103 merchant not active
104 merchant not valid
201 processed before
105 amount must be grater than 1000
106 callbackUrl is not valid
113 amount greater than maximum

you can add validate() function after init like below :

Zibal::init( $amount, 'redirect')->validate(404)->getResponse();

this will redirect the user to 404 page if the result code was anything except 100.


2 . Start :

redirect the user to zibals gateway for payment use :

Zibal::redirect($trackId);

you may combine first and second step into one line of code like this :

Zibal::init( $amount, 'redirect')->validate()->redirect();

that will init the transaction , then redirect the user zibals payment page if init was successful , otherwise it will redirect the user to 422 page


3 . Verify :

you can use this line of code to verify the transaction status:

Zibal::verify($trackId)->validate()->getResponse();

this will return an array consist of below parameters

parameter discription
paidAt datetime of the payment
cardNumber masked card number that used to pay
status status of the payment (discribed below)
amount amount of the payment
refNumber payment reference number (in case of successful operation)
description description of the payment
orderId the same id that you passed in init
result result of the request
message short description of the request

result represents the request status as below.

code meaning
100 successful operation
102 merchant not found
103 merchant not active
104 merchant not valid
201 processed before
202 payment failed (reason in status)
203 invalid trackId

status represents the request status as below.

status meaning
-2 internal failure
-1 wating for payment
1 paid - verified
2 paid - unverified
3 canceled by user
4 invalid card number
5 not enough balance
6 invalid code
7 maximum request length reached
8 maximum daily online payment number reached
9 maximum daily online payment amount reached
10 invalid card issuer
11 switch error
12 card unreachable


Example Controller



namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Invoice;
use Illuminate\Http\Request;
use Llabbasmkhll\LaravelZibal\Facades\Zibal;

class GatewayController extends Controller
{

    /**
     * redirect user to zibal.
     *
     * @param  \Illuminate\Http\Request  $request
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function show(Request $request)
    {
        $invoice = Invoice::find($request->input('invoice'));
        $user    = $invoice->user()->first();


        return Zibal::init(
            $invoice->amount,
            'redirect',
            [],
            $user->id,
            $invoice->id,
            $user->mobile,
        )->validate()->redirect();
    }


    /**
     * validate the transaction.
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function index(Request $request)
    {
        abort_unless($request->has('trackId'), 422);

        $response = Zibal::verify($request->input('trackId'))->getResponse();

        if ($response['result'] == 100) {
            $invoice = Invoice::find($response['orderId']);
            $invoice->update(
                [
                    'status'       => 1,
                    'bank_code'    => $response['refNumber'],
                    'finalized_at' => now(),
                ]
            );
        }

        return redirect('panel');
    }

}


Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.



License

Distributed under the MIT License. See LICENSE for more information.



Contact

Abbas mkhzomi - Telegram@llabbasmkhll - [email protected]

Project Link: https://github.com/llabbasmkhll/laravel-zibal

You might also like...
This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT.

This is a solution implementation for the coderbyte question, CLEAN GET REQUEST RESULT. Two solutions are proposed, the first is a brute force approach while the other is an improved time complexity solution.

PHP Simple Response, XML, JSON,... auto response with accept in request's header

simple-response Simple package to handle response properly in your API. This package does not include any dependency. Install Via Composer $ composer

Symfony bundle that provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications

CSRF Cookie Bundle This Symfony bundle provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications requesting endpoints

Simple solution for form request validation on lumen.

Form Request Validation for Lumen This small package contains a laravel-like solution for request form validation. Contents Form Request Validation fo

Livewire trait (throttling). Limiting request processing speed

Livewire Throttling Installation You can install the package via composer: composer require f1uder/livewire-throttling Usage Livewire component ?php

Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

A Laravel chat package. You can use this package to create a chat/messaging Laravel application.
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

This package provides extended support for our spatie/enum package in Laravel.
This package provides extended support for our spatie/enum package in Laravel.

Laravel support for spatie/enum This package provides extended support for our spatie/enum package in Laravel. Installation You can install the packag

Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Releases(v1.0.0)
Owner
Abbas mkhzomi
Freelance PHP & Laravel developer . born to code
Abbas mkhzomi
Transaction-aware Event Dispatcher for Laravel

Transaction-aware Event Dispatcher for Laravel This Laravel package introduces Transaction-aware Event Dispatcher. It ensures the events dispatched wi

Francisco Neves 299 Nov 29, 2022
Add eloquent model events fired after a transaction is committed or rolled back

Laravel Transactional Model Events Add transactional events to your eloquent models. Will automatically detect changes in your models within a transac

Mark van Duijker 62 Dec 22, 2022
This package can use form request just as Laravel do.

Lumen Form Request This package can use form request just as Laravel do. Installation Install by composer $ composer require chhw/form-request In

null 2 Nov 17, 2021
đź––Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any kind of filters.

Repository Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any

Awes.io 160 Dec 26, 2022
Laravel Logable is a simple way to log http request in your Laravel application.

Laravel Logable is a simple way to log http request in your Laravel application. Requirements php >= 7.4 Laravel version >= 6.0 Installation composer

Sagar 6 Aug 25, 2022
Easily capture every incoming request and the corresponding outgoing response in your Laravel app.

Easily capture every incoming request and the corresponding outgoing response in your Laravel app. This package is designed to work only with the Lara

Mark Townsend 22 Nov 15, 2022
Generate GitHub pull request preview deployments with Laravel Forge

Forge Previewer WARNING: This package is not ready for production usage. Use at your own risk. This package provides a forge-previewer command that ca

Ryan Chandler 43 Dec 15, 2022
Easy way to upload Laravel model related files from the request.

Easy way to upload laravel model related file from the requset.

Emon Khan 5 Dec 15, 2022
Easily validate data attributes through a remote request

Laravel Remote Rule Easily validate data attributes through a remote request. This package allows you to define a subset of custom rules to validate a

H-FARM Innovation 27 Nov 20, 2022
Filter resources with request parameters

FilterWhere Filter resources with request parameters Author: Thomas Jakobi [email protected] License: GNU GPLv2 Features With this MODX Revolu

Thomas Jakobi 1 Jul 12, 2022