Tuesday, July 12, 2016

PayUMoney payment gateway integration in php

Hello friends...

In this post i am going to explain how to setup PayUmoney payment gateway in your web application. Integration of PayU gateway is little confusing for first time and also some of my reader request me for this tutorial. Most of thing are  already in PayU documentation i am just going to explain it in step so you will easily integrate without reading whole document.
Steps for integration PayUMoney gateway.
Step 1. Go to https://test.payumoney.com/ and sign up as a merchant account.
Step 2. At time of sign up use your valid email.
Step 3. Fill all required business details. Use this details for PAN no. ABCDE1234F and DOB – 01/04/1990 .
Step 4. Add your bank detail, note you can add whatever bank name and details use this IFSC – ALLA0212632 in place of IFSC.
Step 5. Don’t worry about bank details verification this is your test account.
Step 6. Once your required steps are completed your account is live if not then write mail to support team : techsupport@payumoney.com

Step 7. Now once above steps are complete you can get your key go to Manage Account ⇒ My Account ⇒ Merchant -Key Salt copy your key and paste in your code.

Once you follow above step your setup for PayUMoney is complete.
Sample Code
index.php
<?php
// Merchant key here as provided by Payu
$MERCHANT_KEY = "hDkYGPQe";

// Merchant Salt as provided by Payu
$SALT = "yIEkykqEH3";

// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = "https://test.payu.in";

$action = '';

$posted = array();
if(!empty($_POST)) {
    //print_r($_POST);
  foreach($_POST as $key => $value) {    
    $posted[$key] = $value; 
  }
}

$formError = 0;

if(empty($posted['txnid'])) {
  // Generate random transaction id
  $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
  $txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
  if(
          empty($posted['key'])
          || empty($posted['txnid'])
          || empty($posted['amount'])
          || empty($posted['firstname'])
          || empty($posted['email'])
          || empty($posted['phone'])
          || empty($posted['productinfo'])
          || empty($posted['surl'])
          || empty($posted['furl'])
 || empty($posted['service_provider'])
  ) {
    $formError = 1;
  } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
$hashVarsSeq = explode('|', $hashSequence);
    $hash_string = '';
foreach($hashVarsSeq as $hash_var) {
      $hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
      $hash_string .= '|';
    }

    $hash_string .= $SALT;


    $hash = strtolower(hash('sha512', $hash_string));
    $action = $PAYU_BASE_URL . '/_payment';
  }
} elseif(!empty($posted['hash'])) {
  $hash = $posted['hash'];
  $action = $PAYU_BASE_URL . '/_payment';
}
?>
<html>
  <head>
  <script>
    var hash = '<?php echo $hash ?>';
    function submitPayuForm() {
      if(hash == '') {
        return;
      }
      var payuForm = document.forms.payuForm;
      payuForm.submit();
    }
  </script>
  </head>
  <body onload="submitPayuForm()">
    <h2>PayU Form</h2>
    <br/>
    <?php if($formError) { ?>
      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
    <?php } ?>
    <form action="<?php echo $action; ?>" method="post" name="payuForm">
      <input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
      <input type="hidden" name="hash" value="<?php echo $hash ?>"/>
      <input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
      <table>
        <tr>
          <td><b>Mandatory Parameters</b></td>
        </tr>
        <tr>
          <td>Amount: </td>
          <td><input name="amount" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount'] ?>" /></td>
          <td>First Name: </td>
          <td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" /></td>
        </tr>
        <tr>
          <td>Email: </td>
          <td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? '' : $posted['email']; ?>" /></td>
          <td>Phone: </td>
          <td><input name="phone" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" /></td>
        </tr>
        <tr>
          <td>Product Info: </td>
          <td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea></td>
        </tr>
        <tr>
          <td>Success URI: </td>
          <td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" /></td>
        </tr>
        <tr>
          <td>Failure URI: </td>
          <td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" /></td>
        </tr>

        <tr>
          <td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>
        </tr>

        <tr>
          <td><b>Optional Parameters</b></td>
        </tr>
        <tr>
          <td>Last Name: </td>
          <td><input name="lastname" id="lastname" value="<?php echo (empty($posted['lastname'])) ? '' : $posted['lastname']; ?>" /></td>
          <td>Cancel URI: </td>
          <td><input name="curl" value="" /></td>
        </tr>
        <tr>
          <td>Address1: </td>
          <td><input name="address1" value="<?php echo (empty($posted['address1'])) ? '' : $posted['address1']; ?>" /></td>
          <td>Address2: </td>
          <td><input name="address2" value="<?php echo (empty($posted['address2'])) ? '' : $posted['address2']; ?>" /></td>
        </tr>
        <tr>
          <td>City: </td>
          <td><input name="city" value="<?php echo (empty($posted['city'])) ? '' : $posted['city']; ?>" /></td>
          <td>State: </td>
          <td><input name="state" value="<?php echo (empty($posted['state'])) ? '' : $posted['state']; ?>" /></td>
        </tr>
        <tr>
          <td>Country: </td>
          <td><input name="country" value="<?php echo (empty($posted['country'])) ? '' : $posted['country']; ?>" /></td>
          <td>Zipcode: </td>
          <td><input name="zipcode" value="<?php echo (empty($posted['zipcode'])) ? '' : $posted['zipcode']; ?>" /></td>
        </tr>
        <tr>
          <td>UDF1: </td>
          <td><input name="udf1" value="<?php echo (empty($posted['udf1'])) ? '' : $posted['udf1']; ?>" /></td>
          <td>UDF2: </td>
          <td><input name="udf2" value="<?php echo (empty($posted['udf2'])) ? '' : $posted['udf2']; ?>" /></td>
        </tr>
        <tr>
          <td>UDF3: </td>
          <td><input name="udf3" value="<?php echo (empty($posted['udf3'])) ? '' : $posted['udf3']; ?>" /></td>
          <td>UDF4: </td>
          <td><input name="udf4" value="<?php echo (empty($posted['udf4'])) ? '' : $posted['udf4']; ?>" /></td>
        </tr>
        <tr>
          <td>UDF5: </td>
          <td><input name="udf5" value="<?php echo (empty($posted['udf5'])) ? '' : $posted['udf5']; ?>" /></td>
          <td>PG: </td>
          <td><input name="pg" value="<?php echo (empty($posted['pg'])) ? '' : $posted['pg']; ?>" /></td>
        </tr>
        <tr>
          <?php if(!$hash) { ?>
            <td colspan="4"><input type="submit" value="Submit" /></td>
          <?php } ?>
        </tr>
      </table>
    </form>
  </body>
