cfPayflowPro Alpha Release
I am happy to announce that I have finally got this code up to par for an alpha release. As the name implies this project is a wrapper for the Paypal Payflow Pro payment gateway. This article will help explain more about the payment gateway, the project itself and why I felt it was needed.
What is Payflow Pro?
If you have been developing for a few years then you may remember that the Payflow Pro gateway was once owned by Verisign. This is the same gateway but in my opinion the product and support has improved in the hands of PayPal. Payflow Pro, a market-leading payment gateway, connects your online store to your existing Internet merchant account. It enables your business to:
- Accept credit cards, debit cards, more. Plus accept PayPal too (U.S.only).
- Optimize the customer experience by letting shoppers complete the checkout process without leaving your website.
- Stay secure with access to one of the most powerful risk-management systems.
- Integrate easily. Payflow Pro is pre-integrated into many shopping carts.
1. Customers make purchases through your website, using your storefront.
2. Your storefront application passes the transaction data to the Payflow Pro gateway client.
3. The client sends the data to PayPal, and the Payflow processing cycle begins. We securely route your customer's information through the network of processors and financial institutions.
4. Your customer's bank authorizes or declines the transaction and notifies PayPal.
5. Upon approval, PayPal sends you a confirmation. The entire approval process usually takes less than three seconds.
6. You decide whether or not to settle the transaction. When you settle the transaction, your bank credits your merchant account.
Payflow Pro Online Payment Gateway
https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside
The Problem
Now that we know a little bit more about the PayflowPro gateway I would like to explain why this project is needed. I have been using the Payflow (Verisign & Paypal) gateway for a couple of years now in my ColdFusion development and it has never been easy. In the past you had to install a CFX tag. Not sure what a cfx tag is?
* ColdFusion Extension (CFX) tags are custom tags that you write in Java or C++. Generally, you create a CFX tag to do something that is not possible in CFML. CFX tags also let you use existing Java or C++ code in your ColdFusion application.
While CFX tags offered a great extension to the ColdFusion language they had to be installed on the server. This made it very hard for those of us in a shared hosting environment. Ok so now we know a little bit about about the problem lets look at the solution
The Solution
The solution was the product of another great open source project. Mark Mandel created JavaLoader and it is really the backbone of this project. The main purpose of this project is that it allows you to load external Java libraries at runtime. With that ability this project was born. cfPayflowPro will load the external Java libraries for the Payflow Pro gateway and allow you to use these libraries in ColdFusion. This project solves 2 big problems. It allows you to integrate PayflowPro without any hard installations and it in turns ads support for ColdFusion 8. I was reading on a forum post that people were having a hard time getting it to work on Scorpio.
The first thing we need to do is load JavaLoader into the server scope. Mark Mandel wrote an interesting article on why you should do this. The path you are setting is the absolute path the payflowpro jar file.
<cfset this.applicationName = "cfPayflowPro">
<cffunction name="onRequest">
<cfargument name="targetTemplate" type="String" required="true" />
<cfif not isDefined("server.init") OR structKeyExists(url,"reinit")>
<!--- JavaLoader handles creation of Java objects from external Java libraries. --->
<cfset loadPaths = arrayNew(1)>
<cfset loadPaths[1] = "C:\ColdFusion8\wwwroot\paypal\lib\Verisign.jar">
<!--- create the loader --->
<cfset loader = createObject("component","com.compoundtheory.javaLoader.javaloader").init(loadPaths)>
<!--- create the class instance --->
<cfset server.pfpro = loader.create("com.Verisign.payment.PFProAPI")>
<cfhtmlhead text="<script language='javascript'>alert('Server.pfpro Initialized')</script>">
<cfset server.init = true>
</cfif>
<cfinclude template="#arguments.targetTemplate#">
</cffunction>
</cfcomponent>
In the index file I set a structure of all the parameters that I need to pass. After I have created my structure I instantiate my PayflowPro component. Next we need to set our certificate path, create our context and set our param list and pass in our structure. Finally we submit our transaction which will return the response from payflow and destroy our context.
<cfset pp = structNew()>
<cfset pp.user = "username">
<cfset pp.vendor = "">
<cfset pp.partner = "paypal">
<cfset pp.pwd = "password">
<cfset pp.trxtype = "S">
<cfset pp.tender = "C">
<cfset pp.acct = "4111111111111111">
<cfset pp.expdate = "06/05">
<cfset pp.accttype = "Visa">
<cfset pp.amt = ".01">
<cfset pp.currency = "USD">
<cfset pp.cvv2 = "111">
<cfset pp.street = "555 Main Streets">
<cfset pp.city = "Cleveland">
<cfset pp.state = "OHIO">
<cfset pp.country = "US">
<cfset pp.zip = "44113">
<cfset pp.firstname = "Dan">
<cfset pp.lastname = "Vega">
<cfset pp.clientip = CGI.REMOTE_ADDR>
<cfset pp.comment1 = "comm1,java test">
<cfset pp.comment2 = "comm2,java test">
<cfset pp.custref = "">
<cfset pp.invnum = "123456">
<!--- pass a reference to our payflow component --->
<cfset payflowpro = createObject("component","com.paypal.PayflowPro").init(server.pfpro)>
<!--- set the certificate path --->
<cfset payflowpro.setCertPath("C:\ColdFusion8\wwwroot\paypal\certs")>
<!--- setup the context --->
<cfset payflowpro.createContext("test-payflow.verisign.com",443,30)>
<!--- pass the transaction parameters --->
<cfset payflowpro.setParamList(pp)>
<!--- submit the transaction, the response from the gateway is a delimited string --->
<cfset response = payflowpro.submitTransaction()>
<!--- destroy the context --->
<cfset payflowpro.destroyContext()>
<!--- parse the response --->
<cfset rh = createObject("component","com.paypal.ResponseHandler").init(response)>
<cfset answer = rh.responseToStruct()>
<cfdump var="#response#">
<cfdump var="#answer#">
After we have got the response back from PayflowPro we instantiate our ResponseHandler component that has one method at the time. This method will take our response string and parse it into a structure.
<cfset rh = createObject("component","com.paypal.ResponseHandler").init(response)>
<cfset answer = rh.responseToStruct()>
<cfdump var="#response#">
<cfdump var="#answer#">
Feedback
I would love to hear what others think of the project and any comments / suggestions / complains are welcome. I have had a couple of alpha testers but a big thanks to Dave Cordes as he provided some great feedback to get me to the alpha release. You can download the project by visiting the project at riaforge.
Links
http://cfpayflowpro.riaforge.org/
http://www.danvega.org/blog/page.cfm/projects/
