X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fprimera_functions.php;h=e1c6fc57e2eeb79877818085ed43e6f41f5f4163;hp=c28da8cc79b7ab824036ffa20906419e044faf39;hb=50cec5fbac1b8b7427f016bf02c93cb1aa7bb9e1;hpb=f4ef7580792a9e424e5456369f40c75a29dbfead diff --git a/inc/libs/primera_functions.php b/inc/libs/primera_functions.php index c28da8cc79..e1c6fc57e2 100644 --- a/inc/libs/primera_functions.php +++ b/inc/libs/primera_functions.php @@ -1,6 +1,6 @@ payPrimera($PayReceiver, $PayAmount, $PayDescription); @@ -105,7 +105,7 @@ class PrimeraApi { /** * URL für das Interface auf dem Primusserver: */ - private $host = "www.primusportal.de"; + private $host = "http://www.primusportal.de"; private $path = "/transfer.interface.2.0.php"; private $errno = 0; @@ -118,6 +118,8 @@ class PrimeraApi { private $data = array(); + private $headers = ""; + /** * Konstruktor */ @@ -130,14 +132,24 @@ class PrimeraApi { /** * Anfrage senden und Rückgabecode in Variable speichern */ - function queryApi ( $data = array() ) { + private function queryApi ( $data = array() ) { + // Base64-encode username and password hash $data["PrimusInterface_Username"] = base64_encode($this->username); - $data["PrimusInterface_Password"] = base64_encode(md5($this->password)); + $data["PrimusInterface_Password"] = base64_encode($this->password); // Send POST request - $return = POST_URL($this->host.$this->path); + $return = POST_URL($this->host.$this->path, $data); + + // Convert the array into a full string + $returnStr = implode("\n", $return); + + // Extract the real content, strip header away + $content = explode("", $returnStr); - $content = explode("", $return); + // Store headers away for debugging + $this->headers = $content[0]; + + // Return the content return $content[1]; } @@ -163,15 +175,15 @@ class PrimeraApi { */ public function payPrimera ($Receiver, $Amount, $Description = "") { $valid = false; - $PostData = array("PrimusInterface_Action" => "Pay", + $postData = array("PrimusInterface_Action" => "Pay", "PrimusInterface_Receiver" => base64_encode($Receiver), "PrimusInterface_Amount" => base64_encode($Amount), "PrimusInterface_Description" => base64_encode($Description) ); - $PostReturn = $this->parseContent( $this->queryApi($PostData) ); + $postReturn = $this->parseContent( $this->queryApi($postData) ); - $this->data = $PostReturn; - if ($PostReturn["status"] == "200") { + $this->data = $postReturn; + if ($postReturn["status"] == "200") { $valid = true; } return $valid; @@ -183,16 +195,16 @@ class PrimeraApi { * - ist er aktiv * @param string/int $User Userid / Username */ - function CheckPrimusUser($User) { + public function CheckPrimusUser($User) { $valid = false; - $PostData = array("PrimusInterface_Action"=> "CheckPrimusUser", + $postData = array("PrimusInterface_Action"=> "CheckPrimusUser", "PrimusInterface_CheckPrimusUser" => $User); - $PostReturn = $this->parseContent( $this->queryApi($PostData) ); + $postReturn = $this->parseContent( $this->queryApi($postData) ); - $this->data = $PostReturn; + $this->data = $postReturn; - if ($PostReturn["status"] == self::PI_USER_CHECK_OK) { + if ($postReturn["status"] == self::PI_USER_CHECK_OK) { $valid = true; } return $valid; @@ -201,18 +213,70 @@ class PrimeraApi { /** * Die Funktion liefer den aktuellen Primerastand */ - function getPrimera() { + public function getPrimera() { $primera = false; - $PostData = array( "PrimusInterface_Action" => "GetPrimera" ); - $PostReturn = $this->parseContent( $this->queryApi($PostData) ); + $postData = array( "PrimusInterface_Action" => "GetPrimera" ); + $postReturn = $this->parseContent( $this->queryApi($postData) ); - $this->data = $PostReturn; - if ($PostReturn["status"] == self::PI_GET_PRIMERA_DONE) { - $primera = $PostReturn["primera"]; + $this->data = $postReturn; + if ($postReturn["status"] == self::PI_GET_PRIMERA_DONE) { + $primera = $postReturn["primera"]; } return $primera; } + /** + * Getter fuer data + */ + public function getData () { + return $this->data; + } +} + +// Function to test the Primera API by getting the amount. If the returned value +// is not false the API data is valid, else invalid +function PRIMERA_TEST_API () { + // Get new instance + $api = new PrimeraApi($_POST['primera_api_name'], $_POST['primera_api_md5']); + + // Was that fine? + return ($api->getPrimera() !== false); } +// Execute the withdraw of a sponsor only! +function PRIMERA_EXECUTE_WITHDRAW ($primusNick, $userMd5, $amount) { + global $_CONFIG; + // Is the sponsor extension installed? + if (!EXT_IS_ACTIVE("sponsor")) { + // No, abort here + return false; + } elseif (!IS_SPONSOR()) { + // No sponsor, not allowed to withdraw! + return false; + } + + // Get new instance + $api = new PrimeraApi($primusNick, $userMd5); + + // Prepare purpose + $eval = "\$purpose = \"".COMPILE_CODE(sprintf(PRIMERA_API_PURPOSE_WITHDRAW, $_COOKIE['sponsorid']))."\";"; + eval($eval); + + // Pay the Primera + return $api->payPrimera($primusNick, $amount, $purpose); +} +// Execute the payout +function PRIMERA_EXECUTE_PAYOUT ($primusNick, $userMd5, $amount) { + global $_CONFIG; + + // Get new instance + $api = new PrimeraApi($_CONFIG['primera_api_name'], $_CONFIG['primera_api_md5']); + + // Prepare purpose + $eval = "\$purpose = \"".COMPILE_CODE(sprintf(PRIMERA_API_PURPOSE_PAYOUT, $GLOBALS['userid']))."\";"; + eval($eval); + + // Pay the Primera + return $api->payPrimera($primusNick, $amount, $purpose); +} // [EOF] -?> \ No newline at end of file +?>