Friday, July 10, 2015

Latest ways Invite Friends on facebook using java script

Create facebook developer account & create an app in it.

Due to this you will get a API

    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'api key',
          xfbml      : true,
          version    : 'v2.2'
        });
      };
    //onclick="fbSendDialog()"
      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/en_US/sdk.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
     
      function fbSendDialog(){
      FB.ui({
      method: 'send',
      name: 'application name',
      link: 'site url'
     });
       }
    </script>
<a href="#" onclick="fbSendDialog()" > Facebook</a>

Friday, July 3, 2015

Draw map route b/w two points in php using google map api

Draw Map Route:

Pre-Requirement:- Installed PHP and web server as well JQuery working in your project.

Step 1:- Include <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.17&sensor=false"></script> in your view where you want to show map.

Step 2:- In your controller get the points in between we want to create road map route. Let the vars are $start(exp Delhi=28.6100,77.2300) and $end(exp Mumbai=18.9750,72.8258).

Step 3:-In view include the below script after the file is included

<script type="text/javascript">
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  function initialize(start,end) {
    var latlng = new google.maps.LatLng(start);
    directionsDisplay = new google.maps.DirectionsRenderer();
calcRoute();
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title:"My location"
    });
  }
  function calcRoute(start,end) {
    var request = {
      origin:start,
      destination:end,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }
</script>

Step 4:- In view take the values in hidden input fields as follows

<input type="hidden" name="start_pt" id="start_pt" value="<?php echo $start; ?>"/>
<input type="hidden" name="end_pt" id="end_pt" value="<?php echo $end; ?>"/>

Step 5:- At the end of the file include the script as follows

    <script>
      window.onload = initialize($('#start_pt').val(),$('#end_pt').val());
    </script>

Step 6:-At the end don't forgot to include the div where you want to show the map with your desired dimentions

<div id="map_canvas" style="width:710px; height:300px"></div>

Friday, June 19, 2015

Deploy using Envoy in Laravel 5.1

Deploy using Envoy:

Recently Laravel launched a stable version that is Laravel 5.1

In Larvel 4.2 Envoy was showing a lot of problem for deploy. But its very easy in Laravel 5.1 .

Steps:

1. Run the command on your Laravel 5.1 root path
    
composer global require "laravel/envoy=~1.0"
Make sure to place the ~/.composer/vendor/bin directory in your PATH so the envoy executable is found when you run the envoy command in your terminal.
 
2. Run this command on your terminal.
  
composer global update

3. Now create a file Envoy.blade.php on your root path and write your task here.
  e.g.
   
@servers(['web' => 'user@192.168.1.1'])

@task('foo', ['on' => 'web'])
    ls -la
@endtask

 4.For run this task use the command.
 
envoy run deploy

For more use of deploy click here

Thanks
 

Friday, June 12, 2015

How to get Signed document from HelloSign API in php?

Get Signed Document in HelloSign:

In my previous blog, you can do a digital signature. But at that time when we download that signed document, sometimes sign was not implemented on that document.

This is done because, Hellosign API takes some time to implement sign on that document.

For download a signed document:

For this firstly you have to set a callback URL.

In my case i am using test.php.

Write down in test.php  without underline
Hello API Event Received

And after sending sign request when to redirect to another page.
Then write this code on this another page.

<?php
try {
require_once 'vendor/autoload.php';
$client = new HelloSign\Client('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$account = new HelloSign\Account;
$signature = Yii::app()->session['signature_req_id'];
$dest_file_path = 'PATH_OF_FILE_WHERE_TO_SAVE_WITH_NAME';
$account->setCallbackUrl'PATH_OF_test.php');
$resp = $client->updateAccount($account);
$response = $client->getSignatureRequest($signature);
if ($response->isComplete()) {
$client->getFiles($signature, $dest_file_path, HelloSign\SignatureRequest::FILE_TYPE_PDF);
} else {
execCommand(); //call this function
}
} catch (Exception $e) {
echo 'Error Occured ' . $e;
}





    public function execCommand()
    {
        require_once 'vendor/autoload.php';
        $client = new HelloSign\Client('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

        $signature = Yii::app()->session['signature_req_id'];
        $dest_file_path = '
PATH_OF_FILE_WHERE_TO_SAVE_WITH_NAME';
        $response = $client->getSignatureRequest($signature);
        if ($response->isComplete()) {
            $client->getFiles($signature, $dest_file_path, HelloSign\SignatureRequest::FILE_TYPE_PDF);
            return true;
        } else {
            $this->execCommand(); //recursion function
        }
    }


?>



Thanks

Friday, June 5, 2015

Easy way to transfer payment from one account to another using STRIPE in php

Transfer payment from one account to another using STRIPE:

This is done by the following way:
1. Deduct the amount from customer using main account of Stripe.
2. Add amount to the merchant using the same main Stripe account.
For this you will be in need of a Stripe testing/working account.
Firstly Register yourself at Stripe.com
and add stripe in your project it will generate a key & configure it in your account
Then Deduct money from any account using this

Stripe_Charge::create(array(
  "amount" => 600,
  "currency" => "usd",
   "card" => array(
    "number" => "4242424242424242",
    "exp_month" => 10,
    "exp_year" => 2015,
    "cvc" => "314"
  ),
  "metadata" => array("order_id" => "6735")
));

It will deduct $6 using this card and will be add to Stripe Account.
Now pay amount to merchant account using this
            $bank_acc = Stripe_Token::create(array( "bank_account" => array( "country" => "US", "routing_number" => "bank_routing_number", "account_number" => "bank_account_no" ) ));
            $recipient = Stripe_Recipient::create(array( "name" => "name", "type" => "individual", "bank_account"=>$bank_acc->id ));
            $payment =  Stripe_Transfer::create(array( "amount" => '600', "currency" => "usd", "recipient" => $recipient->id, "description" => "Transfer for test@example.com" ));
It will add $6 to merchant account.

Thanks

Friday, May 29, 2015

How to get Latitude & Longitude using zipcode in php?

Get Latitude & Longitude:

It is a very simple way to get latitude & longitude using zipcode in php.
For this you have to use google api's.
Here is a function for doing this:
public function getLatLng($zip)
    {
        $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=$zip&sensor=true";
        $xml = simplexml_load_file($request_url) or die("url not loading");
        $status = $xml->status;
        $lat = $lng = 0;
        if ($status == "OK") {
            $lat = $xml->result->geometry->location->lat;
            $lng = $xml->result->geometry->location->lng;
        }
        $loc = array('lat' => $lat, 'lng' => $lng);
        return $loc;
    }
Here $zip is a zipcode variable. It will return a array consisting of latitude & longitude.
Thanks.

Friday, May 22, 2015

Easy & secure way to do digital signature on any online document in php

Easy way for Digital Signature:

For easily digital signature on any online document you have to do some following steps:

1. Create an account on Hellosign.com . Due to this you'll get an API Key.

2. After creating an account create a test app from here. . Due to this you'll get a client id.

Now using this install its package in your project.

Now write this code in your php file.

        require_once 'vendor/autoload.php';
        $client = new HelloSign\Client('YOUR_API_KEY');
        $request = new HelloSign\SignatureRequest;
        $request->enableTestMode();
        $request->setSubject('SUBJECT_NAME');
        $request->setMessage('SUBJECT_MESSAGE');
        $request->addSigner('YOUR_EMAIL', 'Me');
        $request->addFile('PATH_OF_FILE');

        $client_id = 'YOUR_CLIENT_ID';
        $embedded_request = new HelloSign\EmbeddedSignatureRequest($request, $client_id);
        $response = $client->createEmbeddedSignatureRequest($embedded_request);
        $signature = $response->signatures[0]->signature_id;
        $response = $client->getEmbeddedSignUrl($signature);
 

<script type="text/javascript" src="//s3.amazonaws.com/cdn.hellofax.com/js/embedded.js"></script>
<script type="text/javascript">
    window.onload = function() {
    HelloSign.init("YOUR_CLIENT_ID");
    HelloSign.open({
        url: "<?php echo $response->sign_url; ?>",
        allowCancel: true,
        messageListener: function (eventData) {
            alert("HelloSign event received");
        }
    });
    }
</script>

Run this file and see the magic.

Thanks