Tuesday, June 10, 2014

WooCommerce USAePay Payment Gateway


USA ePay is an ECI Certified, Real-Time, Credit Card Processing Gateway.

Secure, Fast and Reliable, the USA ePay Gateway is a vital solution to helping your merchants process Credit Card Transactions online from anywhere in the world.

Features

Set Shop Hour(s) Day(s) and Timezone

- Secure, Fast and Reliable Checkout Process 
- Accepts Major Credit Cards – Visa®, MasterCard®, American Express®, Discover®

Sources Checkout

- Option to set Merchant Source Key. 
- Easy Extension Settings

Wordpress Source Code

- Download here

Screenshots



Monday, June 9, 2014

WooCommerce Google Wallet Payment Gateway



Google Wallet is a free digital wallet that securely stores your credit cards, debit cards, loyalty cards offers and more. With Google Wallet, you can shop in stores and buy online.

In the United States, you can use Google Wallet to shop in stores. Outside of the United States, you can shop online using Google Wallet to make purchases in over 125 countries, and at online merchants in over 160 countries and territories.

Plugin Features

Set Shop Hour(s) Day(s) and Timezone

  1. Smart, virtual wallet that saves you time and money.
  2. Safe and Secure Checkout Process.
  3. Accepts Major Credit Cards / Debit Cards and bank accounts.


Sources Checkout

  1. Option to set Seller Identifier.
  2. Option to set Seller Secret Key.


Easy Extension Settings

  1. Enabled - this setting will enable the gateway which will be used by customers to checkout.
  2. Title - this setting will appear for the payments during checkout. this will be shown on the page- Order Received.
  3. Description - this will appear under the setting - Title, during customer's checkout.Please note that once environment is not "Production" a "Sandbox" notice will be shown.
  4. Return Url - used to choose Return Page or Thank you page.
  5. Environment - this setting is used to post transactions to.

You can either set this to:
  a) Production - if you are using Payment Gateway Production / Live Account
  b) Sandbox - if you are using Payment Gateway Sandbox / Test Account




Monday, June 2, 2014

WePay Payment Gateway for WooCommerce Plugins



Easily Accept Credit Cards and Bank Accounts

Plugin Features
  1.  Fast Setup 
  2.  Option to iframe or redirect the secure checkout
  3. Safe and Secure Checkout Process
  4. Accepts Major Credit Cards / Debit Cards – Visa®, MasterCard®, American Express®, Discover®, and bank accounts
  5. Choose whether you or the customer pays processing fees
  6. Option to select Bank and CC Payments or Credit Card payments or Bank Payments for Funding Sources Checkout
  7. Option to select Return page / Thank you page
  8. Option to select Transaction Type – Goods , Service , Donation , Event and Personal
  9. Choose whether you or the customer pays processing fee

Tuesday, May 6, 2014

FuseDesk API Integration

FuseDesk PHP API Integration Class Wrapper.
Use the cases method to add, find and update cases.
see full documentation: https://fusedesk.com/help/api/cases/

Source Code:
<?php
class fusedesk_api
{
 public $fusedeskAppName = 'XXXXXXXX'; // Your fusedesk app name
 public $fusedeskApiKey  = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your fusedesk api key
 
 function _newcase($params)
 {
  $err = array();
  
  $args['repid']  = (!empty($params['repid']) ? $params['repid'] : ''); 
  $args['contactid']  = (!empty($params['contactid']) ? $params['contactid']: '');
  $args['status']  = (!empty($params['status']) ? $params['status']: '');
  $args['companyid']  = (!empty($params['companyid']) ? $params['companyid']: '');
  $args['date_assigned']  = (!empty($params['date_assigned']) ? $params['date_assigned']: '');
  $args['date_opened']  = (!empty($params['date_opened']) ? $params['date_opened']: '');
  $args['companyid']  = (!empty($params['companyid']) ? $params['companyid']: '');
  
  date_default_timezone_set('Australia/Sydney');
  $args['date_updated']  = date('Y-m-d H:i:s',time());  
  
  if(!empty($params['email'])){
   $args['email']      = $params['email']; 
  }
  
  if(!empty($params['depid'])){
   $args['depid']   = $params['depid'];   
  }else{
   $err[] = 'depid';
  }
  
  if(!empty($params['summary'])){
   $args['summary']  = $params['summary'];    
  }else{
   $err[] = 'summary';
  }

  if(!empty($params['details'])){
   $args['details']  = $params['details'];  
  }else{
   $err[] = 'details';
  }
  
  if(!empty($params['openedby'])){
   $args['openedby']  = $params['openedby']; 
  }else{
   $err[] = 'openedby';
  }

  if(empty($err)){
   $results =  json_encode($this->_apicall("/cases/", $args, 'POST'));
  }else{
   $results = json_encode(array('error' => 'Invalid submission! Please refresh the page and try again.'));
  }
  
  return $results;
 }
 
