4 * -------------------------------------------
5 * Mit dieser Klasse ist ein einfacher Primeratransfer von Ihrem Account
6 * zu dem Account eines bei Primusportal.de registrierten Mitglieds möglich.
8 *------------------ Aenderungen durch Roland Haeder 09.08.2008 ----------------
9 * Klasse umbenannt nach PrimeraApi, damit sie in das Framework besser passt.
10 * Zudem sind alle oeffentlichen Attribute nun privat, der Konstruktor hat den
11 * neuen "magischen" Namen __construct() und "normale" Konstanten sind nach
12 * Klassenkonstanten umbenannt. Unsinnige else-Bloecke sind noch umgewandelt.
13 * Methodennamen fangen nun immer mit einem kleinen Buchstaben an. Zudem sind
14 * die Methoden Pay,Query und Parse umbenannt.
15 *------------------ Aenderungen durch Roland Haeder 09.08.2008 ----------------
17 * Die Einbindung des Interfaces geschieht folgendermaßen:
18 * 1. Einbindung der Klasse in Ihr PHP-Auszahlungsskript:
20 * require_once( "PFAD/ZU/DER/KLASSE/PrimusInterface.class.php" );
21 * $PPUsername = "username"; // Ihr Username bei Primusportal
22 * $PPPassword = "passwort"; // Ihr Passwort bei Primusportal
24 * $Interface = new PrimusInterface($PPUsername, $PPPassword);
25 * 2. Durchführen einer Auszahlung:
27 * $Status = $Interface->payPrimera($PayReceiver, $PayAmount, $PayDescription);
29 * Wobei $PayReicer der Username des Empfängers bei
30 * Primusportal.de ist. $PayAmount ist der gerundete( !! ) Betrag an Primera,
31 * die der Empfänger erhalten soll. $PayDescription ist eine von Ihnen
32 * festgelegte kurze Beschreibung. Die Länge dieses Textes darf 100 Zeichen
33 * nicht überschreiten. Beispiel:
34 * $status = $Interface->payPrimera("garbage", 10000, "Auszahlung IhreSeite.de - ID: 12345");
35 * 3. Überprüfung des Status (Rückgabecode):
38 * // Ein Fehler ist aufgetreten
39 * // Fehlerbehandlung hier einfügen...
41 * // Auszahlung erfolgreich durchgeführt
42 * // Führen Sie hier Ihre Datenbankabfragen durch, um die Auszahlung zu
46 * Die komplette Rückgabe des Interfaces wird als assoziatives Array in der Klassen-
47 * variable __data gespeichert:
48 * __data => array("status" => Rückgabecode (PI_DONE, PI_SENDER_ERROR, ...),
49 * "statustext" => Status in Worten (z.B.: "Transaktion erfolgreich durchgeführt"),
53 * @author Andreas Schmidt <xxgarbagexx@web.de>
54 * @author Roland Haeder <webmaster@ship-simu.org>
56 * @copyright (c) 2007 by Primusportal.de
57 * @copyright (c) 2008 by Roland Haeder
61 * Fehler - Interfacebenutzer
66 * Statuscode für erfolgreich ausgeführte Transaktion
71 * Fehler - User existiert nicht oder ist gesperrt
73 const PI_RECEIVER_ERROR = 301;
76 * Sender-Account Fehler (User nicht existent, gesperrt, ...)
78 const PI_SENDER_ERROR = 401;
83 const PI_AMOUNT_ERROR = 501;
88 const PI_TOO_LESS_PRIMERA = 502;
91 * User nicht aktiv oder existiert nicht
93 const PI_USER_CHECK_ERROR = 601;
98 const PI_USER_CHECK_OK = 602;
101 * Primerastand erfolgreich geholt
103 const PI_GET_PRIMERA_DONE = 701;
106 * URL für das Interface auf dem Primusserver:
108 private $host = "www.primusportal.de";
109 private $path = "/transfer.interface.2.0.php";
114 private $seperator = ":";
116 private $username = "";
117 private $password = "";
119 private $data = array();
124 public function PrimeraApi ($PPUsername, $PPPassword) {
126 $this->username = $PPUsername;
127 $this->password = $PPPassword;
131 * Anfrage senden und Rückgabecode in Variable speichern
133 function queryApi ( $data = array() ) {
134 $data["PrimusInterface_Username"] = base64_encode($this->username);
135 $data["PrimusInterface_Password"] = base64_encode(md5($this->password));
138 $return = POST_URL($this->host.$this->path);
140 $content = explode("<!-- return-start -->", $return);
145 * Funktion parst die Rückgabe vom Transferskript:
147 function parseContent ( $content ) {
148 $x = explode("\n", $content);
150 foreach($x as $currentLine) {
151 $line_exploded = explode(":", $currentLine,2);
152 if (count($line_exploded) > 1) {
153 $return[$line_exploded[0]] = $line_exploded[1];
160 * @param int/string $Receiver UserID / Username des Empfängers
161 * @param int $Amount Betrag in ganzzahligen Primera
162 * @param string $Description Beschreibung (Sichtbar in Einzelauflistung)
164 public function payPrimera ($Receiver, $Amount, $Description = "") {
166 $PostData = array("PrimusInterface_Action" => "Pay",
167 "PrimusInterface_Receiver" => base64_encode($Receiver),
168 "PrimusInterface_Amount" => base64_encode($Amount),
169 "PrimusInterface_Description" => base64_encode($Description) );
171 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
173 $this->data = $PostReturn;
174 if ($PostReturn["status"] == "200") {
181 * Überprüft den Status eines Primus-Users
182 * - existiert der User
184 * @param string/int $User Userid / Username
186 function CheckPrimusUser($User) {
188 $PostData = array("PrimusInterface_Action"=> "CheckPrimusUser",
189 "PrimusInterface_CheckPrimusUser" => $User);
191 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
193 $this->data = $PostReturn;
195 if ($PostReturn["status"] == self::PI_USER_CHECK_OK) {
202 * Die Funktion liefer den aktuellen Primerastand
204 function getPrimera() {
206 $PostData = array( "PrimusInterface_Action" => "GetPrimera" );
207 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
209 $this->data = $PostReturn;
210 if ($PostReturn["status"] == self::PI_GET_PRIMERA_DONE) {
211 $primera = $PostReturn["primera"];