Interesting Hack for PesaPal?

3 Nov

I recently had to integrate PesaPal in a very interesting way, needing me to think out of the box – as usual. To all those who know PesaPal  – integration wise, you are familiar with the way we simply iframe in the $iframe_src we come up with via the standard integration methods. What you may not know is that should you already be in an iframe when before calling in the PesaPal iframe – so that you have the pesapal iframe within another iframe – you break PesaPal functionality.

The functionality affected here is the callback URL. Since in this situation, the PesaPal iframe is already within an iframe, the callback URL which I have come to believe is designed to jump out of one iframe will not work seeing as you will be two iframes in. And by will not work, I mean that you will simply not be redirected to your callback URL.  You will however, get the ‘You are being redirected’ message, with a link to the URL you are supposed to be redirected to. I suppose a user can click that link and get redirected to your callback URL in a new tab or window (depending on your browser) but in my case, my client was not too happy with the message “You are being redirected…” and the actual redirection was actually not happening.

In a bid to follow my clients orders to “fix it!” here is what I came up with.

After getting your relevant $iframe_src, and noting the fact that I was already working in an iframe, instead of calling in another iframe, I simply got the contents of the generated $iframe_src and echoed it.

$iframe_src = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", 
                                                    $iframelink, $params);
$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);
echo $res;

Surprisingly, it worked! I should though, explain the second to last line where I am performing a string replace. This is because the PesaPal form action is a relative URL which will be prefixed with the URL of the iframe you called in. In this case, the URL of the iframe where I am echoing the $res is not so I required the form’s action to be more specific. (I wonder how much more I can do by modifying the html and Javascript code I pull in from PesaPal…maybe a more mobile friendly version of the form…the possibilities are endless….)

I know this hack can be achieved with cURL and / or DOMDocument so do feel free to add those in the comments. The more hacks, the merrier!

In case you are wondering why I had an iframe inside an iframe in the first place…well such is what happens when you need to pull in resources from all over the place to make sites work like they should. And in this case, what I was building was a special PowerPage for The Great Run (

After completing this PowerPage, watch this space for special event PowerPages with online ticket purchasing included via simple, hassle and code free PesaPal (or Ticketsasa) integration.

Should you have any queries, shout them out in the comments!

4 Responses to “Interesting Hack for PesaPal?”

  1. John Kariuki June 30, 2014 at 1:31 PM #

    Hey i was looking for tutorials on how to integrate pesapal to a site from scratch but I have not had any luck so far. Would you please direct me to any helpful materials?
    I am good in all web development languages, specifically php anf, jquery and HTML5/CSS3.
    I have been to the site but I don’t think they explain well

    • Allan Jagwe September 5, 2014 at 5:55 AM #

      Hi John – first of all – sorry for the really late reply to this. Secondly – the site I think explains their plugins as well as is expected and also has sample code for some platforms and any developer worth their salt should be able to make use of their simple examples and modify them to the application required. That said – I do not mind helping you with integration of PesaPal but I would need some information on what parts of the tutorial you do not understand.

  2. Jackson October 19, 2014 at 8:19 PM #

    i have successfully integrated pesapal in my system but am having a problem saving the same data into my database.

    • Allan Jagwe October 22, 2014 at 4:38 PM #

      Hi Jackson – it would be nice to know more about your integration so that I / we may know where to help you from…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: