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:

pap4.xml

<?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>https://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
  <authorEmail>support@qualityunit.com</authorEmail>
  <authorUrl>www.qualityunit.com</authorUrl>
  <version>1.3</version>
  <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>
  <files>
    <filename plugin="pap4">pap4.php</filename>
    <filename plugin="pap4">PapApi.class.php</filename>
  </files>
  <config>
    <fields name="params">
      <fieldset name="basic">
        <field name="pap4_url" type="text" size="100" default="https://www.yoursite.com/pap_4_dir/scripts/server.php" label="PAP4 URL" description="Full URL to your PAP4 installation /scripts/server.php. For example: https://www.yoursite.com/affiliate/scripts/server.php"/>
        <field name="pap4_username" type="text" size="30" default="merchant@example.com" 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"/>
      </fieldset>
    </fields>
  </config>
</extension>

This file contains a plugin definition.

 

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

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

jimport('joomla.plugin.plugin');

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) {
      jimport('joomla.html.parameter');
      require("PapApi.class.php");

      // 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 {
          $clickTracker->track();
          $clickTracker->saveCookies();

          $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);
        $affiliate->setUsername($args['email']);
        $affiliate->setPassword($args['password']);
        $affiliate->setFirstname($args['fname']);
        $affiliate->setLastname($args['lname']);
        $affiliate->setRefid($args['refid']);
        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

×