简体   繁体   English

将CCAvenue与php集成

[英]Integrating CCAvenue with php

I am a total newbie to payment gateways. 我是支付网关的新手。 I would like to integrate CCAvenue to my website using PHP. 我想使用PHP将CCAvenue集成到我的网站。 I have downloaded their Intergration kit, Included my merchant id and working key, set the account to active and tried to do a dummy transaction on the index file they have provided in my localhost. 我已经下载了他们的Intergration工具包,包括我的商家ID和工作密钥,将帐户设置为活动状态,并尝试对他们在我的localhost中提供的索引文件进行虚拟交易。

But,when I click on submit on the form it is taking me to CCAvenue Transaction error page without any error code and error description. 但是,当我点击表单上的提交时,它将我带到CCAvenue Transaction错误页面,没有任何错误代码和错误描述。

Please let me know where I am making the mistake and what else I need to do. 请让我知道我在哪里犯了错误,我还需要做些什么。

I would be great if anyone pointed to me to a tutorial other then the CCAvenue integration manual. 如果有人向我指出除了CCAvenue集成手册之外的其他教程,我会很高兴。

Codes: Checkout.php 代码:Checkout.php

<html>
<head>
<title> Checkout</title>
</head>
<body>

 <?php include('adler32.php')?>
 <?php include('Aes.php')?>
 <?php 

 error_reporting(0);
 $merchant_id=$_POST['Merchant_Id'];  // Merchant id(also User_Id) 
 $amount=$_POST['Amount'];            // your script should substitute the amount here                        in the quotes provided here
 $order_id=$_POST['Order_Id'];        //your script should substitute the order   description here in the quotes provided here
 $url=$_POST['Redirect_Url'];         //your redirect URL where your customer will be redirected after authorisation from CCAvenue
 $billing_cust_name=$_POST['billing_cust_name'];
 $billing_cust_address=$_POST['billing_cust_address'];
 $billing_cust_country=$_POST['billing_cust_country'];
 $billing_cust_state=$_POST['billing_cust_state'];
 $billing_city=$_POST['billing_city'];
 $billing_zip=$_POST['billing_zip'];
 $billing_cust_tel=$_POST['billing_cust_tel'];
 $billing_cust_email=$_POST['billing_cust_email'];
 $delivery_cust_name=$_POST['delivery_cust_name'];
 $delivery_cust_address=$_POST['delivery_cust_address'];
 $delivery_cust_country=$_POST['delivery_cust_country'];
 $delivery_cust_state=$_POST['delivery_cust_state'];
 $delivery_city=$_POST['delivery_city'];
 $delivery_zip=$_POST['delivery_zip'];
 $delivery_cust_tel=$_POST['delivery_cust_tel'];
 $delivery_cust_notes=$_POST['delivery_cust_notes'];


$working_key=/*MY working Key*/;    //Put in the 32 bit alphanumeric key in the quotes provided here.


 $checksum=getchecksum($merchant_id,$amount,$order_id,$url,$working_key); // Method to       generate checksum

  $merchant_data=    'Merchant_Id='.$merchant_id.'&Amount='.$amount.'&Order_Id='.$order_id.'&Redirect_Url='.$url  '&billing_cust_name='.$billing_cust_name.'&billing_cust_address='.$billing_cust_address.'&billing_cust_country='.$billing_cust_country.'&billing_cust_state='.$billing_cust_state.'&billing_cust_city='.$billing_city.'&billing_zip_code='.$billing_zip.'&billing_cust_tel='.$billing_cust_tel.'&billing_cust_email='.$billing_cust_email.'&delivery_cust_name='.$delivery_cust_name.'&delivery_cust_address='.$delivery_cust_address.'&delivery_cust_country='.$delivery_cust_country.'&delivery_cust_state='.$delivery_cust_state.'&delivery_cust_city='.$delivery_city.'&delivery_zip_code='.$delivery_zip.'&delivery_cust_tel='.$delivery_cust_tel.'&billing_cust_notes='.$delivery_cust_notes.'&Checksum='.$checksum  ;

$encrypted_data=encrypt($merchant_data,$working_key); // Method for encrypting the data.

?>

<form method="post" name="redirect"   action="http://www.ccavenue.com/shopzone/cc_details.jsp"> 
<?php
   echo "<input type=hidden name=encRequest value=$encrypted_data>";
   echo "<input type=hidden name=Merchant_Id value=$merchant_id>";

    ?>
 </form>
 <script type='text/javascript'>document.redirect.submit();</script>
 </body>
 </html>

And my Redirecturl.php 还有我的Redirecturl.php

<?php include('Aes.php')?>
<?php include('adler32.php')?>
<?php


