views:

385

answers:

2

Hello, I will be transmitting purchase info (like CC) to a bank gateway and retrieve the result by using Django thus via Python.

What would be the efficient and secure way of doing this?

I have read a documentation of this gateway for php, they seem to use this method:

$xml= Some xml holding data of a purchase.
$curl = `/usr/bin/curl -s -d 'DATA=$xml' "https://url of the virtual bank POS"`;
$data=explode("\n",$curl); //return value is also an xml, seems like they are splitting by each `\n`

and using the $data, they process if the payment is accepted, rejected etc..

I want to achieve this under python language, for this I have done some searching and seems like there is a python curl application named pycurl yet I have no experience using curl and do not know if this is library is suitable for this task. Please keep in mind that as this transfer requires security, I will be using SSL.

Any suggestion will be appreciated.

+2  A: 

Citing pycurl.sourceforge.net:

To sum up, PycURL is very fast (esp. for multiple concurrent operations) and very feature complete, but has a somewhat complex interface. If you need something simpler or prefer a pure Python module you might want to check out urllib2 and urlgrabber. There is also a good comparison of the various libraries.

Both curl and urllib2 can work with https so it's up to you.

Krab
+3  A: 

Use of standard library urllib2 module should be enough:

import urllib
import urllib2

request_data = urlllib.urlencode({"DATA": xml})
response = urlilib2.urlopen("https://url of the virtual bank POS", request_data)

response_data = response.read()
data = response_data.split('\n')

I assume that xml variable holds data to be sent.

Łukasz
Thanks alot lukasz! I am curious if any extra parameter / method to benefit/force HTTPS connection ?
Hellnar
Python's stdlib handles https connections very well if you have socket.ssl installed (not the case for some distributions of python). Besides that only other issue is checking certificate validity, if you need that then httplib.HTTPSConnection will help.
Łukasz