Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Last active October 25, 2016 17:49
Show Gist options
  • Select an option

  • Save Bodacious/5621252 to your computer and use it in GitHub Desktop.

Select an option

Save Bodacious/5621252 to your computer and use it in GitHub Desktop.
PesaPal OpenAuth integration (not working yet)
require 'oauth'
require 'uri'
key = # my Consumer Key (sandbox)
sec = # my Consumer Secret (sandbox)
SITE_URL = 'https://demo.pesapal.com'
# An XML string of param data to include with our request
RAW_XML = <<-XML
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<PesapalDirectOrderInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchemainstance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" Amount=\"12.34\" Description=\"Bob Test 1\" Type=\"MERCHANT\" Reference=\"808\" FirstName=\"Bob\" LastName=\"Tester\" Email=\"[email protected]\" xmlns=\"http://www.pesapal.com\" />
XML
# Escape the XML
@post_xml = URI.escape(RAW_XML)
# Create a new OAuth Consumer
@consumer = OAuth::Consumer.new(key, sec, {
site: SITE_URL,
scheme: :query_string
})
# The signed request object
@signed_request = @consumer.create_signed_request('get', "/API/PostPesapalDirectOrderV4")
# Join the pesapal_request_data and oauth_callback with '&' for valid URL params
@params = {
oauth_callback: URI.escape('http://localhost:3000'),
pesapal_request_data: @post_xml,
}.map { |k,v| "#{k}=#{v}" }.join('&')
# This is the URL we should redirect to
redirect_url = "#{SITE_URL}/#{@signed_request.path}&#{@params}"
@itskingori
Copy link

If anyone else finds themselves here ... you could try the pesapal gem (works and has been production ready since 2014). See releases for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment