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:

pap4.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3" type="plugin"  group="user">
  <name>plg_user_pap4</name>
  <author>Martin Pullmann</author>
  <creationDate>January 2013</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>3.0.0</version>
  <description>PLG_USER_PAP4_XML_DESCRIPTION</description>
  <files>
    <filename plugin="pap4">pap4.php</filename>
    <filename plugin="pap4">PapApi.class.php</filename>
    <filename>index.html</filename>
  </files>
  <languages>
		<language tag="en-GB">en-GB.plg_user_pap4.ini</language>
		<language tag="en-GB">en-GB.plg_user_pap4.sys.ini</language>
	</languages>
  <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="PLG_USER_PAP4_FIELD_PAP_URL" description="PLG_USER_PAP4_FIELD_PAP_URL_DESC"/>
        <field name="pap4_username" type="text" size="30" default="merchant@example.com" 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"/>
      </fieldset>
    </fields>
  </config>
</extension>

This file contains a plugin definition.

 

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

<?php
/**
 * @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);
		//$this->loadLanguage();
	}

	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'];
      
      require_once("PapApi.class.php");
      $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 {
          $clickTracker->track();
          $clickTracker->saveCookies();

          $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);
        $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());
      }
    }

    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

×