Ruby bindings for Payflow Pro (pfpro4r)
About
pfpro4r is a set of bindings for Verisign's Payflow Pro SDK.
If you're distributing an app in Ruby/Rails and you use Verisign's Payflow Pro, you basically have three options (paraphrased from the RoR Wiki):
- Call the Java/Perl/PHP API from Ruby. (Ewww...)
- Call Verisign’s command line scripts. (DO NOT DO THIS. This is highly vulnerable to shell injection attacks.)
- Code a ruby extension which makes use of the Payflow shared library API and make calls directly from Ruby.
pfpro4r is an implementation of the last option.
Screenshot
static VALUE
pfpro4r_exec (VALUE class,
VALUE rb_host_addr,
VALUE rb_host_port,
VALUE rb_parm_list,
VALUE rb_time_out)
{
char *host_addr;
int host_port;
...
License & Download
pfpro4r is released under the MIT License. It's our way of saying thanks and giving back to the Ruby community.
Please, if you make improvements, send me a patch so it can get incorporated back into pfpro4r.
Open Issues
- pfpro_cleanup is not called automatically, would be nice to call at_exit
How to compile and install
$ tar xzvf ~/pfpro_freebsd.tar.gz
$ ruby extconf.rb
$ make
$ make install
After you've installed, the Ruby API is simple! There is one function, Payflow.exec(), which takes a host_name, port_number, parm_list_string, and time_out.
result_string = Payflow.exec("test-payflow.verisign.com",
443,
parm_list,
30)
FAQ
- Is this supported in any way by Verisign?
No.
- Is this supported in any way by LiveMetric LLC?
No. Your best bet is to post to the rails mailing list and hope that someone else has had a similar problem.
- But I really need support for this. We are a business and it is critical. What are your rates?
Please contact service@livemetric.com for consulting projects.
- When I require pfpro4r, I get the message
pfpro4r.so: Shared object "libpfpro.so" not found, required by "pfpro4r.so" - pfpro4r.so (LoadError)
. What gives?
You need to add the directory containing libpfpro.so to your $LD_LIBRARY_PATH.
- Does it compile on Windows?
Yes, but it is a horrible experience and you are bound to lose some hair. Good luck.
- When I run "ruby extconf.rb" on Windows, I get the message
./win32-libmaker.rb:17:in ``': No such file or directory - link -dump -exports ".\verisign\payflowpro\win32\lib\pfpro.dll" (Errno::ENOENT)
. What gives?
You need to set up your VC compiler environment. See WindowsCompiler for more information.
- When I run "make" on Windows, I get the message
'make' is not recognized as an internal or external command,
operable program or batch file.. What gives?
Use "nmake" instead.
- When I run "nmake" on Windows, I get the message
LINK : fatal error LNK1181: cannot open input file 'msvcrt-ruby18.lib'. What gives?
Edit the Makefile, changing "LIBRUBYARG_SHARED = $(LIBRUBY)" to "LIBRUBYARG_SHARED = /link /LIBPATH:C:\ruby\lib $(LIBRUBY)", replacing c:\ruby\lib with the path of your ruby install. (I'm sure there's a cleaner solution to this, patches welcome!)
More information
- README.EXT from the Ruby source code
- ruby embedded into c++ - lots of good info about the ruby C function calls
- ONLamp.com - Extending Ruby with C