 function _apicall( $url, $args = array(), $type = 'GET' )
 {
     $fullurl = 'https://'.$this->fusedeskAppName.'.fusedesk.com/api/v1'.$url; 
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $fullurl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FuseDesk-API-Key: '.$this->fusedeskApiKey));

     if($type == 'POST') {
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
     } else {
         curl_setopt($ch, CURLOPT_URL, $fullurl.'?'.http_build_query($args));
     }
 
  $result = json_decode(curl_exec($ch));
  curl_close($ch);
  
     return $result;
 }
}
?>

Sample Code:

<?php
$params['repid']   = (int) 1;
$params['depid']   = (int) 001;
$params['summary'] = 'Test API summary';
$params['details'] = 'Test API details';
$params['openedby'] = 'Juan Dela Cruz';

$payload = new fusedesk_api();
$cases = $payload->_newcase($params);
print_r($cases);

?>

Wednesday, April 30, 2014

Pinterest Javascript and PHP Integration

Pinterest Sample Code Javascript and PHP Integration , Invite people to pin things from your website using Pin It button , Invite people to follow you on Pinterest from your site using Follow button.

  Source Code
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
                (function (d, buildThese) {
                    var homeScript, newScript, n = buildThese.length, i;
                    for (i = 0; i < n; i = i + 1) {
                        newScript = d.createElement('SCRIPT');
                        newScript.type = 'text/javascript';
                        newScript.async = true;
                        newScript.src = buildThese[i];
                        homeScript = d.getElementsByTagName('SCRIPT')[0];
                        homeScript.parentNode.insertBefore(newScript, homeScript);
                    }
                }(document, [
                    '//assets.pinterest.com/js/pinit.js'
                    /* load more third-party JavaScript here */
                ])
            );
        </script>
    </head>
    <body>
        <!-- Pin It button: Invite people to pin things from your website.-->
        
        <?php
            $url            = urlencode("<YOUR-URL>");
            $media          = urlencode("<YOUR-IMAGE-URL>");
            $description    = "<YOUR-DESCRIPTION>";
            $dataPinConfig  = "above"; /* above, beside, none */
            $buttonPin      = "buttonPin"; /* buttonPin, buttonFollow*/
        ?>
        
        <a 
           data-pin-config  ="<?=$dataPinConfig;?>" 
           href             ="//pinterest.com/pin/create/button/?url=<?=$url;?>&media=<?=$media;?>&description=<?=$description;?>" 
           data-pin-do      ="<?=$buttonPin;?>" >
            <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
        </a>
        
        <!-- Follow button: Invite people to follow you on Pinterest from your site.-->
        
        <?php
            $fullName       = "<YOUR-FULL-NAME>";
            $buttonPin      = "buttonFollow";
        ?>
        
        <a 
            data-pin-do="<?=$buttonPin;?>" 
            href="//pinterest.com/pinterest/"><?=$fullName;?>
        </a>
        
    </body>
</html>



BitPay Api Integration

Simple PHP Class Wrapper using BitPay Api Integration.

Source Code
<?php

class BitPay
{
    var $config = array();
    
    function __construct() {
        $this->config = array(
                'apiKey'            => '', /* bitpay.com Api key*/
                'verifyPos'         => 'true',
                'notificationEmail' => '',
                'notificationURL'   => '',
                'redirectURL'       => '',
                'currency'          => 'BTC',
                'physical'          => 'true',
                'fullNotifications' => 'true',
                'transactionSpeed'  => 'low'
         );
    }
    
    function execute ($url, $apiKey, $post = false){
        $curl   = curl_init($url);
        $length = 0;
        
        if ($post) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
            $length = strlen($post);
        }

