Laravel Sudani is Sudani SPay API integration with Laravel, made to simplify the the process and API calls and let developers focus on other integration parts and logic. See also Laravel Zain.
- PHP >=
7.4.x
- Laravel >=
7.x
composer require alkhatibdev/laravel-sudani
php artisan vendor:publish --tag=laravel-sudani-config
A laravel-sudani.php
config file will be published on your configs
directory, with the following content:
<?php
return [
'base_url' => env('SUDANI_SERVER_BASE_API_URL'),
'provider_key' => env('SUDANI_PROVIDER_KEY'),
'service_code' => env('SUDANI_SERVICE_CODE'),
'username' => env('SUDANI_USERNAME'),
'password' => env('SUDANI_PASSWORD'),
'enable_logging' => true,
];
Don't forget to set all these variable on your .env
file
SUDANI_SERVER_BASE_API_URL=http://196.1.241.110/SPayAPI/Service/
SUDANI_PROVIDER_KEY=xxxxxxxx
SUDANI_SERVICE_CODE=xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
SUDANI_USERNAME=xxxxxx
SUDANI_PASSWORD=xxxxxx
use AlkhatibDev\LaravelSudani\Facades\Sudani;
// Initiate payment request
$response = Sudani::initiate($phone)
When initiate
payment request successfully sent, a SMS with OTP
code will be send to the $phone
number, and $response
will contain a requestId
and you should save it to the next step verify
.
$response = Sudani::verify($otp, $requestId)
$response = Sudani::checkSubscription($phone)
$response = Sudani::unsubscribe($phone)
// cacheToken($response['token'])
Out of the box the package will encrypt the password and login automatically and get the token
and use it for each action initiate
, verify
..etc per request.
If you want cache the token and use it for furthor requests of whole day, you request token
like this:
$token = Sudani::token()
And you can cache it and use for next requests for the next 24 hours, for example:
// $token = getCachedToken()
$response = Sudani::withToken($token)->initiate($phone)
$response = Sudani::withToken($token)->verify($phone)
...
You can enable logging from package config file
'enable_logging' => true,
-
Laravel Zain DSP API Integration
Laravel Sudani is open-sourced software licensed under the MIT license.