Wernis API now reconizes failed API responses
authorRoland Häder <roland@mxchange.org>
Thu, 29 Oct 2009 17:16:26 +0000 (17:16 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 29 Oct 2009 17:16:26 +0000 (17:16 +0000)
inc/language/wernis_de.php
inc/libs/wernis_functions.php
inc/modules/admin/admin-inc.php
inc/modules/admin/what-config_wernis.php
inc/modules/member/what-wernis.php

index 3d1384c..41becd0 100644 (file)
@@ -86,6 +86,7 @@ addMessages(array(
        'WERNIS_API_REQUEST_DATA_INVALID' => "Interner Fehler: Abfragedaten sind defekt!",
        'WERNIS_API_REQUEST_DATA_MISSING' => "Interner Fehler: Abfragedaten sind nicht komplett!",
        'WERNIS_API_REQUEST_ERROR' => "Abfragefehler: <span class=\"data\">%s</span>",
+       'WERNIS_API_REQUEST_PROBLEM' => "Abfrageproblem: Status=<span class=\"data\">%s</span>, R&uuml;ckmeldung=<span class=\"data\">%s</span>",
        'WERNIS_API_REQUEST_FAILED' => "Unbekannter Fehler <span class=\"data\">%s</span> von API erhalten! Bitte im [<a href=\"http://bugs.mxchange.org\" target=\"_blank\" title=\"Direktlink zum Bug-Tracker\">Bug-Tracker posten</a>], den Fehlercode nennen und wie es dazu gekommen ist.",
        'WERNIS_API_REQUEST_FAILED_AUTH' => "Authorisierung an API fehlgeschlagen! Bitte API-ID und Key &uuml;berpr&uuml;fen. [<a href=\"http://www.wds66.com/modules.php?module=export\" target=\"_blank\" title=\"Direkt zum WDS66-Exportaccount\">Hier</a>] direkt zum Export-Account. Sie ben&ouml;tigen Ihren Usernamen und Passwort!",
        'WERNIS_API_REQUEST_FAILED_USER' => "Useraccount nicht gefunden oder Wernis-Passwort ist ung&uuml;ltig!",
@@ -104,7 +105,7 @@ addMessages(array(
        'MEMBER_WERNIS_MODE_CHOOSE2' => "Hier klicken um neue &Uuml;berweisung zu starten...",
        'WERNIS_MEMBER_NO_ACCOUNT' => "Noch kein WDS66-Account? Hier entlang!",
        'WERNIS_MEMBER_API_DATA_MISSING' => "Diese Funktion kann derzeit nicht genutzt werden, da wir sie noch einrichten m&uuml;ssen.",
-       'WERNIS_MEMBER_MIN_PAYOUT' => "Sie haben nicht gen&uuml;gend Wernis zum Auszahlen! Mindestens: <span class=\"data\">%s</span> Wernis.",
+       'WERNIS_MEMBER_MIN_PAYOUT' => "Sie haben nicht gen&uuml;gend Wernis zum Auszahlen! Mindestens: <span class=\"data\">%s</span>, Ihr Guthaben: <span class=\"data\">%s</span> Wernis.",
        'WERNIS_MEMBER_WITHDRAW_TITLE' => "Wernis bei {?MAIN_TITLE?} einzahlen:",
        'WERNIS_MEMBER_WITHDRAW_POINTS_ACCOUNT' => "Wernis hier im Account:",
        'WERNIS_MEMBER_WITHDRAW_MIN_POINTS' => "Mindest einzuzahlendes Wernis-Guthaben:",
index 101c5b3..4d86960 100644 (file)
@@ -112,22 +112,29 @@ function WERNIS_SEND_REQUEST ($scriptName, $requestData =  array()) {
        } // END - if
 
        // All (maybe) fine so remove the response header from server
+       $responseLine = '*INVALID*';
        for ($idx = (count($response) - 1); $idx > 1; $idx--) {
                $line = trim($response[$idx]);
                if (!empty($line)) {
-                       $response = $line;
+                       $responseLine = $line;
                        break;
-               }
-       }
+               } // END - if
+       } // END - for
 
-       // Prepare the returning result for higher functions
-       if (substr($response, 0, 1) == '&') {
-               // Remove the leading & (which can be used in Flash)
-               $response = substr($response, 1);
+       // Is the response leaded by a & symbol?
+       if (substr($responseLine, 0, 1) != '&') {
+               // Something badly happened on server-side
+               return array(
+                       'status'  => 'request_problem',
+                       'message' => sprintf(getMessage('WERNIS_API_REQUEST_PROBLEM'), $response[0], htmlentities($responseLine))
+               );
        } // END - if
 
+       // Remove the leading & (which can be used in Flash)
+       $responseLine = substr($responseLine, 1);
+
        // Bring back the response
-       $data = explode('=', $response);
+       $data = explode('=', $responseLine);
 
        // Default return array (should not stay empty)
        $return = array();
@@ -186,7 +193,7 @@ function WERNIS_SEND_REQUEST ($scriptName, $requestData =  array()) {
                // All fine here
                $return = array(
                        'status'   => 'OK',
-                       'response' => $response
+                       'response' => $responseLine
                );
        }
 
@@ -236,9 +243,9 @@ function WERNIS_EXECUTE_WITHDRAW ($wdsId, $userMd5, $amount) {
        // Prepare the request data
        $requestData = array(
                'sub_request' => 'receive',
-               't_userid'    => bigintval($wdsId),
+               't_uid'       => bigintval($wdsId),
                't_md5'       => $userMd5,
-               'r_userid'    => getConfig('wernis_refid'),
+               'r_uid'       => getConfig('wernis_refid'),
                'amount'      => bigintval($amount),
                'purpose'     => encodeString($purpose, false)
        );
@@ -276,9 +283,9 @@ function WERNIS_EXECUTE_PAYOUT ($wdsId, $amount) {
        // Prepare the request data
        $requestData = array(
                'sub_request' => 'send',
-               't_userid'    => getConfig('wernis_refid'),
+               't_uid'       => getConfig('wernis_refid'),
                't_md5'       => getConfig('wernis_pass_md5'),
-               'r_userid'    => bigintval($wdsId),
+               'r_uid'       => bigintval($wdsId),
                'amount'      => bigintval($amount),
                'purpose'     => encodeString($purpose, false)
        );
index ae4a18e..4cce611 100644 (file)
@@ -534,7 +534,7 @@ function adminMenuSelectionBox_DEPRECATED ($mode, $default = '', $defid = '') {
 }
 
 // Wrapper for $_POST and adminSaveSettings
-function adminSaveSettingsFromPostData ($tableName = "_config", $whereStatement = "config=0", $translateComma = array(), $alwaysAdd = false) {
+function adminSaveSettingsFromPostData ($tableName = '_config', $whereStatement = 'config=0', $translateComma = array(), $alwaysAdd = false) {
        // Get the array
        $postData = postRequestArray();
 
@@ -543,7 +543,7 @@ function adminSaveSettingsFromPostData ($tableName = "_config", $whereStatement
 }
 
 // Save settings to the database
-function adminSaveSettings (&$postData, $tableName = "_config", $whereStatement = "config=0", $translateComma = array(), $alwaysAdd = false) {
+function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement = 'config=0', $translateComma = array(), $alwaysAdd = false) {
        // Prepare all arrays, variables
        $DATA = array();
        $skip = false;
index 51f3f15..dbfd24d 100644 (file)
@@ -52,7 +52,7 @@ if (isFormSent()) {
        if (WERNIS_TEST_API()) {
                // Revert german commata
                foreach (array('payout_factor', 'withdraw_factor', 'payout_fee_percent', 'withdraw_fee_percent') as $revert) {
-                       setRequestPostElement('wernis_'.$revert, convertCommaToDot(postRequestElement('wernis_'.$revert)));
+                       setRequestPostElement('wernis_' . $revert, postRequestElement('wernis_' . $revert));
                } // END - if
 
                // Hash the password and remove clear-text
@@ -68,10 +68,6 @@ if (isFormSent()) {
 }  else {
        // Prepare data for template output
        $content = array(
-               'payout_factor'            => translateComma(getConfig('wernis_payout_factor')),
-               'withdraw_factor'          => translateComma(getConfig('wernis_withdraw_factor')),
-               'payout_fee_percent'       => translateComma(getConfig('wernis_payout_fee_percent')),
-               'withdraw_fee_percent'     => translateComma(getConfig('wernis_withdraw_fee_percent')),
                'wernis_payout_active_y'   => '',
                'wernis_payout_active_n'   => '',
                'wernis_withdraw_active_y' => '',
index 56b201c..33ffa15 100644 (file)
@@ -143,7 +143,11 @@ if ((!isGetRequestElementSet('mode')) || (getRequestElement('mode') == 'choose')
        // Is this enougth for a payout?
        if ($points < getConfig('wernis_min_payout')) {
                // No, then abort here
-               loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_MIN_PAYOUT'), translateComma(getConfig('wernis_min_payout'))));
+               loadTemplate('admin_settings_saved', false, sprintf(
+                       getMessage('WERNIS_MEMBER_MIN_PAYOUT'),
+                       translateComma(getConfig('wernis_min_payout')),
+                       translateComma($points)
+               ));
                return;
        } // END - if
 
@@ -222,10 +226,10 @@ if ((isFormSent()) && (isGetRequestElementSet('mode'))) {
        } else {
                // Check input data depending on the mode and execute the requested mode
                switch (getRequestElement('mode')) {
-                       case "withdraw": // Widthdraws WDS66 -> This exchange
+                       case 'withdraw': // Widthdraws WDS66 -> This exchange
                                if (postRequestElement('amount') < getConfig('wernis_min_withdraw')) {
                                        // Not enougth entered!
-                                       loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_withdraw'))));
+                                       loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), translateComma(getConfig('wernis_min_withdraw'))));
                                } else {
                                        // All is fine here so do the withdraw
                                        $success = WERNIS_EXECUTE_WITHDRAW(postRequestElement('wds66_id'), md5(postRequestElement('wds66_password')), postRequestElement('amount'));
@@ -240,7 +244,7 @@ if ((isFormSent()) && (isGetRequestElementSet('mode'))) {
                                                // All done!
                                                loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_WITHDRAW_DONE'));
                                                return;
-                                       } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
+                                       } elseif ((GET_WERNIS_ERROR_CODE() == 'user_failed') || (GET_WERNIS_ERROR_CODE() == 'own_failed') || (GET_WERNIS_ERROR_CODE() == 'amount_failed')) {
                                                // Wrong login data
                                                loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
                                        } else {
@@ -253,7 +257,7 @@ if ((isFormSent()) && (isGetRequestElementSet('mode'))) {
                        case 'payout': // Payout this exchange -> WDS66
                                if (postRequestElement('amount') < getConfig('wernis_min_payout')) {
                                        // Not enougth entered!
-                                       loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_payout'))));
+                                       loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), translateComma(getConfig('wernis_min_payout'))));
                                } elseif (postRequestElement('amount') > $points) {
                                        // Not enougth points left!
                                        loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestElement('amount')), bigintval($points)));