1. Go to this page and download the library: Download academe/omnipay-elavon 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/ */
academe / omnipay-elavon example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create('Elavon\Hpp');
$gateway->setMerchantAlias('your-merchant-alias');
$gateway->setApiKey('your-api-key');
$gateway->setRegion('eu'); // 'eu' or 'na'
$gateway->setTestMode(true); // Use sandbox environment
// Step 1: Create the authorization request
$response = $gateway->authorize([
'amount' => '10.00',
'currency' => 'USD',
'transactionId' => 'order-123',
'returnUrl' => 'https://example.com/payment/return',
'cancelUrl' => 'https://example.com/payment/cancel',
])->send();
// Step 2: Redirect to Elavon's hosted payment page
if ($response->isRedirect()) {
$response->redirect();
}
// Step 3: On return, verify the transaction
$response = $gateway->completeAuthorize([
'transactionReference' => $_GET['transaction'],
])->send();
if ($response->isSuccessful()) {
$transactionReference = $response->getTransactionReference();
// Store this reference to capture later
}
$response = $gateway->purchase([
'amount' => '10.00',
'currency' => 'USD',
'transactionId' => 'order-124',
'returnUrl' => 'https://example.com/payment/return',
'cancelUrl' => 'https://example.com/payment/cancel',
])->send();
if ($response->isRedirect()) {
$response->redirect();
}
// On return, the payment is already captured
$response->isSuccessful(); // Was the transaction successful?
$response->isRedirect(); // Does this er ID
$response->getMessage(); // Response message
$response->getCode(); // Response code