+ Start a Discussion
Dnyanesh GawaliDnyanesh Gawali 

Hi All, Can any one help me in CCAvenue integration with Salesforce

I want to integrate CCAvenue (online payment gateway solution provider) with Salesforce CRM.
Please share some steps or sample code of integration.

Thansk!
NagendraNagendra (Salesforce Developers) 
Hi Gawali,

First and foremost sincerely regret the delayed reply.

Below information might be helpful for you to accelerate with above requirement.

Description:CCAvenue does not provide integration kit for Salesforce Apex language. They provide Asp.net, Java, NodeJS, iOS, Android, Windows.
How do we encrypt and decrypt data and make request for CCAvenue payment gateway.

Resolution:

Here is Encryption:

/* This PLAIN_TEXT is your data collected from your apex form. Few values are required and lots of values are optional. Please read document provided by ccavenue. */

String PLAIN_TEXT = 'tid=XXXX&merchant_id=XXXX&order_id=XXXX&amount=XX&currency=INR&redirect_url=XXXX&cancel_url=XXXX&language=EN&billing_name=XXXX&billing_address=XXXX&billing_city=XXXX&billing_state=XX&billing_zip=XXXX&billing_country=XXXX&billing_tel=XXXX&billing_email=XXXX&delivery_name=XXXX&delivery_address=XXXX&delivery_city=XXXX&delivery_state=XXXX&delivery_zip=XXXX&delivery_country=XXXX&delivery_tel=XXXX&merchant_param1=XXXX&merchant_param2=XXXX&merchant_param3=XXXX&merchant_param4=XXXX&merchant_param5=XXXX&promo_code=&customer_identifier=&';

//WORKING_KEY is key provided by CCAvenue when you register as Merchant.

Blob cryptoKey = Blob.valueOf('WORKING_KEY');

Blob hash = Crypto.generateDigest('MD5', cryptoKey );

Blob data = Blob.valueOf(PLAIN_TEXT);

Blob encryptedData = Crypto.encryptWithManagedIV('AES128', hash , data);

String encRequest = EncodingUtil.convertToHex(encryptedData );

/*Pass this encRequest with access_code to the https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction using visual force FORM */

Here is Decryption:

Blob cryptoKey = Blob.valueOf('WORKING_KEY');

Blob hash = Crypto.generateDigest('MD5', cryptoKey);

Blob data = EncodingUtil.convertFromHex('ENC_RESPONSE'); //Received from ccAvenue response

Blob decryptedText = Crypto.decryptWithManagedIV('AES128', hash, data);

String PLAIN_TEXT = decryptedText.toString();

Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.

Best Regards,
Nagendra.P
Amritesh SinghAmritesh Singh
Hi Nagendra/Gawali,

Could you please share the details of how you are capturing the ccAvenue response.? 

As per the above code by Nagendra, how we get the "ENC_RESPONSE" in the controller.?

What script do I need to write in redirect URL page?

Thanks in Advance,
Amritesh

 
Amul Baranwal 9Amul Baranwal 9
Hi 
Nagendra  ,

Did you integrated this CCAvenue? Could u please share VF Page and Apex Class tht you have Build?
Mukund Gadave 15Mukund Gadave 15
@Nagendra: Looks like you have just copied from below stack exchange forum. 

Hi Dnyanesh Gawali & Amul Baranwal 9,
Here is original post about CCAvenue integration & solution which was updated in April 2016.
https://stackoverflow.com/questions/36565886/payment-gateway-ccavanue-with-salesforce-apex
https://salesforce.stackexchange.com/questions/117578/ccavanue-payment-gateway-integration-with-salesforce-apex

I can help you to fix issues if you have any.

Regards,
Mukund
AmulAmul
Thanks Mukund for your help.

I am posting UTIL Class that i have Created with help of your Blog.
 
public class CCAvenueUtilClass {
    
