Add action commission to a campaign via API

Here is an example of how you can add an action commission to a campaign via API:
 
<?php
//PapApi.class.php can be downloaded from the merchant panel: 
//Start > Tools >  Integration > API Integration > Download PAP API
// or can be found in the 'api' folder of your installation of Post Affiliate Pro
include 'PapApi.class.php'; 

//log in as merchant
$session = new Pap_Api_Session("https://yoursite.com/PostAffiliatePro/scripts/server.php");
if(!$session->login("merchant@username.com","merchantPassword")) {  //change the merchant
    die("Cannot login. Message: ". $session->getMessage());
}
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "add", $session);
$request->setField("Id","");
//Commission group id
$request->setField("CommissionGroupId","3f0fdf9f"); 
$request->setField("rstatus","");

//type of commission: //"I"=CPM; "A"=per action
$request->setField("rtype","A");
$request->setField("parentcommtypeid","");
//name of "per action" commission
$request->setField("name","ActionName");
//code of "per action" commission
$request->setField("code","ActionCODE");
//approval//"A"=automatic; "M"=manual;
$request->setField("approval","A");
//change to N if no zero cost transaction shall be saved
$request->setField("zeroorderscommission","Y"); 
//change to N if no zero commission transaction shall be saved
$request->setField("savezerocommission","Y"); 
//if you wish to use a fixed cost, use Y  instead of N and define the type
$request->setField("useFixedCost","N"); 
// type of fixde cost: % or $ (or e.g. €  if the currency in your PAP/PAN is set to €)
$request->setField("fixedcosttype","");  
//value of fixed cost 
$request->setField("fixedcostvalue","0");
//1st tier commission type: % or $ (or e.g. €  if the currency in your PAP/PAN is set to €)
$request->setField("N_1_commissionType","%"); 
//1st tier commission value
$request->setField("N_1_commission","10"); 

//2nd tier commission type: % or $ (or e.g. €  if the currency in your PAP/PAN is set to €)
$request->setField("N_2_commissionType","$");
//2nd tier commission value
$request->setField("N_2_commission","1"); //Recurring commissions//recurrence period://"" = no recurrence; //"A"=daily; "B"=weekly; "C"=monthly; "D"=semianually; "Y"=yearly; "Q"=quarterly; "each15m" = each 15 minutes//"varied" = if you are about to use API to trigger recurring commissions
$request->setField("recurrencepresetid","C"); 

//type of 1st tier recurring commission //% or $ (or e.g. €  if the currency in your PAP/PAN is set to €)
$request->setField("R_1_commissionType","%");
//value of 1st tier recurring commission
$request->setField("R_1_commission","5"); 

//type of 2nd tier recurring commission //% or $ (or e.g. €  if the currency in your PAP/PAN is set to €)
$request->setField("R_2_commissionType","$");
//value of 2nd tier recurring commission
$request->setField("R_2_commission","1"); 
try {  // Send the request to PAP
    $request->sendNow();
} catch(Exception $e) {
    die("API call error: " . $e->getMessage());
}
//Get the response as normal array
$response = $request->getStdResponse();

echo $response->message;
?>
Of course, after you added an action commission, you have to enable it. 

How to enable an action commission via API?:
<?php

include 'PapApi.class.php'; 
//log in as merchant
$session = new Pap_Api_Session("https://yoursite.com/PostAffiliatePro/scripts/server.php");
if(!$session->login("merchant@username.com","merchantPassword")) {  //change the merchant
   die("Cannot login. Message: ". $session->getMessage());
}
$request = new Gpf_Rpc_Request("Pap_Merchants_Campaign_Commissions", "changeCommissionTypeStatus", $session);
//Commission type ID of the particular action commission you have created
$request->addParam('commtypeid', '16150309');

$request->addParam('rstatus', 'E')

// send request
try {

  $request->sendNow();

} catch(Exception $e) {

  die("API call error: ".$e->getMessage());

}
// request was successful, get the rows
$result = $request->getStdResponse();
if ($result->success == 'Y') {

  echo $result->infoMessage;

} else {

  echo $result->errorMessage;

}

?>
 
×