X-Git-Url: https://git.mxchange.org/?p=hub.git;a=blobdiff_plain;f=inc%2Fclasses%2Fthird_party%2Fapi%2Fprimusportal%2Fclass_PrimeraApi.php;fp=inc%2Fclasses%2Fthird_party%2Fapi%2Fprimusportal%2Fclass_PrimeraApi.php;h=fba7463490046fd02a5426135a3e9a26a97da59c;hp=0000000000000000000000000000000000000000;hb=c59dccf46c5d0e3b7f2687370b2b15023b1ecdfe;hpb=e2767d5148436d0c90ed66ed9290416353ae6e60 diff --git a/inc/classes/third_party/api/primusportal/class_PrimeraApi.php b/inc/classes/third_party/api/primusportal/class_PrimeraApi.php new file mode 100644 index 000000000..fba746349 --- /dev/null +++ b/inc/classes/third_party/api/primusportal/class_PrimeraApi.php @@ -0,0 +1,240 @@ +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: + */ + private $host = "www.primusportal.de"; + private $path = "/transfer.interface.2.0.php"; + + private $errno = 0; + private $err = ""; + + private $seperator = ":"; + + private $username = ""; + private $password = ""; + + private $data = array(); + + /** + * Konstruktor + */ + public function __construct ($PPUsername, $PPPassword) { + // Call parent constructor + parent::__construct(); + + // Clean up a little + $this->removeSystemArray(); + $this->removeNumberFormaters(); + + // Set data (DEPRECATED!) + $this->username = $PPUsername; + $this->password = $PPPassword; + } + + /** + * Anfrage senden und Rückgabecode in Variable speichern + */ + function queryApi ( $data = array() ) { + $fp = fsockopen($this->host, 80, $this->errno, $this->_err); + if (!$fp) return false; + + $data["PrimusInterface_Username"] = base64_encode($this->username); + $data["PrimusInterface_Password"] = base64_encode(md5($this->password)); + + // POST-Daten übermitteln: + $data = http_build_query($data, '', '&'); + + fputs($fp, "POST {$this->path}HTTP/1.1\r\n"); + fputs($fp, "Host: {$this->host}\r\n"); + fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); + fputs($fp, "Content-length: ". strlen($data) ."\r\n"); + fputs($fp, "Connection: close\r\n\r\n"); + fputs($fp, $data); + + $return = ""; + while (!feof($fp)) { + $return.=fgets($fp,128); + } + + $content = explode("", $return); + 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) + */ + public 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; + } +} + +// [EOF] +?> \ No newline at end of file