PHP code example of visualr / omnipay-tillpayments

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

    

visualr / omnipay-tillpayments example snippets


// Create a gateway
$gateway = Omnipay::create('TillPayments');

// Initialise the gateway
$gateway->initialize(array(
    'apiKey' => 'your-api-key',
    'secretKey' => 'your-secret-key',
    'username' => 'your-username',
    'password' => 'your-password',
    'testMode'  => TRUE, // or FALSE when you are ready for live transactions
    'defaultMerchantTransactionIdPrefix'  => 'omnipay-', // prefix of the merchantTransactionId (optional)
));

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->purchase([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->authorize([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->capture([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->purchase([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'returnUrl' => 'https://www.example.com/return', // optional
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->authorize([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'returnUrl' => 'https://www.example.com/return', // optional
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {

    $request = $gateway->capture([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {

    $request = $gateway->void([
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {

    // You need to define your own $formData array
    $card = new CreditCard($formData);

    $request = $gateway->createCard([
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {

    // You need to define your own $formData array
    $card = new CreditCard($formData);

    $request = $gateway->deleteCard([
        'referenceUuid' => 'ccf0ddd790db9d7ef41b',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

try {

    $request = $gateway->refund([
        'amount'                => '1.25',
        'currency'              => 'AUD',
        'referenceUuid'         => '48bbd15cdf9e5b81985d',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

$response = $gateway->purchase([
    'amount' => '10.00', 
    'currency' => 'AUD', 
    'card' => $card
])->send();

$response->isSuccessful(); // is the response successful?
$response->isRedirect(); // is the response a redirect?
$response->getTransactionReference(); // a transaction uuid generated by the payment gateway
$response->getMessage(); // a message generated by the payment gateway

$response = $gateway->purchase([
    'amount' => '10.00', 
    'currency' => 'AUD', 
    'card' => $card
])->send();

if ($response->isSuccessful()) {
    // payment is complete
} elseif ($response->isRedirect()) {
    $response->redirect(); // this will automatically forward the customer
} else {
    // not successful
}

$url = $response->getRedirectUrl();

try {

    $request = $gateway->refund([
        'amount'                => '1.25',
        'currency'              => 'AUD',
        'referenceUuid'         => '48bbd15cdf9e5b81985d',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here like marking order as complete

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}