php script for ccavenue and ccavenue payment gateway integration in php

In my previous post you get idea on the paypal payment gateway integration and Authorise.net payment gateway implementation. now i will discuss ccavenue payment gateway integration using php.

ccavenue payment gateway integration is very simple and easy, please copy below php code or php script for ccavenue payment gateway integration and set the variable value as per you account.

 
<?php
 
function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
{
	$str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
	$adler = 1;
	$adler = adler32($adler,$str);
	return $adler;
}
 
function verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
{
	$str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
	$adler = 1;
	$adler = adler32($adler,$str);
 
	if($adler == $CheckSum)
		return "true" ;
	else
		return "false" ;
}
 
function adler32($adler , $str)
{
	$BASE =  65521 ;
 
	$s1 = $adler & 0xffff ;
	$s2 = ($adler >> 16) & 0xffff;
	for($i = 0 ; $i < strlen($str) ; $i++)
	{
		$s1 = ($s1 + Ord($str[$i])) % $BASE ;
		$s2 = ($s2 + $s1) % $BASE ;
	}
	return leftshift($s2 , 16) + $s1;
}
 
function leftshift($str , $num)
{
 
	$str = DecBin($str);
 
	for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
		$str = "0".$str ;
 
	for($i = 0 ; $i < $num ; $i++) 
	{
		$str = $str."0";
		$str = substr($str , 1 ) ;
	}
	return cdec($str) ;
}
 
function cdec($num)
{
 
	for ($n = 0 ; $n < strlen($num) ; $n++)
	{
	   $temp = $num[$n] ;
	   $dec =  $dec + $temp*pow(2 , strlen($num) - $n - 1);
	}
 
	return $dec;
}
$Merchant_Id = "User ID" ;//This id(also User Id)  available at "Generate Working Key" of "Settings & Options" 
$Amount = 'Total Amount';//your script should substitute the amount in the quotes provided here
$Order_Id = "Order ID";//your script should substitute the order description in the quotes provided here
$Redirect_Url = "Your Return URL" ;//your redirect URL where your customer will be redirected after authorisation from CCAvenue
 
$WorkingKey = "Your Working Key"  ;//put in the 32 bit alphanumeric key in the quotes provided here.Please note that get this key ,login to your CCAvenue merchant account and visit the "Generate Working Key" section at the "Settings & Options" page. 
$Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey);
 
$billing_cust_name=$customer_name;
$billing_cust_address=$customer_address;
$billing_cust_state=$customer_statename;
$billing_cust_country=$customer_country;;
$billing_cust_tel=$customer_contact_no;
$billing_cust_email=$customer_email;
$delivery_cust_name=$customer_name;
$delivery_cust_address=$customer_address;
$delivery_cust_state = $customer_statename;
$delivery_cust_country = $customer_country;
$delivery_cust_tel=$customer_contact_no;
$delivery_cust_notes=$customer_message;
 
$billing_city = $customer_city;
$billing_zip = $customer_zipcode;
$delivery_city = $customer_city;
$delivery_zip = $customer_zipcode;
?>
 
