Created
June 25, 2013 10:07
-
-
Save infusedmj/5857380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getAffFromIP($ip) { | |
$papURL="http://mobeoffice.com/affiliate"; | |
$merchantUsername = "our-user-name"; | |
$merchantPassword = "our-pass-word"; | |
$session = new Gpf_Api_Session($papURL."/scripts/server.php"); | |
if(!$session->login($merchantUsername, $merchantPassword)) { | |
die("Cannot login. Message: ".$session->getMessage()); | |
} | |
$request = new Gpf_Rpc_Gridrequest("Pap_Merchants_Reports_ClicksGrid","getRows",$session); | |
$request->addFilter("ip", Gpf_Data_Filter::EQUALS,$ip); | |
$request->setLimit(0, 30); | |
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) break; | |
if(!empty($rec)) { | |
$aff = $rec->get('username'); | |
$affiliate = new Pap_Api_Affiliate($session); | |
$affiliate->setUsername($aff, Pap_Api_Affiliate::OPERATOR_EQUALS); | |
$found = true; | |
try { | |
$affiliate->load(); | |
} catch (Exception $e) { | |
$found = false; | |
} | |
if($found) return $affiliate->getRefid(); | |
else return ""; | |
} else return ""; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment