Skip to content

Fayda-Community/fayda-php-sdk

Repository files navigation

PHP SDK - Fayda Platform

❗This repository is work in progress. It is not ready yet and may change a lot.

Read the official specification

document Fayda Platform API Specification.

In order to receive the latest change notifications, please Watch this repository.

Latest Version PHP Version Build Status Total Downloads License

Requirements

Dependency Requirement
PHP >=7.1 <8.2 Recommend PHP8+
guzzlehttp/guzzle ^6.0 | ^7.0
firebase/php-jwt ^5.5

Install

Install package via Composer.

composer require "fayda/fayda-php-sdk"

Usage

Choose environment

Environment BaseUri
Production https://prod.fayda.et
Development https://auth-api.fayda.et(DEFAULT)
// Switch to the prod environment
FaydaApi::setBaseUri('https://prod.fayda.et');

Debug mode & logging

// 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");

Examples

See the examples folder for more.

Example API - OTP Request Service

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();
}

Using Docker

Set up docker environment.

  1. cp .env.example .env
  2. edit .env file with your credentials.
  3. docker-compose up -d

Run the examples inside docker. See the output on console to verify the results.

Request OTP and do kyc

docker-compose exec fayda php ./examples/Example.php

Run tests

Modify your API key in phpunit.xml first.

# 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

License

MIT

Ethiopian National ID