PHP code example of tcgunel / omnipay-nestpay

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


use Omnipay\Omnipay;
use Omnipay\Nestpay\Constants\Bank;

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

$gateway->setBank(Bank::AKBANK);
$gateway->setMerchantUser('your_api_user');
$gateway->setMerchantPassword('your_api_password');
$gateway->setMerchantId('your_client_id');
$gateway->setMerchantStorekey('your_store_key'); // Required for 3D Secure
$gateway->setTestMode(true); // Use test endpoints

$response = $gateway->purchase([
    'amount' => '100.00',
    'currency' => 'TRY',
    'transactionId' => 'ORDER-12345',
    'installment' => '1',
    'secure' => false,
    'card' => [
        'number' => '4355084355084358',
        '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',
    'installment' => '1',
    'secure' => true,
    'returnUrl' => 'https://yoursite.com/payment/success',
    'cancelUrl' => 'https://yoursite.com/payment/fail',
    'card' => [
        'number' => '4355084355084358',
        'expiryMonth' => '12',
        'expiryYear' => '2030',
        'cvv' => '000',
    ],
])->send();

if ($response->isRedirect()) {
    $response->redirect(); // Redirects to bank 3D Secure page
}

$response = $gateway->completePurchase([
    'amount' => '100.00',
    'currency' => 'TRY',
    'transactionId' => 'ORDER-12345',
    'md' => $_POST['md'],
    'xid' => $_POST['xid'],
    'eci' => $_POST['eci'],
    'cavv' => $_POST['cavv'],
    'mdStatus' => $_POST['mdStatus'],
])->send();

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

$response = $gateway->void([
    'transactionReference' => '22302MsqJ11025',
])->send();

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

$response = $gateway->refund([
    'transactionReference' => '22302MsqJ11025',
    'amount' => '50.00',
    'currency' => 'TRY',
])->send();

if ($response->isSuccessful()) {
    echo 'Refund processed.';
}

$response = $gateway->fetchTransaction([
    'orderId' => 'ORDER-12345',
])->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
    echo 'Order status retrieved.';
}
bash
composer analyse