<form name="paymentform" method="post" action="https://www.ccavenue.com/shopzone/cc_details.jsp">
  <input type="hidden" name="Merchant_Id" value="<?php echo $Merchant_Id; ?>">
  <input type="hidden" name="Amount" value="<?php echo $Amount; ?>">
  <input type="hidden" name="Order_Id" value="<?php echo $Order_Id; ?>">
  <input type="hidden" name="Redirect_Url" value="<?php echo $Redirect_Url; ?>">
  <input type="hidden" name="Checksum" value="<?php echo $Checksum; ?>">
  <input type="hidden" name="billing_cust_name" value="<?php echo $billing_cust_name; ?>">
  <input type="hidden" name="billing_cust_address" value="<?php echo $billing_cust_address; ?>">
  <input type="hidden" name="billing_cust_country" value="<?php echo $billing_cust_country; ?>">
  <input type="hidden" name="billing_cust_state" value="<?php echo $billing_cust_state; ?>">
  <input type="hidden" name="billing_zip" value="<?php echo $billing_zip; ?>">
  <input type="hidden" name="billing_cust_tel" value="<?php echo $billing_cust_tel; ?>">
  <input type="hidden" name="billing_cust_email" value="<?php echo $billing_cust_email; ?>">
  <input type="hidden" name="delivery_cust_name" value="<?php echo $delivery_cust_name; ?>">
  <input type="hidden" name="delivery_cust_address" value="<?php echo $delivery_cust_address; ?>">
  <input type="hidden" name="delivery_cust_country" value="<?php echo $delivery_cust_country; ?>">
  <input type="hidden" name="delivery_cust_state" value="<?php echo $delivery_cust_state; ?>">
  <input type="hidden" name="delivery_cust_tel" value="<?php echo $delivery_cust_tel; ?>">
  <input type="hidden" name="delivery_cust_notes" value="<?php echo $delivery_cust_notes; ?>">
  <input type="hidden" name="Merchant_Param" value="<?php echo $Merchant_Param; ?>">
  <input type="hidden" name="billing_cust_city" value="<?php echo $billing_city; ?>">
  <input type="hidden" name="billing_zip_code" value="<?php echo $billing_zip; ?>">
  <input type="hidden" name="delivery_cust_city" value="<?php echo $delivery_city; ?>">
  <input type="hidden" name="delivery_zip_code" value="<?php echo $delivery_zip; ?>">
  <INPUT TYPE="submit" value="submit">
</form>

Please set the values in php variables as per your account setting and your requirement and test it. if you have any issue then you can contact me. i hope that this will help you in your project.

draw pie chart using php in your web-site

Draw pie chart

Now a day, you can see that people use charts in their web-site. if its a static data and we need to generate the chart then we can do it using image and place it where we require in our web-site but when dynamic data which is come from the database then you need to write code which will generate the pie chart run time

Using Google we can easily draw pie chart as we want. Below is the code which is helpful to generate the pie chart.

 
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Office Work',     8],
          ['Freelance Work',      5],
          ['Time with Family',  2],
          ['News Update', 1],
          ['Sleep',    7],
	  ['Other Activity',    1]
        ]);
 
        var options = {
          title: 'My Daily Activities'
        };
 
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="pie_chart_div" style="width: 800px; height: 400px;"></div>
  </body>
</html>

Here, you can see the data which is set in the array, you just need to set the dynamic data using php and your chart will be done. please let me know if you need any other help in this.

Authorise.net payment gateway implementation in php

Authorise.net payment gateway implementation Code in php

In my previous post you know how to integrate paypal payment gateway for your e-commerce web-site. now i will discuss authorise.net payment gateway in this post. there are many payment gateway available in the market and we need to setup payment gateway as per the client’s requirement. below is the simple code for authorise.net payment gateway.

 
<?php
 
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$post_url = "https://test.authorize.net/gateway/transact.dll";
 
$post_values = array(
 
    // the API Login ID and Transaction Key must be replaced with valid values
    "x_login"           => "YOUR_API_LOGIN_ID",//API_LOGIN_ID",
    "x_tran_key"        => "YOUR_TRANSACTION_KEY",//TRANSACTION_KEY",
 
    "x_version"         => "3.1",
    "x_delim_data"      => "TRUE",
    "x_delim_char"      => "|",
    "x_relay_response"  => "FALSE",
 
    "x_type"            => "AUTH_CAPTURE",
    "x_method"          => "CC",
    "x_card_num"        => "4111111111111111",
    "x_exp_date"        => "0115",
 
    "x_amount"          => "19.99",
    "x_description"     => "authorize.net PHP Transaction Code",
 
    "x_first_name"      => "Pinkesh",
    "x_last_name"       => "Patel",
    "x_address"         => "pinkeshpatel2915@gmail.com",
    "x_state"           => "Gujarat",
    "x_zip"             => "390023"
    // Additional fields can be added here as outlined in the AIM integration
    // guide at: http://developer.authorize.net
);
 
// This section takes the input fields and converts them to the proper format
// for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
$post_string = "";
foreach( $post_values as $key => $value )
    { $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );
 