        $uname = base64_encode($apiKey);
        $header = array(
            'Content-Type: application/json',
            "Content-Length: $length",
            "Authorization: Basic $uname",
        );

        curl_setopt($curl, CURLOPT_PORT, 443);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);

        $responseString = curl_exec($curl);

        if ($responseString == false) {
            $response = curl_error($curl);
        } else {
            $response = json_decode($responseString, true);
        }
        
        curl_close($curl);
        return $response;
    }
    
    function CreateInvoice($orderId, $price, $posData, $options = array()) {
        
        $options = array_merge($this->config, $options); 

        $options['posData'] = '{"posData": "' . $posData . '"';
        if ($this->config['verifyPos']) 
            $options['posData'].= ', "hash": "' . crypt($posData, $this->config['apiKey']) . '"';
        $options['posData'].= '}';

        $options['orderID'] = $orderId;
        $options['price'] = $price;

        $postOptions = array(   'orderID', 
                                'itemDesc', 
                                'itemCode', 
                                'notificationEmail', 
                                'notificationURL', 
                                'redirectURL',
                                'posData', 
                                'price', 
                                'currency', 
                                'physical', 
                                'fullNotifications', 
                                'transactionSpeed', 
                                'buyerName',
                                'buyerAddress1', 
                                'buyerAddress2', 
                                'buyerCity', 
                                'buyerState', 
                                'buyerZip', 
                                'buyerEmail', 
                                'buyerPhone'
                            );
        foreach ($postOptions as $o){
            if (array_key_exists($o, $options)){
                $post[$o] = $options[$o];
            }
        }
            
        $post       = json_encode($post);
        $response   = $this->execute('https://bitpay.com/api/invoice/', $this->config['apiKey'], $post);

        return $response;
    }
    
    function VerifyNotification($apiKey = false) {
        
        if (!$apiKey)
            $apiKey = $this->config['apiKey'];

        $post = file_get_contents("php://input");
        if (!$post)
            return 'No post data';

        $json = json_decode($post, true);

        if (is_string($json))
            return $json; // error

        if (!array_key_exists('posData', $json))
            return 'no posData';

        $posData = json_decode($json['posData'], true);
        if ($this->config['verifyPos'] and $posData['hash'] != crypt($posData['posData'], $apiKey))
            return 'authentication failed (bad hash)';
        $json['posData'] = $posData['posData'];

        return $json;
    }
    
    function GetInvoice($invoiceId, $apiKey = false) {
        
        if (!$apiKey)
            $apiKey = $this->config['apiKey'];

        $response = $this->execute('https://bitpay.com/api/invoice/' . $invoiceId, $apiKey);
        if (is_string($response))
            return $response; // error
        $response['posData'] = json_decode($response['posData'], true);
        return $response;
    }
            
}


?>


Google AdSense API PHP Integration

Get More Money/Income from AdSense and Increase your Google Ads Revenue by Integrating and Customizing Ads using Google AdSense API. A sample GenerateAdCode method integration using NuSoap Client for Google AdSense API.

Source Code
<?php

require_once 'soapclient/nusoap.php';
require_once 'common.php';

$live  = FALSE;

define('EMAIL', '<YOUR-GOOGLE-DEVELOPER-EMAIL>');
define('PASSWORD', '<YOUR-GOOGLE-DEVELOPER-PASSWORD>');
define('CLIENT_ID', '<YOUR-GOOGLE-CLIENT-ID>');

if($live){
        $server = 'https://www.google.com';
    }else{
        $server = 'https://sandbox.google.com';
}

$namespace = 'http://www.google.com/api/adsense/v3';

/* Authentication Headers */

$header     = EMAIL . PASSWORD . CLIENT_ID;

/* Creating Soap Client Request */

$wsdl   = $server . '/api/adsense/v3/AccountService?wsdl';
$client = new soapclient($wsdl, true);
$err    = $client->getError();

if ($err) {
  showSoapClientError($err);
  return;
}
$client->soap_defencoding = 'UTF-8';

/* Set the headers; they are needed for authentication */
$client->setHeaders($header);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

/* setting the parameter */
$param = "<ns1:getSyndicationService xmlns:ns1=\"$namespace\"><synServiceType><value>ContentAds</value></synServiceType></ns1:getSyndicationService>";

