Showing posts with label customer httpapi. Show all posts
Showing posts with label customer httpapi. Show all posts

Thursday, March 13, 2014

how to authenticating a token httpapi php

In this blog post we explain you that how you can authenticates the token generated by the Generate Token method for customer using httpapi.com api and returns the Customer details, if token authenticated. It requires GET HTTP Method. You need auth-userid, api-key or auth-password, and token parameters for process. If the token is authenticated then you will be get the below customer details in response:


Customer Id (customerid)
Customer Username (username)
Reseller Id of the Parent Reseller (resellerid)
Name (name)
Company (company)
Email Address (useremail)
Telephone Number Country Code (telnocc)
Telephone Number (telno)
First line of address of the Customer (address1)
Second line of address of the Customer (address2)
Third line of address of the Customer (address3)
City (city)
State (state)
Country Code (country)
ZIP Code (zip)
Personal Identification Number (pin)
Creation Date (creationdt)
Current Status (customerstatus)
Sales Contact Id (salescontactid)
Language Preference for the Control Panel and Emails (langpref)
Total Receipts (totalreceipts)

In case of any errors, a status key with value as ERROR alongwith an error message will be returned. For Authenticating a Token you can use following function.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

function AUTHENTICATE_TOKEN($token)
{

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 
 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

   if(isset($token))
   {

   $check_token = $api_url.'/api/customers/authenticate-token.json?auth-userid='.$auth_userid.'&api-key='.$api_key.'&token='.$token;
   $result = @file_get_contents($check_token);
   $response = json_decode($result, true);
   return $response;
 }

 return false;

}

?>

Function USAGE

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/
 
 $_customer = AUTHENTICATE_TOKEN("token");
 
    if($_customer)
    {

     // Customer details if the token is authenticated

     print_r($_customer);

                              
    }
    else
    {
        echo "Invalid token.";
    }

?>

how to register customer httpapi curl php

Signing Up a Customer Account using the httpapi.com api. It requires POST HTTP Method. You can use following function to register customer account with api intergration. You need auth-userid and api-key or auth-password for that. Look at follow code for more information.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




function SIGNUP_CUSTOMER($data)
{
 // post all required data through via $_POST in $data
 $_data = $data;

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 

 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

 if(isset($auth_userid) && isset($api_key))
 {
  $handle = curl_init();
  curl_setopt($handle, CURLOPT_URL,$api_url.'/api/customers/signup.xml');
  curl_setopt($handle, CURLOPT_POST, 1);
  curl_setopt($handle, CURLOPT_POSTFIELDS,
              'auth-userid='.$auth_userid.'&api-key='.$api_key.'&username='.urlencode($_data['username']).'&passwd='.urlencode($_data['passwd']).'&name='.urlencode($_data['name']).'&company='.urlencode($_data['company']).'&address-line-1='.urlencode($_data['address-line-1']).'&city='.urlencode($_data['city']).'&state='.urlencode($_data['state']).'&country='.urlencode($_data['country']).'&zipcode='.urlencode($_data['zipcode']).'&phone-cc='.urlencode($_data['phone-cc']).'&phone='.urlencode($_data['phone']).'&lang-pref=en');



  // receive server response ...
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  $server_output = curl_exec ($handle);
  curl_close ($handle);


  // echo $server_output;
  if( strpos($server_output,'ERROR') === FALSE)
  {
   echo "You're Almost Done. Your sign up  process is completed.";
   return true;
  }
  else
  {
   echo "".$server_output."";
  }

 }

 return false;


}

?>

Function USAGE
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




 
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {

       SIGNUP_CUSTOMER($_POST);
                              
    }
    else
    {
        $_POST = NULL;
    }

?>


 

© 2014 4everTutorials. All rights resevered.

Back To Top