Wernis extension added
[mailer.git] / inc / libs / wernis_functions.php
index 812fbf20ec0a60dd94ebe5cc12c0f183ae81514d..ae8ed57e564828690e966d5b168488d99e497471 100644 (file)
@@ -209,7 +209,7 @@ function WERNIS_TEST_API () {
 }
 
 // Widthdraw this amount
-function WERNIS_EXECUTE_WITHDRAW($userId, $userMd5, $amount) {
+function WERNIS_EXECUTE_WITHDRAW ($wdsId, $userMd5, $amount) {
        global $_CONFIG;
        $result = false;
 
@@ -220,7 +220,7 @@ function WERNIS_EXECUTE_WITHDRAW($userId, $userMd5, $amount) {
        // Prepare the request data
        $requestData = array(
                'sub_request'   => "receive",
-               't_uid'                 => bigintval($userId),
+               't_uid'                 => bigintval($wdsId),
                't_md5'                 => $userMd5,
                'r_uid'                 => $_CONFIG['wernis_refid'],
                'amount'                => bigintval($amount),
@@ -233,9 +233,15 @@ function WERNIS_EXECUTE_WITHDRAW($userId, $userMd5, $amount) {
        if ($return['status'] == "OK") {
                // All fine!
                $result = true;
+
+               // Log the transfer
+               WERNIS_LOG_TRANSFER($wdsId, $amount, 'IN');
        } else {
                // Status failture text
                WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
+
+               // Log the transfer
+               WERNIS_LOG_TRANSFER($wdsId, $amount, 'FAILED', $return['message'], $return['status']);
        }
 
        // Return result
@@ -244,7 +250,7 @@ function WERNIS_EXECUTE_WITHDRAW($userId, $userMd5, $amount) {
 
 
 // Payout this amount
-function WERNIS_EXECUTE_PAYOUT($userId, $userMd5, $amount) {
+function WERNIS_EXECUTE_PAYOUT ($wdsId, $userMd5, $amount) {
        global $_CONFIG;
        $result = false;
 
@@ -255,7 +261,7 @@ function WERNIS_EXECUTE_PAYOUT($userId, $userMd5, $amount) {
        // Prepare the request data
        $requestData = array(
                'sub_request'   => "send",
-               't_uid'                 => bigintval($userId),
+               't_uid'                 => bigintval($wdsId),
                't_md5'                 => $userMd5,
                'r_uid'                 => $_CONFIG['wernis_refid'],
                'amount'                => bigintval($amount),
@@ -268,9 +274,15 @@ function WERNIS_EXECUTE_PAYOUT($userId, $userMd5, $amount) {
        if ($return['status'] == "OK") {
                // All fine!
                $result = true;
+
+               // Log the transfer
+               WERNIS_LOG_TRANSFER($wdsId, $amount, 'OUT');
        } else {
                // Status failture text
                WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
+
+               // Log the transfer
+               WERNIS_LOG_TRANSFER($wdsId, $amount, 'FAILED', $return['message'], $return['status']);
        }
 
        // Return result
@@ -278,7 +290,7 @@ function WERNIS_EXECUTE_PAYOUT($userId, $userMd5, $amount) {
 }
 
 // Translate the status IN/OUT
-function WERNIS_TRANSFER_STATUS($status) {
+function WERNIS_TRANSFER_STATUS ($status) {
        // Default status
        $return = sprintf(WERNIS_STATUS_UNKNWOWN, $status);
        switch ($status) {
@@ -289,11 +301,21 @@ function WERNIS_TRANSFER_STATUS($status) {
                case "OUT": // Payout
                        $return = WERNIS_STATUS_PAYOUT;
                        break;
+
+               case "FAILED": // Payout
+                       $return = WERNIS_STATUS_FAILED;
+                       break;
        }
 
        // Return the status
        return $return;
 }
 
+function WERNIS_LOG_TRANSFER ($wdsId, $amount, $type = 'FAILED', $message = null, $status = null) {
+       // Register this wernis movement
+       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_wernis (`userid`, `wernis_account`, `wernis_amount`, `wernis_timestamp`, `wernis_type`, `wernis_api_message`, `wernis_api_status`) VALUES(%d, %d, %d, UNIX_TIMESTAMP(), '%s', '%s', '%s')",
+               array($GLOBALS['userid'], bigintval($wdsId), bigintval($amount), $type, $message, $status), __FILE__, __LINE__);
+}
+
 //
 ?>