PHP code example of rotassator / omnipay-payway-restapi

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

    

rotassator / omnipay-payway-restapi example snippets




xception;
use Omnipay\Common\CreditCard;
use Omnipay\Omnipay;

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

$gateway->setApiKeyPublic('REPLACE');
$gateway->setApiKeySecret('REPLACE');
$gateway->setMerchantId('REPLACE');
$gateway->setTestMode(true);

try {
    $response = $gateway->createSingleUseCardToken([
        'card' => new CreditCard([
            'firstName' => 'First Name',
            'lastName' => 'Last Name',
            'number' => '4564710000000004',
            'expiryMonth' => '02',
            'expiryYear' => '2019',
            'cvv' => '847',
        ]),
    ])->send();

    $singleUseTokenId = $response->getData('singleUseTokenId');

    if (empty($singleUseTokenId)) {
        // handle error
    }

    $request = $gateway->purchase([
        'singleUseTokenId' => $singleUseTokenId,
        'customerNumber' => 'AB1245',
        'principalAmount' => '10.00',
        'currency' => 'AUD',
        'orderNumber' => 12,
    ]);

    $response = $request->send();

    if ($response->isSuccessful()) {
        // update order
    }
} catch (Exception $e) {
    // handle error
}

// Example for creating single-use token with Bank Account
$response = $gateway->createSingleUseBankToken([
    'bankAccountBsb' => '999999',
    'bankAccountNumber' => '999999999',
    'bankAccountName' => 'Your Name',
])->send();

$singleUseTokenId = $response->getData('singleUseTokenId');

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

$gateway->setApiKeyPublic('REPLACE');
$gateway->setApiKeySecret('REPLACE');
$gateway->setMerchantId('REPLACE');
$gateway->setTestMode(true);

$gateway->setSSLCertificatePath('path/cacert.pem');