PHP SDK
Comgate PHP SDK
This official PHP library is used for easy integration of the Comgate payment gateway into your projects.
Main Features:
-
Creating Payments: Support for various currencies, test mode, and payment method settings (card, transfer, Apple Pay, etc.).
-
Payment Management: Easy verification of payment status, performing refunds, and managing recurring payments.
-
Notifications: Built-in tools for processing payment confirmations (server-to-server), ensuring a secure update of the order in your system.
-
CloudPOS: Support for terminal payments via CloudPOS.
Quick Start:
-
Installation: Via Composer using the command composer require comgate/sdk.
-
Configuration: Simply enter your Merchant ID and Secret obtained from the Comgate portal.
-
Environment: Requires PHP version 7.3 or higher.
Links and Documentation:
- GitHub Repository: Comgate PHP SDK
Sample Code for Creating a Payment:
use Comgate\SDK\Comgate;
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;
// Setup Klienta
$client = Comgate::defaults()
->setMerchant('123456') // get on portal.comgate.cz
->setSecret('foobarbaz') // get on portal.comgate.cz
->createClient();
// Vytvořit platbu
$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)
->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());
}