manrich/juno

使用guzzle为webgopher提供的Juno支付网关API v2抽象

v1.0 2021-11-24 13:30 UTC

This package is auto-updated.

Last update: 2024-09-04 07:52:19 UTC


README

非官方Sdk

更多信息请访问WIKIJuno api v2文档

开始

要安装,请执行

composer require manrich/juno

发出的调用将始终返回http状态、headers、reason_phrase和结果。

status_code仅在通信失败与服务器或成功时返回http代码。如果是与api相关的错误,将返回api中记录的错误代码。

您可以在以下位置查看错误代码: Juno错误代码

  • 示例
   
include '../vendor/autoload.php';

use Webgopher\Juno\Core\Environment\SandboxEnvironment;
use Webgopher\Juno\Core\Http\JunoClient;

$clientId = '....';
$clientSecret = '......';
$secretToken = '......';

$environment = new SandboxEnvironment($clientId, $clientSecret, $secretToken);

$juno = new JunoClient($environment);

echo '<pre>';
var_dump($juno->execute(new \Webgopher\Juno\Api\Balance\Balance()));

上面的代码将产生以下结果

object(stdClass)#21 (4) {
  ["status_code"]=>
  int(200)
  ["headers"]=>
  array() {
   ...
  }
  ["reason_phrase"]=>
  string(3) "200"
  ["result"]=>
  object(stdClass)#36 (4) {
    ["balance"]=>
    float(160194.99)
    ["withheldBalance"]=>
    float(10768.52)
    ["transferableBalance"]=>
    float(149426.47)
    ["_links"]=>
    object(stdClass)#33 (1) {
      ["self"]=>
      object(stdClass)#38 (1) {
        ["href"]=>
        string(58) "https://sandbox.boletobancario.com/api-integration/balance"
      }
    }
  }
}

您可以这样分离结果

$request = $juno->execute(new \Webgopher\Juno\Api\Balance\Balance());

$status_code = $request->status_code;
$headers = $request->headers;
$reason_phrase = $request->reason_phrase;
$result = $request->result;

使用$reason_phrase$status_code来处理可能的错误,例如:无效的卡片、卡片余额不足等...