How to use Paypal pro (Dodirect payment) in php


Posted on 24 Apr 15 by Vickey

Paypal is a very popular payment gateway system. we have two way to use this on our website 1. PayPal Classic API 2. Direct Payment API here we are talking about Direct Payment API. In this api we do not redirect on paypal website we make payment on our site so the methood is fast then Classic API. So lets start

First create a file pay.php and add this code in body tag

<form method="post" action="paypal.php" >

<table class="second_step">
<td>First Name</td>
<td><input type="text" name="customer_first_name" value=""  required="required"/></td>
<td><input type="text" name="customer_address1" value=""  required="required"/></td>
<td>Last Name</td>
<td><input type="text" name="customer_last_name" value=""  required="required"/></td>
<td><input type="text" name="customer_city" value=""  required="required"/></td>
<td>Credit card type</td>
<select name="customer_credit_card_type">
<option value="visa">Visa</option>
<option value="master_card">Master Card</option>
<option value="discocer">Discover</option>
<option value="visa">Visa</option>

<td><input type="text" name="customer_zip" value=""  required="required"/></td>
<td>Credit Card No</td>
<td><input type="text" name="customer_credit_card_number" value=""  required="required"/></td>
<td ><input type="text" name="customer_state" value=""  required="required"/>( State iso code)</td>

<td>Expiration Date</td>
<select name="cc_expiration_month" style="width: 95px;">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
<select name="cc_expiration_year" style="width: 95px; margin-left: 10px;">
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
<select name="customer_country" required="required">
    <option value="GB">United Kingdom</option>
    <option value="US">United States</option>
    <option value="CM">Cameroon</option>
    <option value="CA">Canada</option>
<td>Card Varification No</td>
<td><input type="text" name="cc_cvv2_number" value=""  required="required"/></td>
<td>Price </td>
<input type="text" name="example_payment_amuont" value="25"  />
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<input type="submit" name="submit" value="Submit"  required="required"/>


Create a file paypal_pro.php and add code

$environment = 'sandbox';    // 'sandbox' or 'beta-sandbox' or 'live'
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    // Set up your API credentials
    $API_UserName = urlencode('spi username'); // set your api username
    $API_Password = urlencode('api password'); // set your api password
    $API_Signature = urlencode('Signature'); // set your spi Signature

    $API_Endpoint = "";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$";
    $version = urlencode('51.0');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
    $httpResponse = curl_exec($ch);
    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    $httpResponseAr = explode("&", $httpResponse);
    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    return $httpParsedResponseAr;

put your api username, password and Signature

Now create a file paypal.php and add code

$paymentType = urlencode('Sale');                
$firstName = urlencode($_POST['customer_first_name']);
$lastName = urlencode($_POST['customer_last_name']);
$creditCardType = urlencode($_POST['customer_credit_card_type']);
$creditCardNumber = urlencode($_POST['customer_credit_card_number']);
$expDateMonth = $_POST['cc_expiration_month'];
$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));
$expDateYear = urlencode($_POST['cc_expiration_year']);
$cvv2Number = urlencode($_POST['cc_cvv2_number']);
$address1 = urlencode($_POST['customer_address1']);
$address2 = urlencode($_POST['customer_address2']);
$city = urlencode($_POST['customer_city']);
$state = urlencode($_POST['customer_state']);
$zip = urlencode($_POST['customer_zip']);
$country = urlencode($_POST['customer_country']);                
$amount = urlencode($_POST['example_payment_amuont']);
$currencyID = urlencode('USD');                            
$nvpStr =    "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    exit('Direct Payment Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
    exit('DoDirectPayment failed: ' . print_r($httpParsedResponseAr, true));

now put all files in your webserver root directory and Test it

How to set cronjob with putty or terminal


Posted on 21 Apr 15 by Vickey

Open your putty or terminal and login via ssh

you will see like this

[root@ip-11-142-86-04 ~]# 

Now run command

[root@ip-11-142-86-04 ~]# crontab -e

this will show the list of cronjobs if already set but you can not edit these. for edit press insert button now you can edit or add new cron job. for example if you want to add new one you will write

*/1   *     *     *    *   curl

at the place of stars you will put cronjob time


*/1 * * * * curl

MIN - Minute 0-60

HOUR - Hour [24-hour clock] 0-23

MDAY - Day of Month 1-31

MON - Month 1-12 OR jan,feb,mar,apr...

DOW - Day Of Week 0-6 OR sun,mon,tue,wed,thu,fri,sat

