This example shows how to add merchant account in Post Affiliate Network.
<?php
include 'PapApi.class.php'; //the PapApi.class.php can be downloaded from the merchant panel: Tools > Integration > API Integration > Download PAP API
$session = new Pap_Api_Session("URL_to_PAP/scripts/server.php");
//----------------------------------------------
// login (as merchant / network owner) is not required, as this request is same as signup merchant account
// but if you use captcha for your signup form, you need to use your merchant credentials
if(@!$session->login("merchant@example.com","merchant_password")) {
die("Cannot login. Message: ".$session->getMessage());
}
//----------------------------------------------
$accountName = 'ExampleAccount';
$email = 'example@account.com';
$merchantFirstName = 'Example';
$merchantLastName = 'Merchant';
$request = new Gpf_Rpc_FormRequest("Pap_Features_AffiliateNetwork_Signup_AccountSignupForm", "add", $session);
$request->addParam('isFromApi', Gpf::YES);
$request->addParam('initSession', Gpf::YES);
$request->setField('name', $accountName);
$request->setField('email', $email);
$request->setField('firstname', $merchantFirstName);
$request->setField('lastname', $merchantLastName);
$request->setField('agreeWithAgreement', 'Y');
try {
$request->sendNow();
} catch(Exception $e) {
die("API call error: ".$e->getMessage());
}
$response = $request->getStdResponse();
if ($response->success == 'Y') {
echo 'Success: ' . $response->message;
$fields = $response->fields;
foreach ($fields as $field) {
if ($field[0] == 'accountid') {
$accountId = $field[1];
}
}
echo ' with accountId: ' . $accountId;
} else {
echo 'Unsuccess: ' . $response->message;
}
?>
If you want to add merchant into existing account (PAN or PAP with multiple merchants):
<?php
include 'PapApi.class.php'; //the PapApi.class.php can be downloaded from the merchant panel: Tools > Integration > API Integration > Download PAP API
//----------------------------------------------
// login (as merchant owner)
$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());
}
//----------------------------------------------
$accountId = 'default1'; //accountId of account where will be merchant added
$email = 'example@account.com';
$merchantFirstName = 'Example';
$merchantLastName = 'Merchant';
$password = 'password';$role = 'net_merc'; //in PAP multiple merchants use 'pap_merc'
$request = new Gpf_Rpc_FormRequest("Pap_Features_MultipleMerchants_AdminForm", "add", $session);
$request->setField('username', $email);
$request->setField('firstname', $merchantFirstName);
$request->setField('lastname', $merchantLastName);
$request->setField('rpassword', $password);
$request->setField('retypepassword', $password);
$request->setField('roleid', $role);
$request->setField('accountid', $accountId);
$request->setField('agreeWithAgreement', 'Y');
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;
}
?>