PHP code example of tohidplus / mellat

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

    

tohidplus / mellat example snippets


'providers' => [
    Tohidplus\Mellat\MellatServiceProvider::class,
];

'aliases' => [
   'Mellat' => Tohidplus\Mellat\Facades\Mellat::class,
];


return [
    'terminalId' => 'your-temrinalId',
    'username' => 'your-username',
    'password' => 'your-password',
    'callBackUrl' => 'http://yourwebsite.com/verifyPayment',
    'convertToRial' => true
];


protected $except = [
    '/verifyPayment'
];



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Tohidplus\Mellat\Facades\Mellat;

class PaymentController extends Controller
{
    public function redirectUserToBank()
    {

        //Mellat::setCallBackUrl(url('/verifyPayment'));

        Mellat::set(100);

        
        return Mellat::redirect(function($message){
            // Do something if there was a problem while redirection
            //dd($message);
        });
    }

    public function verifyPayment(Request $request)
    {
        return Mellat::verify(
        function ($log){
            // The transaction is successfull 
            //dd($log);   
        },function ($log){
            // The trasnsaction is unsuccessful
            //dd($log);
        });
    }
}




namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Tohidplus\Mellat\Models\MellatLog;

class MellatLogController extends Controller
{
    public function index()
    {
        $successfulTransactions = MellatLog::successful()->get();
        $unsuccessfulTransactions = MellatLog::unsuccessful()->get();
        $pendingTransactions = MellatLog::pending()->get();
    }
}

bash
php artisan vendor:publish --provider=Tohidplus\Mellat\MellatServiceProvider
bash
php artisan migrate