PHPackages                             ux2dev/borica - 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. [Payment Processing](/categories/payments)
4. /
5. ux2dev/borica

ActiveLibrary[Payment Processing](/categories/payments)

ux2dev/borica
=============

PHP library for BORICA payment services (Cgi gateway, Infopay Checkout)

v0.2.0(3mo ago)043MITPHPPHP ^8.1

Since Apr 8Pushed 2mo agoCompare

[ Source](https://github.com/ux2dev/borica)[ Packagist](https://packagist.org/packages/ux2dev/borica)[ RSS](/packages/ux2dev-borica/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (5)Versions (6)Used By (0)

ux2dev/borica
=============

[](#ux2devborica)

PHP library for the BORICA eCommerce CGI payment gateway. Handles request signing, response verification, and all six transaction types defined by the BORICA protocol.

Sponsored by [ux2.dev](https://ux2.dev).

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- OpenSSL extension (`ext-openssl`)
- A BORICA merchant account with:
    - Terminal ID (8 alphanumeric characters)
    - Merchant ID
    - RSA private key in PEM format (provided by BORICA or generated per their instructions)

Installation
------------

[](#installation)

```
composer require ux2dev/borica
```

Migrating to v1.0.0-alpha.2
---------------------------

[](#migrating-to-v100-alpha2)

v1.0.0-alpha.2 unifies all three BORICA services behind a single entry point and adopts the shared `ux2dev` SDK shape (typed request/result contracts, a response envelope for HTTP calls, and a tenant-scoped Laravel manager).

**Single client:** the per-service clients (`CgiClient`, `CheckoutClient`, `ErpClient`) are replaced by one `Ux2Dev\Borica\Borica` instance exposing three service areas:

```
$borica->cgi()->payments()->purchase(...);
$borica->checkout()->paymentRequests()->create($session, $dto);
$borica->erp()->payments()->createSepa($session, $request);
```

**Typed input DTOs:** CGI methods take input DTOs instead of scalar arguments — `PaymentInput` (purchase / pre-auth), `ReferencedPaymentInput` (reversal / completion), `StatusInput` (status check).

**Response envelope:** Checkout + ERP HTTP calls that return a result DTO now return an `Ux2Dev\Borica\Http\ApiResponse`. Reach the typed DTO via `->first()`(or `->all()` for lists). CGI keeps honest return types (a signed request object or a verified callback `Response`) — there is no HTTP round-trip to wrap.

**Config rename:** `MerchantConfig` is now `CgiConfig`.

**Laravel config:** the `cgi` / `checkout` / `erp` blocks move under per-tenant entries in a `tenants` array (see [Laravel Integration](#laravel-integration)). Scoping is now per *tenant* (`Borica::tenant('shop-2')->...`) rather than per-merchant/per-integration.

Configuration
-------------

[](#configuration)

Outside Laravel, build a `Borica` instance from a `BoricaConfig` (each service is optional — a tenant may use only CGI, or all three):

```
use Psr\Http\Client\ClientInterface;            // any PSR-18 client (e.g. Guzzle)
use Psr\Http\Message\RequestFactoryInterface;   // any PSR-17 factories
use Psr\Http\Message\StreamFactoryInterface;
use Ux2Dev\Borica\Borica;
use Ux2Dev\Borica\Config\BoricaConfig;
use Ux2Dev\Borica\Config\CgiConfig;
use Ux2Dev\Borica\Enum\Currency;
use Ux2Dev\Borica\Enum\Environment;

$cgi = new CgiConfig(
    terminal: 'V1800001',
    merchantId: '1600000001',
    merchantName: 'My Shop',
    privateKey: file_get_contents('/path/to/private_key.pem'),
    environment: Environment::Development,  // or Environment::Production
    currency: Currency::EUR,                // BGN, EUR, or USD
    country: 'BG',                          // default: 'BG'
    timezoneOffset: '+03',                  // default: '+03'
    privateKeyPassphrase: 'secret',         // optional, if key is encrypted
);

$borica = new Borica(
    new BoricaConfig(cgi: $cgi),
    $httpClient,        // PSR-18 (only used by checkout/erp; CGI needs none)
    $requestFactory,    // PSR-17
    $streamFactory,     // PSR-17
);
```

`CgiConfig` validates all inputs on construction. The private key and passphrase are never exposed through public properties or serialization. Accessing a service that wasn't configured for the tenant (e.g. `$borica->erp()` with no ERP config) throws a `ConfigurationException`.

### PSR-3 Logging

[](#psr-3-logging)

Pass any PSR-3 logger as the fifth `Borica` constructor argument; it is handed to the CGI and Checkout areas.

```
$borica = new Borica(new BoricaConfig(cgi: $cgi), $httpClient, $requestFactory, $streamFactory, $logger);
```

### Gateway URLs

[](#gateway-urls)

The gateway URL is determined by the environment:

EnvironmentURLDevelopment`https://3dsgate-dev.borica.bg/cgi-bin/cgi_link`Production`https://3dsgate.borica.bg/cgi-bin/cgi_link````
$gatewayUrl = $cgi->getGatewayUrl();
```

Usage
-----

[](#usage)

Reach the CGI service area from a configured `Borica` instance (or the `Borica::cgi()` facade in Laravel):

```
$cgi = $borica->cgi();
```

CGI methods take typed input DTOs and return a signed request object ready to be rendered as a form / POSTed to the gateway.

### Payment (Transaction Type 1)

[](#payment-transaction-type-1)

Browser-based payment. Build the request, then POST the form data to the gateway URL.

```
use Ux2Dev\Borica\Cgi\Request\Input\PaymentInput;

$request = $cgi->payments()->purchase(new PaymentInput(
    amount: '49.99',
    order: '000001',
    description: 'Order #000001',
    mInfo: [],
));

// Build an auto-submitting HTML form
$gatewayUrl = $cgi->getGatewayUrl();
$formFields = $request->toArray();
```

Render the form:

```
