wowpowhub/payu

PayU php api, how to create payu payment link in php.


License
MIT

Documentation

Payu php api

PayU php api, how to create payu payment link in php.

Install requirements

sudo apt install redis memcached php php-redis php-memcached php-json php-curl php-hash php-mbstring

Payu api

Php payu api

Payu token cache

Default payu api cache is Redis cache server

<?php
use Payu\Core\Cache;

// Change cache to dir cache
Cache::EnableDir();

// Change cache to memcached server cache
Cache::EnableMemcache();
?>

Php autoload, config

See in: example/init.php, example/config.php

require('vendor/autoload.php');

class Config
{
	const SANDBOX = true; // Or false for production
	const POS_ID = '';
	const MD5_KEY = '';
	const CLIENT_SECRET = '';
	const URL_CONTINUE = 'https://your.domain/example/notify/success.php';
	const URL_NOTIFY = 'https://your.domain/example/payment-notifications.php';
}

Payment link

How to create order and payment link

<?php
use Exception;
use Payu\Send\Auth;
use Payu\Send\Order;
use Payu\Core\OrderBuilder;

try
{
	// Shop unique order id
	$shop_id = 'SHOP-UNIQUE-ORDER-ID';
	// Token
	$token = Auth::Token(Config::POS_ID, Config::CLIENT_SECRET, Config::SANDBOX);

	$o = new OrderBuilder(Config::URL_CONTINUE, Config::URL_NOTIFY);
	$o->Create($shop_id, 12345, 'New order', 'PLN', Config::POS_ID, $_SERVER['REMOTE_ADDR']);
	$o->Product('Vibranium', 2315, 1);
	$o->Product('Galvanium', 10030, 1);
	$o->Buyer('client@email.here', '+48 100 200 300', 'FirstName', 'LastName', 'pl');
	$order = $o->Get();

	// Create payment link
	$res = Order::Create($order, $token, Config::SANDBOX);
	$p = Order::ParseCreate($res);

	if($p->statusCode == 'SUCCESS')
	{
		// Redirect client to this link
		echo $p->redirectUri;

		// Payu orderId it is: PAYU-ORDER-ID
		echo $p->orderId;

		// Your shop order id
		echo $p->extOrderId;
	}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

Retrive payment

How to accept payu payment (disable auto retrive in payu panel)

<?php
use Exception;
use Payu\Send\Auth;
use Payu\Send\Order;

try
{
	// Payu unique orderId
	$orderId = 'PAYU-ORDER-ID';
	$token = Auth::Token(Config::POS_ID, Config::CLIENT_SECRET, Config::SANDBOX);

	$res = Order::Retrive($orderId, $token, Config::SANDBOX);
	$p = Order::ParseRetrive($res);

	if($p->statusCode == 'SUCCESS')
	{
		echo "Order has been retrived !!!";
	}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

Cancel payment

How to cancel payu payment (disable auto retrive in payu panel)

<?php
use Exception;
use Payu\Send\Auth;
use Payu\Send\Order;

try
{
	// Payu unique orderId
	$orderId = 'PAYU-ORDER-ID';
	$token = Auth::Token(Config::POS_ID, Config::CLIENT_SECRET, Config::SANDBOX);

	$res = Order::Cancel($orderId, $token, Config::SANDBOX);
	$p = Order::ParseCancel($res);

	if($p->statusCode == 'SUCCESS')
	{
		echo "Order has been canceled !!!";
	}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

Refund payment

How to refund payu payment

<?php
use Exception;
use Payu\Send\Auth;
use Payu\Send\Order;

try
{
	// Payu unique orderId
	$orderId = 'PAYU-ORDER-ID';
	$token = Auth::Token(Config::POS_ID, Config::CLIENT_SECRET, Config::SANDBOX);

	$res = Order::Refund($orderId, 0, $token, Config::SANDBOX);
	$p = Order::ParseRefund($res);

	if($p->statusCode == 'SUCCESS')
	{
		echo "Order has been refunded !!!";
	}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

Payment status

How to get payu payment status (details)

<?php
use Exception;
use Payu\Send\Auth;
use Payu\Send\Order;

try
{
	// Payu unique orderId
	$orderId = 'PAYU-ORDER-ID';
	$token = Auth::Token(Config::POS_ID, Config::CLIENT_SECRET, Config::SANDBOX);

	$res = Order::Status($orderId, $token, Config::SANDBOX);
	$p = Order::ParseStatus($res);

	if($p->statusCode == 'SUCCESS')
	{
		foreach ($p->orders as $o)
		{
			print_r($o);
		}
	}
}
catch(Exception $e)
{
	echo $e->getMessage();
}

Secure vendor in nginx

Restricting directory access to vendor and .cache directory

location ~ /(Cache|cache|.cache|vendor|.git) {
	deny all;
	return 403;
}

Examples

See in directory

  • Samples in directory: example