class representing session (logged user). You must log in using this object before making any other requests.

Methods:

constructor Pap_Api_Session($url) – creates session object. You have to specify full valid URL to the /scripts/server.php file of your installation.

For example: http://www.yoursite.com/affiliate/scripts/server.php

login($username, $password, $roleType, $languageCode) – authorizes the user and creates session object. The username and password must be your merchant or affilaite login information.

By default the user is considered to be a merchant. If you want to log in as an affiliate, you have to specify the third parameter $roleType = self::AFFILIATE.

$languageCode parameter is optional. If you do not specify any value for this parameter, default language will be used. Language can be secified by its code e.g. en-US, de-DE, sk, cz, ...

If login was successful, it returns true, otherwise false. If you use incompatible API version, login throws Gpf_Api_IncompatibleVersionException (see bellow for more details).

setDebug(true/false) sets debugging. If you set it to true, it will output every request and response in JSON format.

getMessage() - returns error message in case of error

Logging in as merchant:

$session = new Pap_Api_Session("http://demo.postaffiliatepro.com/scripts/server.php");
if(!$session->login("merchant@example.com", "demo")) {
  die("Cannot login. Message: ".$session->getMessage());
}

Logging in as affiliate

$session = new Pap_Api_Session("http://demo.postaffiliatepro.com/scripts/server.php");
if(!$session->login("affiliate@example.com", "demo", Pap_Api_Session::AFFILIATE)) {
  die("Cannot login. Message: ".$session->getMessage());
}

Of course, as an affiliate you don't have access to the functionality of merchant, for example to the list of all affiliates.

If you want to redirect user (merchant/affiliate) to his panel after Pap_Api_Session is created you can do it using following code:

// redirecting to merchant panel (requires merchant session)
header('Location: '.$session->getUrlWithSessionInfo('http://demo.postaffiliatepro.com/merchants/index.php'));

// redirecting to affiliate panel (requires affiliate session)
header('Location: '.$session->getUrlWithSessionInfo('http://demo.postaffiliatepro.com/affiliates/panel.php'));

getAppVersion
Get version of installed application by calling of method getAppVersion. Returns string (version number) or false in case of error was generated.
Example: Print version of Post Affiliate Pro installation.
<?php
include_once('PapApi.class.php');
$session = new Pap_Api_Session('http://www.example.com/affiliate/scripts/server.php');
if ($papversion = $session->getAppVersion()) {
    echo 'Post Affiliate Pro version: ' . $papversion;
} else {
    echo 'Failed to load version with error: ' . $session->getMessage();
}
?>
 
Gpf_Api_IncompatibleVersionException
$session->login(...) throws Gpf_Api_IncompatibleVersionException exception in case when your PapApi.class.php file is not compatible with PostAffiliatePro you are connecting to. Example of handling this exception:
$session = new Pap_Api_Session('http://demo.postaffiliatepro.com/scripts/server.php');
try {
    if (!$session->login('merchant@example.com', 'demo')) {
        die("Unable to login: ".$session->getMessage());
    }
    echo "logged";
} catch (Gpf_Api_IncompatibleVersionException $e) {
    echo "Download new API file here: ".$e->getApiDownloadLink();
}
Method getApiDownloadLink() in Gpf_Api_IncompatibleVersionException returns full url o the PapApi.class.php file of the installation you are connecting to so you can download it and update your PapApi.class.php file.