tumainimosha / credit-info
A Laravel package for integration with Credit Info (Tanzania) API
Requires
- php: >=7.0
- ext-json: *
- ext-simplexml: *
- ext-soap: *
- illuminate/support: ~5.7.0|~5.8.0|^6.0|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- orchestra/testbench: ~3.7.0
- phpunit/phpunit: ^7.0
README
Credit Info (TZ) API Wrapper for Laravel
The Unofficial Credit Info Tanzania API wrapper for Laravel.
- CreditInfo Tanzania website
- WSDL (requires Basic Auth authentication)
Installation
Install via composer
composer require tumainimosha/credit-info
Publish Configuration File
Optional! Publish config file only if you wish to customize the default package config.
php artisan vendor:publish --provider="CreditInfo\ServiceProvider" --tag="config"
Configuration
Authentication
Configure your api username and password in .env
file as follows
CREDIT_INFO_USERNAME=your_api_username CREDIT_INFO_PASSWORD=your_api_password
Apart from authentication configurations, the following remaining configurations are optional.
For basic usage jump straight to Usage Section
URL
The package config file comes with default API url pointing to production
.
CREDIT_INFO_WSDL=https://ws.creditinfo.co.tz/WsReport/v5.39/service.svc?wsdl
To point to test
environment set the CREDIT_INFO_WSDL key in your .env
file to point to test url given. (See below)
CREDIT_INFO_WSDL=https://wstest.creditinfo.co.tz/WsReport/v5.39/service.svc?wsdl
Remember
- The WSDL url should end with a
?wsdl
suffix, don't forget to add this if you haven't already. - You need to first configure correct Authentication details above for your respective environment, as the WSDL url is secured with Basic Auth.
Response Caching
The package by default caches API response from Credit Info to speed up subsequent requests for the same data.
You can control this feature by setting the CREDIT_INFO_CACHE_TTL
value in minutes in your .env
. (See below)
By default data is cached for 24 hours = 1440 minutes
CREDIT_INFO_CACHE_TTL=1440
Set the value to zero(0) to completely disable caching.
WSDL Caching
Default behaviour of PHP Soap Client is to Cache WSDL files for improved performance.
However, during development you may require for debugging reasons to disable WSDL caching of the soap client.
To do so set the CREDIT_INFO_CACHE_WSDL
key in your .env
file to false
(See below)
Caution: Disabling WSDL caching will significantly slow down performance. Please remember to always revert this option to true
after you are done debugging.
CREDIT_INFO_CACHE_WSDL=false
Usage
Vehicle Report
Method getVehicleReport()
queries vehicle information by Vehicle Registration ID
$creditInfoService = new \CreditInfo\CreditInfo(); $details = $creditInfoService->getVehicleReport($registration_number);
Driving License Report
Method getDrivingLicenseReport()
queries drivers license information by Driving License Number
$creditInfoService = new \CreditInfo\CreditInfo(); $details = $creditInfoService->getDrivingLicenseReport($driving_license_no);
National Id Report
Method getNationalIdReport()
queries an individual information by National Id Number
$creditInfoService = new \CreditInfo\CreditInfo(); $details = $creditInfoService->getNationalIdReport($national_id);
Exception Handling
The above methods throws the following exceptions
Exception | Condition |
---|---|
CreditInfo\Exceptions\Exception |
This is the package's base exception. All exceptions from this library inherit from it. *** This should be caught last as a catch-all statement. |
CreditInfo\Exceptions\InvalidReferenceNumberException |
Thrown if supplied reference number fails validation requirements. |
CreditInfo\Exceptions\DataNotFoundException |
Thrown if no data found for given reference number |
CreditInfo\Exceptions\TimeoutException |
Thrown if request timeouts |
See usage below with exception catching
use CreditInfo\Exceptions\DataNotFoundException; use CreditInfo\Exceptions\Exception; use CreditInfo\Exceptions\InvalidReferenceNumberException; use CreditInfo\Exceptions\TimeoutException; use CreditInfo\CreditInfo; ... public function testVehicleInfo() { $registration = 't100abc'; $creditInfoService = new CreditInfo(); try { $details = $creditInfoService->getVehicleReport($registration); } catch(InvalidReferenceNumberException $ex) { // Handle case invalid reference number case throw($ex); } catch(TimeoutException $ex) { // Handle case if request timeout throw($ex); } catch(DataNotFoundException $ex) { // Handle case if registration number not found throw($ex); } catch(Exception $e) { // Handle other API errors throw($e); } dd($details); } ...
TODO
- Vehicle Report
- Driving license Report
- National ID Report
- TIN Report
Security
If you discover any security related issues, please email Me instead of using the issue tracker.
Credits
This package is bootstrapped with the help of melihovv/laravel-package-generator.