PHP code example of aqshah20 / mezpay

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

    

aqshah20 / mezpay example snippets


'providers' => [
    // Other service providers...
    MezPay\MezPayServiceProvider::class,
]

return [
    'username' => env('MEZPAY_USERNAME', ''),
    'password' => env('MEZPAY_PASSWORD', ''),
    'success_callback' => env('MEZPAY_SUCCESS_CALLBACK', ''),
    'failed_callback' => env('MEZPAY_FAILED_CALLBACK', ''),
];

return [
    'username' => env('MEZPAY_USERNAME', ''),
    'password' => env('MEZPAY_PASSWORD', ''),
    'success_callback' => env('MEZPAY_SUCCESS_CALLBACK', 'success'),
    'failed_callback' => env('MEZPAY_FAILED_CALLBACK', 'failed'),
];

use App\Http\Controllers\OrdersController;

Route::get('/success/{orderId?}', [OrdersController::class, 'orderSucceeded'])->name('success');
Route::get('/failed/{orderId?}', [OrdersController::class, 'orderFailed'])->name('failed');

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OrdersController extends Controller
{
    public function orderSucceeded(Request $request)
    {
        // Get the orderId from the URL parameter or any other source as needed
        $orderId = $request->orderId;

        // Perform actions for successful payment
        // For example, update order status, send notifications, etc.

        // You can also pass the $orderId to a view if needed
        return view('success', compact('orderId'));
    }

    public function orderFailed(Request $request)
    {
        // Get the orderId from the URL parameter or any other source as needed
        $orderId = $request->orderId;

        // Perform actions for failed payment
        // For example, update order status, send notifications, etc.

        // You can also pass the $orderId to a view if needed
        return view('failed', compact('orderId'));
    }
}


use MezPay\Facade\MezPayFacade;

$paymentGateway = MezPayFacade::registerOrder([
    'order_id' => 152,
    'currency' => 586, // 586 = PKR | 540 = USD
    'amount' => 2000,
]);

// Call getOrderStatus method with orderId
$response = MezPayFacade::getOrderStatus(152);

// Dump the response for debugging
dd($response);

array:17 [
  "errorCode" => "0"
  "errorMessage" => "Success"
  "orderNumber" => "152"
  "orderStatus" => 2
  "actionCode" => 0
  "actionCodeDescription" => "Request processed successfully"
  "amount" => 2000
  "currency" => "586"
  "date" => 1689879175356
  "ip" => "39.57.43.95"
  "merchantOrderParams" => array:3 [▶]
  "attributes" => array:1 [▶]
  "cardAuthInfo" => array:3 [▶]
  "authDateTime" => 1689879256478
  "terminalId" => "10007077"
  "authRefNum" => "000025936268"
  "fraudLevel" => 0
]
bash
php artisan vendor:publish --tag=config

php artisan vendor:publish --tag=mezpay-migrations --ansi

php artisan migrate