fayda / fayda-php-sdk
Fayda API 的 PHP SDK
v1.0.2
2024-01-23 15:08 UTC
Requires
- php: >=7.1
- ext-json: *
- ext-openssl: *
- firebase/php-jwt: ^5.5
- guzzlehttp/guzzle: ^6.0|^7.0
- monolog/monolog: ~1.0|~2.0|^3.0
Requires (Dev)
- phpunit/phpunit: >=5.7
README
❗此存储库正在开发中。它尚未准备好,可能会有很大变化。
阅读官方规范
文档 Fayda 平台 API 规范。
为了接收最新的更改通知,请
关注此存储库。
需求
安装
通过 Composer 安装包。
composer require "fayda/fayda-php-sdk"
使用方法
选择环境
// Switch to the prod environment FaydaApi::setBaseUri('https://prod.fayda.et');
调试模式与日志记录
// Debug mode will record the logs of API to files in the directory "FaydaApi::getLogPath()" according to the minimum log level "FaydaApi::getLogLevel()". FaydaApi::setDebugMode(true); // Logging in your code // FaydaApi::setLogPath('/tmp'); // FaydaApi::setLogLevel(Monolog\Logger::DEBUG); FaydaApi::getLogger()->debug("I'm a debug message");
示例
更多示例请查看 示例 文件夹。
示例 API - OTP 请求服务
use Fayda\SDK\Api\Otp; use Fayda\SDK\Auth; use Fayda\SDK\Exceptions\BusinessException; use Fayda\SDK\Exceptions\HttpException; use Fayda\SDK\Exceptions\InvalidApiUriException; // Set the base uri for your environment. Default is https://auth-api.fayda.et //FaydaApi::setBaseUri('https://prod.fayda.et'); try { $api = new Otp(); $transactionId = time(); // unique transaction id $individualId = ''; // your Fayda FIN/FCN $result = $api->requestNew($transactionId, $individualId); print "============ OTP Request Result ============\n"; print json_encode($result) . "\n\n"; $otp = readline("Enter OTP: "); print "============ eKyc ============\n"; $dataKyc = new DataKyc(); $authentication = $dataKyc->authenticate( $result['transactionID'], // transactionID from the previous request $individualId, $otp, [ 'otp' => false, 'demo' => true, 'bio' => false, ] ); print json_encode($authentication) . "\n\n"; } catch (HttpException $e) { print $e->getMessage(); } catch (BusinessException $e) { print $e->getMessage(); } catch (InvalidApiUriException $e) { print $e->getMessage(); }
使用 Docker
设置 Docker 环境。
cp .env.example .env- 使用您的凭证编辑
.env文件。 docker-compose up -d
在 Docker 中运行示例。在控制台上查看输出以验证结果。
请求 OTP 并进行 KYC
docker-compose exec fayda php ./examples/Example.php
运行测试
首先在
phpunit.xml中修改您的 API 密钥。
# Add your API configuration items into the environmental variable first export FAYDA_BASE_URL=https://dev.fayda.et export FAYDA_VERSION=1.0 export FAYDA_ENV=prod export FAYDA_SKIP_VERIFY_TLS=0 export FAYDA_DEBUG_MODE=1 composer test