/* invoke web service */
showCall('getSyndicationService', $param);
$response = $client->call('getSyndicationService', $param, $namespace);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

/* get back the response */
$response = $response['return'];
$synServiceId = $response['id'];
showSynServiceId($synServiceId);


/* showing the soap */
showRequestResponse($client);


// setup client soap for another webservice
$wsdl = $server . '/api/adsense/v3/AdSenseForContentService?wsdl';
$client = new soapclient($wsdl, true);
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}
$client->soap_defencoding = 'UTF-8';

/* Set the headers; they are needed for authentication */
$client->setHeaders($header);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

/* setting up adstyle parameter */
$ads_param = '<adStyle>';
$ads_param .= "<name>demoStyle</name>";
$ads_param .= '<borderColor>#0000FF</borderColor>';
$ads_param .= '<backgroundColor>#FFFFFF</backgroundColor>';
$ads_param .= '<titleColor>#FF0000</titleColor>';
$ads_param .= '<textColor>#00FF00</textColor>';
$ads_param .= '<urlColor>#FFFF00</urlColor>';
$ads_param .= '</adStyle>';

/* setting up parameter */
$param = '<synServiceId>'.$synServiceId.'</synServiceId>';
$param .= $ads_param;
$param .= '<adUnitType><value>TextOnly</value></adUnitType>';
$param .= '<layout><value>728x90</value></layout>';
$param .= '<alternate>#FFFFFF</alternate>';
$param .= '<isFramedPage type="xsd:boolean">false</isFramedPage>';
$param .= '<channelName xsi:nil="true"/>';
$param .= '<cornerStyles><value>DEFAULT</value></cornerStyles>';

$param = "<ns1:generateAdCode xmlns:ns1=\"$namespace\">" . $param . "</ns1:generateAdCode>";

/* invoke the web service */
showCall('generateAdCode', $param);
$response = $client->call('generateAdCode', $param, $namespace);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

$response = $response['return'];
$snippet = $response;
showSnippet($snippet);

/* showing the soap */
showRequestResponse($client);

?>


Posting Status in your Facebook Page with PHP API Class Wrapper

Post your Status in Facebook Page with PHP API Class Wrapper

Get Your App Id and App Secret 
http://developers.facebook.com

Facebook PHP SDK (v.3.2.2)
https://github.com/facebook/facebook-php-sdk

Source Code

<?php

/* Post your Status in your Facebook Page with PHP API Integration */

require 'src/facebook.php';

/* Configure Facebook Apps Settings */

define('APP_ID', '<YOUR-APP-ID>');
define('APP_SECRET', '<YOUR-APP-SECRET>');
define('APP_PERMISSION', 'publish_stream, manage_pages');
define('FILE_UPLAOD', FALSE);


/* Configure Facebook */

$facebook = new Facebook(
                array(
                    'appId'         => APP_ID,
                    'secret'        => APP_SECRET,
                    'fileUpload'    => FILE_UPLAOD
                )
        );

try {
    
    $user = $facebook->getUser();

    if ($user) {
        
        $page_id = '<YOUR-PAGE-ID>';
        $page_info = $facebook->api("/$page_id?fields=access_token");
        
        if( !empty($page_info['access_token']) ) {
            $data = array(
                            'access_token'  => $page_info['access_token'],
                            'message'       => '<YOUR-POST-MESSAGE>', 
                            'picture'       => '<YOUR-PICTURE-URL-LINK>', 
                            'link'          => '<YOUR-WEBSITE-URL-LINK>',
                            'description'   => '<YOUR-POST-DESCRIPTION>', 
                            'name'          => '<YOUR-POST-NAME>'

                        );
            $post_id = $facebook->api("/$page_id/feed","post",$data);
       } else {
        $permissions = $facebook->api("/me/permissions");
        if( !array_key_exists('publish_stream', $permissions['data'][0]) || !array_key_exists('manage_pages', $permissions['data'][0])) {
            echo("<script>top.location.href='" . $facebook->getLoginUrl(array( 'scope' => APP_PERMISSION )) . "'</script>");
        }

    }
        
    }else{
        echo("<script>top.location.href='" . $facebook->getLoginUrl(array( 'scope' => APP_PERMISSION )) . "'</script>");
    }

} catch (FacebookApiException $e) {
    echo $e->getMessage();
    $user = null;
}

