PHP code example of andylibrian / omnipay-veritrans

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

    

andylibrian / omnipay-veritrans example snippets




mnipay\Omnipay;
use Omnipay\Common\CreditCard;

$gateway = Omnipay::create('Veritrans_VTWeb');
$gateway->setServerKey('server-key-replace-with-yours');
$gateway->setEnvironment('sandbox'); // [production|sandbox] default to production

$data = array(
    'transactionId' => '123456',
    'amount'        => '145000.00',
    'card'          => new CreditCard(),
    'vtwebConfiguration' => array(
        'credit_card_3d_secure' => true,
    ),  
    'currency'      => 'IDR',
);

$response = $gateway->purchase($data)->send();

if ($response->isSuccessful()) {
    // payment success, update database
    // using VT-Web, you will always get redirected to offsite (veritrans page)
    // so here won't be reached.
} elseif ($response->isRedirect()) {
    // redirect to offsite payment gateway
    $response->redirect();
} else {
    echo $response->getMessage();
}