Laravel Sudani is Sudani SPay API integration with Laravel, made to simplify 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' => false,
];
Don't forget to set all these variables 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 the initiate
payment request is successfully sent, an SMS with an OTP
code will be sent 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)
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 to cache the token and use it for further requests, you can request a token
like this:
$token = Sudani::token()
And you can cache it and use it for each request 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 the package config file
'enable_logging' => true,
-
Laravel Zain DSP API Integration
Laravel Sudani is open-sourced software licensed under the MIT license.