PHP code example of geniv / nette-comgate

1. Go to this page and download the library: Download geniv/nette-comgate 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/ */

    

geniv / nette-comgate example snippets


/** @var Comgate @inject */
public $comgate;

try {
    // process Comgate
    $payment = $this->comgate->createPayment($values['order_price'] * 100, $values['order_id'], $values['email'], $game['name']);
    $payment->setPrepareOnly(true);

    $response = $this->comgate->sendResponse($payment);
    if ($response->isOk()) {
        // edit checkout_id
        $this->model->editItem($id, ['checkout_id' => $response->getTransId()]);
        $this->redirectUrl($response->getRedirectUrl());
    }
} catch (\Comgate\Exception\InvalidArgumentException $e) {
    Debugger::log($e);
    $this->redirect('error');
} catch (\Comgate\Exception\LabelTooLongException $e) {
    Debugger::log($e);
    $this->redirect('error');
}

public function actionStatus()
{
    $this->getHttpResponse()->setContentType('application/javascript');
    $request = $this->getHttpRequest();
    if ($request->isMethod('POST')) {
        $transId = $request->getPost('transId');
        $status = $request->getPost('status');
        if ($transId && $status) {
            $item = $this->model->getByCheckoutId($transId);
            if ($item) {
                if ($this->model->editItem((int) $item['id'], ['status' => $status, 'checkout_date%sql' => 'NOW()', 'active' => ($status == PaymentStatus::PAID)])) {
                    $this->sendResponse(new ComgateResponse('code=0&message=OK'));
                }
                $this->sendResponse(new ComgateResponse('code=1&message=SAVE_ERROR'));
            }
            $this->sendResponse(new ComgateResponse('code=1&message=TRANS_ID_NOT_FOUND'));
        }
        $this->sendResponse(new ComgateResponse('code=1&message=MISSING_PARAMETERS'));
    }
    $this->sendResponse(new ComgateResponse('code=1&message=FAIL'));
}

public function actionResult(string $id, string $refId)
{
    $item = $this->model->getByCheckoutId($id);
    if ($item) {
        if ($item['status'] == PaymentStatus::PAID) {
            //success
        } else {
            //danger
        }
    }
    $this->redirect('Homepage:');
}
json
"php": ">=7.0.0",
"nette/nette": ">=2.4.0",
"renat-magadiev/comgate-client": "^1.0"