定制 llabbasmkhll/laravel-zibal 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

llabbasmkhll/laravel-zibal

Composer 安装命令:

composer require llabbasmkhll/laravel-zibal

包简介

transaction request library for zibal

README 文档

README


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

<?php

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 - llabbasmkhll@gmail.com

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

llabbasmkhll/laravel-zibal 适用场景与选型建议

llabbasmkhll/laravel-zibal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 87 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 llabbasmkhll/laravel-zibal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 llabbasmkhll/laravel-zibal 我们能提供哪些服务?
定制开发 / 二次开发

基于 llabbasmkhll/laravel-zibal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 87
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-01