error_reporting(0);
$workingKey=/*My Working Key*/;     //Working Key should be provided here.
$encResponse=$_POST["encResponse"];         //This is the response sent by the CCAvenue Server


$rcvdString=decrypt($encResponse,$workingKey);      //AES Decryption used as per the specified working key.
$AuthDesc="";
$MerchantId="";
$OrderId="";
$Amount=0;
$Checksum=0;
$veriChecksum=false;

$decryptValues=explode('&', $rcvdString);
$dataSize=sizeof($decryptValues);
//******************************    Messages based on Checksum & AuthDesc   **********************************//
echo "<center>";


for($i = 0; $i < $dataSize; $i++) 
{
    $information=explode('=',$decryptValues[$i]);
    if($i==0)   $MerchantId=$information[1];    
    if($i==1)   $OrderId=$information[1];
    if($i==2)   $Amount=$information[1];    
    if($i==3)   $AuthDesc=$information[1];
    if($i==4)   $Checksum=$information[1];  
}

$rcvdString=$MerchantId.'|'.$OrderId.'|'.$Amount.'|'.$AuthDesc.'|'.$workingKey;
$veriChecksum=verifyChecksum(genchecksum($rcvdString), $Checksum);

if($veriChecksum==TRUE && $AuthDesc==="Y")
{
    echo "<br>Thank you for shopping with us. Your credit card has been charged and your transaction is successful. We will be shipping your order to you soon.";

    //Here you need to put in the routines for a successful 
    //transaction such as sending an email to customer,
    //setting database status, informing logistics etc etc
}
else if($veriChecksum==TRUE && $AuthDesc==="B")
{
    echo "<br>Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail";

    //Here you need to put in the routines/e-mail for a  "Batch Processing" order
    //This is only if payment for this transaction has been made by an American Express Card
    //since American Express authorisation status is available only after 5-6 hours by mail from ccavenue and at the "View Pending Orders"
}
else if($veriChecksum==TRUE && $AuthDesc==="N")
{
    echo "<br>Thank you for shopping with us.However,the transaction has been declined.";

    //Here you need to put in the routines for a failed
    //transaction such as sending an email to customer
    //setting database status etc etc
}
else
{
    echo "<br>Security Error. Illegal access detected";

    //Here you need to simply ignore this and dont need
    //to perform any operation in this condition
}


echo "<br><br>";


//************************************  DISPLAYING DATA RCVD ******************************************//

echo "<table cellspacing=4 cellpadding=4>";
for($i = 0; $i < $dataSize; $i++) 
{
    $information=explode('=',$decryptValues[$i]);
        echo '<tr><td>'.$information[0].'</td><td>'.$information[1].'</td></tr>';
}

echo "</table><br>";
echo "</center>";
?>

I have also included Adler.php and Aes.php which comes with the integration kit 我还包括了集成套件附带的Adler.php和Aes.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. ccavenue支付网关集成非常简单,请复制下面的PHP代码或php脚本进行ccavenue支付网关集成,并根据您的帐户设置变量值。

<?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>

Steps to Integrate Payment Gateway : 集成支付网关的步骤:

  1. At first create a merchant account on https://dashboard.ccavenue.com/web/registration.do?command=Preview . 首先在https://dashboard.ccavenue.com/web/registration.do?command=Preview上创建一个商家帐户。

  2. After successful registration CCavenue team will verify your provided phone no. 成功注册后,CCavenue团队将验证您提供的电话号码。 and email Id. 和电子邮件ID。

  3. After account activation your website will be verified and the team will provided your the merchant Id and working key which will be needed while integrating the payment gateway. 帐户激活后,您的网站将得到验证,并且团队将提供您在集成支付网关时所需的商家ID和工作密钥。

  4. Login to your account on https://dashboard.ccavenue.com/jsp/merchant/merchantLogin.jsp 通过https://dashboard.ccavenue.com/jsp/merchant/merchantLogin.jsp登录您的帐户

  5. Go to dashboard and click on setting tab then select API KEYS. 转到仪表板并单击设置选项卡,然后选择API KEYS。

  6. Copy all three keys Merchant ID, Access Code and Working Key. 复制所有三个键商家ID,访问代码和工作密钥。

    Now follow the following code steps to integrate Ccavenue : 现在按照以下代码步骤集成Ccavenue:

    Create a file containing the form eg index.php and paste below code: 创建一个包含表单的文件,例如index.php并粘贴到代码下面:

    Follow below link for step by step execution : 按照以下链接逐步执行:

https://www.lelocode.com/posts/integrate-ccavenue-payment-gateway-in-php-with-simple-step---lelocode https://www.lelocode.com/posts/integrate-ccavenue-payment-gateway-in-php-with-simple-step---lelocode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM