The plugin will handle synchronization of user signup with your Post Affiliate Pro 4 installation.


To develop a new plugin in Joomla we have to create these two main files:


<?xml version="1.0" encoding="utf-8"?>
<extension version="3" type="plugin"  group="user">
  <author>Martin Pullmann</author>
  <creationDate>January 2013</creationDate>
  <copyright>(C) 2012 Quality Unit</copyright>
  <license> GNU/GPL</license>
    <filename plugin="pap4">pap4.php</filename>
    <filename plugin="pap4">PapApi.class.php</filename>
		<language tag="en-GB">en-GB.plg_user_pap4.ini</language>
		<language tag="en-GB">en-GB.plg_user_pap4.sys.ini</language>
    <fields name="params">
      <fieldset name="basic">
        <field name="pap4_url" type="text" size="100" default="" label="PLG_USER_PAP4_FIELD_PAP_URL" description="PLG_USER_PAP4_FIELD_PAP_URL_DESC"/>
        <field name="pap4_username" type="text" size="30" default="" label="PLG_USER_PAP4_FIELD_USERNAME" description="PLG_USER_PAP4_FIELD_USERNAME_DESC"/>
        <field name="pap4_password" type="text" size="30" default="demo" label="PLG_USER_PAP4_FIELD_PASSWORD" description="PLG_USER_PAP4_FIELD_PASSWORD_DESC"/>

This file contains a plugin definition.


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

 * @package     Joomla.Plugin
 * @subpackage  User.profile
 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt

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

class plgUserPap4 extends JPlugin {

	 * Constructor
	 * @access      protected
	 * @param       object  $subject The object to observe
	 * @param       array   $config  An array that holds the plugin configuration
	 * @since       1.5
	public function __construct(& $subject, $config) {
		parent::__construct($subject, $config);

	public function onUserAfterSave($user, $isNew, $result, $error) {
    if (!$isNew) return true;

    $userId	= JArrayHelper::getValue($user, 'id', 0, 'int');

		if ($userId && $result) {
      $args = array();
      $pos = strpos($user['name']," ");
      if ($pos !== false) {
        $args['fname'] = substr($user['name'],0,$pos-1);
        $args['lname'] = substr($user['name'],$pos+1);
      else {
        $args['fname'] = "Joomla";
        $args['lname'] = $user['name'];

      $args['email'] = $user['email'];
      $args['refid'] = $user['username'];
      $args['password'] = $user['password_clear'];
      $pap4Url = $this->params->get('pap4_url', 1);
      $pap4Username = $this->params->get('pap4_username', 1);
      $pap4Pwd = $this->params->get('pap4_password', 1);

      try {
        // login to API
        $session = new Pap_Api_Session($pap4Url);
        if (!$session->login($pap4Username, $pap4Pwd)) {
          die("Please contact affiliate manager. Error message: ".$session->getMessage());

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

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

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

        // create new affiliate
        $affiliate = new Pap_Api_Affiliate($session);
        if ($referralid != '') {
        if(!$affiliate->add()) {
          die("Cannot add record, please contact affiliate manager. Error message: ".$affiliate->getMessage());
        else {
          //echo("Affiliate successfully added");
      catch(Exception $e) {
        die("PAP4 API call error, please contact affiliate manager. Error message: ".$e->getMessage());

    return true;

This is a simple plugin, it can be improved in many ways. Besides these two main files, there are also two language files (en-GB.plg_user_pap4.ini and en-GB.plg_user_pap4.sys.ini) with predefined language constants.


Installing the plugin

You can download these example files. Make sure you overwrite PapApi.class.php file with your API file - you can get it in merchant panel Tools> Integration> API integration


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