PHP code example of llabbasmkhll / laravel-zibal

1. Go to this page and download the library: Download llabbasmkhll/laravel-zibal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

llabbasmkhll / laravel-zibal example snippets


   return [
         'merchant' => 'zibal',
   ];
   

use Llabbasmkhll\LaravelZibal\Facades\Zibal;



Zibal::init(
    1000000,            //ack        - 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();




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


   Zibal::redirect($trackId);
   

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

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




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');
    }

}

sh
   php artisan vendor:publish