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

ActiveLibrary[API Development](/categories/api)

comgate/sdk
===========

Comgate PHP SDK

v1.8.0(4mo ago)13327.8k↓27.1%15[2 PRs](https://github.com/comgate-payments/sdk-php/pulls)MITPHPPHP ^7.3 || ^8.0CI passing

Since Mar 29Pushed 2mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (28)Versions (37)Used By (0)

Comgate / PHP SDK
=================

[](#comgate--php-sdk)

 💰 PHP library for communication with Comgate.

 [![](https://camo.githubusercontent.com/7f201331301223dc710f13bc57af7381071b538b216c299a9b8b037e288c0ef7/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f636f6d676174652d7061796d656e74732f73646b2d706870)](https://github.com/comgate-payments/sdk-php/actions) [![](https://camo.githubusercontent.com/7e089f577c31b1741124e9f7b3e4d513971ec8cc0149d0c1e1fac0761b083d82/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f646d2f636f6d676174652f73646b)](https://packagist.org/packages/comgate/sdk) [![](https://camo.githubusercontent.com/c842d0d43fa0a9548ec163131823c3f72b0194a9ea325b33f2cfb9dff7363994/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f636f6d676174652f73646b)](https://packagist.org/packages/comgate/sdk) [![](https://camo.githubusercontent.com/d8aa14bd1723db495a4d77a87de9160cff5178b79ae4f8945800459fe783b4f7/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f636f6d676174652f73646b)](https://packagist.org/packages/comgate/sdk) [![](https://camo.githubusercontent.com/35d780323bf8316c9474e2e37f3468b398cad4acc2bc07adbd0ea662c2639f27/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f636f6d676174652d7061796d656e74732f73646b2d706870)](https://github.com/comgate-payments/sdk-php)

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

To install latest version of `comgate/sdk` use [Composer](https://getcomposer.org).

```
composer require comgate/sdk
```

You have to install php-xml extension on your PHP server (e.g.: Ubuntu: apt-get install php-xml).

### Documentation

[](#documentation)

-  (english version)
-  (czech version)

### Registration

[](#registration)

1. At first register your account at our side [comgate.cz](https://www.comgate.cz).
2. You will get **merchant indentificator** and **secret**.
3. Allow your eshop server IPv4 address at [portal.comgate.cz](https://portal.comgate.cz).
4. Set PAID, CANCELLED, PENDING and STATUS URL at [portal.comgate.cz](https://portal.comgate.cz).

Usage
-----

[](#usage)

- [Setup client](#setup-client)
- [Create payment](#create-payment)
- [Check payment status](#finish-the-order-and-show-payment-status-to-returning-payer)
- [Handle notification](#receive-payment-notification-server-to-server)

### Setup client

[](#setup-client)

```
use Comgate\SDK\Comgate;

$client = Comgate::defaults()
    ->setMerchant('123456') // get on portal.comgate.cz
    ->setSecret('foobarbaz') // get on portal.comgate.cz
    ->createClient();
```

### Create payment

[](#create-payment)

```
use Comgate\SDK\Entity\Codes\CategoryCode;
use Comgate\SDK\Entity\Codes\CurrencyCode;
use Comgate\SDK\Entity\Codes\DeliveryCode;
use Comgate\SDK\Entity\Codes\PaymentMethodCode;
use Comgate\SDK\Entity\Money;
use Comgate\SDK\Entity\Payment;
use Comgate\SDK\Utils\Helpers;
use Comgate\SDK\Entity\Codes\RequestCode;
use Comgate\SDK\Exception\ApiException;

$payment = new Payment();
$payment
    ->setPrice(Money::ofInt(50)) // 50 CZK
    ->setPrice(Money::ofFloat(50.25)) // 50,25 CZK
    ->setPrice(Money::ofCents(5025)) // 50,25 CZK
    // -----
    ->setCurrency(CurrencyCode::CZK)
    ->setLabel('Test item')
    // or ->setParam('label', 'Test item') // you can pass all params like this
    ->setReferenceId('test001')
    ->setEmail('foo@bar.tld')
    ->addMethod(PaymentMethodCode::ALL)
    //->setRedirect()
    //->setIframe()
    ->setTest(false)
    ->setFullName('Jan Novák')
    ->setCategory(CategoryCode::PHYSICAL_GOODS_ONLY)
    ->setDelivery(DeliveryCode::HOME_DELIVERY)
    ->setInitRecurring(true) // Marks as the initial payment in a recurring series
    ->setInitRecurringId('XXXX-YYYY-ZZZZ'); // For subsequent recurring payments. Do not combine with setInitRecurring

try {
    // Used when creating subsequent recurring payments instead of createPayment
    // $createPaymentResponse = $client->initRecurringPayment($payment);
    $createPaymentResponse = $client->createPayment($payment);
    if ($createPaymentResponse->getCode() === RequestCode::OK) {
        // Redirect the payer to Comgate payment gateway (use proper method of your framework)
        Helpers::redirect($createPaymentResponse->getRedirect());
    } else {
        var_dump($createPaymentResponse->getMessage());
    }
} catch (ApiException $e) {
    var_dump($e->getMessage());
}
```

Example of successfull response for `$client->createPayment`.

```
$transactionId = $createPaymentResponse->getTransId(); // XXXX-YYYY-ZZZZ
$code = $createPaymentResponse->getCode(); // 0
$message = $createPaymentResponse->getMessage(); // OK
$redirect = $createPaymentResponse->getRedirect(); // https://payments.comgate.cz/client/instructions/index?id=XXXX-YYYY-ZZZZ
```

Example of error response for `$client->createPayment`.

```
$code = $e->getCode(); // 1109
$message = $e->getMessage(); // Invalid payment method [fake]
```

### Get methods

[](#get-methods)

```
use Comgate\SDK\Exception\ApiException;

try {
    $methodsResponse = $client->getMethods();
    foreach ($methodsResponse->getMethodsList() as $method) {
        var_dump([
            $method->getId(),
            $method->getName(),
            $method->getDescription(),
            $method->getLogo(),
            $method->getGroup(),
            $method->getGroupLabel(),
        ]);
    }
} catch (ApiException $e) {
    var_dump($e->getMessage());
}
```

### Finish the order and show payment status to returning payer

[](#finish-the-order-and-show-payment-status-to-returning-payer)

- Example PAID URL: [https://your-eshop.tld/order-finish.php?id=${id}&amp;refId=${refId}&amp;status=PAID](https://your-eshop.tld/order-finish.php?id=$%7Bid%7D&refId=$%7BrefId%7D&status=PAID)
- Example PAID CANCELLED: [https://your-eshop.tld/order-finish.php?id=${id}&amp;refId=${refId}&amp;status=CANCELLED](https://your-eshop.tld/order-finish.php?id=$%7Bid%7D&refId=$%7BrefId%7D&status=CANCELLED)
- Example PAID PENDING: [https://your-eshop.tld/order-finish.php?id=${id}&amp;refId=${refId}&amp;status=PENDING](https://your-eshop.tld/order-finish.php?id=$%7Bid%7D&refId=$%7BrefId%7D&status=PENDING)

```
use Comgate\SDK\Entity\Payment;
use Comgate\SDK\Entity\PaymentNotification;
use Comgate\SDK\Entity\Codes\PaymentStatusCode;

$transactionId = $_GET['id']; // XXXX-YYYY-ZZZZ
$refId = $_GET['refId']; // your order number

try {
    $paymentStatusResponse = $client->getStatus($transactionId);

    switch ($paymentStatusResponse->getStatus()){
        case PaymentStatusCode::PAID:
            // Your code (set order as paid)
            echo "Your payment was PAID successfully.";
            break;

        case PaymentStatusCode::CANCELLED:
            // Your code (set order as cancelled)
            echo "Your order was CANCELLED.";
            break;

        case PaymentStatusCode::PENDING:
            // Your code (order is still pending)
            echo "We are waiting for the payment.";
            break;

        case PaymentStatusCode::AUTHORIZED:
            // Your code (set order as authorized)
            echo "Payment was authorized successfully.";
            break;
    }
} catch (ApiException $e) {
    var_dump($e->getMessage());
}
```

### Receive payment notification (server-to-server)

[](#receive-payment-notification-server-to-server)

Example URL:

```
use Comgate\SDK\Entity\PaymentNotification;
use Comgate\SDK\Entity\Codes\PaymentStatusCode;
use Comgate\SDK\Exception\ApiException;

// Create from $_POST global variable
// $notification = PaymentNotification::createFromGlobals();

// Create from your framework
$data = $framework->getHttpRequest()->getPostData();

// Use PaymentNotification only for getting transactionId
// For other details about payment please use $client->getStatus with appropriate getter
$notification = PaymentNotification::createFrom($data);
$transactionId = $notification->getTransactionId();

try {
    // it's important to check the status from API
    $paymentStatusResponse = $client->getStatus($transactionId);

    switch ($paymentStatusResponse->getStatus()){
        case PaymentStatusCode::PAID:
            // Your code (set order as paid)
            break;

        case PaymentStatusCode::CANCELLED:
            // Your code (set order as cancelled)
            break;

        case PaymentStatusCode::AUTHORIZED:
            // Your code (set order as authorized)
            break;

        // PaymentStatusCode::PENDING - is NOT send via push notification
    }

    echo "OK"; // important response with HTTP code 200

} catch (ApiException $e) {
    if ($e->getCode() >= 500 && $e->getCode() < 600) { // map error codes to something sensible
		    $status = 502;
	  } else {
    		$status = 400;
	  }

	  http_response_code($status); // set the response code to server and print the error to the screen
	  print_r([
		    'error' => true,
    		'code' => $status,
		    'message' => $e->getMessage()
	  ]);
}
```

### Create a refund

[](#create-a-refund)

```
use Comgate\SDK\Entity\Refund;
use Comgate\SDK\Exception\ApiException;
use Comgate\SDK\Entity\Money;
use Comgate\SDK\Entity\Codes\RequestCode;

$refund = new Refund();
$refund->setTransId('XXXX-YYYY-ZZZZ')
    ->setAmount(Money::ofCents(100))
    ->setRefId('11bb22');

try{
    $refundResult = $client->refundPayment($refund);
    if($refundResult->getCode() == RequestCode::OK) {
        // refund created successfully
    }
} catch (ApiException $e){
    var_dump($e->getMessage());
}
```

### Create terminal CloudPOS payment

[](#create-terminal-cloudpos-payment)

#### API Documentation

[](#api-documentation)

```
use Comgate\SDK\Comgate;
use Comgate\SDK\Entity\Codes\CurrencyCode;
use Comgate\SDK\Entity\Codes\RequestCode;
use Comgate\SDK\Entity\Money;
use Comgate\SDK\Entity\TerminalPayment;
use Comgate\SDK\Entity\TerminalRefund;
use Comgate\SDK\Exception\ApiException;

$clientTerminal = Comgate::defaultsRest()
    ->setMerchant('123456') // get on portal.comgate.cz
    ->setSecret('foobarbaz') // get on portal.comgate.cz
    ->createTerminalClient();

$terminalPayment = new TerminalPayment();
$terminalPayment
    ->setPrice(Money::ofInt(4))
    ->setCurr(CurrencyCode::CZK)
    ->setRefId('123456');

try {
    $createTerminalPaymentResponse = $clientTerminal->createPayment($terminalPayment);
    if ($createTerminalPaymentResponse->getCode() === RequestCode::OK) {

        // save ID of terminal payment in your system
        echo 'created terminal payment: ' . $createTerminalPaymentResponse->getTransId();

    } else {
        var_dump($createTerminalPaymentResponse->getMessage());
    }
} catch (ApiException $e) {
    var_dump($e->getMessage());
}
```

### Debugging

[](#debugging)

#### Logging

[](#logging)

> We are using [PSR-3](https://www.php-fig.org/psr/psr-3/) for logging.

```
use Comgate\SDK\Comgate;
use Comgate\SDK\Logging\FileLogger;
use Comgate\SDK\Logging\StdoutLogger;

$client = Comgate::defaults()
    ->setLogger(new FileLogger(__DIR__ . '/comgate.log'))
    ->createClient();
```

Take a look at [our tests](https://github.com/comgate-payments/sdk-php/blob/master/tests/fixtures) to see the logger format.

Maintenance
-----------

[](#maintenance)

If you find a bug, please submit the issue in [Github](https://github.com/comgate-payments/sdk-php/issues) directly.

Thank you for using our Comgate payment.

License
-------

[](#license)

Copyright (c) 2024 Comgate a.s. [MIT Licensed](LICENSE).

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance82

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity61

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

Recently: every ~44 days

Total

29

Last Release

131d ago

PHP version history (2 changes)v1.0.0PHP ^7.2 || ^8.0

v1.0.2PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/51fd6185389a4fa92fc9d76d55733c865a627a91bc204adbedff807bd4d4e7c0?d=identicon)[comgate](/maintainers/comgate)

---

Top Contributors

[![Comgate-a-s](https://avatars.githubusercontent.com/u/240486898?v=4)](https://github.com/Comgate-a-s "Comgate-a-s (17 commits)")[![SimonZanta](https://avatars.githubusercontent.com/u/81022297?v=4)](https://github.com/SimonZanta "SimonZanta (15 commits)")[![marekMin](https://avatars.githubusercontent.com/u/51647999?v=4)](https://github.com/marekMin "marekMin (6 commits)")[![iki-cz](https://avatars.githubusercontent.com/u/1101936?v=4)](https://github.com/iki-cz "iki-cz (6 commits)")[![sirluky](https://avatars.githubusercontent.com/u/38957065?v=4)](https://github.com/sirluky "sirluky (6 commits)")[![f3l1x](https://avatars.githubusercontent.com/u/538058?v=4)](https://github.com/f3l1x "f3l1x (3 commits)")[![menzelkuba](https://avatars.githubusercontent.com/u/201933118?v=4)](https://github.com/menzelkuba "menzelkuba (2 commits)")[![paavlsaurus](https://avatars.githubusercontent.com/u/148801290?v=4)](https://github.com/paavlsaurus "paavlsaurus (2 commits)")[![vikijel](https://avatars.githubusercontent.com/u/2683048?v=4)](https://github.com/vikijel "vikijel (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![droutin](https://avatars.githubusercontent.com/u/17362753?v=4)](https://github.com/droutin "droutin (1 commits)")[![JakubVcelak](https://avatars.githubusercontent.com/u/91059131?v=4)](https://github.com/JakubVcelak "JakubVcelak (1 commits)")[![janakdom](https://avatars.githubusercontent.com/u/10292894?v=4)](https://github.com/janakdom "janakdom (1 commits)")[![jaroslavlibal](https://avatars.githubusercontent.com/u/450740?v=4)](https://github.com/jaroslavlibal "jaroslavlibal (1 commits)")[![peszo](https://avatars.githubusercontent.com/u/12842431?v=4)](https://github.com/peszo "peszo (1 commits)")

---

Tags

phpapimoneypaymentcomgate

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[algolia/algoliasearch-client-php

API powering the features of Algolia.

69433.0M114](/packages/algolia-algoliasearch-client-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[contributte/comgate

Comgate Payment Gateway for Nette Framework

19839.7k1](/packages/contributte-comgate)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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