Here is a sample script how to configure a campaign's commission structure (the default commission group) -- Sale or Click commission.
If you wish to add an action commission to a campaign via API then check the notes below this sample code or click here.
<?php //your PapApi.class.php file can be downloaded in the merchant panel: Tools>Integration>API Integration>Download PAP API include '../pap/api/PapApi.class.php'; $papUrl = "https://yoursite.com/PostAffiliatePro"; //URL leading to your Post Affiliate Pro $merchantUsername = "merchant@example.com"; //merchant username $merchantPassword = "demo"; //merchant password $campaignID = "c6fce328"; //Campaign ID of the campaign you wish to configure it's commissions $commissionType = 'S'; //S = "per Sale" commission type, C = "per Click" commission type $session = new Pap_Api_Session($papUrl."/scripts/server.php"); //login as merchant if(!$session->login($merchantUsername,$merchantPassword)) { die("Cannot login. Message: ". $session->getMessage()); } $request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "save", $session); //ID of the particular commissoin group -- MANDATORY //how to find out 'commission group id' via API: https://support.qualityunit.com/235875-How-to-get-commission-group-id $request->setField("CommissionGroupId",getDefaultCommissionGroupID($campaignID, $session)); //ID of the per Sale or per Click commission type. -- MANDATORY $request->setField("Id",getCommissionTypeID($campaignID, $commissionType, $session)); //Status of the commission. --Mandatory // "E" = enabled. "D" = disabled. $request->setField("rstatus","E"); //Type of commission -- MANDATORY //"S" = sale, "C" = click $request->setField("rtype",$commissionType); //Leave it blank -- MANDATORY $request->setField("parentcommtypeid",""); //Approval -- MANDATORY. "A" = automatic, "M" - manual $request->setField("approval","A"); //Save transaction also for zero orders (Total Cost = 0) -- MANDATORY //default value "N". In order to allow that option, use "Y" instead of "N". $request->setField("zeroorderscommission","N"); //Save transaction with zero commission -- MANDATORY //default value "N". In order to allow that option, use "Y" instead of "N". $request->setField("savezerocommission","N"); //FIXED COST //use fixed cost -- MANDATORY //default value "N" - not to use FixedCost $request->setField("useFixedCost","N"); // Type of fixed cost: "%" or "$" -- Mandatory if the previous field uses "Y" instead of "N" $request->setField("F_1_commissionType","$"); // numeric value of fixed cost -- MANDATORY $request->setField("F_1_commission","0"); //Type of Default (1st tier) commission -- MANDATORY $request->setField("N_1_commissionType","%"); //Value of Default (1st tier) commission -- MANDATORY $request->setField("N_1_commission","3"); //TIER COMMISSIONS -- OPTIONAL //N_X_ while X represents the tier $request->setField("N_2_commissionType","$"); // Value of 2nd tier commission $request->setField("N_2_commission","1"); //RECURRING COMMISSIONS -- OPTIONAL //Period of recurrence: //"varied" -> more info here: https://support.qualityunit.com/197572-Pap_Api_RecurringCommission //"each15m" = each 15 minutesus, "A" = Daily, "B" = Weekly, "C", Monthly, "Q" = Quaterly, "D" = Semianually, "E" = yearly $request->setField("recurrencepresetid","varied"); //Type of 1st tier recurring commission -- Mandatory if the previous field is set $request->setField("R_1_commissionType","$"); //Value of 1st tier recurring commission -- Mandatory if the previous field is set $request->setField("R_1_commission","1"); // If you wish to define more tiers of recurring commissions, then use R_X_ while X represents the corresponding tier 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; function getDefaultCommissionGroupID($campaignID, $session) { $request = new Gpf_Rpc_Request("Pap_Merchants_Campaign_CommissionGroups","loadCommissionGroups",$session); // Set the campaign id for which we want the commission group $request->addParam("campaignid",$campaignID); try { $request->sendNow(); } catch(Exception $e){ die("API call error: " . $e->getMessage()); } $response = $request->getStdResponse(); $groupName = 'Default commission group'; foreach ($response as $resp) { if ($resp[1] == $groupName ) { return $resp[0]; } } } function getCommissionTypeID($campaignID, $commissionType, $session) { $request = new Gpf_Rpc_Request("Pap_Merchants_Campaign_Commissions", "loadCommissionTypes", $session); $request->addParam('campaignid', $campaignID); // send request try { $request->sendNow(); } catch(Exception $e) { die("API call error: ".$e->getMessage()); } // request was successful, get the rows $result = $request->getStdResponse(); $rtypeKey = array_search('rtype', $result[0]); $commtypeidKey = array_search('commtypeid', $result[0]); // find certain commissiontypeid by commissiontype foreach ($result as $row) { if ($row[$rtypeKey] == $commissionType) { $commtypeid = $row[$commtypeidKey]; } } return $commtypeid; } ?>
That's it.
In order to add an action commission, the following changes have to be applied in the above given sample code:
1) In
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "save", $session);
you have to use "add" instead of "save".
So the changed row will result in:
$request = new Gpf_Rpc_FormRequest("Pap_Merchants_Campaign_CommissionTypeForm", "add", $session);
2) Use $commissionType = 'A';
So instead of "S" or "C" the value is "A".
Also, right after the line of $commissionType = 'A';
define (add) the following:
$actionCode = 'something'; // code of action commission
$actionName = 'something else'; // name of action commission
where of course you set the desired code and name of action commission.
3) In the code instead of
$request->setField("Id",getCommissionTypeID($campaignID, $commissionType, $session));
use:
$request->setField("Id","");
4) Finally right after the code of
$request->setField("rtype",$commissionType);
add the following block of code:
if ($commissionType == 'A') {
$request->setField("code",$actionCode);
$request->setField("name",$actionName);
}
That's it.