473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(details)

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(details)
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('pfpro',
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(PyObject *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_ParseTuple(args, "siis", &server, &port, &timeout,
&request);

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

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

requestLength = strlen(request);
pfproSubmitTransaction(context, request, requestLength, &response);
returnValue = Py_BuildValue("s", response);
pfproCompleteTransaction(response);
pfproDestroyContext(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_documentation[] =
"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_documentation,
(PyObject*)NULL,
PYTHON_API_VERSION);

/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("pfpro.error");
PyDict_SetItemString(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 = '5105105105105100'
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.verisign.com'
port = 443
timeout = 10

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

Jul 18 '05 #1
1 2259
Mark McEahern <ma**@mceahern.com> wrote in
news:ma***************************************@pyt hon.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(details)

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(details)
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
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...
0
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...
7
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...
3
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...
5
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...
4
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...
29
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...
16
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.