</html>
success.php

<?php
$status=$_POST["status"];
$firstname=$_POST["firstname"];
$amount=$_POST["amount"];
$txnid=$_POST["txnid"];
$posted_hash=$_POST["hash"];
$key=$_POST["key"];
$productinfo=$_POST["productinfo"];
$email=$_POST["email"];
$salt="yIEkykqEH3";

If (isset($_POST["additionalCharges"])) {
       $additionalCharges=$_POST["additionalCharges"];
        $retHashSeq = $additionalCharges.'|'.$salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
        
                  }
else {  

        $retHashSeq = $salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;

         }
$hash = hash("sha512", $retHashSeq);
 
       if ($hash != $posted_hash) {
      echo "Invalid Transaction. Please try again";
  }
  else {
              
          echo "<h3>Thank You. Your order status is ". $status .".</h3>";
          echo "<h4>Your Transaction ID for this transaction is ".$txnid.".</h4>";
          echo "<h4>We have received a payment of Rs. " . $amount . ". Your order will soon be shipped.</h4>";
           
  }         
?>
failure.php
<?php
$status=$_POST["status"];
$firstname=$_POST["firstname"];
$amount=$_POST["amount"];
$txnid=$_POST["txnid"];

$posted_hash=$_POST["hash"];
$key=$_POST["key"];
$productinfo=$_POST["productinfo"];
$email=$_POST["email"];
$salt="yIEkykqEH3";

If (isset($_POST["additionalCharges"])) {
       $additionalCharges=$_POST["additionalCharges"];
        $retHashSeq = $additionalCharges.'|'.$salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
        
                  }
else {  

        $retHashSeq = $salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;

         }
$hash = hash("sha512", $retHashSeq);
  
       if ($hash != $posted_hash) {
      echo "Invalid Transaction. Please try again";
  }
  else {
         echo "<h3>Your order status is ". $status .".</h3>";
         echo "<h4>Your transaction id for this transaction is ".$txnid.". You may try making the payment by clicking the link below.</h4>";
} 
?>
<!--Please enter your website homepagge URL -->
<p><a href=http://localhost/testing/success_failure/PayUMoney_form.php> Try Again</a></p>

