Note that there are some explanatory texts on larger screens.

plurals
  1. POOAuth signature_invalid error using PesaPal API with Ruby
    text
    copied!<p>I'm having a real nightmare trying to get the PesaPal API to work for me using Ruby...</p> <p>I appreciate that it's probably not the most commonly used API but if there's anybody online here who has more experience using OAuth, and/or PHP experience who could offer a fresh pair of eyes I'd appreciate it.</p> <p>So the PesaPal developer site is here: <a href="http://developer.pesapal.com" rel="nofollow">http://developer.pesapal.com</a> Their <a href="http://developer.pesapal.com/how-to-integrate/api-reference" rel="nofollow">API docs</a> don't give away too many clues about how to use OAuth with their site and I don't understand PHP well enough to be sure I've read their <a href="http://developer.pesapal.com/how-to-integrate/php-sample" rel="nofollow">PHP sample</a> correctly.</p> <p>Here's my attempt at implementing this in Ruby:</p> <pre><code>require 'oauth' require 'uri' key = '&lt;my sandbox key&gt;' sec = '&lt;my sandbox secret&gt;' API_DOMAIN = 'https://demo.pesapal.com' # An XML string of param data to include with our request RAW_XML = %{&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;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=\"Bo\" LastName=\"Tester\" Email=\"bodacious@bodacious.com\" xmlns=\"http://www.pesapal.com\" /&gt;} # Escape the XML @post_xml = URI.escape(RAW_XML) # Create a new OAuth Consumer @consumer = OAuth::Consumer.new(key, sec, { site: API_DOMAIN, scheme: :query_string }) # The signed request object @signed_request = @consumer.create_signed_request('get', "#{API_DOMAIN}/API/PostPesapalDirectOrderV4") # Join the pesapal_request_data and oauth_callback with '&amp;' for valid URL params @params = { oauth_callback: URI.escape('http://localhost:3000'), pesapal_request_data: @post_xml, }.map { |k,v| "#{k}=#{v}" }.join('&amp;') # This is the URL we should redirect to puts redirect_url = "#{@signed_request.path}&amp;#{@params}" </code></pre> <p>When I try to visit the URL returned by this code, I get: <code>Problem: signature_invalid | Advice: &gt; |</code> back from the API.</p> <p>Can anyone think of what I'm doing wrong here?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload