smartdog23/gerencianet-sdk-php

GN API SDK PHP

3.0.0 2021-02-11 13:44 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": "3.*"
},
...

安装依赖项

$ composer install

要求

  • PHP >= 5.6
  • 扩展 ext-simplexml

测试环境

php 5.6 and 7.X

入门指南

需要模块和命名空间

require __DIR__ . '/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 */
}

开始之前,您必须在 config.json 文件中配置参数。实例化您的应用程序的 client_idclient_secret 以及 sandbox 等于 true(如果您的环境是测试),或 false(如果是生产)。如果您使用 Pix 订单,请在 pix_cert 属性中告知 .pem 格式的证书目录和名称。

开发环境

实例化模块,使用您的 client_id、client_secret,并将 sandbox 设置为 true

$options = [
  'client_id' => 'client_id',
  'client_secret' => 'client_secret',
  'pix_cert' => '../certs/developmentCertificate.pem',
  'sandbox' => true,
  'debug' => false,
  'timeout' => 30
];

$api = new Gerencianet($options);

生产环境

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

$options = [
  'client_id' => 'client_id',
  'client_secret' => 'client_secret',
  'pix_cert' => '../certs/productionCertificate.pem',
  'sandbox' => false,
  'debug' => false,
  'timeout' => 30
];

$api = new Gerencianet($options);

要生成证书,请在 https://gerencianet.com.br/fale-conosco 上提交工单,告知您的账户号码、应用程序名称和环境(测试/生产)。我们的团队将返回 .p12 证书,以便您使用端点。

用于 PHP 的证书必须转换为 .pem。以下将提供使用 OpenSSL 命令进行转换的示例。

OpenSSL 命令

// Gerar certificado e chave em único arquivo
openssl pkcs12 -in certificado.p12 -out certificado.pem -nodes

运行示例

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

php -S localhost:9000

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

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

版本指南

附加文档

有关所有可用端点的完整文档在 https://dev.gerencianet.com.br/

许可证

MIT