Thursday, July 7, 2016

Installing Laravel on Amazon EC2

Amazon EC2 makes it very easy to scale the servers that our web applications live on. This video tutorial will show you how to load up an Amazon EC2 ubuntu server and setup Apache, PHP, & MySQL on the server. I will then go through the basics of setting up the environment for a basic Laravel 4 installation.
———- Installing Apache ———-
$ sudo apt-get install apache2
———- Installing Latest PHP ———-
$ sudo add-apt-repository ppa:ondrej/php5

$ sudo apt-get update

$ sudo apt-get install php5 libapache2-mod-php5
———- Installing PHP Mcrypt ext. ———-
$ sudo apt-get install php5-mcrypt
———- Installing MYSQL ———-
$sudo apt-get install mysql-server
———- Installing GIT ———-
$ sudo apt-get install git-core
———- Laravel GIT Repo ———-
https://github.com/laravel/laravel.git

———- Installing Composer ———-
curl -sS https://getcomposer.org/installer | php
Here are a few additional resources:
This is the command I used at the beginning of the video to run apt-get update:
$sudo apt-get update --fix-missing
Here is the URL to the documentation on how to SSH into your Amazon EC2 instance:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.htm

Wednesday, July 6, 2016

How to Update a WordPress Theme without Losing Customization

Hello Guys,

As a beginner, when you want to customize your WordPress theme, you simply paste code snippets directly into your theme files. This becomes a problem when a new update is released for your theme because updating a theme wipes out all customization. Recently one of our readers asked if it was possible to update a theme without losing the customization he made. In this article, we will show you how to update a WordPress theme without losing customization.

If you don’t like the video or need more instructions, then continue reading.
First thing you need to do is connect to your website using an FTP client. Go to /wp-content/themes/ and download your theme folder to your computer.


Now visit your theme’s website and download the latest version of your theme. Locate theme’s zip file on your computer and extract it.
You should now have both, new version of the theme and your old customized theme on your computer. If you remember the changes you made to your theme, then simply copy and paste the code snippets from old theme to the new version.
On the other hand, if you do not remember the changes you made, then you will have to find them first.
The easiest way to do this is by comparing your theme files. You will need to use a file comparison software like WinMerge (kaleidoscope for Mac, Meld for Linux). Open both theme directories in WinMerge to compare them.

WinMerge will show you a list of files in both directories. It will indicate which files are not identical and which files are new.

You can right click and select Compare to see the changes. Locate the customization you have added and carefully copy and paste them into your new theme.

After copying your changes to the new theme, you need to upload the new theme directory to WordPress using FTP.
Your FTP client will warn you that the files with the same name already exist. You need to choose Overwrite to make sure that your old theme files are replaced by new files.
That’s all. You have successfully updated your WordPress theme. Visit your website to make sure that everything is working as expected.

Making Theme Updates Easier by Using Child Themes

Now that you have successfully updated your theme, it is time for you to learn how to properly customize your theme. It is always a best practice to use a child theme for all your customization. Here is a step by step guide on how to create a WordPress child theme.
Using a child theme makes it easier for you to update the parent theme. Your changes will remain untouched during the update, and you will not have to go through this lengthy process again. See all the pros and cons of using a WordPress child theme.
We hope this article helped you update your WordPress theme without losing customization. If you come across any issues, then check out our guide on most common WordPress errors and how to fix them.




Tuesday, July 5, 2016

PHP 7

Are you a web developer or a website owner? Do your sites run on PHP-enabled CMS such as WordPress, Drupal, Joomla or Magento? Then I have good news for you: the feature-complete beta of the new PHP 7 was recently released. The 7.0.0 major release contains so many cool features that we decided to dedicate a whole post to it. But first, we need to slide in a few reminders.
Note that PHP 7 is still in the development phase so don’t use it in productionuntil November when the final version will be released. If – as a future user – you want to take your fair share from the development process, you can help with downloading the latest beta, playing around with it in your testing environment and reporting bugs you found during the testing. To find out when the next beta will be out, here’s the project timetable.
With that out of the way, let’s check out PHP 7.

1. The Name’s PHP 7 (Not 6)

The current stable release uses the version number PHP 5.6. After some disputethe development team decided they would omit the PHP 6 name for the next major release. PHP 6 already existed in the past as an experimental project but never reached the production phase.
To prevent users from mixing up the former attempt with the latest development, the new major release will run under the name of PHP 7.