    public static string getencRequest(string tid
                                       , string merchant_id
                                       , string order_id
                                       , string amount
                                       , string strcurrency
                                       , string redirect_url
                                      , string cancel_url
                                      , string language
                                      , string billing_name
                                      , string billing_address
                                      , string billing_city
                                      , string billing_state
                                      , string billing_zip
                                      , string billing_country
                                      , string billing_tel
                                      , string billing_email
                                      , string delivery_name
                                      , string delivery_address
                                      , string delivery_city
                                      , string delivery_state
                                      , string delivery_zip
                                      , string delivery_country
                                      , string delivery_tel
                                      , string customer_identifier
                                      ){
        String encRequest='';
        String PLAIN_Request ='tid='+ tid;
        PLAIN_Request = PLAIN_Request +'&'+  'merchant_id=' + merchant_id;
        PLAIN_Request = PLAIN_Request +'&'+  'order_id=' + order_id;
        PLAIN_Request = PLAIN_Request +'&'+  'amount=' + amount;
        PLAIN_Request = PLAIN_Request +'&'+  'currency=' + strcurrency;
        PLAIN_Request = PLAIN_Request +'&'+  'redirect_url=' + redirect_url;
        PLAIN_Request = PLAIN_Request +'&'+  'cancel_url=' + cancel_url;
        PLAIN_Request = PLAIN_Request +'&'+  'language=' + language;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_name=' + billing_name;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_address=' + billing_address;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_city=' + billing_city;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_state=' + billing_state;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_zip=' + billing_zip;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_country=' + billing_country;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_tel=' + billing_tel;
        PLAIN_Request = PLAIN_Request +'&'+  'billing_email=' + billing_email;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_name=' + delivery_name;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_address=' + delivery_address;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_city=' + delivery_city;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_state=' + delivery_state;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_zip=' + delivery_zip;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_country=' + delivery_country;
        PLAIN_Request = PLAIN_Request +'&'+  'delivery_tel=' + delivery_tel;
        PLAIN_Request = PLAIN_Request +'&'+  'customer_identifier=' + customer_identifier;                                          
        
        system.debug('PLAIN_Request' + PLAIN_Request);                                  
                                          
        Blob cryptoKey = Blob.valueOf(system.label.CCAvenueWorking_key);
        Blob hash = Crypto.generateDigest('MD5', cryptoKey );
        Blob data = Blob.valueOf(PLAIN_Request);
        Blob encryptedData = Crypto.encryptWithManagedIV('AES128', hash , data);
        encRequest = EncodingUtil.convertToHex(encryptedData );
                                          
        return encRequest;
    }

}

And I am calling this class from my VF Page and Controller class
 
<apex:page controller="ServiceOrderPaymentController" lightningStylesheets="true">
<apex:PageMessages ></apex:PageMessages>
<apex:form id="frm">
    <apex:pageBlock title="My Order Payment">

        <apex:pageBlockTable value="{!ListOP}" var="item">

            <apex:column value="{!item.name}"/>
            <!--<apex:column value="{!item.Customer_Service_Booking__c}"/>-->
            <apex:column value="{!item.Payment_Due_Date__c }"/>
            <!--<apex:column value="{!item.CAR_MAKE__c}"/>-->
            <apex:column value="{!item.CAR_MODEL__c}"/>
            <apex:column value="{!item.CAR_BRAND__c}"/>
            <apex:column value="{!item.CAR_Registration_No__c}"/>
            <apex:column value="{!item.CAR_OWNER_NAME__c}"/>
            <apex:column value="{!item.CAR_OWNER_EMAIL__c}"/>
             <apex:column value="{!item.CAR_OWNER_MOBILE__c}"/>
            <apex:column value="{!item.Payment_Amount__c}"/>
            <apex:column >
                <apex:commandLink value="Pay Now" action="{!PayNow}" styleclass="slds-button" >
                <apex:param name="nickName"     value="{!item.id}"    assignTo="{!selectedOrder}"/>
            </apex:commandLink>    
   

            </apex:Column>
           </apex:pageBlockTable>
           
           

        

    </apex:pageBlock>
 </apex:form> 
</apex:page>

controller class
 
public class ServiceOrderPaymentController {
    public list<Order_Payment__c> ListOP{get;set;}
    public String selectedOrder{get; set;}
    
    public ServiceOrderPaymentController(){
        ListOP=[Select id, Name , Customer_Service_Booking__c,Payment_Amount__c, Payment_Due_Date__c, CAR_MAKE__c, CAR_MODEL__c, CAR_BRAND__c
        , CAR_Registration_No__c
        , CAR_OWNER_EMAIL__c
        , CAR_OWNER_NAME__c
        , CAR_OWNER_MOBILE__c from Order_Payment__c];
        
        
    }
    
