payPrimera($PayReceiver, $PayAmount, $PayDescription); * * Wobei $PayReicer der Username des Empf�ngers bei * Primusportal.de ist. $PayAmount ist der gerundete( !! ) Betrag an Primera, * die der Empf�nger erhalten soll. $PayDescription ist eine von Ihnen * festgelegte kurze Beschreibung. Die L�nge dieses Textes darf 100 Zeichen * nicht �berschreiten. Beispiel: * $status = $Interface->payPrimera("garbage", 10000, "Auszahlung IhreSeite.de - id: 12345"); * 3. �berpr�fung des Status (R�ckgabecode): * CODE: * if (!$status) { * // Ein Fehler ist aufgetreten * // Fehlerbehandlung hier einf�gen... * }else { * // Auszahlung erfolgreich durchgef�hrt * // F�hren Sie hier Ihre Datenbankabfragen durch, um die Auszahlung zu * // best�tigen... * } * * Die komplette R�ckgabe des Interfaces wird als assoziatives Array in der Klassen- * variable __data gespeichert: * __data => array('status' => R�ckgabecode (PI_DONE, PI_SENDER_ERROR, ...), * "statustext" => Status in Worten (z.B.: "Transaktion erfolgreich durchgef�hrt"), * ") * * * @author Andreas Schmidt * @author Roland Haeder * @version 1.0 - beta * @copyright (c) 2007 by Primusportal.de * @copyright (c) 2008 by Roland Haeder */ class PrimeraApi { /** * Fehler - Interfacebenutzer */ const PI_ERROR = -1; /** * Statuscode f�r erfolgreich ausgef�hrte Transaktion */ const PI_DONE = 200; /** * Fehler - User existiert nicht oder ist gesperrt */ const PI_RECEIVER_ERROR = 301; /** * Sender-Account Fehler (User nicht existent, gesperrt, ...) */ const PI_SENDER_ERROR = 401; /** * Betrag fehler */ const PI_AMOUNT_ERROR = 501; /** * Zu wenig Primera */ const PI_TOO_LESS_PRIMERA = 502; /** * User nicht aktiv oder existiert nicht */ const PI_USER_CHECK_ERROR = 601; /** * User aktiv */ const PI_USER_CHECK_OK = 602; /** * Primerastand erfolgreich geholt */ const PI_GET_PRIMERA_DONE = 701; /** * URL f�r das Interface auf dem Primusserver: */ var $host = "http://www.primusportal.de"; var $path = "/transfer.interface.2.0.php"; var $errno = '0'; var $err = ''; var $seperator = ':'; var $username = ''; var $password = ''; var $data = array(); var $headers = ''; /** * Konstruktor */ function PrimeraApi ($PPUsername, $PPPassword) { // Set data $this->username = $PPUsername; $this->password = $PPPassword; } /** * Anfrage senden und R�ckgabecode in Variable speichern */ function queryApi ( $data = array() ) { // Base64-encode username and password hash $data['PrimusInterface_Username'] = base64_encode($this->username); $data['PrimusInterface_Password'] = base64_encode($this->password); // Send POST request $return = sendPostRequest($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); // Store headers away for debugging $this->headers = $content[0]; // Return the content return $content[1]; } /** * Funktion parst die R�ckgabe vom Transferskript: */ function parseContent ( $content ) { $x = explode("\n", $content); $return = array(); foreach($x as $currentLine) { $line_exploded = explode(':', $currentLine,2); if (count($line_exploded) > 1) { $return[$line_exploded[0]] = $line_exploded[1]; } } return $return; } /** * @param int/string $Receiver UserID / Username des Empf�ngers * @param int $Amount Betrag in ganzzahligen Primera * @param string $Description Beschreibung (Sichtbar in Einzelauflistung) */ function payPrimera ($Receiver, $Amount, $Description = '') { $valid = false; $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) ); $this->data = $postReturn; if ($postReturn['status'] == '200') { $valid = true; } return $valid; } /** * �berpr�ft den Status eines Primus-Users * - existiert der User * - ist er aktiv * @param string/int $User Userid / Username */ function CheckPrimusUser($User) { $valid = false; $postData = array('PrimusInterface_Action'=> 'CheckPrimusUser', 'PrimusInterface_CheckPrimusUser' => $User); $postReturn = $this->parseContent( $this->queryApi($postData) ); $this->data = $postReturn; if ($postReturn['status'] == self::PI_USER_CHECK_OK) { $valid = true; } return $valid; } /** * Die Funktion liefer den aktuellen Primerastand */ function getPrimera() { $primera = false; $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']; } return $primera; } /** * Getter fuer data */ 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 testPrimeraApi () { // Get new instance $api = new PrimeraApi(postRequestParameter('primera_api_name'), postRequestParameter('primera_api_md5')); // Was that fine? return ($api->getPrimera() !== false); } // Execute the withdraw of a sponsor only! function executePrimeraWithdraw ($primusNick, $userMd5, $amount) { // Is the sponsor extension installed? if (!isExtensionActive('sponsor')) { // No, abort here return false; } elseif (!isSponsor()) { // No sponsor, not allowed to withdraw! return false; } // Get new instance $api = new PrimeraApi($primusNick, $userMd5); // Prepare purpose eval("\$purpose = \"".compileRawCode(getMaskedMessage('PRIMERA_API_PURPOSE_WITHDRAW', getSession('sponsorid')))."\";"); // Pay the Primera return $api->payPrimera($primusNick, $amount, $purpose); } // Execute the payout function executePrimeraPayout ($primusNick, $userMd5, $amount) { // Get new instance $api = new PrimeraApi(getConfig('primera_api_name'), getConfig('primera_api_md5')); // Prepare purpose eval("\$purpose = \"".compileRawCode(getMaskedMessage('PRIMERA_API_PURPOSE_PAYOUT', getMemberId()))."\";"); // Pay the Primera return $api->payPrimera($primusNick, $amount, $purpose); } // [EOF] ?>