Invite Friends In FACEBOOK with API Apprequest Method Implementation

This sample Code is a Facebook API method implementation which uses Javascript SDK. A simple source code that can invite your friends to use your Facebook Application.

Source Code


 <!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <script type="text/javascript">
            window.fbAsyncInit = function() {
                FB.init({
                    appId: "<YOUR-APP-ID>",
                    status: true,
                    cookie: true
                });
            };
            
            // Load the SDK Asynchronously
            (function(d){
                var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
                if (d.getElementById(id)) {return;}
                js = d.createElement('script'); js.id = id; js.async = true;
                js.src = "//connect.facebook.net/en_US/all.js";
                ref.parentNode.insertBefore(js, ref);
            }(document));
            
            function invite_your_friends() {
                FB.ui({
                    method: "apprequests",
                    message: "Check out this Fantastic App!"
                }, invite_your_friends_callback);
            }
            
            function invite_your_friends_callback(response) {
                console.log(response);
            }

  </script>
  <center>
      <a href="javascript:;" onclick="invite_your_friends();">
          <h3>Invite Your Friends and Share this Fantastic App!</h3>
      </a>
  </center>
    </body>
</html>



PHP Twitter OAuth Login Dialog Implementation

This simple code is used for authentication in twitter. It is an OAuth Login using PHP SDK Codebird Adapter.

Get Your Twitter Developer Account ( Consumer Key & Consumer Secret )
https://dev.twitter.com/

Source Code
<?php session_start();

require_once 'codebird.php';

define('CONSUMER_KEY', '<YOUR-CONSUMER-KEY>');
define('COMSUMER_SECRET', '<YOUR-CONSUMER-SECRET>');

Codebird::setConsumerKey(CONSUMER_KEY, COMSUMER_SECRET);
$tweet = Codebird::getInstance();

