czetech/paygateapi

There is no license information available for the latest version (dev-main) of this package.

Library for connecting with Payment Gateway

dev-main 2021-10-26 13:21 UTC

This package is not auto-updated.

Last update: 2024-05-15 20:24:25 UTC


README

Paygateapi is a PHP library to access the State Treasury of Slovak Republic Payment Gateway.

Requirements

  • PHP 7.1 and above
  • Built-in libcurl support
  • Git
  • Composer

Installation

The installation is done using a Composer. If you don't already have Composer installed, first install it by following one of these instructions depends on your OS of choice:

To install the paygateapi library, run the following command in the library directory:

composer install

Usage

Availability of the payment gateway:

$paymentGate = new PaymentGate();

$status = $paymentGate->callIsActive();
var_dump($status);

Download the payment gateway certificate:

$paymentGate = new PaymentGate();

$cert = $paymentGate->callGetCertificate();
var_dump($cert);

Make a payment and check the status of payment:

$paymentGate = new PaymentGate();

$key = 'file://key.pem');
$cert = $paymentGate->callGetCertificate();

$paymentRequest = new PaymentRequest('MID00001', new DateTime(),
    'http://localhost:4200/', '1');
$paymentRequest->setVs('123456789');
$location = $paymentGate->callPaymentRequest($paymentRequest, $key);
var_dump($location);

$checkStatePaymentRequest = new CheckStatePaymentRequest("MID00001", '1');
$checkStatePaymentRequest->setVs('123456789');
$arrayStatusResponse = $paymentGate->callCheckStatePayment(
    $checkStatePaymentRequest, $key, $cert);
var_dump($arrayStatusResponse);

Make a refund and check the status of refund:

$paymentGate = new PaymentGate();

$key = 'file://key.pem');
$cert = $paymentGate->callGetCertificate();

$refundPaymentRequest = new RefundPaymentRequest("MID00001", '1', 10000);
$refundPaymentRequest->setVs(123456789);
$refundPaymentResult= $paymentGate->callRefundPayment($paymentRequest, $key,
    $cert);
var_dump($refundPaymentResult);

$checkStateRefundPaymentRequest = new CheckStateRefundPaymentRequest("MID00001",
    $refundPaymentResult->getRefundId());
$refundStateResponse = $paymentGate->callCheckStateRefundPayment(
    $checkStateRefundPaymentRequest, $key, $cert);
var_dump($refundStateResponse);

Generate and get a report:

$paymentGate = new PaymentGate();

$key = 'file://key.pem');

$reportRequest = new ReportRequest("MID00001", new DateTime());
$resultCreateReport = $paymentGate->callGenerateReports($reportRequest, $key);
var_dump($resultCreateReport);

$reportRequest = new GetReportRequest("MID00001",
    $resultCreateReport->getReportId());
$reportResultObject = $paymentGate->callGetReport($reportRequest, $key);
if (! $reportResultObject->getReady()) {
    sleep($reportResultObject->getTryAgain());
    $reportResultObject = $paymentGate->callGetReport($reportRequest, $key);
}
var_dump($reportResultObject);

Check the validity of result for the merchant:

$paymentGate = new PaymentGate();

$cert = $paymentGate->callGetCertificate();

$resultForMerchant = new ResultForMerchant('OK',
    '2d886f42ba58f8c9f057c3e8d4d76a09901f54ac966e8224066a900b120e2d92', '5');
$resultForMerchant->setVs('123456789');
$resultForMerchant->setSs('1111');
$resultForMerchant->setKs('1111');
$resultForMerchant->setSign(
    'SCcSuPZsInOq7H/h4Agph5GVCKxV2a2b3SILQCkngCHALn+T6zIHq1DiI7vQFENnlsmIow1k' .
    '+FYTRFNMFGbtgmU6zV+BIKXk4DG6qSpdGBu0iVvO/hctQlaZSBJ2P5JQOmSGcRsexHd01gyw' .
    '4RvrLlMU5QTMnExSG+09u7MB0QXVLbcZutpn/5s31VVv1lm3ReXBszVXTjo/6Jl0i36a9f48' .
    'jezfm0hgkAsfTAePgqGR/feOjugHEFNrxxdcSxpp6nsx8j9sPx2ItU8vkLSfYLtfvR6UMHw+' .
    'oRMpfLj8Aea53QLfzTCsfpS/K6vB2HaRJ5+JSAe6z/o9a0dzg6Paew==');
$validity = $resultForMerchant->verifySign($cert);
var_dump($validity);

Tests

There are two environment variables for configuration:

  • PAYGATEAPI_URL: Base URL for API, default value https://sppay.hpito.sk/api/
  • PAYGATEAPI_KEY: Path to private key, default value key.pem

It is necessary to place the private key named key.pem to a folder with a library or determine his path by setting environment variable:

export PAYGATEAPI_KEY=/full/path/to/private_key.pem

The unit test is started by Composer with argument test:

composer test

Or alternatively by running ./vendor/bin/phpunit with argument tests:

./vendor/bin/phpunit tests

For more informations see PHPUnit.

Documentation

Documentation is generated by Composer with argument docs:

composer docs

Or alternatively by running ./vendor/bin/phpdoc:

./vendor/bin/phpdoc

Documentation is generated in build/docs directory.

For more informations see phpDocumentor.