4

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 Answers 2

10

Use of the standard library urllib2 module should be enough:

import urllib
import urllib2

request_data = urllib.urlencode({"DATA": xml})
response = urllib2.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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks alot lukasz! I am curious if any extra parameter / method to benefit/force HTTPS connection ?
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.
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.