fayda/fayda-php-sdk

Fayda API 的 PHP SDK

v1.0.2 2024-01-23 15:08 UTC

This package is auto-updated.

Last update: 2024-09-24 11:46:40 UTC


README

❗此存储库正在开发中。它尚未准备好,可能会有很大变化。

阅读官方规范

文档 Fayda 平台 API 规范

为了接收最新的更改通知,请 关注 此存储库。

Latest Version PHP Version Build Status Total Downloads License

需求

安装

通过 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 环境。

  1. cp .env.example .env
  2. 使用您的凭证编辑 .env 文件。
  3. 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

许可协议

MIT

Ethiopian National ID