Git Product home page Git Product logo

gateway-sdk-php's Introduction

Dokobit Gateway PHP Client

Build Status Scrutinizer Code Quality Code Coverage Build Status

This library makes it easier to integrate Dokobit Gateway API in PHP applications by wrapping all of the Gateway API calls and responses in PHP objects.

How to start?

  1. Instantiate a client object:

    use Dokobit\Gateway\Client;
    
    // <...>
    $client = Client::create([
        'apiKey' => 'xxxxxx',
        'sandbox' => true,
    ]);

    If you want to log requests, just pass a PSR-3 LoggerInterface compatible logger (such as a Monolog instance) as the second parameter to the create() method, like this:

    use Dokobit\Gateway\Client;
    use Monolog\Handler\StreamHandler;
    use Monolog\Logger;
    
    // <...>
    $log = new Logger('requests');
    $log->pushHandler(new StreamHandler(__DIR__ . '/path/to/info.log', Logger::INFO));
    
    $client = Client::create([
        'apiKey' => 'xxxxxx',
        'sandbox' => true,
    ], $log);
  2. Use the client instantiated above to make the desired API calls. To do that, instantiate a respective request object and pass it to the get() method of the client. For example, to upload a file to Gateway:

    use Dokobit\Gateway\Query\File\Upload;
    
    // <...>
    $request = new Upload('/path/to/your/document.pdf');
    $result = $client->get($request);
    echo $result->getStatus(); // Request status
    echo $result->getToken(); // Uploaded file token

    The client performs an HTTP request and returns a result object, which has getters for all response fields. Should the request fail for any reason, an exception will be thrown, which should help you debug the issue.

The request (query) and response (result) classes closely mirror the API calls, which are documented at https://gateway-sandbox.dokobit.com/api/doc.

To make downloading of signed files more convenient, the Client class also provides the downloadFile() method. To download a signed file, just call this method like this:

$client->downloadFile($signedFileUrl, $downloadedFilePath);

Note: this method will append your access token to the URL automatically, so you can pass it the URLs you receive from the Gateway's postbacks in their verbatim form, without any changes. The same method can also be used to download arbitrary files from other locations, if necessary. Should you want to do that, just pass false as the third argument to avoid appending the access token, like this:

$client->downloadFile($signedFileUrl, $downloadedFilePath, false);

For further code usage examples, please check integration tests under tests/Integration.

Debugging

To dig more into occured error use following methods:

echo (string) $exception->getMessage()
echo (string) $exception->getPrevious()->getResponse()
var_dump( $exception->getResponseData() )

These methods are available on all exception classes except UnexpectedError and QueryValidator.

Develop

Whole testsuite including integrational tests

phpunit

Don't forget to define SANDBOX_API_KEY in your phpunit.xml.

Running unit tests only:

phpunit --testsuite=Unit

Running integrational tests only:

phpunit --testsuite=Integration

Running single testcase:

phpunit tests/Integration/CheckTest.php

gateway-sdk-php's People

Contributors

rimas-kudelis avatar kuusas avatar koliaq avatar elvinaskacerauskas avatar randohinn avatar prialgauskaslt avatar vbdoko 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.