Skip to content

Instantly share code, notes, and snippets.

@okal
Created May 28, 2012 10:30
Show Gist options
  • Select an option

  • Save okal/2818413 to your computer and use it in GitHub Desktop.

Select an option

Save okal/2818413 to your computer and use it in GitHub Desktop.
Pesapal Python Snippet
"""
MIT License
Copyright 2012 Okal Otieno
A (very rough) port of the Pesapal PHP IFrame integration code to Python.
PHP source at https://www.pesapal.com/Content/downloads/pesapal-iframe.php.txt
Uses Leah Culver's python-oauth library for Oauth 1.0 integration. https://github.com/leah/python-oauth
"""
import oauth.oauth as oauth
token = None
params = None
consumer_key = 'lhiP9QWtQQsXWU+G5HdFHEUr41COHMiI' # Pesapal demo consumer key
consumer_secret = '5k6xJ7E0G5JFgUowlc+13SFEfkY=' # Pesapal demo consumer secret
signature_method = oauth.OauthSignatureMethod_HMAC_SHA1()
iframe_link = 'https://www.pesapal.com/api/PostPesapalDirectOrderV4'
post_xml = """
<?xml version="1.0" encoding="utf-8"?>
<PesapalDirectOrderInfo
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Amount="4000.00"
Description="Order payment"
Type="MERCHANT"
Reference="123sdf"
email="okal@justokal.com"
xmlns="http://www.pesapal.com"/>
"""
consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
iframe_src = oauth.OAuthRequest.from_consumer_and_token(
consumer,
http_url=iframe_link,
http_method="GET",
)
iframe_src.set_parameter('oauth_callback', callback_url)
iframe_src.set_parameter('pesapal_request_data', post_xml)
iframe_src.sign_request(signature_method, consumer, token)
print iframe_src.to_url() # Get the iframe url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment