Tuesday, August 05, 2008

A Smarter E-junkie Thank You Page

I'm a big fan of the E-junkie e-commerce selling solution. They make it drop dead easy to start selling stuff on your website, and have nice support for the creation of dynamic codes. That is, you can sell an access code that is generated by your site, yet sold via E-junkie.

One feature E-junkie offers is the ability to host your own Thank You page. This way, folks start on your site, buy something over at E-junkie, and end up at your own site. You can put whatever you want on this page. This is mostly good news, except, if you host your own Thank You page, you can't get a hold of various facts about the transaction - like how much the order was. This means that you can't print a clever message if the user spent over a certain amount (of course, there are other reasons you'd want to know this besides clever messages).

For one of my client's sites, I needed to get the total price on this page, but it wasn't at all obvious how to do it. That is, until I read through this forum thread. Here's what I ended up with as a solution:

  • Log into E-junkie, click on Account Preferences
  • Enter your thank you page url (www.somesite.com/thanks.php)
  • Fill in something like the following for the Common Thank You Page HTML:
    @@total:[%total%]@@
    
  • In your thank you page (thanks.php above) grab the GET parameter named txn_id
  • Using CURL, make a behind the scenes request over to E-junkie:
    $url = "https://www.e-junkie.com/ecom/rp.php?noredirect=true&txn_id=$txn_id";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # Needed to talk SSL w/ E-junkie
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $ej_html = curl_exec($ch);
    
  • Now, parse out the value of total using a regexp like:
    $total = preg_replace('/^.*@@total: *([^@]+)@@.*$/ms', '$1', $ej_html);
    
  • And there you go, you have $total as a variable you can include on your Thank You Page

Now, if E-junkie would just put together some sort of API so I could remotely manage my items, I'd be totally happy. Though, I have to say, if you have just a handful of items to sell, they really are hard to beat.

1 comment:

  1. Hello Ben,

    This looks really good and promising.

    I am currently looking into ejunkie. The mayor drawback I have encountered is the text used in the download link on the thankyou page that gets inserted on my site using the iframe.

    I have a Spanish site and don't want to show my clients an English download link saying "Click here to download".

    Do you think using CURL I should be able to change that links' text?

    Greetings.

    ReplyDelete