PHP code example of sloukapetr / comgate-laravel-package

1. Go to this page and download the library: Download sloukapetr/comgate-laravel-package library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sloukapetr / comgate-laravel-package example snippets


use Sloukapetr\ComgateLaravelPackage\ComgateService;

$comgate = app(ComgateService::class);

$response = $comgate->createPayment([
    'price' => 1000,
    'curr' => 'CZK',
    'label' => 'ORDER-1001',
    'refId' => '1001',
    'method' => 'ALL',
]);

$redirectUrl = $comgate->redirectUrl($response);

$redirect = $comgate->paymentRedirect([
    'price' => 1000,
    'curr' => 'CZK',
    'label' => 'ORDER-1001',
    'refId' => '1001',
    'method' => 'ALL',
]);

$init = $comgate->createInitialRecurringPayment([
    'price' => 1000,
    'curr' => 'CZK',
    'label' => 'SUBSCRIPTION-INIT',
    'refId' => 'SUB-42',
    'method' => 'CARD_CZ_CS',
]);

$charge = $comgate->recurringPayment([
    'initRecurringId' => $init['transId'] ?? null,
    'price' => 1000,
    'curr' => 'CZK',
    'label' => 'SUBSCRIPTION-RENEW',
    'refId' => 'SUB-42-2026-09',
]);

$preauth = $comgate->createPayment([
    'price' => 1500,
    'curr' => 'CZK',
    'preauth' => true,
    'label' => 'PREAUTH-ORDER-1',
]);

$capture = $comgate->capture([
    'transId' => $preauth['transId'] ?? null,
]);

$cancel = $comgate->cancelPreauth([
    'transId' => $preauth['transId'] ?? null,
]);

$refund = $comgate->refund([
    'transId' => 'YOUR_TRANSACTION_ID',
    'amount' => 500,
]);

$cancelPayment = $comgate->cancelPayment([
    'transId' => 'YOUR_PENDING_TRANSACTION_ID',
]);

$status = $comgate->status([
    'transId' => 'YOUR_TRANSACTION_ID',
]);

$transferList = $comgate->transferList('2025-04-25');
$singleTransfer = $comgate->singleTransfer('1234567');

$methods = $comgate->methods([
    'country' => 'CZ',
    'curr' => 'CZK',
    'price' => 1000,
    'lang' => 'cs',
    'initRecurring' => true,
]);

$health = $comgate->gatewayHealth();
$outages = $comgate->outages();

$availability = $comgate->paymentAvailability(
    [
        'country' => 'CZ',
        'curr' => 'CZK',
        'price' => 1000,
        'initRecurring' => true,
    ],
    ['CARD_CZ_CSOB_2', 'BANK_CZ_KB']
);

if (! $availability['available']) {
    $summary = $availability['summary'];
    $reasons = $availability['reasons'];
    $usableMethods = $availability['usableMethods'];
}

$report = $comgate->paymentAvailabilityReport(
    ['country' => 'CZ', 'curr' => 'CZK', 'price' => 1000],
    ['CARD_CZ_CSOB_2']
);

if (! $report->isAvailable()) {
    $summaryKey = $report->summaryKey;
    $localizedSummary = $report->summaryFor('cs');
    $reasonCodes = $report->reasonCodes;
    $reasonMessages = $report->reasonMessages('cs');
}

use Sloukapetr\ComgateLaravelPackage\Exceptions\PaymentUnavailableException;

try {
    $response = $comgate->createPaymentChecked([
        'country' => 'CZ',
        'price' => 1000,
        'curr' => 'CZK',
        'label' => 'ORDER-1001',
        'refId' => '1001',
        'method' => 'CARD_CZ_CSOB_2',
    ]);
} catch (PaymentUnavailableException $exception) {
    $availability = $exception->availability();
}

use Sloukapetr\ComgateLaravelPackage\Events\ComgateWebhookReceived;

class HandleComgateWebhook
{
    public function handle(ComgateWebhookReceived $event): void
    {
        // Keep this listener idempotent: Comgate can retry webhook delivery.
        if ($this->alreadyProcessed($event->notification->transId)) {
            return;
        }

        if ($event->notification->isPaid()) {
            $transactionId = $event->notification->transId;
            $referenceId = $event->notification->refId;

            // mark order or subscription renewal as paid
        }
    }

    private function alreadyProcessed(?string $transactionId): bool
    {
        return false;
    }
}

use Comgate;

$response = Comgate::status(['transId' => 'YOUR_TRANSACTION_ID']);

$fake = Comgate::fake([
    'status' => ['code' => 0, 'message' => 'OK', 'transId' => 'TX-001', 'status' => 'PAID'],
]);
bash
php artisan vendor:publish --tag=comgate-config