    public PageReference PayNow(){
        
        //string selectedOrder= apexpages.currentPage().getParameters().get('selectOrder');
        String encRequest;
        PageReference ReturnPage;
        string redirect_url='https://dev-firstcarwashcustomer.cs58.force.com/customer/CancelCCAvenue';
        string cancel_url='https://dev-firstcarwashcustomer.cs58.force.com/customer/CancelCCAvenue';
        //CCAvenueUtilClass.getencRequest
        
        system.debug('@@selectedOrder@@'+ selectedOrder);
        
        Order_Payment__c[] OP=[Select id, Name , Customer_Service_Booking__c,Payment_Amount__c, Payment_Due_Date__c, CAR_MAKE__c, CAR_MODEL__c, CAR_BRAND__c
        , CAR_Registration_No__c
        , CAR_OWNER_EMAIL__c
        , CAR_OWNER_NAME__c
        , CAR_OWNER_MOBILE__c from Order_Payment__c where Id=:selectedOrder];
        
         system.debug('@@OP SIZE@@'+ OP.size());
         
        if(OP.size()>0){
        
            order_Payment__c Record=OP[0];
            system.debug('Record' + Record);
            encRequest=CCAvenueUtilClass.getencRequest(Record.Name,system.Label.CCAvenuemerchant_id  , Record.Name
                                                        , string.valueOf(Record.Payment_Amount__c)
                                                        , 'INR'
                                                        , redirect_url
                                                        , cancel_url
                                                        , 'EN'
                                                        , Record.CAR_OWNER_NAME__c
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , Record.CAR_OWNER_MOBILE__c 
                                                        , Record.CAR_OWNER_EMAIL__c
                                                        , Record.CAR_OWNER_NAME__c
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , ''
                                                        , Record.CAR_OWNER_MOBILE__c
                                                        , '');
                                                        
         system.debug('encRequest' + encRequest);
                                                        
         string strURL=system.Label.CCAvenue_URL + '/transaction/transaction.do?command=initiateTransaction&encRequest=' + encRequest + '&access_code=' + system.Label.CCAvenueaccess_code;
         //system.debug('strURL' + strURL);
         ReturnPage = new PageReference(strURL); 
         //ReturnPage.setRedirect(true);
         
        
        }
        
        
        
        
        
        return ReturnPage ;
    }


}

 could you please help I am getting Error Code: 10002     Merchant Authentication failed.
 
Mukund Gadave 15Mukund Gadave 15
Hi Amul, 
We need to whitelist URL for transaction call. You need to add your VF page in Ccavenue merchant account. Please find document here http://cp.thinkcept.com/kb/answer/2417 OR from latest document from CCavenue. 

Also I would suggest to use different URL's for redirect URL Cancel URL because your response decription should process on RedirectURL.

Please try whitelisting URL once.

Thanks,
Mukund
Gulam Mustafa 10Gulam Mustafa 10
Still not able to capture Ccavanue response that is return after the successfull transaction. I have gone through jsp integration kit, In jsp you can get response by following code
String encResp= request.getParameter("encResp");
 So In apex,I thought following code work 
String encResp=  ApexPages.currentPage().getParameters().get('encResp');
But it does not work. Any Help??
 
prasad vivekprasad vivek
Hi Narendra,

I was trying to use a similar logic that you have shared with encryption and decryption. But When I decrypt I was getting decrypted string of this format vivek&#124;INR&#124; but ideally it should be of vivek|INR|.Can you help out or did you face a similar issue?

One more thing, when I was sending the encrypted string to CCAvenue, they told me that when they decrypt they were getting some additional characters in front of the original string(vivek|INR), they were getting something like hdkdjdvivek|INR. can you please tell me if you faced this issue and how did u solve this.
prasad vivekprasad vivek
Hi All, I have an update from my above concern, I came to know that if we check the debug in SF it will show '|' as &#124; only bcz salesforce already uses this.
When I send my request it's getting decrypted as below, does anyone have any solution for this.


C�[��6� �� ]{��vivek|INR|2|days|1.00|SMS|123456987|terms and condition|9874563215|Pls call 022-2121212121 to pay your LegalEntity_Name bill # Invoice_ID for Invoice_Currency Invoice_Amount or pay online at Pay_Link.|xxxxx.xxxx@xxxx.com|test invoice mail|this invoice generate for testing|invoice.doc$77u/SGVsbG8gaW5kaWEK|