How did I connect the portal services with FastSpring e-commerce platform

It took me a while to decide that FastSpring was the best e-commerce platform to manage the subscriptions to my online code-generation services .

There is a full range of options, including the DIY option, e.g. opening your own merchant account or using the PayPal API to program your own payment processing interface. The DIY option allows you to pay lower rates for each processed transaction but I wanted to focus on my added-value, the code-generation services, and not waste my time implementing complex payment processing logic myself. Therefore, FastSpring seemed from the beginning a much better option: easy user interface; multiple currencies, products and prices supported; takes care of VAT calculations; multiple payment methods (credit card, paypal,…) and so forth.

The only thing that worried me was how to configure FastSpring so that:

  1. I could inform FastSpring about the internal user id at the beginning of the transaction
  2. FastSpring would return that same id after the transaction was successfully completed (so that I could update my database to activate the user account for that service)

It turns out that this is also very easy to setup. You can pass a custom referrer via the URL that links to your product page in FastSpring to override the automatically detected referring URL (HTTP_REFERER). In my case the user id is mapped to this referrer parameter. If you are using Drupal to manage the users, you just need to use this PHP code snippet


   // we have to access the content of the global-scope variable $user
   global $user;
   //Checking that the user can subscribe to the service
   //(e.g. the user has to be a registered user ...)
      // ...
   // Then forwarding the user to the FastSpring page, sending the
   // user id as parameter
   header('Location:   

http://sites.fastspring.com/modelinglanguages/product/UMLtoDB?

                                      referrer='.$user->uid);

(if you are interested in learning how to block access to certain pages to non-registered users in Drupal check this older post )

Next, we just need to define a HTTP notification rule in FastSpring, indicating the portal page that will receive a HTTP (POST) call after a transaction has been completed. As part of the call, we can indicate the order parameters we can receive as part of the call, and of course, one of the parameters can be the referrer parameter set by ourselves at the beginning. Then, activating the service is just a matter of retrieving the value of this parameter and updating the database, using a simple PHP code snippet like this one (assuming that the user is a new user of the service:


  if($_POST)
  {
    db_query('UPDATE X SET LEVEL="Professional", endDate=
        DATE_ADD(NOW(),INTERVAL 1 MONTH)  WHERE
        USER=%s',$_POST['OrderReferrer']);
  }

One thing that FastSpring is not yet offering is the option of setting recurrent payments (e.g. an automatic renewal of a monthly subscription). However, this was not a problem in my case since I explicitly ruled out this option. I want the users to decide when to use service and not to worry about remembering canceling the service on time for those periods in which they don’t need it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress