fayda / fayda-php-sdk
PHP SDK for Fayda API
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
❗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.
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.
cp .env.example .env
- edit
.env
file with your credentials. 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