douglaszuqueto/gerencianet-sdk-php

dev-master 2017-10-06 13:17 UTC

This package is not auto-updated.

Last update: 2024-09-26 06:51:42 UTC


README

为 Gerencianet Pagamentos' API 提供的 SDK。有关参数和值的更多信息,请参阅 Gerencianet 文档。

Build Status Code Climate Test Coverage

安装

使用 composer 需要此包

$ composer require gerencianet/gerencianet-sdk-php

或者在您的 composer.json 文件中包含它

...
"require": {
  "gerencianet/gerencianet-sdk-php": "1.*"
},
...

要求

  • PHP >= 5.4

测试与

php 5.4 and 5.5

入门

需要模块和命名空间

require __DIR__ . '/../sdk/vendor/autoload.php';

use Gerencianet\Gerencianet;

尽管 Web 服务响应为 json 格式,但 SDK 会将任何服务器响应转换为数组。代码必须在 try-catch 块内,异常可以按以下方式处理

try {
  /* code */
} catch(GerencianetException $e) {
  /* Gerencianet's api errors will come here */
} catch(Exception $ex) {
  /* Other errors will come here */
}

对于开发环境

使用您的 client_id、client_secret 和 sandbox 等于 true 来实例化模块

$options = [
  'client_id' => 'client_id',
  'client_secret' => 'client_secret',
  'sandbox' => true
];

$api = new Gerencianet($options);

对于生产环境

要将环境更改为生产,只需将第三个 sandbox 设置为 false 即可

$options = [
  'client_id' => 'client_id',
  'client_secret' => 'client_secret',
  'sandbox' => false
];

$api = new Gerencianet($options);

运行测试

要运行测试,请安装 PHPUnit 并运行以下命令

$ phpunit -c config.xml

运行示例

将 examples/config.json 文件中的应用程序的 client_id 和 client_secret 更新。

您可以使用任何 Web 服务器,如 Apache 或 nginx,或者简单地按以下方式启动一个 php 服务器

php -S localhost:9000

然后在浏览器中打开任何示例。

⚠️ 一些示例需要您更改一些参数才能运行,例如 examples/charge/detail.php,其中您必须更改 id 参数。

附加文档

完整文档(包括所有可用端点)在 https://dev.gerencianet.com.br/

许可

MIT