I'm having a real nightmare trying to get the PesaPal API to work for me using Ruby...
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.
So the PesaPal developer site is here: http://developer.pesapal.com Their API docs 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 PHP sample correctly.
Here's my attempt at implementing this in Ruby:
require 'oauth'
require 'uri'
key = '<my sandbox key>'
sec = '<my sandbox secret>'
API_DOMAIN = 'https://demo.pesapal.com'
# An XML string of param data to include with our request
RAW_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=\"Bo\" LastName=\"Tester\" Email=\"[email protected]\" xmlns=\"http://www.pesapal.com\" />}
# 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 '&' 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
puts redirect_url = "#{@signed_request.path}&#{@params}"
When I try to visit the URL returned by this code, I get: Problem: signature_invalid | Advice: > |
back from the API.
Can anyone think of what I'm doing wrong here?
Thanks