PAN: change merchant password via API

The following script enables the network owner to change the password of any merchant belonging to his Post Affiliate Network via php API.
 
<?php
//your PapApi.class.php file can be downloaded in the merchant panel:
//Tools > Integration > API Integration > Download PAP API

//this include assumes the PapApi.class.php is in the same dir as this script
include ("PapApi.class.php"); 
  
$panURL ="https://yoursite.com/PostAffiliateNetwork"; //URL to PAN without trailing slash

// change it here for your username and password 
$networkOwnerUsername = "merchant@username.com";
$networkOwnerPassword = "test";

//details of the merchant whose password we want to change
$merchantUsername = "merchant2@username.com";
$newMerchantPassword = 'NewPassword111'; //new password for the particular merchant


$session = new Pap_Api_Session($panURL."/scripts/server.php"); 
//login as merchant
if(!$session->login($networkOwnerUsername, $networkOwnerPassword)) { 
  die("Cannot login. Message: ".$session->getMessage());
}

//Pap_Features_MultipleMerchants_AdminsGrid

$request = new Gpf_Rpc_GridRequest("Pap_Features_MultipleMerchants_AdminsGrid","getRows" , $session);

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

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

foreach($recordset as $rec) {
	if ($merchantUsername == $rec->get('username')) { 
		//echo 'ID: '.$rec->get('id'). ' || AccountId: ' . $rec->get('accountid'). ' || Name: ' . $rec->get('firstname').' '.$rec->get('lastname').' || Email: ' . $rec->get('username').' || Status: ' . $rec->get('rstatus').'<br>';
		
		$request = new Gpf_Rpc_FormRequest("Pap_Features_MultipleMerchants_AdminForm", "save", $session);
		//ID and username are mandatory fields even if you are changing only the password
		$request->setField('Id', $rec->get('id'));
		$request->setField('username', $rec->get('username'));
		
		//set the new password
		$request->setField('rpassword',$newMerchantPassword);
		
		try {
		  $request->sendNow();
		} catch(Exception $e) {
			die("API call error: ".$e->getMessage());
		}
		
		$response = $request->getStdResponse();

		if ($response->success == 'Y') {
			echo 'Success: ' . $response->message;
		} else {
			echo 'Unsuccess: ' . $response->message;
		}
		
	}
}


?>
 
×