Integration with Joomla 1.5.X and lower

Task - when a user signs up to Joomla, sign them up also to the affiliate system.

For this example, we'll use Joomla 1.5.8, and we'll develop a simple Joomla plugin that will call PAP4 API upon user registration in Joomla.

To develop a new plugin in Joomla we need to create two files:


<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="user" method="upgrade">
  <name>User - PAP4 Register</name>
  <author>Maros Fric</author>
  <creationDate>December 2008</creationDate>
  <copyright>(C) 2008 Maros Fric</copyright>
  <license> GNU/GPL</license>
  <description>Plugin that registers new user also to PAP4 using the API</description>
    <filename plugin="pap4">pap4.php</filename>
    <filename plugin="pap4">PapApi.class.php</filename>

This file contains a definition of the plugin.


The second file pap4.php is the file where the API call happens:

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );


class plgUserPap4 extends JPlugin {

    function plgUserPap4(& $subject, $config) {
        parent::__construct($subject, $config);

    function onAfterStoreUser($user, $isnew, $succes, $msg) {
        global $mainframe;

        if ($isnew) {
            // here we start executing our API code
            try {
                // login to API
                $session = new Pap_Api_Session("");
                if(!$session->login("", "demo")) {
                    // cannot login to API
                    // do something with the error

                //identify the referrer (affiliate)
                $clickTracker = new Pap_Api_ClickTracker($session);
                try {

                    $affiliate = $clickTracker->getAffiliate();
                    $referralid = '';

	            //if cookies were found - so an affiliate was recongized as a referrer
	            if ($affiliate !== null) { 
		           $referralid = @$affiliate->getParam('refid'); //get the referral id of the referring affiliate
                 catch (Exception $e) {
		    //echo("No parent affiliate recognized: ".$e->getMessage());

                // create new affiliate
                $affiliate = new Pap_Api_Affiliate($session);
                if ($referralid != '') $affiliate->setParentUserId($referralid); //setting the parent affiliate

                if(!$affiliate->add()) {
                    // cannot add record
                    // do something with the error
                } else {
                    // affiliate was successfully added
            } catch(Exception $e) {
                // do something with the error

This is a very simple plugin, it can be improved in many ways. For example, it does not notify us about an error when the API call fails. So if you cannot log in to API, or adding user fails, you won't know about it.

To make it work in production, you should implement some email notifications or logging when API call fails or returns an error.


Installing the plugin

You can download the full source of this example.

Unzip files into a directory and then install the plugin using Joomla> Extensions> Install/Uninstall, then activate it in Joomla> Extensions> Plugin manager