Pap_Api_Affiliate class is a row object which represents one affiliate record. You can use it to retrieve, edit and add affiliates.

Methods:

load() - loads record with given user id or other parameters. You have to set at least one field before calling this method.
Note: If you try to load some affiliate data, you must first setup data to load from, for example username, then call load method and after that all other available informations will be available to you.

save() - save changes in given record (record must be loaded first).

add() - inserts new record

getMessage() - returns error message in case of error

 

assignToPrivateCampaign($campaignID) – assigns the affiliate to private campaign.

sendConfirmationEmail() – sends the affiliate confirmation signup email, use it when new user is registered, or if user object contains user ID "getUserid()/setUserid($value)"

disableSignupBonus() – signup bonus is created by default (depends on settings), but this function will disable it for the new affiliate.

disableReferralCommissions() – referral commission is created by default (depends on settings), but this function will disable it for the new affiliate.

setLanguage('en-US') or setField('lang', 'en-US') – notification signup email will be sent in 'en-US' language instead of default language, this function is for adding affiliate.

 

The following methods get/set the corresponding fields:

 

getUserid(), setUserid($value)

getRefid(), setRefid($value), setRefid($value, $operator) – as $operator parameter you can use Pap_Api_Affiliate::OPERATOR_EQUALS or Pap_Api_Affiliate::OPERATOR_LIKE (by default is used operator like)

getParentUserId(), setParentUserId($value) - creating affiliate would fail if incorrect $value is passed. If you want to ignore incorrect value and not fail the process use also setField('parentUserIdValidate', 'N')

getUsername(), setUsername($value), setUsername($value, $operator) – as $operator parameter you can use Pap_Api_Affiliate::OPERATOR_EQUALS or Pap_Api_Affiliate::OPERATOR_LIKE (by default is used operator like)

setPassword($value) - do NOT use method setPassword as one of the parameters when loading affiliate. Loading affiliate by his password is not permitted (reasonable).

getFirstname(), setFirstname($value), setFirstname($value, $operator) – as $operator parameter you can use Pap_Api_Affiliate::OPERATOR_EQUALS or Pap_Api_Affiliate::OPERATOR_LIKE (by default is used operator like)

getLastname(), setLastname($value), setLastname($value, $operator) – as $operator parameter you can use Pap_Api_Affiliate::OPERATOR_EQUALS or Pap_Api_Affiliate::OPERATOR_LIKE (by default is used operator like)

getStatus(), setStatus($value) – allowed values: A – approved, P – pending, D - declined

getNote(), setNote($value) – note about the affiliate

getPhoto(), setPhoto($value) – URL to the file with photo

getIp() , setIp($value) – Works only with save() method. So you can use it only after you load() an affiliate.

getMinimumPayout() , setMinimumPayout($value)

getNotificationEmail(), setNotificationEmail($value)

getPayoutOptionId(), setPayoutOptionId($value)

setPayoutOptionField($code, $value)

 

There are another three special methods related to the way PAP handles affiliate information.

Every affiliate has up to 25 custom fields named data1, data2, ... data25. These fields are configurable, and you can use them to store any information about affiliate.

For example data1 can be Street, data2 = City, etc.

You can edit these assignments in merchant panel -> Configuration -> Affiliate signup -> Fields.

 

Special methods:

getData($index), setData($index, $value), setData($index, $value, $operator) – gets/sets data value given in $index variable, as $operator parameter you can use Pap_Api_Affiliate::OPERATOR_EQUALS or Pap_Api_Affiliate::OPERATOR_LIKE (by default is used operator like)

getDataName($index) – returns assigned name of the data in given index (index can be: 1 to 25), for example “Street” for data1. It returns empty string for undefined field.

getDataStatus($index) – returns status of data field in given index (index can be: 1 to 25), available values: M – mandatory, O – optional, U - hidden/readonly

setField('dontSendEmail','Y') – if this parameter is used, then no welcome email notification will be sent to the affiliate created via API.

 

Example of using the affiliate object:

 

//----------------------------------------------
// get affiliate with userid = b7ab1580

$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUserid("b7ab1580");
try {
  $affiliate->load();
} catch (Exception $e) {
  die("Cannot load record: ".$e->getMessage());
}
echo "Affiliate ".$affiliate->getFirstname()." ".$affiliate->getLastname()." loaded<br>";

//----------------------------------------------
// now we'll change first name and save the change
$affiliate->setFirstname("John");
try {
  if ($affiliate->save()) {
    echo "Affiliate saved successfully";
  } else {
    die("Cannot save affiliate: ".$affiliate->getMessage());
  }
} catch (Exception $e) {
    die("Error while communicating with PAP: ".$e->getMessage());
}

//----------------------------------------------
// inserting new affiliate
// the mandatory fields might differ depending
// on your settings in the merchant panel at Configuration > Affiliate signup > Fields (tab)

$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUsername("some@email.com");
$affiliate->setFirstname("John");
$affiliate->setLastname("Smith");

try {
  if ($affiliate->add()) {
    echo "Affiliate saved successfully";
  } else {
    die("Cannot save affiliate: ".$affiliate->getMessage());
  }
} catch (Exception $e) {
    die("Error while communicating with PAP: ".$e->getMessage());
}
NOTE I.: You can find the userid of an affiliate via the following API:
https://support.qualityunit.com/608550-Pap_Api_AffiliatesGrid

NOTE II.: Do not forget to initiate an API session (log in as merchant via API) as shown here.
×