if (!isset($_REQUEST['oauth_verifier'])) {

        $response = $tweet->oauth_requestToken(array('oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
        $tweet->setToken($response->oauth_token, $response->oauth_token_secret);

        $_SESSION['OAUTH_TOKEN']        = $response->oauth_token;
        $_SESSION['OAUTH_TOKEN_SECRET'] = $response->oauth_token_secret;

        $auth_url = $tweet->oauth_authorize();
        header('Location: ' . $auth_url);
        exit;
    
    } else {
    
        $tweet->setToken($_SESSION['OAUTH_TOKEN'], $_SESSION['OAUTH_TOKEN_SECRET']);
        $response = $twitt->oauth_accessToken(array('oauth_verifier' => $_REQUEST['oauth_verifier']));

        $_SESSION['OAUTH_TOKEN']        = $response->oauth_token;
        $_SESSION['OAUTH_TOKEN_SECRET'] = $response->oauth_token_secret;
}

/* Get your account details.*/

$tweet->setReturnFormat(CODEBIRD_RETURNFORMAT_ARRAY);
$acct_info = $tweet->account_verifyCredentials();
var_dump($acct_info);




Send SMS PHP Integration Using Twilio API

This sample source code is a simple PHP Integration which uses Twilio API.

Get Your API ACCOUNT SID and AUTH TOKEN 
http://www.twilio.com/user/account/

Source Code
<?php

   require_once 'Services/Twilio.php';

   define('ACCOUNT_SID', '<YOUR-ACCOUNT-SID>');  
   define('AUTH_TOKEN', '<YOUR-AUTH-TOKEN>');  
   
   $client = new Services_Twilio(ACCOUNT_SID, AUTH_TOKEN);
   
   /* Send an SMS */
   
   $twilioNumber = "XXX-XXX-XXXX";  /* Twilio number that you've purchased*/
   $mobilePhoneNumber = "+63XXXXXXXXXXX"; /* the number you are sending */
   
   $artist = "Juan Dela Cruz";
   $message = "Rock N Roll!. - {$artist}";
   
   $sendSMS = $client->account->sms_messages->create($twilioNumber , $mobilePhoneNumber , $message );
   
   /* Response */
   echo $sendSMS->sid;
   
  
?>
   

LinkedIn API PHP Integration

Simple LinkedIn Share API Integration, This sample code has the ability to posts activities of users and share rich contents.

Get Your API key and App Secret 
http://developer.linkedin.com/

Simple-linkedinphp PHP SDK
http://code.google.com/p/simple-linkedinphp/


 Source Code
<?php session_start();

/**
 * Name         : LinkedIn API PHP Integration 
 * Description  : Simple LinkedIn Share API Integration
 * Author       : Ryan Tipones
 * Version      : 0.1
 * Author URI   : http://bikolexpressonline.com
 *  
 */

require_once "linkedin.php";

try {
    
    define('CALLBACK_URL', '<YOUR-CALLBACK-URL>');
    define('APP_KEY', '<YOUR-APP-KEY>');
    define('APP_SECRET', '<YOUR-APP-SECRET>');

    $linkedin = new LinkedIn(array(
                        'callbackUrl'   => CALLBACK_URL,
                        'appKey'        => APP_KEY,
                        'appSecret'     => APP_SECRET
                    )
            );

    if (isset($_REQUEST['oauth_verifier'])){
        
        /* Verify  Section */
        
        $response = $linkedin->retrieveTokenAccess(
                        $_SESSION['oauth_token'], 
                        $_SESSION['oauth_token_secret'], 
                        $_GET['oauth_verifier']
                );
        
        if($response['success'] === TRUE) {
             $_SESSION['oauth_access']  = $response['linkedin'];
        }
        
    }else{
        
        /* Auth Section */
        
        $response = $linkedin->retrieveTokenRequest();
        if($response['success'] === TRUE) {
                $_SESSION['oauth_token']        = $response['linkedin']['oauth_token'];
                $_SESSION['oauth_token_secret'] = $response['linkedin']['oauth_token_secret'];
                header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); 
            } else {
                throw new LinkedInException('Request token retrieval failed');
        }
    }
    
    
    /* Shared Section */
    
    $linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
    $linkedin->setTokenAccess($_SESSION['oauth_access']);
    $response = $linkedin->profile('~/email-address');

    if($response['success']){
            $content                        = array();
            $content['comment']             = '<YOUR-POST-COMMENT>';
            $content['title']               = '<YOUR-POST-TITLE>';
            $content['submitted-url']       = '<YOUR-POST-SUBMITTED-URL>';
            $content['submitted-image-url'] = '<YOUR-POST-SUBMITTED-IMAGE-URL>';
            $content['description']         = '<YOUR-POST-DESCRIPTION>';
            $private                        = FALSE;

            $response = $linkedin->share('new', $content, $private); /* Post and Share to LinkedIn*/
            /* Debug */
            print_r($response);

    }else{
        throw new LinkedInException($response['error']);
    }

} catch(LinkedInException $e) {
  echo $e->getMessage();
}





Modify your linkedIn PHP SDK for Auth Permission Scope value under retrieveTokenRequest() Line 1851 add this permision scope=r_basicprofile+r_emailaddress+rw_nus

$response = $this->fetch(self::_METHOD_TOKENS, self::_URL_REQUEST.'?scope=r_basicprofile+r_emailaddress+rw_nus', NULL, $parameters);

Simple Facebook API PHP Integration

This is a PHP Integration using Facebook PHP SDK (v.3.2.2) This sample code will help you on how to post messages, pictures, links, descriptions,names and captions into your wall.

 Get Your App Id and App Secret 
http://developers.facebook.com

Facebook PHP SDK (v.3.2.2)
https://github.com/facebook/facebook-php-sdk

Source Code


<?php
/**
 * Name         : Simple Facebook API PHP Integration
 * Description  : Post message, picture, link, description, name, caption to your wall!. 
 * Author       : Ryan Tipones
 * Version      : 0.1
 * Author URI   : wpmigrator.wordpress.com
 *  
 */

require 'src/facebook.php';

/* Configure Facebook Apps Settings */

define('APP_ID', '<YOUR_APP_ID>');
define('APP_SECRET', '<YOUR_APP_SECRET>');
define('APP_PERMISSION', 'publish_stream,read_stream');
define('FILE_UPLAOD', FALSE);

$facebook = new Facebook(
                array(
                    'appId'         => APP_ID,
                    'secret'        => APP_SECRET,
                    'fileUpload'    => FILE_UPLAOD
                )
        );

try {
    
    $user = $facebook->getUser();

    if ($user) {
        
        $user_info = $facebook->api('/me'); 
        
        if ($user_info) { 
            
            /* Your basic profile information */

            $id           = $user_info['id'];
            $name         = $user_info['name'];
            $first_nam    = $user_info['first_nam'];
            $last_name    = $user_info['last_name'];
            $username     = $user_info['username'];
            $birthday     = $user_info['birthday'];
            $hometown     = $user_info['hometown']['name'];
            $gender       = $user_info['gender'];
            $email        = $user_info['email'];

        }
        
        $privacy = array(
                'value'     => 'ALL_FRIENDS', // EVERYONE, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM
                'friends'   => '', //FRIENDS_OF_FRIENDS, ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS
                'allow'     => '', // Change this to your friends ids
                'deny'      => '' // Change this to your friends ids 
            );
                    
        $post_id = $facebook->api('/me/feed', 'post', 
                array(
                        'message'   => 'Simple Facebook API PHP Integration', 
                        'picture'   => '<YOUR-IMAGE-LINK-URL>', 
                        'link'      => 'http://bikolexpressonline.com',
                        'description'   =>'Simple PHP Integration using Facebook PHP SDK (v.3.2.2)', 
                        'name'          => 'Test API Facebook SDK', 
                        'privacy'       => json_encode($privacy),
                        'caption'       => 'BikolExpress Online Free Source Code for life!'
                    )
             );
        
        /* Debug */
        print_r($post_id);
        
    }else{
        echo("<script>top.location.href='" . $facebook->getLoginUrl(array( 'scope' => APP_PERMISSION )) . "'</script>");
    }

} catch (FacebookApiException $e) {
    echo $e->getMessage();
    $user = null;
}

Salesforce AddLead and Task API Webservice

Salesforce Webservice API Integration using PHP SOAP Client library.
 Method AddLead and Create Task for Leads.
 Get Salesforce developer account to.

http://developer.force.com

Source Code
<?php

/**
 * Name         : Salesforce - AddLead and Task API Webservice
 * Description  : Salesforce Webservice API Integration using PHP SOAP Client library. 
 * Author       : Ryan Tipones
 * Version      : 0.1
 * Author URI   : wpmigrator.wordpress.com
 * Salesforce Developer : http://developer.force.com/
 *  
 */


ini_set("soap.wsdl_cache_enabled", "0");

require_once 'soapclient/SforcePartnerClient.php';
require_once 'soapclient/SforceHeaderOptions.php';

$wsdl       = 'soapclient/partner.wsdl.xml';
$userName   = "YOUR_SALES_FORCE_USERNAME";
$password   = "YOUR_SALES_FORCE_PASSWORD";

$client     = new SforcePartnerClient();
$client->createConnection($wsdl);
$client->login($userName, $password);

/* Salesforce Create New Lead */ 

$lead = new sObject();
$lead->type = 'Lead';
$lead->fields = array(
    'FirstName'     => '',
    'LastName'      => '',
    'Company'       => '',
    'Email'         => '',
    'Country'       => '',
    'MobilePhone'   => ''
);

/* Submitting the Lead to Salesforce */

$result = $client->create(array($lead), 'Lead');

/* Debug */

 print_r($response); 


/* Salesforce Create Task */

/* Check Lead Email if Exist*/

$response  = $client->query("SELECT Id,Email from Lead WHERE Email='{$email}'");

if(!empty($response->records)){
    
     $data      = (array) $response->records;
     $LeadId    = $data[0]->Id;
     $fields    = array (
                    'Status'        => '', // Not Started , In Progress , Completed
                    'Description'   => '',
                    'Subject'       => '',
                    'WhoId'         => $LeadId,
                    'ActivityDate'  => date('c')
    );
     
    $sObject            = new SObject();
    $sObject->fields    = $fields;
    $sObject->type      = 'Task';
    $response           = $client->create(array($sObject));
    
    /* Debug */
    
    print_r($response); 
}
        
       


StorMan Webservice API PHP Integration

StorMan WS_AddContact Webservice API Integration using PHP NuSoap wsdl client library.

StorMan WS_AddContact Method Documentation.
http://www.storman.com/api/WS_AddContact.pdf

StorMan API documents
http://my.storman.com/support/knowledgebase/onlineservices/api.php

PHP NuSoap Library
http://sourceforge.net/projects/nusoap/ 

Source Code

<?php
/**
 * Name         : StorMan - WS_AddContact Webservice
 * Description  : StorMan Webservice API Integration using PHP NuSoap wsdl client library. 
 * Author       : Ryan Tipones
 * Version      : 0.1
 * Author URI   : http://wpmigrator.wordpress.com
 * StorMan Reference Docs : http://www.storman.com/api/WS_AddContact.pdf
 *  
 */
require_once 'lib/nusoap.php';
 
/* Your StorMan Endpoint Server Url*/
$endPointUrl = "http://ipaddressofStorMancomputer:19812/4dwsdl"; $client = new nusoap_client( $endPointUrl, true); $err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2>' . $err;
}
$result = $client->call("WS_AddContact", 
        array(
                'WS_CTFacility'     => '', 
                'WS_CTContactName'  => '', 
                'WS_CTTitle'        => '', 
                'WS_CTFirstName'    => '', 
                'WS_CTUserName'     => '', 
                'WS_CTMailAddress'  => '', 
                'WS_CTMailCity'     => '', 
                'WS_CTMailState'    => '', 
                'WS_CTMailZIPCode'  => '', 
                'WS_CTMailCountry'  => '', 
                'WS_CTContactPhone' => '', 
                'WS_CTPhoneBus'     => '', 
                'WS_CTMobilePhone'  => '', 
                'WS_CTEmailAddress' => '', 
                'WS_CTOrganization' => '',                 
                'WS_CTMarketSrce'   => '', 
                'WS_CTCustType'     => '', 
                'WS_CTCategory'     => '', 
                'WS_CTStoredBefore' => '', 
                'WS_CTStoredGoods'  => '', 
                'WS_CTWhenRequired' => '', 
                'WS_CTExpDuration'  => '', 
                'WS_asQTAnalysisCode' => array(), 
                'WS_asQTSize'           => array(), 
                'WS_asQTUnitTypeCode'   => array(), 
                'WS_asQTNote'           => array(), 
                'WS_asQTPrice'          => array(), 
                'WS_CTOldContactNo'     => '', 
                'WS_WebServicePassword' => '' 
            )
        );
