PHPackages                             openpayu/openpayu\_php\_sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. openpayu/openpayu\_php\_sdk

ActiveLibrary

openpayu/openpayu\_php\_sdk
===========================

OpenPayU PHP Library

2.3.6(2y ago)187244.6k↓25.4%84[10 issues](https://github.com/PayU/openpayu_php/issues)[3 PRs](https://github.com/PayU/openpayu_php/pulls)6apache-2.0PHPPHP &gt;=5.5.19 | &gt;=5.6.3CI failing

Since Apr 2Pushed 2y ago51 watchersCompare

[ Source](https://github.com/PayU/openpayu_php)[ Packagist](https://packagist.org/packages/openpayu/openpayu_php_sdk)[ RSS](/packages/openpayu-openpayu-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (38)Used By (6)

Official OpenPayU PHP Library
=============================

[](#official-openpayu-php-library)

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

Dependencies
------------

[](#dependencies)

PHP &gt;= 5.3 with extensions [cURL](http://php.net/manual/en/book.curl.php) and [hash](http://php.net/manual/en/book.hash.php)

Documentation
-------------

[](#documentation)

Full implementation guide: [English](http://developers.payu.com/en/), [Polish](http://developers.payu.com/pl/).

To process operations such as:

- [order status update](examples/v2/order/OrderStatusUpdate.php)
- [order retrieve](examples/v2/order/OrderRetrieve.php)
- [order cancel](examples/v2/order/OrderCancel.php)

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
------------

[](#installation)

### Composer

[](#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

[](#manual-installation)

Obtain the latest version of openpayu\_php SDK with:

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

Getting started
---------------

[](#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
---------

[](#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**](https://www.payu.pl/en/commercial-offer) or [**please register in Sandbox**](https://secure.snd.payu.com/boarding/#/form&pk_campaign=Plugin-Github&pk_kwd=SDK)

Example "Configuration keys" from Merchant Panel

[![pos_configuration](readme_images/pos_configuration.png)](readme_images/pos_configuration.png)

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

OAuth configuration
-------------------

[](#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
---------------------

[](#connection-over-proxy)

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

Cache
-----

[](#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 () to be installed on the server along with Memcached PHP module ()

    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
-----

[](#usage)

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

### Creating order using REST API

[](#creating-order-using-rest-api)

File with working example: [examples/v2/order/OrderCreate.php](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'] = 'dd@ddd.pl';
    $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

[](#retrieving-order-from-openpayu)

File with working example: [examples/v2/order/OrderRetrieve.php](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

[](#retrieving-transactions-for-order-from-openpayu)

File with working example: [examples/v2/order/OrderTransactionRetrieve.php](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

[](#cancelling-order)

File with working example: [examples/v2/order/OrderCancel.php](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

[](#updating-order-status)

File with working example: [examples/v2/order/OrderStatusUpdate.php](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

[](#handling-notifications-from-payu)

File with working example: [examples/v2/order/OrderNotify.php](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

[](#refund-money)

File with working example: [examples/v2/refund/RefundCreate.php](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

[](#retrieving-pay-methods-from-pos)

File with working example: [examples/v2/retrieve/RetrievePaymethods.php](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

[](#delete-card-token)

File with working example: [examples/v2/token/TokenDelete.php](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

[](#get-shop)

File with working example: [examples/v2/shops/Get.php](examples/v2/shops/Get.php)

You can retrieve shop data.

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

Contributing
------------

[](#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

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community39

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~97 days

Recently: every ~161 days

Total

36

Last Release

1027d ago

PHP version history (3 changes)2.0PHP &gt;=5.2.1

2.2.0PHP &gt;=5.3.0

2.3.4PHP &gt;=5.5.19 | &gt;=5.6.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/742606eed947fa5901c0a42a19885bc8802c7e93d1d714bb5b4dca73bf8c3797?d=identicon)[athlan](/maintainers/athlan)

---

Top Contributors

[![regdos](https://avatars.githubusercontent.com/u/4245011?v=4)](https://github.com/regdos "regdos (91 commits)")[![agnagna](https://avatars.githubusercontent.com/u/7677033?v=4)](https://github.com/agnagna "agnagna (37 commits)")[![openpayu](https://avatars.githubusercontent.com/u/1412550?v=4)](https://github.com/openpayu "openpayu (17 commits)")[![gniewkoo](https://avatars.githubusercontent.com/u/1536812?v=4)](https://github.com/gniewkoo "gniewkoo (10 commits)")[![bigbookpl](https://avatars.githubusercontent.com/u/6040260?v=4)](https://github.com/bigbookpl "bigbookpl (9 commits)")[![tomasz-regdos-payu-gpo](https://avatars.githubusercontent.com/u/216694454?v=4)](https://github.com/tomasz-regdos-payu-gpo "tomasz-regdos-payu-gpo (5 commits)")[![jkondratowicz](https://avatars.githubusercontent.com/u/3799879?v=4)](https://github.com/jkondratowicz "jkondratowicz (4 commits)")[![Maks3w](https://avatars.githubusercontent.com/u/1301698?v=4)](https://github.com/Maks3w "Maks3w (3 commits)")[![piotrpyznarski](https://avatars.githubusercontent.com/u/6533793?v=4)](https://github.com/piotrpyznarski "piotrpyznarski (2 commits)")[![piotrbelina](https://avatars.githubusercontent.com/u/1667676?v=4)](https://github.com/piotrbelina "piotrbelina (2 commits)")[![turneliusz](https://avatars.githubusercontent.com/u/624797?v=4)](https://github.com/turneliusz "turneliusz (2 commits)")[![gabriel-woronowicz-payu-gpo](https://avatars.githubusercontent.com/u/41322012?v=4)](https://github.com/gabriel-woronowicz-payu-gpo "gabriel-woronowicz-payu-gpo (2 commits)")[![stawip](https://avatars.githubusercontent.com/u/173826?v=4)](https://github.com/stawip "stawip (1 commits)")[![trbolat](https://avatars.githubusercontent.com/u/7612146?v=4)](https://github.com/trbolat "trbolat (1 commits)")[![vojtasvoboda](https://avatars.githubusercontent.com/u/374917?v=4)](https://github.com/vojtasvoboda "vojtasvoboda (1 commits)")[![wojciechgabrys](https://avatars.githubusercontent.com/u/153263?v=4)](https://github.com/wojciechgabrys "wojciechgabrys (1 commits)")[![ChieftainY2k](https://avatars.githubusercontent.com/u/968529?v=4)](https://github.com/ChieftainY2k "ChieftainY2k (1 commits)")[![dzus](https://avatars.githubusercontent.com/u/7983114?v=4)](https://github.com/dzus "dzus (1 commits)")[![Emstawicki](https://avatars.githubusercontent.com/u/19185866?v=4)](https://github.com/Emstawicki "Emstawicki (1 commits)")[![krowinski](https://avatars.githubusercontent.com/u/1478555?v=4)](https://github.com/krowinski "krowinski (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/openpayu-openpayu-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/openpayu-openpayu-php-sdk/health.svg)](https://phpackages.com/packages/openpayu-openpayu-php-sdk)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
