• Stars
    star
    179
  • Rank 207,570 (Top 5 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created about 12 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenPayu SDK

Official OpenPayU PHP Library

The OpenPayU PHP library provides integration access to the REST API 2.1

Dependencies

PHP >= 5.3 with extensions cURL and hash

Documentation

Full implementation guide: English, Polish.

To process operations such as:

You will need to provide a parameter called orderId. The value of orderId is your order identifier that is set by PayU Payment system, and it's used to invoke remote methods.

There are two ways to get orderId:

  1. It is present inside the received notification message from PayU Payment System as a result of payment.
  2. In the response from method OpenPayU_Order::create.

In both cases you will find orderId using this statement: $response->getResponse()->orderId.

Installation

Composer

To install with Composer, simply add the requirement to your composer.json file:

{
  "require" : {
    "openpayu/openpayu" : "2.3.*"
  }
}

Then install by running

composer.phar install

Manual installation

Obtain the latest version of openpayu_php SDK with:

git clone https://github.com/PayU/openpayu_php.git

Getting started

If you are using Composer use autoload functionality:

include "vendor/autoload.php";

Or simply add this lines anywhere in your application:

    require_once 'lib/openpayu.php';
    require_once realpath(dirname(__FILE__)) . '/../../config.php';

Configure

Important: SDK works only with 'REST API' (Checkout) points of sales (POS). If you do not already have PayU merchant account, please register in Production or please register in Sandbox

Example "Configuration keys" from Merchant Panel

pos_configuration

To configure OpenPayU environment you must provide a set of mandatory data in config.php file.

For production environment:

    //set Production Environment
    OpenPayU_Configuration::setEnvironment('secure');

    //set POS ID and Second MD5 Key (from merchant admin panel)
    OpenPayU_Configuration::setMerchantPosId('145227');
    OpenPayU_Configuration::setSignatureKey('13a980d4f851f3d9a1cfc792fb1f5e50');

    //set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
    OpenPayU_Configuration::setOauthClientId('145227');
    OpenPayU_Configuration::setOauthClientSecret('12f071174cb7eb79d4aac5bc2f07563f');    

For sandbox environment:

    //set Sandbox Environment
    OpenPayU_Configuration::setEnvironment('sandbox');

    //set POS ID and Second MD5 Key (from merchant admin panel)
    OpenPayU_Configuration::setMerchantPosId('300046');
    OpenPayU_Configuration::setSignatureKey('0c017495773278c50c7b35434017b2ca');

    //set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
    OpenPayU_Configuration::setOauthClientId('300046');
    OpenPayU_Configuration::setOauthClientSecret('c8d4b7ac61758704f38ed5564d8c0ae0');

If you want to use sandbox environment, register at this link https://secure.snd.payu.com/cp/register?lang=en

OAuth configuration

SDK supports two PayU OAuth grant types: client_credentials and trusted_merchant. Default is client_credentials.

If you want to change grant type use:

    OpenPayU_Configuration::setOauthGrantType('grant_type');

grant_type can be one of the following OauthGrantType::CLIENT_CREDENTIAL or OauthGrantType::TRUSTED_MERCHANT

Parameters needed for client_credentials

    //set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
    OpenPayU_Configuration::setOauthClientId('300046');
    OpenPayU_Configuration::setOauthClientSecret('c8d4b7ac61758704f38ed5564d8c0ae0');

Parameters needed for trusted_merchant

    //set Oauth Client Id and Oauth Client Secret (from merchant admin panel)
    OpenPayU_Configuration::setOauthClientId('clent_id');
    OpenPayU_Configuration::setOauthClientSecret('clent_secret');

    //set Oauth Email and Oauth Ext Customer Id
    OpenPayU_Configuration::setOauthEmail('email');
    OpenPayU_Configuration::setOauthExtCustomerId('ext_customer_id');

Connection over Proxy

    OpenPayU_Configuration::setProxyHost('address');
    OpenPayU_Configuration::setProxyPort(8080);
    OpenPayU_Configuration::setProxyUser('user');
    OpenPayU_Configuration::setProxyPassword('password');

Cache

OpenPayU library automatically stores OAuth authentication data in the Cache.

OpenPayU library has two classes implemented to manage the Cache:

  • OauthCacheFile - data is stored in the file system. This is a default and automatic Cache method which stores the data in lib/Cache folder. ATTENTION: for security reasons it is recommended to change the Cache folder, so it would not be accessible from the web browser.

    Configuration:

    OpenPayU_Configuration::setOauthTokenCache(new OauthCacheFile($directory));

    $directory - absolute path to the data folder; if the parameter is missing, the folder is lib/Cache

  • OauthCacheMemcached - data is stored in Memcached This method requires Memcached (https://memcached.org/) to be installed on the server along with Memcached PHP module (http://php.net/manual/en/book.memcached.php)

    Configuration:

    OpenPayU_Configuration::setOauthTokenCache(new OauthCacheMemcached($host, $port, $weight));

    $host - Memcached server address - localhost by default $port - Memcached server port - 11211 by default $weight - Memcached server priority - 0 by default

It is possible to implement another method to manage cache. In such a case it needs to implement OauthCacheInterface

Usage

Remember: All keys in "order array" must be in lowercase.

Creating order using REST API

File with working example: examples/v2/order/OrderCreate.php

To create an order using REST API in back-end you must provide an Array with order data:

in your controller

    $order['continueUrl'] = 'http://localhost/'; //customer will be redirected to this page after successfull payment
    $order['notifyUrl'] = 'http://localhost/';
    $order['customerIp'] = $_SERVER['REMOTE_ADDR'];
    $order['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
    $order['description'] = 'New order';
    $order['currencyCode'] = 'PLN';
    $order['totalAmount'] = 3200;
    $order['extOrderId'] = '1342'; //must be unique!

    $order['products'][0]['name'] = 'Product1';
    $order['products'][0]['unitPrice'] = 1000;
    $order['products'][0]['quantity'] = 1;

    $order['products'][1]['name'] = 'Product2';
    $order['products'][1]['unitPrice'] = 2200;
    $order['products'][1]['quantity'] = 1;

    //optional section buyer
    $order['buyer']['email'] = '[email protected]';
    $order['buyer']['phone'] = '123123123';
    $order['buyer']['firstName'] = 'Jan';
    $order['buyer']['lastName'] = 'Kowalski';

    $response = OpenPayU_Order::create($order);

    header('Location:'.$response->getResponse()->redirectUri); //You must redirect your client to PayU payment summary page.

Retrieving order from OpenPayU

File with working example: examples/v2/order/OrderRetrieve.php

You can retrieve order by its PayU order_id

    $response = OpenPayU_Order::retrieve('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId

Retrieving transactions for order from OpenPayU

File with working example: examples/v2/order/OrderTransactionRetrieve.php

You can retrieve transactions for order by its PayU order_id

    $response = OpenPayU_Order::retrieveTransaction('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId

Cancelling order

File with working example: examples/v2/order/OrderCancel.php

You can cancel order by its PayU order_id

    $response = OpenPayU_Order::cancel('Z963D5JQR2230925GUEST000P01'); //as parameter use orderId

Updating order status

File with working example: examples/v2/order/OrderStatusUpdate.php

You can update order status to accept order.

    $status_update = array(
        "orderId" => 'Z963D5JQR2230925GUEST000P01', //as value use ORDER_ID
        "orderStatus" => 'COMPLETED'
    );

    $response = OpenPayU_Order::statusUpdate($status_update);

Handling notifications from PayU

File with working example: examples/v2/order/OrderNotify.php

PayU sends requests to your application when order status changes

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $body = file_get_contents('php://input');
        $data = trim($body);

        $response = OpenPayU_Order::consumeNotification($data);
        $response->getResponse()->order->status; //NEW PENDING CANCELED REJECTED COMPLETED WAITING_FOR_CONFIRMATION

        header("HTTP/1.1 200 OK");
    }

Refund money

File with working example: examples/v2/refund/RefundCreate.php

You can create refund to refund money on buyer account

    $refund = OpenPayU_Refund::create(
        'Z963D5JQR2230925GUEST000P01', //as a value use ORDER_ID
        'Money refund', //Description - required
        '100', //Amount - If not provided, returns whole transaction, optional
        'ext-customer-id', // External submerchant ID, required only for marketplace
        'ext-refund-id' // External refund ID, required only for marketplace
    );

Retrieving pay methods from POS

File with working example: examples/v2/retrieve/RetrievePaymethods.php

You can retrieve pay methods from POS

    $response = OpenPayU_Retrieve::payMethods();

You can add optional parameter lang to payMethods()

    $response = OpenPayU_Retrieve::payMethods('en');

Delete card token

File with working example: examples/v2/token/TokenDelete.php

You can delete user's card token.

Token deletion is possible only for trusted_merchant grant type.

    $refund = OpenPayU_Token::delete(
        'TOKC_EXAMPLE_TOKEN' // as a value use user card token
    );

Get Shop

File with working example: examples/v2/shops/Get.php

You can retrieve shop data.

    $shop = OpenPayU_Shop::get(
        'PUBLIC_SHOP_ID' // Shop ID from Merchant Panel
    );

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

More Repositories

1

plugin_prestashop

PayU plugin for PrestaShop 1.6 and 1.7
PHP
61
star
2

apple-pay

This library is used to decode tokens for Apple Pay.
PHP
48
star
3

woo-payu-payment-gateway

PayU Payment Gateway for WooCommerce
PHP
41
star
4

paytouch-android

37
star
5

alu-client-php

Automatic Live Update Client
PHP
25
star
6

plugin_magento

plugin for Magento version 1.6+
PHP
20
star
7

openpayu_ruby

Ruby
19
star
8

plugin_magento_2

Plugin for Magento versions: >2.0.6, 2.1, 2.2
PHP
18
star
9

paytouch-ios

PayTouch SDK for IOS
Objective-C
15
star
10

PayU-Flutter

Flutter package gives a set of Flutter mobile components for: pay-by-link, one-time card payments, storing card options, scanning card data, and one-click payments (Google Pay, Apple Pay, BLIK). Card is processed via PayU Backend and package sends request, but each merchant will receive card tokens in retrieve method(), so the card data does not go through merchant backend. User Interface in package can be adjusted to merchant branding/style guide.
Dart
11
star
11

plugin_magento_23

Plugin for Magento version 2.3
PHP
9
star
12

plugin_opencart

plugin for OpenCart 1.5.3.1
PHP
8
star
13

plugin_opencart_2

PayU Payment Gateway for OpenCart 2.x
PHP
7
star
14

payu-client-java

Example implementation for payu ro/tr/ru platform in java
Java
5
star
15

card-info-client-php

PHP
4
star
16

plugin_magento_24

Plugin for Magento version 2.4
PHP
4
star
17

plugin_opencart_3

PayU Payment Gateway for OpenCart 3.x
PHP
4
star
18

hessianphp

Exported from code.google.com/p/hessianphp
PHP
3
star
19

plugin_UA_RU_Webasyst

Paymet module for WebAsyst Shop Script (For PayU Ukraine and Russian ONLY)
PHP
3
star
20

plugin_UA_RU_WordPress_E-commerce

Payment module for WordPress E-commerce (For PayU Ukraine and Russian ONLY)
PHP
2
star
21

plugin_osc

PHP
2
star
22

plugin_UA_RU_OpenCart-1.5

Payment module for OpenCart ver. 1.5.x (For PayU Ukraine and Russian ONLY)
PHP
2
star
23

PayU-iOS

Objective-C
2
star
24

paytouch-windows

PayTouch SDK for Windows
C#
2
star
25

plugin_opencart_4

PayU Payment Gateway for OpenCart 4.x
PHP
1
star
26

plugin_UA_RU_Universal-payment-button

Universal payment button (For PayU Ukraine and Russian ONLY)
PHP
1
star
27

plugin_UA_RU_Bitrix

Payment module for 1C-Bitrix (For PayU Ukraine and Russian ONLY)
PHP
1
star
28

PayU-iOS-Swift

Swift
1
star
29

plugin_UA_RU_Joomla-1.5

Payment module for Joomla 1.5 Virtuemart 1.x (For PayU Ukraine and Russian ONLY)
PHP
1
star
30

SDK-Light-Android-Sample

Kotlin
1
star
31

openpayu_xsd_1_x

OpenPayU XSD Documents
1
star
32

plugin_UA_RU_Prestashop-1.4

Paymet module for Prestashop ver. 1.4.x (For PayU Ukraine and Russian ONLY)
PHP
1
star
33

plugin_UA_RU_Standart

Standart payment class (PHP) (For PayU Ukraine and Russian ONLY)
PHP
1
star
34

plugin_UA_RU_Shop-Script-Premium-1.24

Payment module for Shop-Script Premium ver. 1.24 (For PayU Ukraine and Russian ONLY)
PHP
1
star
35

fx-client-php

client library for https://secure.payu.ro/docs/fx/ API
PHP
1
star
36

plugin_UA_RU_ShopCMS

Payment module for ShopCMS (For PayU Ukraine and Russian ONLY)
PHP
1
star
37

plugin_UA_RU_Melbis

Payment module for Melbis (For PayU Ukraine and Russian ONLY)
PHP
1
star
38

plugin_UA_RU_Prestashop-1.3

Paymet module for Prestashop ver. 1.3.x (For PayU Ukraine and Russian ONLY)
PHP
1
star
39

card-storage-client-php

PHP
1
star
40

plugin_UA_RU_Magento

Paymet module for Magento 1.7 (For PayU Ukraine and Russian ONLY)
PHP
1
star