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. ux2dev/borica

ActiveLibrary

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

PHP library for BORICA eCommerce CGI payment gateway interface

v0.1.0(1mo ago)01↓100%MITPHPPHP ^8.1

Since Apr 8Pushed 2w agoCompare

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

READMEChangelogDependencies (2)Versions (2)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 from v0.2.x to v0.3.x
-------------------------------

[](#migrating-from-v02x-to-v03x)

v0.3 restructures the library around per-service resource-based clients to accommodate additional BORICA services (Infopay Checkout is next).

**Namespace change:** `Ux2Dev\Borica\Borica` is replaced by `Ux2Dev\Borica\Cgi\CgiClient`. Request and Response classes moved from `Ux2Dev\Borica\Request` / `Ux2Dev\Borica\Response` to `Ux2Dev\Borica\Cgi\Request` / `Ux2Dev\Borica\Cgi\Response`.

**Method mapping:**

v0.2v0.3`$borica->createPaymentRequest()``$cgi->payments()->purchase()``$borica->createReversalRequest()``$cgi->payments()->reverse()``$borica->createPreAuthRequest()``$cgi->preAuth()->create()``$borica->createPreAuthCompleteRequest()``$cgi->preAuth()->complete()``$borica->createPreAuthReversalRequest()``$cgi->preAuth()->reverse()``$borica->createStatusCheckRequest()``$cgi->status()->check()``$borica->parseResponse()``$cgi->responses()->parse()`**Laravel config:** wrap the existing `default` + `merchants` block under a top-level `cgi` key:

```
return [
    'cgi' => [
        'default' => env('BORICA_MERCHANT', 'default'),
        'merchants' => [ /* existing entries unchanged */ ],
    ],
    // routes, redirect unchanged
];
```

**Facade:** `Borica::createPaymentRequest(...)` becomes either `Borica::payments()->purchase(...)` (shorthand via `__call` proxy to the default CGI merchant) or `Borica::cgi()->payments()->purchase(...)` (explicit).

**Request DTOs:** Constructor properties on `PaymentRequest`, `ReversalRequest`, `PreAuthRequest`, `PreAuthCompleteRequest`, `PreAuthReversalRequest`, and `StatusCheckRequest` remain `private`. Read values via `->toArray()`, `->getTransactionType()`, and `->getSigningFields()`.

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

[](#configuration)

Create a `MerchantConfig` instance with your merchant credentials:

```
use Ux2Dev\Borica\Cgi\CgiClient;
use Ux2Dev\Borica\Config\MerchantConfig;
use Ux2Dev\Borica\Enum\Currency;
use Ux2Dev\Borica\Enum\Environment;

$config = new MerchantConfig(
    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
);

$cgi = new CgiClient($config);
```

The config validates all inputs on construction. The private key and passphrase are never exposed through public properties or serialization.

### PSR-3 Logging

[](#psr-3-logging)

Pass any PSR-3 logger as the second argument:

```
$cgi = new CgiClient($config, $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)

### Payment (Transaction Type 1)

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

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

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

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

Render the form:

```
