Integrate CCAvenue Payment Gateway to frappe Web Forms

I have been trying to integrate CCAvenue Payment Gateway in frappe Web Form. CCAvenue has provided python sample code which is using Flask webframework.

Sample html code - dataform.html

<form method="POST" name="customerData" action="/ccavRequestHandler">		
		<table width="40%" height="100" border='1' align="center">
			<tr>
				<td>Merchant Id</td>
				<td><input type="text" name="merchant_id" id="merchant_id" value="2954" /> </td>
			</tr>
			<tr>
				<td>Order Id</td>
				<td><input type="text" name="order_id" value="" /></td>
			</tr>
			<tr>
				<td>Currency</td>
				<td><input type="text" name="currency" value="INR" /></td>
			</tr>
			<tr>
				<td>Amount</td>
				<td><input type="text" name="amount" value="1.00" /></td>
			</tr>
			<tr>
				<td></td>
				<td><INPUT TYPE="submit" value="Checkout"></td>
			</tr>
		</table>
	</form>

Sample Python code - ccavRequestHandler.py

@app.route('/ccavRequestHandler', methods=['GET', 'POST'])
def login():
	p_merchant_id = request.form['merchant_id']
	p_order_id = request.form['order_id']
	p_currency = request.form['currency']
	p_amount = request.form['amount']
	p_redirect_url = request.form['redirect_url']
	p_cancel_url = request.form['cancel_url']
	

	merchant_data='merchant_id='+p_merchant_id+'&'+'order_id='+p_order_id + '&' + "currency=" + p_currency + '&' + 'amount=' + p_amount+'&'+'redirect_url='+p_redirect_url+'&'+'cancel_url='+p_cancel_url+'&'+'language='+p_language+'&'+'billing_name='+p_billing_name+'&'+'billing_address='+p_billing_address+'&'+'billing_city='+p_billing_city+'&'+'billing_state='+p_billing_state+'&'+'billing_zip='+p_billing_zip+'&'+'billing_country='+p_billing_country+'&'+'billing_tel='+p_billing_tel+'&'+'billing_email='+p_billing_email+'&'+'delivery_name='+p_delivery_name+'&'+'delivery_address='+p_delivery_address+'&'+'delivery_city='+p_delivery_city+'&'+'delivery_state='+p_delivery_state+'&'+'delivery_zip='+p_delivery_zip+'&'+'delivery_country='+p_delivery_country+'&'+'delivery_tel='+p_delivery_tel+'&'+'merchant_param1='+p_merchant_param1+'&'+'merchant_param2='+p_merchant_param2+'&'+'merchant_param3='+p_merchant_param3+'&'+'merchant_param4='+p_merchant_param4+'&'+'merchant_param5='+p_merchant_param5+'&'+'promo_code='+p_promo_code+'&'+'customer_identifier='+p_customer_identifier+'&'
		
	encryption = encrypt(merchant_data,workingKey)

	html = '''\
<html>
<head>
	<title>Sub-merchant checkout page</title>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<form id="nonseamless" method="post" name="redirect" action="https://test.ccavenue.com/transaction/transaction.do?command=initiateTransaction"/> 
		<input type="hidden" id="encRequest" name="encRequest" value=$encReq>
		<input type="hidden" name="access_code" id="access_code" value=$xscode>
		<script language='javascript'>document.redirect.submit();</script>
</form>    
</body>
</html>
'''
	fin = Template(html).safe_substitute(encReq=encryption,xscode=accessCode)
			
	return fin

Essentially it’s an html <form method="POST" action="\python-method"/> and on submit button it’s calling python-method to redirect to CCAvenue url.

Approach to integrate in Frappe:

  1. Create a web form with doctype to store values and Allow Guest User to access.
  2. Create custom submit button in doctype and onclick in web form, it will call frappe.call with dotted path to python method to redirect to CCAvenue url. But it’s not getting called.
@frappe.whitelist(allow_guest=True, xss_safe=True)
def confirm_payment(merchant_id,order_id,currency,amount):
	try:
		params = "merchant_id="+merchant_id+'&'+"order_id="+order_id+'&'+"currency=" +'INR'+'&'+"amount="+amount;
		encryption = encrypt(params,'###Working_Key provided###')
		post_data = {
			"encRequest": encryption,
			"access_code": ###Access Code Provided###
		}
		html = '''\
<html>
<head>
	<title>Sub-merchant checkout page</title>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<form id="nonseamless" method="post" name="redirect" action="https://test.ccavenue.com/transaction/transaction.do?command=initiateTransaction"/> 
		<input type="hidden" id="encRequest" name="encRequest" value=$encReq>
		<input type="hidden" name="access_code" id="access_code" value=$xscode>
		<script language='javascript'>document.redirect.submit();</script>
</form>    
</body>
</html>
'''
	     fin = Template(html).safe_substitute(encReq=encryption,xscode=###Access Code Provided###)
         return fin
	except Exception as e:
		return str(e)`

html code is not getting executed in python.
URL Redirection to CCAvenue gateway is not getting trigger in frappe python method.

Any inputs/approach would be really appreciated.

1 Like

@jparikh were you able to set this up?

Yes, I have created web page (.html & .py) in www folder and used context object.

For reference, you could check this code for more details