PHP code example of tcgunel / omnipay-ahlpay

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

    

tcgunel / omnipay-ahlpay example snippets


use Omnipay\Omnipay;

$gateway = Omnipay::create('Ahlpay');

$gateway->setMerchantId('100');           // Your member ID
$gateway->setMerchantUser('user@email'); // Login email
$gateway->setMerchantPassword('pass');    // Login password
$gateway->setMerchantStorekey('key');     // Store key for hash
$gateway->setToken('jwt-token');          // Auth token (obtained separately)
$gateway->setTokenType('Bearer');         // Token type
$gateway->setAhlpayMerchantId(5001);      // Ahlpay merchant ID (from token response)
$gateway->setTestMode(true);

$response = $gateway->purchase([
    'amount'      => '100.00',
    'currency'    => 'TRY',
    'transactionId' => 'ORDER-12345',
    'secure'      => false,
    'card'        => [
        'number'      => '4508034508034509',
        'expiryMonth' => '12',
        'expiryYear'  => '2030',
        'cvv'         => '000',
    ],
])->send();

if ($response->isSuccessful()) {
    echo 'Transaction ID: ' . $response->getTransactionReference();
} else {
    echo 'Error: ' . $response->getMessage();
}

$response = $gateway->purchase([
    'amount'      => '100.00',
    'currency'    => 'TRY',
    'transactionId' => 'ORDER-12345',
    'secure'      => true,
    'returnUrl'   => 'https://yoursite.com/payment/success',
    'cancelUrl'   => 'https://yoursite.com/payment/fail',
    'card'        => [
        'number'      => '4508034508034509',
        'expiryMonth' => '12',
        'expiryYear'  => '2030',
        'cvv'         => '000',
    ],
])->send();

if ($response->isRedirect()) {
    // Ahlpay returns HTML content for 3D redirect
    echo $response->getRedirectHtml();
}

$response = $gateway->completePurchase([
    'transactionId' => $_POST['orderId'],
    'rnd'           => $_POST['rnd'],  // optional
])->send();

if ($response->isSuccessful()) {
    echo 'Payment confirmed! Transaction: ' . $response->getTransactionReference();
} else {
    echo 'Payment failed: ' . $response->getMessage();
}

$response = $gateway->void([
    'orderNumber' => 'ORDER-12345',
    'currency'    => 'TRY',
])->send();

if ($response->isSuccessful()) {
    echo 'Transaction voided.';
} else {
    echo 'Error: ' . $response->getMessage();
}

$response = $gateway->refund([
    'orderNumber' => 'ORDER-12345',
    'amount'      => '50.00',
    'currency'    => 'TRY',
])->send();

if ($response->isSuccessful()) {
    echo 'Refund processed.';
} else {
    echo 'Error: ' . $response->getMessage();
}
bash
composer analyse