One of my clients decided to make the switch from Authorize.net to PayPal’s Payflow Pro gateway last week. I knew this would be a headache, but I decided to offer a reasonable time estimate for the task of integrating with the gateway API (knowing I’d likely go over budget).
Everything went smoothly until the very last step of submitting a payment request. So, I’m going to share my experience to save everyone else the trouble. I’ll list out the steps below, but also provide the full code at the end.
- Visit https://developer.paypal.com and create a sandbox application. You’ll need the client id and client secret.
- Get an authorization token. In true OAuth fashion, we exchange the client id and secret for an authorization token. This is actually pretty simple, once you figure out how to make it happen with ColdFusion’s CFHTTP tag.The trick was to actually pass the client id and secret in the username and password arguments of the CFHTTP call.
- Issue a request. In my case, I only needed to make a payment request. The PayPal documentation was a bit tricky, it’s syntax looked like this:Authorization: Bearer <access-token>So naturally, I wrapped the access token in <..> and the calls continued to fail. Once I formatted the Authorization header like this, everything worked:<cfhttpparam type=”header” name=”Authorization” value=”Bearer #accessToken#”>
- Setting up a test. Here’s where days went by with no solution. PayPal support was unfortunately unresponsive. My test looked like this (calling a CFC method I created):
<cfset response = paypal.capture( card_type = "visa", card_number = "4111111111111111", card_exp_month = "12", card_exp_year = "2016", card_firstname = "Bob", card_lastname = "Smith", amount = 5.25, description = "Order 1001")>
Looks okay, right? Using “real-looking” data and the usual test credit card number that we’re all familiar with.
Wrong! PayPal, for some reason, does not support the 4111… credit card #!After a couple days, I found this out on StackOverflow, and changed the test card number to 4556747948786484.
That’s it! I got a valid response from PayPal.
So, with all that trial and error behind me, here’s the full code to the ColdFusion PayPal Payflow Pro REST API CFC that I created.
And, quick code to test against the CFC:
<cfset paypal = createObject("component", "components.PayPalPayFlow").init(
client_id = "your_client_id",
client_secret = "your_client_secret",
sandbox = true)>
<cfset response = paypal.capture(
card_type = "visa",
card_number = "4556747948786484",
card_exp_month = "12",
card_exp_year = "2016",
card_firstname = "Bob",
card_lastname = "Smith",
amount = 5.25,
description = "Order 1001")>
<cfoutput>#response#</cfoutput>