PHP code example of akcybex / laravel-jazzcash

1. Go to this page and download the library: Download akcybex/laravel-jazzcash 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/ */

    

akcybex / laravel-jazzcash example snippets


// ...

// Get request data after validation while submitting checkout
$i = $request->all();

// will return form fields
$data = \AKCybex\JazzCash\Facades\JazzCash::request()->setAmount($i['amount'])->toArray($i);

// ...

{{-- ... --}}

@php
    $jazzcash_environment = config('jazzcash.environment');
@endphp
<form name="redirect-to-payment-gateway" method="POST" action="{{ config("jazzcash.$jazzcash_environment.endpoint") }}">
    @foreach($data as $key => $value)
        <input type="hidden" name="{{ $key }}" value="{{ $value }}">
    @endforeach
</form>
<script>
    setTimeout(function () {
        document.forms['redirect-to-payment-gateway'].submit();
    }, 1000);
</script>

{{-- ... --}}


// ...

Route::post('/jazzcash/payment', function (\Illuminate\Http\Request $request, $gateway) {
    $jazzcash = \AKCybex\JazzCash\Facades\JazzCash::response();
    if ($jazzcash->code() == 000) {
        // Checkout form details you can get here
        $order = $jazzcash->order();
        
        // ...
    } else {
        $error = $jazzcash->message();
        // ...
    }

});

// ...

php artisan migrate