PHP code example of nattreid / comgate

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

    

nattreid / comgate example snippets


/** @var \NAttreid\Comgate\ComgateClient @inject */
public $comgateClient;

private function actionProcess(): void {
    $comgateClient = $this->comgateClient;
    
    $transaction= new \NAttreid\Comgate\Helpers\Transaction;
    $transaction->refId=$this->order->id;
    $transaction->country=$this->order->customer->country->code;
    $transaction->currency=$this->order->currency->code;
    $transaction->price=$this->order->price;

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

    $this->order->setComgateTransactionId($response->transactionId);

    $this->sendResponse($response->response);
}

private function actionRefund(float $price): void {
    $comgateClient = $this->comgateClient;

    $refund = new \NAttreid\Comgate\Helpers\Refund;
    $refund->transactionId = $this->order->comgateTransactionId;
    $refund->price = $price;
    $refund->currency = $this->order->currency->code;

    $response = $comgateClient->refund($refund);

    return $response->isOk();
}

public function actionComgateStatus(): void
	{
		$response = $this->comgateClient->getStatus();
		if ($response->isOk()) {
			if ($response->status === 'PAID') {
				// paid code
			}
		} else {
			// error code
		}

		$this->sendResponse($response->reponse);
	}