dokobit/gateway-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dokobit/gateway-php-sdk

最新稳定版本:1.3.1

Composer 安装命令:

composer require dokobit/gateway-php-sdk

包简介

Client for Dokobit Gateway API

README 文档

README

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

统计信息

  • 总下载量: 22.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-30