IP2Currency: ColdFusion Sample Code

The sample code below provide you an example on how to obtain the latest currency exchange rate and the homeland currency by visitor's IP address.


<!--
//////////////////////////////////////////////////////////////////////////////////
//
//  This source code is only licensed to our premium subscribers. It is provided "as is" and without warranties.
//
//  http://www.fraudlabs.com © All Rights Reserved 2012
//
/////////////////////////////////////////////////////////////////////////////////
-->
<html>
<head>
<title>IP2Currency webservice client-Coldfusion</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center"> 

<!--- Variable needed to retreive the user inputted data --->
<cfparam name="visitorip" default="68.142.197.65">
<cfparam name="fromcurrencycode" default="CAN">
<cfparam name="tocurrencycode" default="">
<cfparam name="fromamount" default="">
<cfparam name="license" default="<Enter License Key>">

<!--- Variables needed to display the resultant information 
from the IP2PCurrency web service invocation--->
<cfparam name="Outcome" default="">
		
<!--- The action paramater of the HTML tag FORM is set to 
point to the same page so that the results are displayed
within the same page. Flags are being used to 
display the resquired web service data--->
<form action="" method="post">
<table cellpadding="0" cellspacing="0" border="0">	
<tbody>
	<tr>
		<td width="190" align="left"> 
			Visitor IP
		</td>
		<td>
			<input name="visitorip" size="300" value="<cfoutput>#visitorip#</cfoutput>">
		</td>
	</tr>
	<tr>
		<td width="190" align="left"> 
			From Currency Code
		</td>
		<td>
			<input name="fromcurrencycode" size="300" value="<cfoutput>#fromcurrencycode#</cfoutput>">
		</td>
	</tr>
	<tr>
		<td width="190" align="left"> 
			To Currency Code
		</td>
		<td>
			<input name="tocurrencycode" size="300" value="<cfoutput>#tocurrencycode#</cfoutput>">
		</td>
	</tr>
	<tr>
		<td width="190" align="left"> 
			From Amount
		</td>
		<td>
			<input name="fromamount" size="300" value="<cfoutput>#fromamount#</cfoutput>">
		</td>
	</tr>
	<tr>
		<td width="190" align="left"> 
			License
		</td>
		<td>	
			<input name="license" size="300" value="<cfoutput>#license#</cfoutput>">
		</td>		
	</tr>
	<tr>		
		<td align="center" colspan="2">
		<br>
			<input name="submit" type="submit" value="Submit">
			</form>
		</td>
	</tr>
	</tbody>			
</table>	
<br>
<hr>
<br>

<cfif len(trim(visitorip)) or len(trim(fromcurrencycode)) or len(trim(tocurrencycode)) or len(trim(fromamount))>
	<!--- Setting the data structures to accept the resultant
	data from the web service --->
	<cfset response=StructNew()>
	<cfset outcome="">
	<cfset aErr="">

	<cfscript> 
		stArgs = structNew(); 
		stArgs.VISITORIP = "#trim(visitorip)#"; 
		stArgs.FROMCURRENCYCODE = "#trim(fromcurrencycode)#"; 
		stArgs.TOCURRENCYCODE = "#trim(tocurrencycode)#"; 
		stArgs.FROMAMOUNT = "#trim(fromamount)#"; 
		stArgs.LICENSE = "#trim(license)#"; 

		stArgs2 = structNew(); 
		stArgs2.inputdata = "#stArgs#"; 
</cfscript> 
	
	<cfinvoke 
		 webservice="http://v1.fraudlabs.com/ip2currencywebservice.asmx?wsdl"
		 method="IP2Currency"
		 argumentcollection="#stArgs2#"
		 returnvariable="response">
	</cfinvoke>
	
	
<!--- checking if data exists in the ticker input fields, consequently 
if data is present the web service is invoked--->
<cfset fromcurrencycode = "">
<cfset tocurrencycode = "">
<cfset tocurrencysymbol = "">
<cfset fromamount = "">
<cfset toamount = "">
<cfset conversionrate = "">
<cfset tocountryname = "">
<cfset tocountrycode = "">
<cfset creditsavailable = "">
<cfset message = "">
	
	<cftry>
		<cfset fromcurrencycode = response.FROMCURRENCYCODE>
		<cfset tocurrencycode = response.TOCURRENCYCODE>
		<cfset tocurrencysymbol = response.TOCURRENCYSYMBOL>
		<cfset fromamount = response.FROMAMOUNT>
		<cfset toamount = response.TOAMOUNT>
		<cfset conversionrate = response.CONVERSIONRATE>
		<cfset tocountryname = response.TOCOUNTRYNAME>
		<cfset tocountrycode = response.TOCOUNTRYCODE>
		<cfset creditsavailable = response.CREDITSAVAILABLE>
		<cfset message = response.MESSAGE>
		<cfcatch>
			<cfset aErr = response.Error.Desc>
		</cfcatch>
	</cftry>
		
<cfelse>
	<cfoutput>
	 		<cfset message = "">
	 </cfoutput>
</cfif>

	<!--- outputing the resultant information contained in the previously set
	local variables in an HTML table. Such information is only displayed if flag
	contains data. The flag variable is set when the particular web service
	returns ALL the required data --->
			<cfoutput>
			<div align="center">
			<font face="Arial, Helvetica, sans-serif" size="+2">
			<br>
			<br>
				<table width="46%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
            <td colspan="2" align="center"><strong><font color="##FF0000">Returned Details</font></strong></td>
				  </tr>
          <tr> 
            <td colspan="2" width="75%" align="center"><br></td>
				  </tr>
			<tr>
				<td nowrap align="left">FROMCURRENCYCODE</td>
				<td align="center">#FROMCURRENCYCODE#</td>
			</tr>
			<tr>
				<td nowrap align="left">TOCURRENCYCODE</td>
				<td align="center">#TOCURRENCYCODE#</td>
			</tr>
			<tr>
				<td nowrap align="left">TOCURRENCYSYMBOL</td>
				<td align="center">#TOCURRENCYSYMBOL#</td>
			</tr>
			<tr>
				<td nowrap align="left">FROMAMOUNT</td>
				<td align="center">#FROMAMOUNT#</td>
			</tr>
			<tr>
				<td nowrap align="left">TOAMOUNT</td>
				<td align="center">#TOAMOUNT#</td>
			</tr>
			<tr>
				<td nowrap align="left">CONVERSIONRATE</td>
				<td align="center">#CONVERSIONRATE#</td>
			</tr>
			<tr>
				<td nowrap align="left">TOCOUNTRYNAME</td>
				<td align="center">#TOCOUNTRYNAME#</td>
			</tr>
			<tr>
				<td nowrap align="left">TOCOUNTRYCODE</td>
				<td align="center">#TOCOUNTRYCODE#</td>
			</tr>
			<tr>
				<td nowrap align="left">CREDITSAVAILABLE</td>
				<td align="center">#CREDITSAVAILABLE#</td>
			</tr>
			<tr>
				<td nowrap align="left">MESSAGE</td>
				<td align="center">#MESSAGE#</td>
			</tr>
				  <tr>
						<td colspan="2"><br><hr><br></td>
				  </tr>
				</table>
				</font>
			</div>
			</cfoutput>
	
<font color="#FF0000"><strong><cfoutput>#aErr#</cfoutput></strong></font>
</div>
</body>
</html>

Download the source code
You need a license key for the solution. And, it is free and available at IP2Currency Free License