Wallogit.com
2017 © Pedro Peláez
Duphlux API PHP Library
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
composer require duphlux/duphlux
or, (*3)
add '"duphlux/duphlux": "1.0.0"' to the require section of your composer.json file, then run:, (*4)
composer install
First of all, create an account on Duphlux - You will need your account token to use the service., (*5)
There are two operations that can be performed on the system:, (*6)
authenticate: Initialize a phone number verification request, (*7)
use duphlux/Duphlux; //duphlux account token $token = [your-duphlux-account-token]; // Instantiate the duphlux class, requires your account token $duphlux = new Duphlux($token); //you can generate reference using the generateRef method (note that uniqueness is not guaranteed) //you may choose to generate your reference another way $reference = $duphlux->generateRef(32); //set up the request parameters for the authentication request $options = ['phone_number'=>[phone-number-to-verify],'transaction_reference'=>$reference, 'timeout'=>60,'redirect_url'=>[my-redirect-url]]; // Initializing an authentication request //you can chain this method with the redirect method to immediately redirect to the duphlux verification url $duphlux->authenticate($options);
or, (*8)
//chained authenticate request with redirect method $duphlux->authenticate($options)->redirect();
To check if the api call was successfull, (*9)
//checks if an error occurred during the operation if ($duphlux->hasError) { //gets the request error $error = $duphlux->getError(); } else { //gets the request response returned from the request //you may specify a specific key to get the value from the response information $response = $duphlux->getResponse(); // }
checkStatus: Check the status of a previous request, (*10)
use duphlux/Duphlux; //duphlux account token $token = [your-duphlux-account-token]; // Instantiate the duphlux class $duphlux = new Duphlux($token); //previous authentication request reference for which you want to inquire about the status $reference = getReferenceFromMyDb(); // check the status of an authentication request // the previous authentication request reference is required, it is passed as a parameter $status = $duphlux->checkStatus($reference);
you can chain the above method with the following:, (*11)
//checks the response gotten to see whether the phone number verification was successfull $verified = $status->isVerified(); //checks the response gotten to see whether the phone number verification is still pending $pending = $status->isPending(); //checks the response gotten to see whether the phone number verification failed $failed = $status->isFailed();
Also, you can set the following properties - beforeSend and afterSend, which must be callbacks, before performing any operation. They are passed an instance of the Duphlux class and are called before and after an api request is made. See example below:, (*12)
use duphlux/Duphlux; //duphlux account token $token = [your-duphlux-account-token]; //previous authentication request reference for which we want to inquire about the status $reference = getReferenceFromMyDb(); // Instantiate the duphlux class $duphlux = new Duphlux($token); //this sets the beforeSend handler which is triggered before a any request is made //this can be any callable (anonymous function or class method) $duphlux->beforeSend = function($duphlux) { //here you can now perform any logic u want log($duphlux->getRequestOptions()); }; //this sets the afterSend handler which is triggered after a request is made //this can be any callable (anonymous function or class method) $duphlux->afterSend = function($duphlux) { //here you can now perform any logic u want log($duphlux->getResponse()); }; // verify the status of an authentication request // the previous authentication request reference is required, it is passed as a parameter $duphlux->checkStatus($reference);