PHPackages                             barion/barion-web-php - 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. [API Development](/categories/api)
4. /
5. barion/barion-web-php

ActiveLibrary[API Development](/categories/api)

barion/barion-web-php
=====================

PHP libary for Barion Smart Gateway API integration

v2.1.0(6mo ago)5033.2k↑122.6%44[4 PRs](https://github.com/barion/barion-web-php/pulls)1Apache-2.0PHPPHP &gt;=8.2

Since May 25Pushed 6mo ago13 watchersCompare

[ Source](https://github.com/barion/barion-web-php)[ Packagist](https://packagist.org/packages/barion/barion-web-php)[ RSS](/packages/barion-barion-web-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (10)Used By (1)

Barion Web PHP Library
======================

[](#barion-web-php-library)

[![version](https://camo.githubusercontent.com/dd1b51eac051b316a3173585bc64d36e19fa2d4e90a4581734cc292c175130f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d322e302e302d626c75652e737667)](https://packagist.org/packages/barion/barion-web-php) [![Total Downloads](https://camo.githubusercontent.com/2233be756d169aa20168d413037a13229e8e36853bcbed48d9d9db042b8847f2/68747470733a2f2f706f7365722e707567782e6f72672f626172696f6e2f626172696f6e2d7765622d7068702f646f776e6c6f6164732e737667)](https://packagist.org/packages/barion/barion-web-php) [![License](https://camo.githubusercontent.com/f9a62593b1972b10b88ad342b5c9bae7261f0a7e6fe4cc94e722948d7ea4b978/68747470733a2f2f706f7365722e707567782e6f72672f626172696f6e2f626172696f6e2d7765622d7068702f6c6963656e73652e737667)](https://packagist.org/packages/barion/barion-web-php)

A compact PHP library to manage online e-money and card payments via the *Barion Smart Gateway*.
It allows you to accept credit card, e-money, and wire transfer payments in just a few lines of code.

This library will help you

- Start an online payment easily in various scenarios (immediate payment, reservation/escrow, delayed capture, third-party payments, recurring/token payment etc.)
- Get details about a given payment
- Finish an ongoing reservation payment completely or partially, with automatic refund support
- Refund a completed payment transaction completely or partially

All with just a few simple pieces of code!

System requirements
===================

[](#system-requirements)

- PHP 8.2 or higher
- cURL module enabled (at least v7.18.1)
- SSL enabled (systems using OpenSSL with the version of 0.9.8f at least)

Legacy version support
----------------------

[](#legacy-version-support)

If you are using PHP versions 8.1 or lower, download our library version [1.4.11](https://github.com/Adyen/adyen-php-api-library/releases/tag/1.4.11).
Please note that the use of End-Of-Support and End-Of-Life software during integration is highly discouraged.

Supported API versions
======================

[](#supported-api-versions)

BarionClient methodEndpoint descriptionCurrent API versionPreparePaymentPrepares a new payment in the Barion system**v2**PaymentStateRequests the full current state of a payment**v4**FinishReservationFinishes a previously reserved Reservation payment**v2**CaptureCaptures the final amount of a Delayed Capture payment**v2**CancelAuthorizationCancels the authorization on a Delayed Capture payment**v2**Complete3DSPaymentCompletes a previously 3D-Secure authenticated payment**v2**RefundPaymentRefunds a previously completed payment**v2***GetPaymentState**Requests the full current state of a payment (deprecated)****v2****GetPaymentQRImage**Requests a QR code image for a payment (deprecated)****v1***Installation
============

[](#installation)

Composer
--------

[](#composer)

You can install the library via [Composer](http://getcomposer.org/). Run the following command:

```
composer require barion/barion-web-php

```

Then generate the necessary [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading) files using Composer.
The library automatically detects Composer-generated autoload files and uses them for autoloading.

Manual installation
-------------------

[](#manual-installation)

If you do not wish to use Composer, just copy the contents of the **barion** library into the desired folder.
The library will use its own autoloading mechanism if no Composer-generated files are detected.

> **Note**
> Be sure to set the necessary access to the path when running your PHP script.

Basic usage
===========

[](#basic-usage)

Include the **BarionClient** class in your PHP script:

```
require_once 'library/BarionClient.php';
```

> **Note**
> BarionClient will autoload everything for you, regardless of whether you used Composer ot not.

Then instantiate a Barion client. To achieve this, you must supply three key parameters:

1\. The secret key of the online store registered in Barion (called *POSKey*)

```
$myPosKey = "9c165cfccbd1452f830721a3a9cee664";
```

2\. The target Barion API version number (2 by default)

```
$apiVersion = 2;
```

3\. The environment to connect to. This can be the test/sandbox system, or the production environment.

```
// Test environment
$environment = \Barion\Enumerations\BarionEnvironment::Test;

// Production environment
$environment = \Barion\Enumerations\BarionEnvironment::Prod;
```

With these parameters you can create an instance of the **BarionClient** class:

```
$BC = new \Barion\BarionClient(
    poskey: $myPosKey,
    version: $apiVersion,
    env: $environment,
    useBundledRootCerts: false
);
```

> **Note**
> Only set `useBundledRootCerts` to `true` as a last resort if you are having SSL connection problems. It is your own responsibility to use up-to-date software that includes the latest international trusted CA certificate chains. The authors take no responsibility for loss of service resulting from the use of the certificate chain bundled with the library.

Base flow
=========

[](#base-flow)

Using the library, managing a payment process consists of two steps:

1. Starting the payment
-----------------------

[](#1-starting-the-payment)

### 1.1. Creating the request object

[](#11-creating-the-request-object)

To start an online payment, you have to create one or more **Payment Transaction** objects, add transaction **Items** to them, then group these transactions together in a **Payment** object.

First, create an **ItemModel**:

```
$item = new \Barion\Models\Common\ItemModel();
$item->Name = "TestItem";
$item->Description = "A test product";
$item->Quantity = 1;
$item->Unit = "piece";
$item->UnitPrice = 1000;
$item->ItemTotal = 1000;
$item->SKU = "ITEM-01";
```

Then create a **PaymentTransactionModel** and add the **Item** mentioned above to it:

```
$trans = new \Barion\Models\Payment\PaymentTransactionModel();
$trans->POSTransactionId = "TRANS-01";
$trans->Payee = "webshop@example.com";
$trans->Total = 1000;
$trans->Comment = "Test transaction containing the product";
$trans->AddItem($item);
```

Finally, create a **PreparePaymentRequestModel** and add the **PaymentTransactionModel** mentioned above to it:

```
$ppr = new \Barion\Models\Payment\PreparePaymentRequestModel();
$ppr->GuestCheckout = true;
$ppr->PaymentType = \Barion\Enumerations\PaymentType::Immediate;
$ppr->FundingSources = array(FundingSourceType::All);
$ppr->PaymentRequestId = "PAYMENT-01";
$ppr->PayerHint = "user@example.com";
$ppr->Locale = \Barion\Enumerations\UILocale::EN;
$ppr->OrderNumber = "ORDER-0001";
$ppr->Currency = \Barion\Enumerations\Currency::HUF;
$ppr->RedirectUrl = "https://webshop.example.com/afterpayment";
$ppr->CallbackUrl = "https://webshop.example.com/processpayment";
$ppr->AddTransaction($trans);
```

> **Note**
> The secret *POSKey* used for authentication is not part of the request object.
> The Barion client class automatically injects this value into every request sent to the Barion API.

### 1.2. Calling the Barion API

[](#12-calling-the-barion-api)

Now you can call the **PreparePayment** method of the Barion client with the request model you just created:

```
$myPayment = $BC->PreparePayment($ppr);
```

The Barion API now prepares a payment entity that can be paid by anyone.

The `$myPayment` variable holds the response received from the Barion API, which is an instance of a `PreparePaymentResponseModel` object.

### 1.3. Redirecting the user to the Barion Smart Gateway

[](#13-redirecting-the-user-to-the-barion-smart-gateway)

You can use the **PaymentId** value in the response to redirect the user to the Barion Smart Gateway. You have to supply this identifier in the **ID** query string parameter.
The complete redirect URL looks like this:

```
https://secure.barion.com/Pay?id=

```

The user can now complete the payment at the Barion Smart Gateway.

2. Getting information about a payment
--------------------------------------

[](#2-getting-information-about-a-payment)

In this example we are going to get detailed information about the payment we just created above.

### 2.1. Creating the request object

[](#21-creating-the-request-object)

To request details about a payment, you only need one parameter: the payment identifier. This is the **PaymentId** we have used earlier to redirect the user.

```
64157032d3dc4296aedafd4b0994c64e

```

### 2.2. Calling the Barion API

[](#22-calling-the-barion-api)

To request payment details, we call the **PaymentState** method of the Barion client class with the identifier above.

```
$BC->SetVersion(4);
$paymentDetails = $BC->PaymentState("64157032d3dc4296aedafd4b0994c64e");
```

> **Note**
> The PaymentState API is available in API version 4. The v2 GetPaymentState API is now deprecated.

Based on the payment status and parameters received in the response, the shop can now decide whether the payment was successful or not.

API documentation
=================

[](#api-documentation)

It is essential to get a basic understanding of the various statuses and errors returned by the Barion API during HTTP calls.
Please refer to the official [Barion API Documentation](https://docs.barion.com) to learn more about the various API endpoints and their responses.

Basic troubleshooting
=====================

[](#basic-troubleshooting)

Here are a few common mistakes you might want to double-check for before reaching out to our support:

**1. I get a "User authentication failed" error when sending my request**

- Check if you are sending the correct POSkey to the correct environment, e.g. if you want to call the API in the TEST environment, use the POSkey of the shop that you registered on the TEST website.
- Check if the sent data is actually a valid JSON string, without any special characters, delimiters, line-breaks or invalid encoding.

**2. I get a "Shop is closed" error message in the TEST environment**

- Check if your shop is open after logging in to the Barion Test website. Please note that you must fill out every data of your shop and then send it to approval. After this, approval will automatically be completed and your shop will be in Open status. This only applies to the TEST environment.

**3. I get SSL errors about invalid certificates when trying to call the API**

- Be sure to double-check your server certificates and the issuer's trusted status. Always renew your server certificates in time to avoid loss of service.
- Check every single component of your architecture for outdated software. Be sure to use the latest PHP, other runtimes, and even operating systems whenever possible. Trusted certificate chains may expire or get revoked, and Barion has no control over them. Using End-Of-Support and End-Of-Life software is highly discouraged.
- As a last resort, you may try creating the `BarionClient` instance with `useBundledRootCerts` set to `true`. But be advised, there is no guarantee that the bundled certificate chain remains valid at all times.

Getting help
============

[](#getting-help)

If you have any questions or need help with usage of this plugin, [join our Discord server](https://discord.gg/Wq4g7TBACd) and ask the developer community!

License
=======

[](#license)

This repository is available under the [Apache 2.0 License](https://github.com/barion/barion-web-php/blob/master/LICENSE).

Contributing
============

[](#contributing)

How to contribute to the Barion API library
-------------------------------------------

[](#how-to-contribute-to-the-barion-api-library)

1. Fork the `barion/barion-php-web` repository.
2. Create a new branch in your fork, make the desired changes, then push the changes to your fork.
3. Create a pull request to the `barion/barion-php-web` repository.
    In the pull request, please describe the functionality you developed or the problem you solved in detail.

We will try to review your pull request as soon as possible.

Version history
===============

[](#version-history)

- **2.1.0** October 30. 2025
- **2.0.0** July 16. 2024
- **1.4.11** April 2. 2024
- **1.4.10** June 13. 2022
- **1.4.9** June 9. 2022
- **1.4.8** June 9. 2022
- **1.4.7** May 25. 2022
- **1.4.6** April 28. 2021
- **1.4.5** April 15. 2021
- **1.4.4** February 17. 2021
- **1.4.3** December 11. 2020
- **1.4.2** August 15. 2019.
- **1.4.1** August 14. 2019.
- **1.4.0** August 08. 2019.
- **1.3.2** August 05. 2019.
- **1.3.1** March 20. 2019.
- **1.3.0** March 12. 2019.
- **1.2.9** May 16. 2017.
- **1.2.8** April 13. 2017.
- **1.2.7** February 14. 2017.
- **1.2.5** November 07. 2016.
- **1.2.4** May 25. 2016.
- **1.2.3** January 14. 2016.
- **1.2.2** January 11. 2016.
- **1.1.0** November 27. 2015.
- **1.0.1** November 26. 2015.
- **1.0.0** November 17. 2015.

For details about version changes, please refer to the [changelog.md](https://github.com/barion/barion-web-php/blob/master/changelog.md) file.

Further examples
================

[](#further-examples)

To view more examples about the usage of the Barion library, refer to the ***docs*** and ***examples*** folders of the repository.

*© 2024 Barion Payment Inc.*

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance66

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 66.2% of commits — single point of failure

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 ~179 days

Recently: every ~308 days

Total

8

Last Release

200d ago

Major Versions

v1.4.11 → v2.0.02024-07-16

PHP version history (2 changes)v1.4.7PHP &gt;=7.3

v2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/e674a726763db0c92ed3ce86c9b3cab09151f26df59110483a7ffb05df631929?d=identicon)[barion-vinczei](/maintainers/barion-vinczei)

![](https://www.gravatar.com/avatar/9e13ea7b7bb34f46bd03c074e3d18f65a88763f19fb46047140b0244120179d1?d=identicon)[pifta](/maintainers/pifta)

![](https://www.gravatar.com/avatar/9a61d24d78b5b164533afa4b8906a20047dbdc83dfb2fd1ab300811054079b2d?d=identicon)[attilabotz](/maintainers/attilabotz)

![](https://www.gravatar.com/avatar/e3d538862415138abe8003fc2a1d24718e5cbf0f37b84ecfcd0540a8ffc5f0a6?d=identicon)[AronStankovics](/maintainers/AronStankovics)

---

Top Contributors

[![barion-vinczei](https://avatars.githubusercontent.com/u/25821426?v=4)](https://github.com/barion-vinczei "barion-vinczei (104 commits)")[![attilabotz](https://avatars.githubusercontent.com/u/14994257?v=4)](https://github.com/attilabotz "attilabotz (25 commits)")[![emery303](https://avatars.githubusercontent.com/u/7056397?v=4)](https://github.com/emery303 "emery303 (11 commits)")[![szelpe](https://avatars.githubusercontent.com/u/192612?v=4)](https://github.com/szelpe "szelpe (3 commits)")[![Richyy](https://avatars.githubusercontent.com/u/7610756?v=4)](https://github.com/Richyy "Richyy (2 commits)")[![makacsakosSC](https://avatars.githubusercontent.com/u/82799557?v=4)](https://github.com/makacsakosSC "makacsakosSC (2 commits)")[![piftaba](https://avatars.githubusercontent.com/u/183622465?v=4)](https://github.com/piftaba "piftaba (2 commits)")[![alexkiss](https://avatars.githubusercontent.com/u/2719703?v=4)](https://github.com/alexkiss "alexkiss (1 commits)")[![webprogramozo](https://avatars.githubusercontent.com/u/4670604?v=4)](https://github.com/webprogramozo "webprogramozo (1 commits)")[![AronStankovics](https://avatars.githubusercontent.com/u/2668318?v=4)](https://github.com/AronStankovics "AronStankovics (1 commits)")[![KristofMorva](https://avatars.githubusercontent.com/u/5695015?v=4)](https://github.com/KristofMorva "KristofMorva (1 commits)")[![michalpixel](https://avatars.githubusercontent.com/u/123660030?v=4)](https://github.com/michalpixel "michalpixel (1 commits)")[![mohalaci](https://avatars.githubusercontent.com/u/3183841?v=4)](https://github.com/mohalaci "mohalaci (1 commits)")[![socketblind](https://avatars.githubusercontent.com/u/1552024?v=4)](https://github.com/socketblind "socketblind (1 commits)")[![viplezer](https://avatars.githubusercontent.com/u/2778196?v=4)](https://github.com/viplezer "viplezer (1 commits)")

### Embed Badge

![Health badge](/badges/barion-barion-web-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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