Integration with Joomla 2.5.X

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


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


<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin"  group="user">
  <name>User - Post Affiliat Pro signup synchro</name>
  <author>Martin Pullmann with Brendon Hatcher</author>
  <creationDate>June 2012</creationDate>
  <copyright>(C) 2012 Quality Unit</copyright>
  <license> GNU/GPL</license>
  <description>The plugin creates an affiilate account for new users registered in your Joomla. Make sure the API file is the same as the one in your Post Affiliate Pro installation.</description>
    <filename plugin="pap4">pap4.php</filename>
    <filename plugin="pap4">PapApi.class.php</filename>
    <fields name="params">
      <fieldset name="basic">
        <field name="pap4_url" type="text" size="100" default="" label="PAP4 URL" description="Full URL to your PAP4 installation /scripts/server.php. For example:"/>
        <field name="pap4_username" type="text" size="30" default="" label="PAP4 merchant username" description="Your PAP4 merchant username"/>
        <field name="pap4_password" type="text" size="30" default="demo" label="PAP4 merchant password" description="Your PAP4 merchant password"/>

This file contains a plugin definition.


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 onUserAfterSave($user, $isnew, $succes, $msg) {
    global $mainframe;

    // convert the user parameters to a format for the external application
    $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'];

    if ($isnew) {

      // load plugin params info
      $plugin =& JPluginHelper::getPlugin('user', 'pap4');
      $pluginParams = new JParameter( $plugin->params );

      $pap4Url = $pluginParams->get('pap4_url', 1);
      $pap4Username = $pluginParams->get('pap4_username', 1);
      $pap4Pwd = $pluginParams->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 - 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); }
        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());

This is a simple plugin, it can be improved in many ways.


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