Showing posts with label payment gateway. Show all posts
Showing posts with label payment gateway. Show all posts

Monday, May 3, 2010

Integration of CCAVENUE Payment gateway

Integration of CCAVENUE Payment Cart in Your Shopping Section 


CCavenue is most popular Payment gateway for online Shopping. It provide payment through using International credit card as well using your Bank (who have bond with CCavenue) online Account or using it's debit card(ATM card). It is one of the most secure place for given your money to online shop.

For Integrate it with your website you should have ccavenue account and they give you a merchant id and a unique key for your site that is most important for money transaction.


Php Function's Require TO Validate Require Value for CCAvenue Payment.


<?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 ;
  //echo "s1 : $s1 <BR> s2 : $s2 <BR>";


}
  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 ) ;
  //echo "str : $str <BR>";
  }
  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;
  }
  ?>







CCAvenue Passing Parameter That Require for Complete the Shopping


<?php
    $Merchant_Id = "";//This id(also User Id)  available at "Generate Working Key" of "Settings & Options"
    $Amount = $orderdata[5];//your script should substitute the amount in the quotes provided here
    $Order_Id = $orderdata[0];;//your script should substitute the order description in the quotes provided here
    $WorkingKey = "";//Given to merchant by ccavenue
    $Redirect_Url ="http://www.example.com/shopping.php";
    $Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey); // Validate All value
    ?>
<p align="center" style="font-family:Calibri; font-size:18px;"><img src="http://www.example.com/images/loader.gif" alt="loader"></p>
<p align="center" style="font-family:Calibri; font-size:24px;color:#3670A7;">Processing to CCAvenue..............</p>
<form id="form2" 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="<?= $orderdata[7].' '.$orderdata[8];?>"> <!--Pass Customer Full Name -->
<input type="hidden" name="billing_cust_address" value="<?= $orderdata[9].' '.$orderdata[10];?>"><!--Pass Customer Full Address-->
<input type="hidden" name="billing_cust_country" value="<?= $orderdata[15];?>"> <!--Pass Customer Country -->
<input type="hidden" name="billing_cust_state" value="<?= $orderdata[14];?>"><!--Pass Customer State -->
<input type="hidden" name="billing_cust_city" value="<?= $orderdata[13];?>"> <!--Pass Customer City -->
<input type="hidden" name="billing_zip" value="<?= $orderdata[16];?>"> <!--Pass Customer Zip Code-->
<input type="hidden" name="billing_cust_tel" value="<?= $orderdata[11];?>"> <!--Pass Customer Phone No-->
<input type="hidden" name="billing_cust_email" value="<?= $orderdata[12];?>"> <!--Pass Customer Email address-->
<input type="hidden" name="delivery_cust_name" value="<?= $orderdata[7].' '.$orderdata[8];?>"> <!--Pass Same or other other detail fill by customer-->
<input type="hidden" name="delivery_cust_address" value="<?= $orderdata[9].' '.$orderdata[10];?>">
<input type="hidden" name="delivery_cust_country" value="<?= $orderdata[15];?>">
<input type="hidden" name="delivery_cust_state" value="<?= $orderdata[14];?>">
<input type="hidden" name="delivery_cust_tel" value="<?= $orderdata[11];?>">
<input type="hidden" name="delivery_cust_notes" value="">
<input type="hidden" name="Merchant_Param" value="">
<input type="hidden" name="billing_zip_code" value="<?= $orderdata[16];?>">
<input type="hidden" name="delivery_cust_city" value="<?= $orderdata[13];?>">
<input type="hidden" name="delivery_zip_code" value="<?= $orderdata[16];?>">


</form>



Monday, November 30, 2009

Paypal Pro use in php for payment gateway

Implement payment gateway in your site using paypal pro account. use below script by changing some variable and value






<?php



$paymentType = $this->input->post('paymentType');

  $creditCardType= $this->input->post('creditCardType'); //Contain information about card type

  $creditCardNumber = $this->input->post('creditCardNumber'); //contain information about no of card

  $expDateMonth = $this->input->post('expDateMonth'); //contain information about expire month of card

  $expDateYear = $this->input->post('expDateYear'); //contain information about expire year of card

  $cvv2Number = $this->input->post('cvv2Number'); //contain security code of card which is card dependent

  $firstname =$this->input->post('user_fname'); //customer first name

  $lastname= $this->input->post('user_lname'); //customer last name

  $addr=   $this->input->post('address'); //customer postal address 1

  $addr1=   $this->input->post('address1'); //customer postal address 2

  $city =   $this->input->post('city'); //customer postal address city

  $state =   $this->input->post('state');


