PHP code example of sylapi / omnipay-payu

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

    

sylapi / omnipay-payu example snippets


$gateway = \Omnipay\Omnipay::create('PayU');  
$gateway->setPosId('--Merchant Pos Id--');
$gateway->setClientSecret('--Client Secret--');
$gateway->setSecondKey('--Second key--');
$gateway->setIp('--IP--');

$response = $gateway->purchase(
    [
        "amount" => "10.00",
        "currency" => "PLN",
        "description" => "My Payment",
        "transactionId" => "12345",
        "email" => "[email protected]",
        "name" => "Jan Kowalski",
        "payMethod" => "m",
        "items" => [
            [
                "name" => "Product name",
                "price" => "10.00",
                "quantity" => 1
            ]
        ],
        "returnUrl" => "https://example.org/payu-success.php",
        "cancelUrl" => "https://example.org/payu-error.php",
        "notifyUrl" => "https://example.org/payu-callback.php",
    ]
)->send();

// Process response
if ($response->isSuccessful()) {

    if ($response->isRedirect()) {
        $response->redirect();
    }
    else {
        $data = $response->getData();
    }
} 
else {
    $error = $response->getMessage();
    $code = $response->getCode();
}

$response = $gateway->completePurchaseNotify($_POST);

if ($response->isSuccessful()) {

    $message = $response->getMessage();
    $status = $response->getStatus();
}
else {
    $error = $response->getMessage();
    $code = $response->getCode();
}