开发者

Integrate with RBS WorldPay Hosted Payment Page (XML Redirect) using Python

开发者 https://www.devze.com 2023-01-31 03:20 出处:网络
Does anyone have any example code for integrating with RBS WorldPay开发者_开发百科 using Python?Specifically posting the XML order to WorldPayIt\'s an HTTP POST with Basic Authentication. Basic Authen

Does anyone have any example code for integrating with RBS WorldPay开发者_开发百科 using Python? Specifically posting the XML order to WorldPay


It's an HTTP POST with Basic Authentication. Basic Authentication is described in the official Fetch Internet Resources Using urllib2 HOWTO. So, where XML is the XML you're sending, URL is the URL you're posting to, and MERCHANT_CODE and PASSWORD are self explanatory, the following works:

import urllib2
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, URL, MERCHANT_CODE, PASSWORD)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
request = Request(URL, XML, {'Content-Type': 'text/xml'})
response = opener.open(request, XML)

# do something with the response

response.close()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号