$zipcode =   $this->input->post('user_postalcode'); //customer postal code

  $phone =   $this->input->post('phone'); //customer phone no

  $email=   $this->input->post('user_email'); //customer Email address

  $package=   $this->input->post('pack'); //customer pack information if needed

  $a=explode('-',$package);

  $cochid = $a[0];

  $amount = $a[1]; //amount to pay

  $address1=$addr.$addr1;

 

 

 

 

  define('API_USERNAME', 'paypal_pro_user name');

  define('API_PASSWORD', 'paypal_pro_user password');

  define('API_SIGNATURE', 'paypal given id');

  define('API_ENDPOINT', 'https://api-3t.sandbox.paypal.com/nvp');

  define('USE_PROXY',FALSE);

  define('PROXY_HOST', '127.0.0.1');

  define('PROXY_PORT', '808');

  define('PAYPAL_URL', 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=');

  define('VERSION', '53.0');




session_start();


/**

  * hash_call: Function to perform the API call to PayPal using API signature

  * @methodName is name of API  method.

  * @nvpStr is nvp string.

  * returns an associtive array containing the response from the server.

  */




function hash_call($methodName,$nvpStr)

  {

  ini_set('max_execution_time', 300);

  //declaring of global variables

 

  global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header;

  $API_UserName=API_USERNAME;




$API_Password=API_PASSWORD;




$API_Signature=API_SIGNATURE;




$API_Endpoint =API_ENDPOINT;




$version=VERSION;

  

  //setting the curl parameters.

  $ch = curl_init();

 

  curl_setopt($ch, CURLOPT_URL,$API_Endpoint);

  curl_setopt($ch, CURLOPT_VERBOSE, 1);

 

  //turning off the server and peer verification(TrustManager Concept).

  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);

  //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.

  //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php

 

  if(USE_PROXY)

  //echo CURLOPT_PROXY;

  curl_setopt ($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT);

 

 

  //NVPRequest for submitting to server

  //echo $version;

  $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($version)."&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature).$nvpStr;

 

  //setting the nvpreq as POST FIELD to curl

  //CURLOPT_POSTFIELDS;

  curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

 

  //getting response from server

  $response = curl_exec($ch);

  // echo gettype($response);

  //echo "lkj"; die;

  //convrting NVPResponse to an Associative Array

  $nvpResArray=deformatNVP($response);

 

  $nvpReqArray=deformatNVP($nvpreq);

  //print_r($nvpReqArray);

  $_SESSION['nvpReqArray']=$nvpReqArray;

 

  if (curl_errno($ch)) {

 

  // moving to display page to display curl errors

  echo $_SESSION['curl_error_no']=curl_errno($ch) ;

  echo $_SESSION['curl_error_msg']=curl_error($ch); die;

 

  $location = "APIError.php";

  header("Location: $location");

  } else {

  //closing the curl

  curl_close($ch);

  }

 

  return $nvpResArray;

  }


/** This function will take NVPString and convert it to an Associative Array and it will decode the response.

  * It is usefull to search for a particular key and displaying arrays.

  * @nvpstr is NVPString.

  * @nvpArray is Associative Array.

  */


function deformatNVP($nvpstr)

  {

 

  $intial=0;

  $nvpArray = array();

 

 

  while(strlen($nvpstr)){

  //postion of Key

  $keypos= strpos($nvpstr,'=');

  //position of value

  $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);

 

  /*getting the Key and Value values and storing in a Associative Array*/

  $keyval=substr($nvpstr,$intial,$keypos);

  $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);

  //decoding the respose

  $nvpArray[urldecode($keyval)] =urldecode( $valval);

  $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));

  }

  return $nvpArray;

  }

 

  $paymentType =urlencode( $this->input->post('paymentType'));

  $firstname =urlencode($firstname);

  $lastName =urlencode($lastname);

  $creditCardType =urlencode($creditCardType);

  $creditCardNumber = urlencode($creditCardNumber);

  $expDateMonth =urlencode( $this->input->post('expDateMonth'));

 

  // Month must be padded with leading zero

  $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);

 

  $expDateYear =urlencode( $this->input->post('expDateYear'));

  $cvv2Number = urlencode($this->input->post('cvv2Number'));

  $address1 = urlencode($address1);

  //$address2 = urlencode($this->input->post('address2'));

  $city = urlencode($city);

  $state =urlencode($state);

  $zipcode = urlencode($zipcode);

  $amount = urlencode($amount);

  //$currencyCode=urlencode($_POST['currency']);

  $currencyCode="USD";

  $paymentType=urlencode($this->input->post('paymentType'));

  $nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=".$padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstname&LASTNAME=$lastname&STREET=$address1&CITY=$city&STATE=$state".

  "&ZIP=$zipcode&COUNTRYCODE=US&CURRENCYCODE=$currencyCode";

  //print_r($nvpstr);

  /* Make the API call to PayPal, using API signature.

  The API response is stored in an associative array called $resArray */

  $resArray=hash_call("doDirectPayment",$nvpstr);

  ///print_r($resArray);

  /* Display the API response back to the browser.

  If the response from PayPal was a success, display the response parameters'

  If the response was an error, display the errors received using APIError.php.

  */

  $this->view->data12=$resArray;

 

  /*$uid= $this->session->userdata('user_login_id');

  $q=$this->db->query("select email from user_account where uid=$uid");

  $row=$q->result_array();

  $date1=date('d/m/y');


//$data=array('id'=>$id,'user_name'=>$firstName,'Payment'=>$amount,'date'=>$date1);

  mysql_query("insert into balboa_transaction('uid','user_name','Payment','date','email')values($uid,'$firstName','$amount','$date1','$row[0]['email']')");

  //$this->db->insert('balboa_transaction',$data);

  //   $this->db->query("insert into balboa_transaction ('id','user_name','Payment','date')values('$id','".$firstName."','".$amount."','$date1')"); die;*/

  $ack = strtoupper($resArray["ACK"]);

  //echo $ack;

  if($ack=='FAILURE'){

  ///$this->load->view('home/thanks');

  $this->load->view('errorpage');

  }

  else{

  $this->load->view('success page');

  }

?>