/* Debug */
if ($client->fault) {
    echo '<h2>Fault</h2>';
        print_r($result);
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2>' . $err . '';
    } else {
        // Display the result
        echo '<h2>Result</h2>';
        print_r($result);
  
    }
}



Simple Google URL Shortener PHP Class Wrapper

This is a simple PHP Class Wrapper using Google API URL

<?php

class GoogleUrlShortener 
{
        public $endPoint = 'https://www.googleapis.com/urlshortener/v1/url';
        public $key      = 'YOUR_GOOGLE_API_KEY';
        
        /* Shorten a long URL */
        function shorten($url)
        {
            $data = $this->execute($url,1);
            
            if(isset($data['id'])){
                    $result = $data['id'];
                }else{
                    $result = FALSE;
            }
            
            return $result;
        }
        
        /* Expand a short URL */
        function expand($url) 
        {
            $data = $this->execute($url,0);
            
            if(isset($data['longUrl'])){
                    $result = $data['longUrl'];
                }else{
                    $result = FALSE;
            }
            
            return $result;
        }
        
        /* Send Request to Google */
        function execute($url,$status) 
        {
            $curl           = curl_init();
            $googleApiUrl   = $this->endPoint.'?key='.$this->key;
            
            if($status == 1) {
                    curl_setopt($curl,CURLOPT_URL,$googleApiUrl);
                    curl_setopt($curl,CURLOPT_POST,1);
                    curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode(array("longUrl"=>$url)));
                    curl_setopt($curl,CURLOPT_HTTPHEADER,array("Content-Type: application/json"));
                }else {
                    curl_setopt($curl,CURLOPT_URL,$googleApiUrl.'&shortUrl='.$url);
            }
            
            curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
            $res = curl_exec($curl);
            curl_close($curl);
            
            return json_decode($res,true);
        }    
}

Examples
  • Shorten URL
<?php

$shorten_my_url = new GoogleUrlShortener();
echo $shorten_my_url->shorten("http://wpmigrator.wordpress.com");
output : http://goo.gl/MZ4bW
  • Expand URL
<?php

$expand_my_url = new GoogleUrlShortener();
echo $expand_my_url->expand("http://goo.gl/MZ4bW");
output : http://wpmigrator.wordpress.com
Genesis Framework for WordPress