Giter Site home page Giter Site logo

paygateapi-php's Introduction

Paygateapi library

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.

paygateapi-php's People

Contributors

czepiec avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.