473,769 Members | 3,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add PayFlow Pro wrapper to standard library?

I just wrote a very simple wrapper for the PayFlow Pro SDK (see below).

A friend of mine did this before, but I didn't have access to his
source, so I took it as a learning opportunity for me to write a C
wrapper. I did a little searching to see whether anyone had done
anything like this for Python. I didn't find anything.

I did find that PHP comes with an extension for PayFlow Pro that you can
compile into the language:

http://www.phpbuilder.com/manual/ref.pfpro.php

This inspired me to imagine something similar being added to Python's
standard library. The basic idea: This would mean someone like me
wouldn't have to reinvent the wheel over and over. Do other folks use
Python for payment processing? Do they use something other than
Verisign? Verisign--with all its warts--is particularly nice because it
supports recurring billing, which means I don't have to store the credit
card number, I just setup a recurring billing profile and they do the
recurring billing. You can't beat that.

I'd be willing to do most of the work, but I'm probably going to need
help.

What I imagine is there would be a pure Python module that provides a
high level interface to process transactions like this:

import pfpro
result = pfpro.process(d etails)

This will then use a C wrapper to call the PayFlow Pro dynamic library.

The Python wrapper would also support using the context functions:

import pfpro
context = pfpro.context(d etails)
for tx in transactions:
tx.result = context.process (tx.details)

# context's __del__ could handle destroying itself, etc.

What's the next step? I don't know since I've never been involved in
adding anything to the standard library.

Further, I can imagine Zope/CMF/Plone wrappers on top of this too.

Thanks,

// m

p.s. Here's the code; consider it 0.0.0.1. ;-)

# setup.py

"""
Before you run this, you need to:

1. Copy the dynamic library from the PayFlow Pro SDK for your
platform to /usr/local/lib.

2. Copy the pfpro.h from the PayFlow Pro SDK for your platform
to /usr/local/include.

TODO:

- For Windows, there's a COM server--use that or use the dynamic
library?

- Add a pure Python module "on top" of the C wrapper.
"""

from distutils.core import setup, Extension

pfpro = Extension('pfpr o',
sources = ['pfpromodule.c'],
libraries = ['pfpro'],
runtime_library _dirs = ['/usr/local/lib'],
include_dirs = ['/usr/local/include'])

setup (name = 'pfpro',
version = '1.0',
description = 'PayFlowPro',
ext_modules = [pfpro])

# pfpromodule.c

#include <Python.h>
#include <string.h>
#include "pfpro.h"

/* This is very, very raw. */

static PyObject *ErrorObject;

static PyObject *
pfpro_process(P yObject *self, PyObject *args)
{
int ok;
char *server;
int port;
int timeout;
char *proxyAddress = NULL;
int proxyPort = 0;
char *proxyLogon = NULL;
char *proxyPassword = NULL;
int context;
char *request;
int requestLength;
char *response;
PyObject *returnValue;

ok = PyArg_ParseTupl e(args, "siis", &server, &port, &timeout,
&request);

if (pfproInit()) {
// "raise"
return Py_BuildValue(" i", 1);
}

if (pfproCreateCon text(&context, server, port, timeout, proxyAddress,
proxyPort, proxyLogon, proxyPassword)) {
// "raise"
return Py_BuildValue(" i", 2);
}

requestLength = strlen(request) ;
pfproSubmitTran saction(context , request, requestLength, &response);
returnValue = Py_BuildValue(" s", response);
pfproCompleteTr ansaction(respo nse);
pfproDestroyCon text(context);
pfproCleanup();

return returnValue;
}

static PyMethodDef pfpro_methods[] = {
{"process", pfpro_process, METH_VARARGS,
"Process a PayFlowPro transaction and return the result."},
{NULL, NULL, 0, NULL} /* Sentinel */
};

static char pfpro_module_do cumentation[] =
"pfpro - Python wrapper for the PayFlowPro library."
;

void
initpfpro()
{
PyObject *m, *d;

/* Create the module and add the functions */
m = Py_InitModule4( "pfpro",
pfpro_methods,
pfpro_module_do cumentation,
(PyObject*)NULL ,
PYTHON_API_VERS ION);

/* Add some symbolic constants to the module */
d = PyModule_GetDic t(m);
ErrorObject = PyString_FromSt ring("pfpro.err or");
PyDict_SetItemS tring(d, "error", ErrorObject);

/* XXXX Add constants here */

/* Check for errors */
if (PyErr_Occurred ())
Py_FatalError(" can't initialize module pfpro");
}

