Download the PHP package prinx/sevotransact without Composer
On this page you can find all versions of the php package prinx/sevotransact. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sevotransact
SEVOTRANSACT PHP SDK
Sevotransact Payment Gateway PHP SDK Can be used with your favorite framework or your plain PHP project.
Installation
The package can be installed via composer. Install it if you don't have it yet. Then open a terminal in your project root folder and run:
Usage
First create a .env
file in your project root folder, if you don't have any already.
Next, configure the .env by putting your sevotransact credentials and account informations:
The primary and secondary callbacks are URL where SEVOTRANSACT
will send the result of the transaction. YOu can check how to handle the transaction callback here.
The secondary callback is optional.
Request a payment
Voucher code
Some networks (typically VODAFONE) require the user to generate a voucher code. This code can be easily passed to the request:
The voucher code is now optional. If not passed, the user will directly receive a prompt on their phone to accept the transaction.
Mobile money request response
The mobile money request will automatically return a response from which you can determine if the request is being processed or not.
WARNING: This response is just to notify you that your request has been received and is been processed or something went wrong when sending the request. This is not the actual response of the mobile money request. The actual response of the mobile money request will be sent to your provided callback URL.
Process callback
The result of the transaction will be sent to the callback URL provided when sending the request.
To process the callback, create a new route in your favorite framework, or create an php file in your project to handle the callback. The URL resolving to that route or that file is (must be) the one you provided in the .env.
as callback URL.
Now you can create a callback instance that will receive the status of your transactions:
Or if you are using a framework and the callback route is handled by a controller:
We can now register the callback functions that will be run on success, failure or some defined custom condition of the mobile money transaciton. The callback functions will receive the $callback
instance.
You are not require to use all the callbacks. Just use the one that is needed.
Now, run everything, by calling the process
method on the callback.
The full code will be:
TIP: In case you have only one callback function that will be run whether the transaction is successful or not, you can simply pass the function to the process method:
Successful transaction
The code of the transaction determines if the transaction is successful or has failed. By default, the successful transaction codes are in the array returned by $callback->getSuccessCodes()
. You can decide (for any reason it may be) to consider a failure code as success code by adding it to the success codes with the $callback->addSuccessCode($code)
method.
The on
method
The on
method is a powerful way of listening to the transaction request callbacks. It takes as first parameter an array of conditions that can match the request payload and as second parameter a callback function that will be run if the conditions match the payload.
A string can be passed as condition, then it will be considered as the code sent in the payload to the callback URL.
The Callback class implements the fluent interface. You can chain most of its methods (like the on
, success
, failure
methods), in any order.
The callbacks will be run in the order they were registered.
The payload
A payload is sent to the callback URL. It contains 8 parameters:
code
The code of the request.
status
details
The detail message of the status.
id
The transaction ID.
phone
The phone number to which the request was made.
network
The network to which belong the phone number.
amount
The amount of the transaction.
currency
The currency in which the transaction was made.
You can get all the payload array by calling the getPayload
method without parameter.
You can also get any of the payload parameters by passing the name of the parameter to the getPayload
method, for example:
Message associated to the request
You can get the message associated to the request by calling the message
method of the callback instance.
The message is associated to the code in the payload.
Messages
These are the possible messages:
Using the mobile money callback instance in the closure
The callback instance is automatically passed to the closure. You can then use it as below:
Passing other parameter(s) to the closure
You can easily pass other parameters to the closure by using the PHP use
keyword on the closure:
Using a class to handle callbacks
Instead of directly passing the callbacks closures to the success
, failure
or on
methods, you can move all the callbacks to a class and just pass the class to the process
method.
First, create a class containing a callbacks
methods:
The callbacks
method must return an array containing the mapping of your conditions with the callback closures:
The mappings can be duplicated:
Or you can rather passed an array of closures:
You can pass the custom conditions success
, failure
or always
:
You can also pass an array of conditions:
All these can be mixed according to your need:
Instead of returning directly closures in the callbacks methods, you can create public methods in the callback handler class and reference those methods in the array returned in the callbacks
method:
After writing the callback handler class, you just need to pass it to the process method:
Logging
Logging locally
You can provide a log folder where the transactions will be automatically logged.
If no folder has been set, a default log folder will be created at YOUR_PROJECT_ROOT_FOLDER/storage/logs/sevotransact/
.
You can disable local logs by using the env variable (It is enabled by default):
Logging to SLACK
You can provide in your .env
file a slack webhook to automatically log transactions to slack.
You can disable logging to SLACK by putting in the .env
:
It is enabled by default.
Disable logs
To disable the whole logging system, put in your .env
file:
Contribute
Star :star: the repo, fork it, fix a bug, add a new feature, write tests, correct documentation, and submit a pull request.
License
MIT
All versions of sevotransact with dependencies
prinx/dotenv Version ^1.0
prinx/notify Version ^0.0
symfony/http-client Version ^5.1
illuminate/collections Version ^8.16
symfony/http-foundation Version ^5.1
respect/validation Version ^2.2