PHP code example of webtoucher / omnipay-payonline

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

    

webtoucher / omnipay-payonline example snippets


    $gateway = \Omnipay\Omnipay::create('PayOnline');
    $gateway->setMerchantId('[MERCHANT_ID]');
    $gateway->setApiKey('[API_PRIVATE_KEY]');
    $gateway->setLanguage('ru'); // default - en

    try {
        $request = $this->gateway->purchase([
            'order_id' => 123,
            'amount' => 10,
            'currency' => 'EUR',
            'description' => 'Test payment',
            'user' => 1234,
            'email' => '[email protected]',
            'return_url' => 'https://your.domain.com/your-callback/?result=1',
            'cancel_url' => 'https://your.domain.com/your-callback/?result=0',,
        ]);

        $response = $request->send();

        if ($response->isSuccessful()) {
            $url = $response->getUrl();
            // Use this url as iframe source or for redirect
        }
    } catch (\Omnipay\Common\Exception\OmnipayException $e) {
        // Your handler
    }

    if (/* is post request */) {
        try {
            $request = $this->gateway->completePurchase([
                'result' => $result,
                'datetime' => $DateTime,
                'transaction_id' => $TransactionID,
                'order_id' => $OrderId,
                'amount' => $Amount,
                'currency' => $Currency,
                'token' => $RebillAnchor,
                'card_number' => $CardNumber,
                'user' => $User,
                'error_code' => isset($Code) ? $Code : $ErrorCode,
            ]);

            $response = $request->send();

            $success = $response->isSuccessful();
        } catch (\Omnipay\Common\Exception\OmnipayException $e) {
            $success = false;
            // Your handler
        }
        // Your logic
    } else {
        // Your logic for return/fail URL
    }

    $cardNumber = $request->getCardNumber();
    $token = $request->getToken();
    // Your logic

    try {
        $request = $this->gateway->rebill([
            'token' => $token,
            'order_id' => 124,
            'amount' => 10,
            'currency' => 'EUR',
        ]);

        $response = $request->send();

        $success = $response->isSuccessful();
    } catch (\Omnipay\Common\Exception\OmnipayException $e) {
        $success = false;
        // Your handler
    }

$ php composer.phar