# test.py
#!/usr/bin/env python

import pfpro

username = # your username
password = # your password
cardExpiration = '1209'
cardNumber = '51051051051051 00'
amount = '1.00'

values = {'VENDOR': username,
'TRXTYPE': 'S',
'ExpDate': cardExpiration,
'PWD': password,
'USER': username,
'ACCT': cardNumber,
'TENDER': 'C',
'PARTNER': 'verisign',
'AMT': amount}

server = 'test-payflow.verisig n.com'
port = 443
timeout = 10

request = '&'.join(['%s=%s' % (k, v) for k, v in values.iteritem s()])
response = pfpro.process(s erver, port, timeout, request)
print response

Jul 18 '05 #1
1 2288
Mark McEahern <ma**@mceahern. com> wrote in
news:ma******** *************** *************** *@python.org:
What I imagine is there would be a pure Python module that provides a
high level interface to process transactions like this:

import pfpro
result = pfpro.process(d etails)

This will then use a C wrapper to call the PayFlow Pro dynamic library.

The Python wrapper would also support using the context functions:

import pfpro
context = pfpro.context(d etails)
for tx in transactions:
tx.result = context.process (tx.details)

# context's __del__ could handle destroying itself, etc.

What's the next step? I don't know since I've never been involved in
adding anything to the standard library.


First off, forget about adding it to the standard library until a long way
down the line, if at all. This sounds like a useful but specialised module,
so it doesn't need to be shipped as standard.

Next, I suggest you have a look at Greg Ewing's Pyrex, which is a language
specifically for writing Python Extension modules. This should make your
life much easier than handling the C api directly. (There are plenty of
other options, but I prefer Pyrex).

Pyrex should make it easy for you to define an appropriate context type
directly in your extension module. This is probably a better solution than
trying to put a Python wrapper around a set of procedures as it means you
can control access to the C functions much more tightly.
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2535
by: John Siefer | last post by:
-- I have a problem that I am hoping someone can help me with. I am trying to design a custom shopping cart for a friend. He wants it designed a specific way so an integrated cart won't work for his purposes. No problem there. We have a VeriSign/PayFlow Pro account with an SSL cert, however the hosting company which we are using did not compile PHP with the --with-pfpro extension and claim that they can not recompile as it is a shared...
0
1657
by: JStrummer | last post by:
Does anyone know if oscommerce has a module to support Verisign's Payflow Pro? I downloaded the one listed as "pro" here http://www.oscommerce.com/community/contributions,167/category,1/search,verisign], and the documentation talks only about Payflow Link. Has anyone used this module? Does it work with Payflow Pro as well? If anyone knows for sure that oscommerce doesnt' work with Payflow Pro, could you point me to other free...
7
5911
by: Brian | last post by:
Anyone worked with Verisign's Payflow Pro object in ASP? We've had it up and running for weeks without a problem and recently we've started to get some undesirable behavior: at the point where the component sends the transaction data, about 1 in 4 times it will go through, but otherwise it will sit and spin until the script or the browser session times out. may or may not be related to a server maintenance change. I'm not a server...
3
10245
by: Ian | last post by:
Has anyone had any experience in writing wrappers for older C libraries? What I'm looking at doing is creating a wrapper C++ object as a front end to an older C library, also the library is not thread-safe, which I have to somehow make safe for multi-threading (CRITICAL_SECTIONS maybe) for integration into a server. Thanks, Ian
5
1932
by: Fred Paris | last post by:
Hi I'm writing a class to act as a wrapper around a C library. This C library exposes functions like: SetSomeInfo( char *pTheInfo ); In my wrapper class, the info in question is in a STL string.
4
1934
by: Stephen | last post by:
Hi I am currently developing a web application that has a third party component on it. The third party component is a graph component from Xceed that uses a number of dlls. The problems occur when we attempt to deploy the application and the third party component causes a security exception. Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required...
29
2219
by: mastermagrath | last post by:
Hi, Sorry for the possibly silly question. Am i right in saying that the C library i use on a windows machine really utilises the windows API for all its operations e.g. opening files, printing to the console etc.etc. Thanks in advance
16
3449
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
0
1135
by: Dave | last post by:
Hello, I'm trying to get payflow working with php5 as a loadable extension. My configure line has: '--with-pfpro=shared,/usr/local' and php5 installed fine via FreeBSD ports. I then installed Payflow pro also via FreeBSd ports. I'm getting an error with payflow_init which tells me payflow and php are not talking. Some urgency! Thanks.
0
10205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.