cfPayflowPro Alpha Release

Word Count: 1261

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.

So now you know what it is and I bet your asking well how does it work? Glad you asked

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 Code
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.
<cfcomponent displayname="Application Component" output="false">

   <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.
<!--- PayFlow Pro Paramaters --->
   <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.
<!--- parse the response --->
   <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/


Comments

#1 Posted By: Dan Wilson Posted On: 6/21/07 11:57 AM
Nice work Dan, I am going to give this a shot.
#2 Posted By: Dan Posted On: 6/21/07 12:02 PM |
Author Comment
Thanks Dan! I look forward to you comments.
#3 Posted By: Sana Posted On: 6/22/07 12:03 PM
Its great work, I did similar stuff a year back and posted teh solution on adobe-forum. I love your JavaLoader stuff rather having specific installation process.

thanks
#4 Posted By: Dan Posted On: 6/22/07 12:09 PM |
Author Comment
Sana,
Did you create a wrapper for the original PayPal stuff? If so I think I was using it for awhile :) Just to be clear, I did not create JavaLoader. That project was created by Mark Mandel (www.compoundtheory.com) and it was the reason this project came together. Thanks for your comments, please let me know how everything works out for you.
#5 Posted By: Travis Posted On: 10/17/07 7:07 PM
I am getting an error Could not find the ColdFusion Component or Interface com.paypal.PayflowPro. i am able to get the server.pfpro to initialize any ideas?
#6 Posted By: Duncan Loxton Posted On: 10/17/07 8:14 PM
Dan, I am having the same issue as Travis, I have checked and double checked the readme etc but cant yet lay my finger on why this path isn't included. I am guessing that the Verisign.jar has this in it, as there are no more jar files being loaded. Any help would be greatly appreciated.
#7 Posted By: Travis Posted On: 10/17/07 8:19 PM
What payflowpro.cfc are you useing and where are you getting it? I assume that is the call that is causing the problem
#8 Posted By: Duncan Loxton Posted On: 10/17/07 10:30 PM
@travis I am using the svn zip download from the riaforge page, it was generated yesterday, so its pretty new.
#9 Posted By: Dan Vega Posted On: 10/17/07 11:04 PM |
Author Comment
If you are not finding the component com.paypal.PayflowPro then it is simply a pathing issue. If you have a root directory and then payflowpro inside the root you could either change the path to payflowpro.com.paypal.payflowpro / move the com folder to the root directory / or add it to your custom tag paths. Please let me know if this helps.
#10 Posted By: Duncan Loxton Posted On: 10/17/07 11:43 PM
@Dan - thanks for the info, should the com.paypal.payflowpro be pointing to your cfpayflowpro (from the zip file) directory or to the Verisign.jar? We don't have a payflowpro directory as indicated in your last comment.
#11 Posted By: Duncan Loxton Posted On: 10/18/07 1:54 AM
I worked it out, I downloaded Dave Cordes version http://www.apoktechnology.com/blog/index.cfm/2007/... and notices that a bunch of CFC's are missing from the riaforge SVN download. His zip makes much more sense. And now it works fine as there is a paypal directory there with a PayflowPro.cfc! @Dan - would be great if you could update the SVN so others dont have to go through this issue!


Post Your Comment







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.