COMMAND - command-line

when you have done, press Esc key and you will be exit from edit mode

now type :wq and press enter you will exit from cronjob window

How to login with opensshkey on ubuntu terminal


Posted on 21 Apr 15 by Vickey

Locate to dirctory in which ppk file exist

cd /home

and run the below command

puttygen web.ppk -O private-openssh -o my-openssh-keyD

now you can see my-openssh-key file in your directory. again run a command

sudo ssh -v root@123.456.8.99 -i my-openssh-key

now you will login with ssh key

How to add new column in databse table by laravel Migrate


Posted on 21 Apr 15 by Vickey

For add new column by migrate run this command

php artisan migrate:make add_status_to_users

in Laravel 5 use

php artisan make:migration add_status_to_users

now go in your migrate directory you will see new migrate file with this name open

Schema::table('users', function($table){



you can add more column

Schema::table('users', function($table){



save this file and run

php artisan migrate

Get state country of a given city or address


Posted on 20 Apr 15 by Vickey

If you are searching acode for get country and state of a given address you can use this code. I this code i just passed name of city and it will return country and state

$getFullAddress = getLocation("Agra");
echo "$getFullAddress";

function getLocation($address) {

  $address = str_replace(" ", "+", "$address");
  $url = "$address&sensor=false";
  $result = file_get_contents("$url");
  $json = json_decode($result);
  foreach ($json->results as $result)
    foreach($result->address_components as $addressPart) {
      if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types)))
          $city = $addressPart->long_name;
        else if((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types)))
          $state = $addressPart->long_name;
        else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types)))
          $country = $addressPart->long_name;

  if(($city != '') && ($state != '') && ($country != ''))
    $address = $city.', '.$state.', '.$country;
  else if(($city != '') && ($state != ''))
    $address = $city.', '.$state;
  else if(($state != '') && ($country != ''))
    $address = $state.', '.$country;
  else if($country != '')
    $address = $country;
  return "$country/$state/$city";


How to install xampp on ubuntu desktop

Ubuntu Desktop

Posted on 20 Apr 15 by Vickey

If we want to install lampp on ubuntu server then we need to run different commands for mysql phpmyadmin, php apache but we can install all these things from a single package name as xampp installer so let install xampp by these steps

  1. First download from this url

  1. Save this in your home folder

  2. Give 755 permission to this file

    sudo chmod 755

  3. Now install this by this command

    sudo ./

you will see a popup click on next button and continue

once you have completed process you can start it by command

/opt/lampp/lampp start

How to start xampp server on ubuntu

Ubuntu Desktop

Posted on 19 Apr 15 by Vickey

If you have installed xampp server on ubuntu then when you start your system you will need to start xampp server manually. by this command you can start your xampp server

ubuntu@ubuntu-HP-2000-Notebook-PC:~$ sudo /opt/lampp/lampp start

For stop server

ubuntu@ubuntu-HP-2000-Notebook-PC:~$ sudo /opt/lampp/lampp start

For restart server

ubuntu@ubuntu-HP-2000-Notebook-PC:~$ sudo /opt/lampp/lampp restart

Copy file from server to local and local system to server on ubuntu by command

Ubuntu Desktop

Posted on 19 Apr 15 by Vickey

By command we can copy file from server to local and from local to server. here i am using ubuntu terminal for copy files

1 Copy from server to local

ubuntu@ubuntu-HP-2000-Notebook-PC:~$ scp root@ /var/www

in this command first i give file location on server and then directory path of local system where i want to download file

2. Copy files from local to server

ubuntu@ubuntu-HP-2000-Notebook-PC:/var/www$ scp root@

How to use constant variables in Yii


Posted on 16 Apr 15 by Vickey

In Yii we can define our constant in /config/params.php file

return [
    'adminEmail'        => '',
    'application_name'  => 'My App',

and in our views an controller we can access these by using

Yii::app()->params['application_name'];  // in yii 1

Yii::$app->params['application_name']; // in yii 2

How to use constant variables in Laravel


Posted on 16 Apr 15 by Vickey

Some times we need to show same text at more then one pages or places in a website so we need a global variable or constant for doing this. If we want to change that text then we can change it from only one place where we defined it. We can do this in laravel very easily

Create a file constants.php under app/config directory


Now add

return [
    'APP_NAME' => 'My App'

you can add your constant like this

and now you can access it in your views and controllers

echo Config::get('constants.APP_NAME');

output will be My App