PHP code example of armezit / omnipay-jibit

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

    

armezit / omnipay-jibit example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Jibit');
$gateway->setApiKey('API_KEY');
$gateway->setSecretKey('SECRET_KEY');
$gateway->setReturnUrl('https://www.example.com/return');

// Send purchase request
$response = $gateway->purchase([
    'amount' => $amount,
    'currency' => $currency,
    'transactionId' => $transactionId, // referenceNumber in Jibit api doc
    'userId' => $userId, // userIdentifier in Jibit api doc
])->send();

// Process response
if ($response->isSuccessful() && $response->isRedirect()) {
    // store the order identifier to use in completePurchase()
    $orderIdentifier = $response->getTransactionReference();
    // Redirect to offsite payment gateway
    $response->redirect();
} else {
    // Payment failed: display message to customer
    echo $response->getMessage();
}

// Send purchase complete request
$response = $gateway->completePurchase([
    'transactionReference' => $orderIdentifier, 
])->send();

// Process response
if ($response->isPending()) {
    // In case of pending, you must inquiry the order later
    return;
}

if (!$response->isSuccessful() || $response->isCancelled()) {
    // Payment failed: display message to customer
    echo $response->getMessage();
} else {
    // Payment was successful
    print_r($response);
}

$response = $gateway->fetchTransaction([
    'transactionReference' => $orderIdentifier,
])->send();

if ($response->isPending()) {
    // In case of pending, you must inquiry the order later
    return;
}

if ($response->isCancelled()) {
    // Payment failed: display message to customer
    echo $response->getMessage();
} else if ($response->isSuccessful()) {
    // Payment was successful
    print_r($response);
}