ColdFusion Implementation of Virtual Merchant

CF Webtools works on plenty of e-commerce sites. Some generate only a trivial amount of revenue and others generate millions every year. The most common implementations we see and deal with are authorize.net and paypal. Both have very standard APIs and a feature list that is continuously expanding. Recently I was given a project which required implementing Virtual Merchant into Site Director and Farcry. It also required the ability to use multiple merchants through the same implementation in Farcry. Here’s what I did…

Virtual Merchant provides several examples of how to interact with their system, all of which require direct form posts to their server. Here’s an example of a form post that does a post to their server which will provide a detailed breakdown of the transaction and a button to return to the referring page:

<form action="https://www.myvirtualmerchant.com/VirtualMerchant/process.do" method="post">
	<!-- Identifiers -->
	<input type="hidden" name="ssl_merchant_id" value="some_merchant_id">
	<input type="hidden" name="ssl_user_id" value="some_user_id">
	<input type="hidden" name="ssl_pin" value="some_pin">
	<input type="hidden" name="ssl_show_form" value="false">
	<input type="hidden" name="ssl_test_mode" value="true">
	<input type="hidden" name="ssl_transaction_type" value="ccsale">

	<!-- Customer Info -->
	<input type="hidden" name="ssl_first_name" value="first_name">
	<input type="hidden" name="ssl_last_name" value="last_name">
	<input type="hidden" name="ssl_avs_address" value="address1">
	<input type="hidden" name="ssl_address2" value="address2">
	<input type="hidden" name="ssl_city" value="city">
	<input type="hidden" name="ssl_state" value="state">
	<input type="hidden" name="ssl_avs_zip" value="zip">
	<input type="hidden" name="ssl_phone" value="phone">
	<input type="hidden" name="ssl_email" value="email">

	<!-- Transaction Info -->
	<input type="hidden" name="ssl_invoice_number" value="Inv-123-ABC">
	<input type="hidden" name="ssl_amount" value="15.00">
	<input type="hidden" name="ssl_salestax" value="2.50">
	<input type="hidden" name="ssl_card_number" value="4111111111111111">
	<input type="hidden" name="ssl_cvv2cvc2_indicator" value="1">
	<input type="hidden" name="ssl_cvv2cvc2" value="213">
	<input type="hidden" name="ssl_exp_date" value="0109">

	<!-- Receipt/Redirect Info -->
	<input type="hidden" name="ssl_result_format" value="HTML">
	<input type="hidden" name="ssl_error_url" value="https://www.somedomain.com/error.cfm">
	<input type="hidden" name="ssl_receipt_link_method" value="POST">
	<input type="hidden" name="ssl_receipt_link_url" value="https://www.somedomain.com/receipt.cfm">

	<input type="submit" value="Submit Form">
</form>

This works great if you don’t mind re-directing users off to Virtual Merchant’s servers for a bit and either automatically redirecting them back or relying on them to click a link or button to get back. Thanks, but no thanks. I prefer a bit nicer, more sophisticated implementation. So, the solution was the following: wrap these form variables into a cfhttp post Virtual Merchant and carefully breakdown the results that return to display my own receipt.

One change to make is to pass ssl_result_format with the value “ASCII” instead of “HTML”. You will no longer need to pass in ssl_error_url or ssl_receipt_link_url because there will be no redirecting. I also created a nice function that would break down the items returned from the cfhttp call and give you a structure to look at rather than a big mangled string. Here’s how that function works:

<!--- for use in gateway response --->
<cffunction name="convertResponse" returntype="struct" access="private">
	<cfargument name="response" default="" required="true" type="string">
	<cfset var stReturn = StructNew()>
	<cfloop from="1" to="#ListLen(response,Chr(10))#" step="1" index="i">
		<cfset stReturn[trim(ListFirst(ListGetAt(response,i,Chr(10)),'='))] = trim(ListLast(ListGetAt(response,i,Chr(10)),'='))>
	</cfloop>
	<cfreturn stReturn>
</cffunction>

This was my first run-in with Virtual Merchant and I’m pleased to say that the end result is a fully functioning payment gateway. I’ve abstracted the functionality in a CFC which I can now use for Site Director and Farcry and whatever else I might want. If anyone else is running into the need for a ColdFusion implementation of Virtual Merchant, please feel free to contact me directly jake@cfwebtools.com or contact CF Webtools through our website http://www.cfwebtools.com

Leave a Reply