PHP code example of naimeken / omnipay-mobilexpress

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

    

naimeken / omnipay-mobilexpress example snippets




$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getAuthorizeParams();
    $response = $gateway->authorize($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'bankTransId' => $response->getTransactionReference(),
        'mobileExpressTransId' => $response->getMobilExpressTransId(),
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getCaptureParams();
    $response = $gateway->capture($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'bankTransId' => $response->getTransactionReference(),
        'mobileExpressTransId' => $response->getMobilExpressTransId(),
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getPurchaseParams();
    $response = $gateway->purchase($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'bankTransId' => $response->getTransactionReference(),
        'mobileExpressTransId' => $response->getMobilExpressTransId(),
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getPurchase3DParams();
    $response3d = $gateway->purchase($params)->send();

    $result = [
        'status' => $response3d->isSuccessful() ?: 0,
        'redirect' => $response3d->isRedirect() ?: 0,
        'redirectUrl' => $response3d->getRedirectUrl(),
        'redirectData' => $response3d->getRedirectData(),
        'redirectMethod' => $response3d->getRedirectMethod(),
        'mobileExpressTransId' => $response3d->getMobilExpressTransId(),
        'message' => $response3d->getMessage(),
        'requestParams' => $response3d->getServiceRequestParams(),
        'response' => $response3d->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getCompletePurchaseParams();
    $response = $gateway->completePurchase($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'bankTransId' => $response->getTransactionReference(),
        'mobileExpressTransId' => $response->getMobilExpressTransId(),
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getRefundParams();
    $response = $gateway->refund($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}



$loader = ('Examples\\', __DIR__);

use Omnipay\MobilExpress\Gateway;
use Examples\Helper;

$gateway = new Gateway();
$helper = new Helper();

try {
    $params = $helper->getVoidParams();
    $response = $gateway->void($params)->send();

    $result = [
        'status' => $response->isSuccessful() ?: 0,
        'redirect' => $response->isRedirect() ?: 0,
        'message' => $response->getMessage(),
        'requestParams' => $response->getServiceRequestParams(),
        'response' => $response->getData()
    ];

    print("<pre>" . print_r($result, true) . "</pre>");
} catch (Exception $e) {
    throw new \RuntimeException($e->getMessage());
}