// The following section provides an example of how to add line item details to
// the post string.  Because line items may consist of multiple values with the
// same key/name, they cannot be simply added into the above array.
//
// This section is commented out by default.
/*
$line_items = array(
    "item1<|>mobile phone<|><|>2<|>18.95<|>Y",
    "item2<|>tablet<|>tablet with simcard, black color<|>1<|>39.99<|>Y",
    "item3<|>PHP Freelancer<|>$10 per hours<|>1<|>10.00<|>Y");
 
foreach( $line_items as $value )
    { $post_string .= "&x_line_item=" . urlencode( $value ); }
*/
 
// This sample code uses the CURL library for php to establish a connection,
// submit the post, and record the response.
// If you receive an error, you may want to ensure that you have the curl
// library enabled in your php configuration
$request = curl_init($post_url); // initiate curl object
    curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
    curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
    $post_response = curl_exec($request); // execute curl post and store results in $post_response
    // additional options may be required depending upon your server configuration
    // you can find documentation on curl options at http://www.php.net/curl_setopt
 
curl_close ($request); // close curl object
 
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);
 
// The results are output to the screen in the form of an html numbered list.
echo "<OL>\n";
foreach ($response_array as $value)
{
    echo "<LI>" . $value . "&nbsp;</LI>\n";
}
echo "</OL>\n";
// individual elements of the array could be accessed to read certain response
// fields.  For example, response_array[0] would return the Response Code,
// response_array[2] would return the Response Reason Code.
// for a list of response fields, please review the AIM Implementation Guide
?>

Here, you need to set the x_login and x_tran_key which is provide by your client and your code is ready.

Paypal integration using php in your e-commerce web-site

Paypal integration

When you are working with the e-commerce web-site and you need to setup payment gateway to make a payment for your web-site owner then its very easy using the paypal payment gateway.

Paypal gateway provide many methods to setup online payment for your web-site and here we will discuss one method which is very simple and easy to integrate in your e-commerce web-site. you need to set up below form and form elements.

<form name="frmpaypal" action="<?php echo $paypal_action_url;?>" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="<?php echo $client_paypal_email_id;?>" />
    <input type="hidden" name="item_name" value="<?php echo $item_name;?>" />
    <input type="hidden" name="item_number" value="<?php echo $item_number;?>" />
 
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="return" value="<?php echo $success_url;?>" />
    <input type="hidden" name="cancel_return" value="<?php echo $cancel_url;?>" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="amount" value="<?php echo $amount;?>" />
    <input type="hidden" name="custom" value="<?php echo $custom_id;?>" />
 
    <input type="hidden" name="first_name" value="<?php echo $FirstName;?>" />
    <input type="hidden" name="last_name" value="<?php echo $LastName;?>" />
    <input type="hidden" name="address1" value="<?php echo $Address;?>" />
    <input type="hidden" name="city" value="<?php echo $City;?>" />
    <input type="hidden" name="state" value="<?php echo $State;?>" />
    <input type="hidden" name="zip" value="<?php echo $ZipCode;?>" />
    <input type="hidden" name="country" value="<?php echo $Country;?>" />
    <input type="hidden" name="image_url" id="image_url" value="<?php echo $company_logo_url;?>" />
 
    <input type="hidden" name="notify_url" value="<?php echo $notify_url;?>" />
    <input type="submit" name="submit" value="Submit"/>
</form>

Here, $paypal_action_url is the php variable where you need to set the paypal url. there is two type of url where one is live url and second one for testing purpose. when you set testing url then actual money transaction will not done. while in the live url your money will be deducted and you need to rollback if you are testing.

$paypal_action_url = “https://www.sandbox.paypal.com/cgi-bin/webscr”; ( Set this url for testing purpose)
$paypal_action_url = “https://www.paypal.com/cgi-bin/webscr”; ( Set this url for your real paypal payment)

I hope this will be helpful to setup paypal gateway in your web-site.

Why You Can’t Succeed with Generic Website Hosting

The website hosting package you’re paying for is of critical importance. Although it seems like one of those behind-the-scenes factors that don’t make much of a difference, your choice of host actually affects the success of your eCommerce website.

Handling Traffic
One of the big things about eCommerce websites is that they’re often subject to high numbers of visitors. Although you probably aren’t flooded with consumers most of the time, you can expect big spikes during sales, after popular viral video promotions or even just as a result of sending out an email campaign. This can mean trouble.

