How to get commissiontypeid for campaign and commissiontype

This example shows how to get commissiontypeid for certain campaign and commissiontype. When you create transaction using class Pap_Api_Transaction, you need know commissiontypeid. You can find it manually in Merchant panel: Start -> Campaigns manager -> Edit -> Commissions settings
 
 
<?php

include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory

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

//----------------------------------------------

$campaignId = '11111111';
$commissiontype = 'S';  //for click use 'C'
$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];
  }
}

echo 'Commissiontypeid: ' . $commtypeid . ' (for campaign id: ' . $campaignId . ' and commission type: ' . $commissiontype . ')';          

?>
×