lecompteanytime/api-php-sdk

此包最新版本(1.11.0)没有提供许可信息。

用于使用Anytime API的PHP SDK

1.11.0 2020-10-26 08:09 UTC

README

此包的目的是为了方便实现我们的API。

有关完整的API文档和食谱,请访问我们的开发者网站

安装

composer require lecompteanytime/api-php-sdk

实现

按照以下示例创建您的客户端和请求。

实例化客户端

使用Anytime提供的连接信息填写以下参数

$client = (new ApiClientFactory())->create([
    'version'           =>  'v1.0',
    'client-id'         =>  'YourOAuth2ClientId',
    'client-secret'     =>  'YourOAuth2ClientSecret',
    'username'          =>  'YourOAuth2Username',
    'password'          =>  'YourOAuth2Password',
    'private-key'       =>  'YourPrivateRSAKey'
], Environment::SANDBOX);

使用 Environment::PRODUCTION 创建生产客户端。

可用API

在发送请求之前,让我们看看可用的API

  • AccountBalance
  • AccountCardList
  • AccountCreation
  • AccountIbanCreation
  • AccountIbanStatement
  • AccountCreditTransfer
  • AccountInfo
  • AccountKyc
  • AccountList
  • AccountStatement
  • AccountStatementDetails
  • AccountUpdate
  • AccountVirtualIbanCreation
  • ApiCheck
  • ApiCheckPost
  • CardCredit
  • CardDebit
  • CardDetailsDisplay
  • CardInfo
  • CardOrder
  • CardSendPan
  • CardSendPin
  • CardGetPan
  • CardGetPin
  • CardTransaction
  • CardTransactionDetails
  • CardUpdate
  • OrderTracking
  • RequestMultiRequest

所有这些API都可以通过api()方法调用,如下所示

$api = $client->api()->theApiName();

创建令牌

如果您还没有有效的令牌,可以通过调用客户端的"generateToken"方法创建它。令牌将被直接初始化在客户端并由方法返回

try {
    $token = $client->generateToken();
    echo $token;
} catch(ApiClientException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

如果您已经有了令牌,只需调用客户端的"initToken"方法即可

$client->initToken($yourToken);

辅助工具

我们已创建几个辅助类,以帮助您使用正确的值填写请求参数。这些辅助类是只包含常量的类

  • AccountType : 包含2个可能的账户类型值(商业和消费者)
  • CardStatus : 不同的卡片状态(已阻止、已激活等...)
  • CardType : 塑料、虚拟...
  • Country : 可用国家代码列表
  • Currency : 所有货币
  • Environment : 可用环境(生产 & 测试)
  • Gender : M / F
  • Language : 可用语言

发送请求

流程总是相同的

  1. 您创建一个请求
  2. 如有必要,填写参数
  3. 发送请求并返回响应对象。

所有返回数据都可通过响应对象的getter方法访问。

您的第一个请求

要检查一切是否正常工作,您可以尝试调用"GET apicheck" API

$api = $client->api()->apiCheck();

$request = $api->createRequest();

try {
    $response = $api->sendRequest($request);
    echo $response->getDateTime()->format('Y-m-d H:i:s');
} catch(ApiClientException $e) {
    echo "ERROR: " . $e->getMessage();
}

您也可以使用"POST apicheck" API检查POST方法

$api = $client->api()->apiCheckPost();

$request = $api->createRequest()
    ->setTestParam('This is a test value');
;

try {
    $response = $api->sendRequest($request);
    echo $response->getTestParam(); // This should print "This is a test value"
} catch(ApiClientException $e) {
    echo "ERROR: " . $e->getMessage();
}

检索账户列表

$accountListApi = $client->api()->accountList();
$request = $accountListApi->createRequest();

try {
    $response = $accountListApi->sendRequest($request);

    foreach($response->getAccounts() as $account) {
        echo $account->getAccId() . ' - ' . $account->getAccType() . "\n";
    }
} catch(ApiClientException $e) {
    echo 'ERROR: ' . $e->getMessage();
}