As anyone who has been around web technology for long enough knows, many website hosts have a big problem with handling sudden visitor increases. Websites being visited by many people at once often experience a number of critical problems and errors, including:

  • Major loading speed decreases for images, streaming videos, file downloads and even basic page text
  • Operational glitches like the loss of filled-in form data
  • Site not found errors or complete failures to load

These problems make your website harder for people to use, often scaring them away permanently. They also make you look bad. In the end, you’d be better off with a hosting service that can handle visitor fluctuations, even if you don’t expect them.

The Problems with Generic Hosts
Many generic webhosts are just not wired up to handle visitor overflows. In addition, they fail to provide many of the extra features that you absolutely can’t get by without.

As a business, you handle a lot of sensitive data. Although there are times when your consumers will buy your products through auction sites and other external portals that take care of transmission security for you, you can’t succeed and avoid data handling at the same time.

Sooner or later, you’re going to have to store, retrieve and transmit private credit card, address or identification info. Generic web hosting services often fail to monitor your servers for the telltale signs that this data has been stolen or illegally accessed.

Generic hosts also fail when it comes to business data gathering. At a minimum, you need to know when people visit your site, how long they stayed, what they clicked on and whether or not they made purchases. Most generic hosts only go so far as to let you know how many visitors you got per month. for a business owner looking to improve their operating model, this is clearly insufficient.

What Sort of Things Should Your Website Hosting Provide?
A business web hosting service needs to go above and beyond to meet your needs. They need to provide you with consistent support in addition to security monitoring, because you never know when your site will have issues. They ought to use known technologies and software standards so you can assure your customers of your trustworthiness. Above all, it is critical that they can easily devote more shared server computing power to your site in case you experience high volume traffic.

Basically, you need to look for a website hosting service that keeps you in control and has experience working with firms. Hosting services that understand the difference in importance between your company’s eCommerce website and someone’s personal blog are the only reliable sources of web space for discerning professionals and the firms they represent.

Mobile Website Design Tips & Tricks

When designing for the mobile web, ease of use and quick access to information are the most important things to consider. Mobile means that users are on the go, and they want information fast. A high-quality mobile website design lets them find what they’re looking for without slowing them down.

Focus on Simplicity
To make a mobile-friendly site, you can’t just shrink down your full site and expect it to work. Instead, focus on streamlining the style. Remove excess images and unnecessary text in favor of putting the most sought-after information front and center on your mobile homepage. The fewer things that have to load, the better. Mobile website designs should be approached with speed and usability in mind. Remember, some mobile users are on limited plans, and too much site clutter can eat up precious bandwidth.

Understand Screen Resolution
Keep in mind that you’re designing a site for tablet and Smart phone screens, not big HD monitors. The smaller the screen, the more important text size and layout are. Mobile users don’t want to have to zoom in to read large blocks of text. Instead, break up your content into manageable bits using subheadings, bullet lists and collapsible navigation menus. Balance text, images and white space in natural ways so that your site is easy to view and easy to read.

Make it Recognizable
Whether they’re visiting your desktop or mobile website, visitors should be able to recognize your company. Using the same colors, fonts and images for both sites keeps your brand presence consistent across platforms. This helps users who are familiar with your company feel “at home” on your mobile site and provides new customers with a sense of authenticity.

Streamline Navigation
Visitors don’t like having to click around too much on any website to find what they’re looking for. On a mobile device, multi-level navigation becomes even more frustrating, since customers are using their fingers or a stylus to tap on links. Strive to make navigation on your mobile site as simple as possible. If you sell products, make sure that the path from arrival to purchase point has as few steps as possible. Place relevant information on the homepage and cut down on the amount of pages in the site as a whole. Data input should also be simple and require as little text entry as possible.

Make Both Sites Available
Whether you choose an m-dot URL or a sub domain for your mobile site, you should use a mobile redirect to detect when a visitor is using a mobile device. This will bring them to your mobile site even if they enter your regular site URL. However, no matter how well-designed your mobile presence is, some people will need information that isn’t included. Offer clear links to the full site so that these users can navigate there when they need to find something specific. Another option is to offer the choice of viewing the mobile or full site when a user first enters your URL.

The key thought to keep in mind for mobile website design is that simplicity is a must. By providing the information that mobile users want in an easy-to-use format, you create an optimal mobile experience that can open up a whole new market for your business.