Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 

Duphlux API PHP Library

Installation

The preferred way to install this extension is through composer.

Either run

composer require duphlux/duphlux

or

add '"duphlux/duphlux": "1.0.0"' to the require section of your composer.json file, then run:

composer install

Usage

First of all, create an account on Duphlux - You will need your account token to use the service.

There are two operations that can be performed on the system:

  • authenticate: Initialize a phone number verification request

      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

      //chained authenticate request with redirect method
      $duphlux->authenticate($options)->redirect();

    To check if the api call was successfull

      //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

      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:

    //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:

      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);

About

Duphlux API PHP Library

Resources

License

Packages

No packages published

Languages