The following example shows how to delete a merchant via API, while we filter the merchant via his/her username (e-mail address)
 
<?php
//the PapApi.class.php can be downloaded from the merchant panel:
//Tools > Integration > API Integratoin > Download PAP API
include 'PapApi.class.php'; 

//----------------------------------------------
// login as main merchant or network-owner in case of PAN
$session = new Pap_Api_Session("https://URL_TO_PAP/scripts/server.php");

if(!@$session->login("mainmerchant@username.com","passwordOfMainMerchant")) {
  die("Cannot login. Message: ".$session->getMessage());
} 

//----------------------------------------------
$email = 'merchant@toBeDeleted.com'; //email address (username) of merchant to be deleted

//-----------------------------------------------
//Get the list of existing merchants
$request = new Gpf_Rpc_GridRequest("Pap_Features_MultipleMerchants_AdminsGrid", "getRows", $session);

//filter merchant with the particular email address (username)
$request->addFilter('username', Gpf_Data_Filter::EQUALS, $email); 

try {
  $request->sendNow();
} catch(Exception $e) {
  die("API call error: ".$e->getMessage());
}

$response = $request->getStdResponse();

// request was successful, get the grid result
$grid = $request->getGrid();
// get recordset from the grid
$recordset = $grid->getRecordset();

foreach($recordset as $rec) {
	echo $rec->get('id')." | ". $rec->get('firstname')." | ".$rec->get('firstname')." | ".$rec->get('username')."<br>";
	deleteMerchant($rec->get('id'), $session);
}

//Delete merchant
function deleteMerchant($userid, $session) {
	$userIds = array($userid);
	$request = new Gpf_Rpc_Request("Pap_Features_MultipleMerchants_AdminForm", "deleteRows", $session);
	$request->addParam('ids', new Gpf_Rpc_Array($userIds));

	try {
	  $request->sendNow();
	} catch(Exception $e) {
	  die("API call error: ".$e->getMessage());
	}

	$response = $request->getStdResponse();
	if ($response->success == 'Y') {
	  echo 'Success: ' . $response->infoMessage;
	} 
}

?>
 
×