定制 znojil/comgate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

znojil/comgate

Composer 安装命令:

composer require znojil/comgate

包简介

📦 A simple and modern PHP library for communicating with the Comgate API.

README 文档

README

Latest Stable Version PHP Version Require License Tests

A simple and modern PHP library for communicating with the Comgate payment gateway API.

🚀 Installation

composer require znojil/comgate

📖 Usage

1. Client Initialization

use Znojil\Comgate\Client;
use Znojil\Comgate\Config;

$config = new Config(
	merchant: 'YOUR_MERCHANT_ID',
	secret: 'YOUR_SECRET',
	test: false // true for test mode
);

$client = new Client($config);

2. Creating a Payment

use Znojil\Comgate\DTO\PaymentDTO;
use Znojil\Comgate\Enum\Currency;
use Znojil\Comgate\Request\CreateRequest;

$payment = new PaymentDTO(
	price: 10000, // in cents, 10000 = 100.00 CZK
	curr: Currency::Czk,
	label: 'Order #1234',
	refId: 'order-1234',
	fullName: 'John Doe',
	email: 'john@example.com'
);

$result = $client->send(new CreateRequest($payment));

$result->transId; // AB12-CD34-EF56
$result->redirect; // redirect URL for payment gateway

If you prefer to redirect the customer directly to the payment gateway:

use Znojil\Comgate\Request\CreateRedirectRequest;

$redirectUrl = $client->send(new CreateRedirectRequest($payment));
// redirect the customer to $redirectUrl

3. Checking Payment Status

use Znojil\Comgate\Request\StatusRequest;

$status = $client->send(new StatusRequest('AB12-CD34-EF56'));

$status->transId; // AB12-CD34-EF56
$status->status; // PaymentStatus enum
$status->price; // int (cents)
$status->curr; // Currency enum

4. Using a Custom HTTP Client

You can inject your own HTTP client implementation by passing it as the second argument to the Client constructor. Your client must implement the Znojil\Comgate\Http\Client interface.

use Znojil\Comgate\Client;
use Znojil\Comgate\Http\Client as ComgateHttpClient;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

class MyCustomHttpClient implements ComgateHttpClient{
	public function send(string $method, string|UriInterface $uri, array $headers = [], mixed $data = null, array $options = []): ResponseInterface{
		// your implementation
	}
}

$client = new Client($config, new MyCustomHttpClient);

⚠️ Error Handling

The client throws exceptions to help you identify the issue:

  • Znojil\Comgate\Exception\ApiException: For API-level errors returned by Comgate (e.g. invalid parameters). Contains code and message from the API response.
  • Znojil\Comgate\Exception\ClientException: For HTTP client-side errors (4xx).
  • Znojil\Comgate\Exception\ServerException: For HTTP server-side errors (5xx).
  • Znojil\Comgate\Exception\ResponseException: For other unsuccessful HTTP responses.
  • Znojil\Comgate\Exception\InvalidArgumentException: For invalid input (e.g. invalid credentials, missing required data).
use Znojil\Comgate\Exception\ApiException;
use Znojil\Comgate\Exception\ClientException;
use Znojil\Comgate\Exception\ServerException;

try{
	$result = $client->send(new CreateRequest($payment));
}catch(ApiException $e){
	echo $e->getMessage(); // error message from Comgate
	echo $e->getCode(); // error code from Comgate
}catch(ServerException $e){
	// Comgate server error (5xx)
}catch(ClientException $e){
	// HTTP client error (4xx)
}

📄 License

This library is open-source software licensed under the MIT license.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固