lzaplata/payu

There is no license information available for the latest version (dev-master) of this package.

PayU wrapper for Nette Framework.

dev-master 2018-02-05 08:31 UTC

This package is auto-updated.

Last update: 2024-03-25 06:19:26 UTC


README

This is small Nette Framework wrapper for PayU gateway.

Installation

The easiest way to install library is via Composer.

$ composer require lzaplata/payu: dev-master

or edit composer.json in your project

"require": {
        "lzaplata/payu": "dev-master"
}

You have to register the library as extension in config.neon file.

extensions:
        payu: LZaplata\PayU\DI\Extension

Now you can set parameters...

payu:
        posId           : *
        clientId        : *
        clientSecret    : *
        key2            : *
        sandbox         : true

...and autowire library to presenter

use LZaplata\PayU\Service;

/** @var Service @inject */
public $payu;

Usage

In first step you must create order instantion.

$order = $this->payu->createOrder([
        "description" => $description,          
        "currencyCode" => $currency,            
        "totalAmount" => $price,                    // order price in lowest currency unit (1 CZK = 100)
        "extOrderId" => $id,                        // eshop unique id
        "notifyUrl" => $notifyUrl,                  // url form sending notifications from PayU  
        "continueUrl" => $continueUrl,              // url to redirect after successful payment     
        "products" => [
                0 => [
                        "name" => $productName,
                        "unitPrice" => $unitPrice,  // product price in lowest currency unit (1 CZK = 100)
                        "quantity" => $quantity
                ]
        ],
        "buyer" => [
                "email" => $email,
                "phone" => $phone,
                "firstName" => $name,
                "lastName" => $surname
        ]
]);

Second step decides if creating order is successful...

try {
        $response = $this->payu->pay($order);
} catch (\OpenPayU_Exception $e) {
        print $e->getMessage();
}

...and finally you can redirect to gateway.

$this->sendResponse($response);