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.

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.