Integrating HDFC Payment Gateway in ASP.NET
Last time when I was trying to integrated in hdfc payment gateway I searched online
But little help was available reading long manual learning terms used is no doubt essential but some time you want to know you are following right path. From by personal experience I can now help someone caught in similar situation like mine.
Code provided bellow is not elegant though it works fine. I am showing bellow the simplest way to get work done then in your comfort zone do the modification.
I hope this will be helpful to at least one guy scratching his head.
When merchant buys hdfc payment gateway he will be provided with files for integration those file include resource.cgn .The dll provided in kit
“e24PaymentPipe.dl” needs to be registered using regsvr32 command.
Then you will have a folder named trans which contain the asp files namely
a)Buy.asp
b)Success.asp
c)TransFailure.asp
d) redirect.asp
e)Pay.asp
f)index.asp
it will contain a merchant.config file you need to modify the file
The Content Is as Follows
tran.currency=356’currency INR
consumer.language=USA’prefered language
tran.action=4
merchant.receiptURL=http://www.yoursite.com/Trans/redirect.asp
merchant.errorURL=http://www.yoursite.com/Trans/tranfailure.asp
gateway.headerCount=1
gateway.header=1
gateway.resource.path=yourpathto/resource/
gateway.terminal.alias=yourAlias
gateway.Institute.alias=HDFC
gateway.InstituteDesc.alias=HDFC VISA Payment Mode
From your ASPX page do response.redirect to Buy.asp with releveant information
How Buy.asp looks like
<HTML><HEAD><TITLE>YourSite</TITLE>
<%
Dim MyObj
Dim vargatewayheader
Dim id
Dim StartRecord
dim inc
inc = 0
dim gatevalues
dim TranCurrency,ConsumerLanguage,TranAction,MerchantReceiptURL,MerchantErrorURL
Dim ResourcePath,TerminalAlias
Dim Headcount
'Creating the object of e24PaymentPipe(DLL registered)
Set MyObj = Server.CreateObject("e24PaymentPipe.e24PaymentPipe.1")
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("Merchant.config"), 1)
StartRecord = "FALSE"
id = request.form("InstituteID")
Response.write("Institute ID : "& id) & "<br>"
do while f.AtEndOfLine <> true
vargatewayheader = f.readline
splitline = split(vargatewayheader,"=")
if splitline(0) = "tran.currency" then
TranCurrency = splitline(1)
elseif splitline(0) = "consumer.language" then
ConsumerLanguage= splitline(1)
elseif splitline(0) = "tran.action" then
TranAction = splitline(1)
elseif splitline(0) = "merchant.receiptURL" then
MerchantReceiptURL= splitline(1)
elseif splitline(0) = "merchant.errorURL" then
MerchantErrorURL= splitline(1)
elseif splitline(0) = "gateway.headerCount" then
Headcount = splitline(1)
Response.write("Header Count : "& Headcount) & "<br>"
elseif splitline(0) = "gateway.header" then
if HeadCount = 1 then
id = splitline(1)
Response.write("One Institute ID : "& id) & "<br>"
end if
end if
if vargatewayheader = "gateway.header=" & id then
StartRecord = "TRUE"
else
if StartRecord = "TRUE" then
if inc = 0 then
gatevalues = split(vargatewayheader,"=")
ResourcePath = gatevalues(1)
'response.write(ResourcePath) &"<br>"
inc =1
elseif inc = 1 then
'Response.write(vargatewayheader) & "<BR>"
gatevalues = split(vargatewayheader,"=")
TerminalAlias = gatevalues(1)
response.write(TerminalAlias) &"<br>"
inc = 2
elseif inc = 2 then
'Response.write(vargatewayheader) & "<BR>"
inc =3
elseif inc = 3 then
'Response.write(vargatewayheader) & "<BR>"
inc =0
StartRecord = "FALSE"
end if
end if
end if
loop
MyObj.ResourcePath = ResourcePath
MyObj.Alias = TerminalAlias
response.write(ResourcePath) &"<br>"
response.write(TerminalAlias) &"<br>"
MyObj.Action = 4
MyObj.Amt = Request.QueryString("Amt")
MyObj.Currency = TranCurrency
MyObj.ResponseURL = MerchantReceiptURL
MyObj.ErrorURL = MerchantErrorURL
trackid = cstr(session.sessionid) + cstr(second(now)) + cstr(minute(now)) 'Generating Merchant Track ID
MyObj.TrackId = trackid
response.write("trackid : " &MyObj.TrackId) &"<br>" 'trackid
response.write("TranAction : " &MyObj.Action) &"<br>" 'TranAction
response.write("session amt --:"&MyObj.Amt) &"<br>"
response.write("Currency :"&TranCurrency) &"<br>" '
response.write("Consumer Language: "&ConsumerLanguage) &"<br>"
response.write("MerchantReceiptURL : " &MyObj.ResponseURL) &"<br>" ' MerchantReceiptURL
response.write("MerchantErrorURL: " &MyObj.ErrorURL) &"<br>"
MyObj.Udf1 = Request.QueryString("ordno")
MyObj.Udf2 = Request.QueryString("Email")
MyObj.Udf3 = Request.QueryString("phone")
MyObj.Udf4 = Request.QueryString("Area")
MyObj.Udf5 = Request.QueryString("Pincode")
response.write("UDF1 =" &MyObj.Udf1) &"<br>"
response.write("UDF2 =" &MyObj.Udf2) &"<br>"
response.write("UDF3 =" &MyObj.Udf3) &"<br>"
response.write("UDF4 =" &MyObj.Udf4) &"<br>"
response.write("UDF5 =" &MyObj.Udf5) &"<br>"
Dim TransVal,varPaymentId, varPaymentPage,varErrorMsg,varRawResponse
'perform the transaction
TransVal = MyObj.PerformInitTransaction 'returns 0 for succes AND -1 for failure
response.write("tranval--:"&TransVal) &"<br>"
varRawResponse = MyObj.RawResponse
varPaymentId = MyObj.PaymentId
varPaymentPage = MyObj.PaymentPage
varErrorMsg = MyObj.ErrorMsg
response.write("varRawResponse : " &varRawResponse) &"<br>"
response.write("varErrorMsg : " &varErrorMsg) &"<br>"
response.write("url--:"&varPaymentPage) &"<br>"
Response.write(varPaymentPage & "?PaymentID=" & varPaymentId )
if(Transval=0) Then
Response.redirect(varPaymentPage & "?PaymentID=" & varPaymentId)
else
Response.write("REDIRECT=http://YourSite.com/Trans/tranfailure.asp?PaymentID="& varPaymentid)
end If
%>
</HEAD> </HTML>
How Redirect.asp looks Like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD></head>
<body bgcolor="#FFFFFF">
<%
Dim ErrorTx,ErrorResult,payID,result,tranid,trackid,postdate,auth,ref,amt,udf1,udf2,udf3,udf4,udf5,s
ErrorTx = request("Error")
ErrorResult = request("ErrorText")
payID = request("paymentid")
result = request("result")
tranid = request("tranid")
trackid = request("trackid")
postdate = request("postdate")
auth = request("auth")
ref=request("ref")
amt=request("amt")
udf1 = request("udf1")
udf2 = request("udf2")
udf3 = request("udf3")
udf4 = request("udf4")
udf5 = request("udf5")
s=""
if result="CANCELED" then
response.write("REDIRECT=http://YourSite.com/Trans/tranfailure.asp?paymentid="&payID&"&auth="&auth&"&amt="&amt&"&ref="&ref&"&tranid="&tranid&"&trackid="&trackid&"&postdate="&postdate&"&result="&result&"&Udf1="&udf1&"&Udf2="&udf2&"&Udf3="&udf3&"&Udf4="&udf4&"&Udf5="&udf5)
ElseIf errorTx <> Null Then
response.write("REDIRECT=http://YourSite.com.com/Trans/tranfailure.asp?paymentid="&payID&"&auth="&auth&"&amt="&amt&"&ref="&ref&"&tranid="&tranid&"&trackid="&trackid&"&postdate="&postdate&"&result="&result&"&Udf1="&udf1&"&Udf2="&udf2&"&Udf3="&udf3&"&Udf4="&udf4&"&Udf5="&udf5&"&ErrorResult="&ErrorResult)
Else
response.write("REDIRECT=http://YourSite.com/Trans/success.asp?paymentid="&payID&"&auth="&auth&"&amt="&amt&"&ref="&ref&"&tranid="&tranid&"&trackid="&trackid&"&postdate="&postdate&"&result="&result&"&Udf1="&udf1&"&Udf2="&udf2&"&Udf3="&udf3&"&Udf4="&udf4&"&Udf5="&udf5&"&ErrorResult="&ErrorResult)
End If
%>
</body>
</HTML>
How Success.asp look like
<%
Dim s,postdate,tranid,auth,trackid,payID,udf1,amt,ref
s=request("result")
postdate=request("postdate")
tranid=request("tranid")
auth=request("auth")
trackid=request("trackid")
payID = request("paymentid")
udf1 = request("udf1")
amt=request("amt")
ref=request("ref")
ErrorResult=request("ErrorResult")
%>
<HTML>
<HEAD>
<TITLE>Himalaya Fine Art: Transaction Result</TITLE>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META name="GENERATOR" content="Microsoft FrontPage 6.0">
</HEAD>
<BODY bgcolor="#FFFFFF">
<CENTER>
<div align="center">
<br>
<table>
<tr>
<TD height="25">
<strong>Your transaction was <b><font color="blue"><%=s%><%=ErrorResult%></font></b></strong>
</TD>
</tr>
</table>
<br>
</div>
<div align="center">
<center>
<TABLE border=1 bordercolor=black width="306" bgcolor="#F0F2FF" style="border-collapse: collapse; border: 1px outset #999999" cellpadding="0" cellspacing="0"><tr>
<td width="296">
<div align="center">
<center>
<TABLE border=1 bordercolor=#FFFFFF width="90%" style="border-collapse: collapse" cellpadding="3"><tr><td>
<TR>
<TD colspan="2" align="center" height="25" valign="bottom">
<FONT size="4"><B>Transaction Details </B></FONT>
</TD>
</TR>
<TR>
<TD colspan="2" align="center" height="25">
<HR>
</TD>
</TR>
<TR>
<TD width="40%" bgcolor="#FFFFFF" height="25"><b>
<font size="2" face="Arial">Track ID</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=trackid%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">Result</font></b></TD>
<TD height="25"><font color="blue"><b><%=s%><%=ErrorResult%></b></TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">Payment ID</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=payID%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">Transaction ID</font></b></TD>
<TD height="25"><%=tranid%></TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">Post Date</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=postdate%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">Amount</font></b></TD>
<TD height="25"><%=amt%></TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">Auth Code</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=auth%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">Reference ID</font></b></TD>
<td height="25"><%=ref%></td>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">
Order No.</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=udf1%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">E-mail</font></b></TD>
<TD height="25"><%=request("udf2")%></TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">Tel
No.</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=request("udf3")%></TD>
</TR>
<TR>
<TD height="25"><b><font size="2" face="Arial">Address</font></b></TD>
<TD height="25"><%=request("udf4")%></TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF" height="25"><b><font size="2" face="Arial">
City, PIN</font></b></TD>
<TD bgcolor="#FFFFFF" height="25"><%=request("udf5")%></TD>
</TR>
</td></tr></table></center>
</div>
</td></tr></table>
</center>
</div>
<div align="center" style="font-size:20px;"><br><br>
<p>
<% if ErrorResult <> "APPROVED" then %>
<a href="http://www.YourSite.com/yourpage.aspx" >Select another payment option</a>
<% End if %>
</p>
<a href="http://www.YourSite.com/yourpage.aspx">Close</a>
</div>
</BODY>
</HTML>
How transfailure.asp looks like
<HTML>
<HEAD>
<TITLE>Transaction Failure Page</TITLE>
</HEAD>
<BODY>
<center>
<div align="center"><br>
<strong>OOPS!</strong> There was some problem. Your transaction was <strong>NOT</strong> successful<br>
<br>
<%
dim tranID
tranID=request("tranid")
dim result,canResult,errortx
canResult=request("result")
ErrorResult=request("ErrorResult")
If canResult <> null and canResult="CANCELED" then
%>
</div>
<div align="center">
<TABLE border=1 bordercolor=black width="437" bgcolor="#E8F3FF"><tr><td>
<div align="center">
<TABLE border=0 bordercolor=black cellspacing="6" cellpadding="3" width="362"><tr><td>
<TR>
<TD colspan="2" align="center">
<FONT size="4"><B>Transaction Details</B></FONT>
</TD>
</TR>
<TR>
<TD colspan="2" align="center">
<HR>
</TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Result </TD>
<TD bgcolor="#F9FCFF"><font color="blue"><b><%=canResult%><%=ErrorResult%></b></TD>
</TR>
<TR>
<TD>Payment ID</TD>
<TD><%=request("paymentid")%></TD>
</TR>
<TR>
<TD width="40%" bgcolor="#F9FCFF">Track ID</TD>
<TD bgcolor="#F9FCFF"><%=request("trackid")%></TD>
</TR>
<TR>
<TD>Order No.</TD>
<TD><%=request("udf1")%></TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Email</TD>
<TD bgcolor="#F9FCFF"><%=request("udf2")%></TD>
</TR>
<TR>
<TD>Tel</TD>
<TD><%=request("udf3")%></TD>
<TR>
<TD bgcolor="#F9FCFF">Address</TD>
<TD bgcolor="#F9FCFF"><%=request("udf4")%></TD>
</TR>
<TR>
<TD>Pin</TD>
<TD><%=request("udf5")%></TD>
</TR>
</td></tr></table></div>
</td></tr></table>
</div>
<% else%>
<div align="center">
<TABLE border=1 bordercolor=black width="437" bgcolor="#E8F3FF"><tr><td>
<div align="center">
<TABLE border=0 bordercolor=black cellspacing="6" cellpadding="3" width="360"><tr><td>
<TR>
<TD colspan="2" align="center">
<FONT size="4"><B>Transaction Details </B></FONT>
</TD>
</TR>
<TR>
<TD colspan="2" align="center">
<HR>
</TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Result </TD>
<TD bgcolor="#F9FCFF"><font color="red"><b><%=canresult%><%=ErrorResult%></b></TD>
</TR>
<TR>
<TD width="40%">Payment ID</TD>
<TD><%=request("paymentid")%></TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Order No.</TD>
<TD bgcolor="#F9FCFF"><%=request("udf1")%></TD>
</TR>
<TR>
<TD>Email</TD>
<TD><%=request("udf2")%></TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Tel</TD>
<TD bgcolor="#F9FCFF"><%=request("udf3")%></TD>
</TR>
<TR>
<TD>Address</TD>
<TD><%=request("udf4")%></TD>
</TR>
<TR>
<TD bgcolor="#F9FCFF">Pin</TD>
<TD bgcolor="#F9FCFF"><%=request("udf5")%></TD>
</TR>
</td></tr></table></div>
</td></tr></table>
</div>
<%End if%>
<br>
<center>
<p><a href="http://www.YourSite.com/done.aspx">Quit</a></p>
<p><a href="http://www.YourSite.com/payment.aspx">Select another payment
option</a></p>
</center>
</HTML>
How Pay.asp look like
<%@ Page Language="VB" AspCompat="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub page_load(ByVal sender As Object, ByVal e As EventArgs)
If (Not Page.IsPostBack) Then
Dim MyObj
Dim vargatewayheader
Dim id
Dim StartRecord
Dim inc
inc = 0
Dim gatevalues
Dim TranCurrency, ConsumerLanguage, TranAction, MerchantReceiptURL, MerchantErrorURL, Amt
Dim ResourcePath, TerminalAlias
Dim Headcount
MyObj = Server.CreateObject("e24PaymentPipe.e24PaymentPipe.1")
Dim fs = Server.CreateObject("Scripting.FileSystemObject")
ResourcePath = "YourPath/Trans/Merchant.config"
TerminalAlias = "Term1"
TranAction = "4"
Amt = "1000"
MerchantReceiptURL = "http://YourSite.com/Trans/success.asp"
MerchantErrorURL = "http://YourSite.com/Trans/tranfailure.asp"
'Response.Redirect("https://securepgtest.fssnet.co.in:443/pgway/gateway/payment/payment.jsp?PaymentID=XXXXXXXXXX")
StartRecord = "FALSE"
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("Buy.asp?Amt=123000.00")
End Sub
</script>
Create a trans & resource folder on your site in same folder where you have aspx files lies
Caution:
Make sure that you do not play with resource.cgn, out of curiosity if you open this file it become useless.
When you are redirecting from your aspx page you can use query string as follows
Trans/Buy.asp?Amt=100&OrdNo=666&Email=sangram2681@gmail.com&phone=986786687&
Area=address&Pincode=Mumbai 400074
The gateway let us to pass 5 custom field with udf1, udf2, udf3, udf4 & udf5.I am here using ufd1 for order-no,udf2 for emailed,udf3 for contact number,udf4 for address and udf5 for city & pin separated by space. The url passed from aspx page to buy.asp is parsed to get values for order,address,phone number,emailid and get assigned to corresponding udf field.
In buy.asp we retrieve data from merchant.config file and using asp file file handling read file line by line ,split each line on “=” sign the second part in array in required value while 1st part is key to it.
Now try your luck!
No comments:
Post a Comment