403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.188.161.182
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/jenniferflocom/www/wp-content/plugins/mstore-api/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/jenniferflocom/www/wp-content/plugins/mstore-api/controllers/flutter-tera-wallet.php
<?php
require_once(__DIR__ . '/flutter-base.php');

/*
 * Base REST Controller for flutter
 *
 * @since 1.4.0
 *
 * @package Tera Wallet
 */

class FlutterTeraWallet extends FlutterBaseController
{
    /**
     * Endpoint namespace
     *
     * @var string
     */
    protected $namespace = 'api/flutter_tera_wallet';

    /**
     * Register all routes releated with stores
     *
     * @return void
     */
    public function __construct()
    {
        add_action('rest_api_init', array($this, 'register_flutter_tera_wallet_routes'));
    }

    public function register_flutter_tera_wallet_routes()
    {
        register_rest_route($this->namespace, '/transactions', array(
            array(
                'methods' => "GET",
                'callback' => array($this, 'get_transactions'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/balance', array(
            array(
                'methods' => "GET",
                'callback' => array($this, 'get_balance'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/transfer', array(
            array(
                'methods' => "POST",
                'callback' => array($this, 'transfer'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/check_recharge', array(
            array(
                'methods' => "POST",
                'callback' => array($this, 'check_recharge'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/process_payment', array(
            array(
                'methods' => "POST",
                'callback' => array($this, 'process_payment'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/partial_payment', array(
            array(
                'methods' => "POST",
                'callback' => array($this, 'partial_payment'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));

        register_rest_route($this->namespace, '/check_email', array(
            array(
                'methods' => "POST",
                'callback' => array($this, 'check_email'),
                'permission_callback' => function () {
                    return parent::checkApiPermission();
                }
            ),
        ));
    }

    private function getUserInfo($user_id, &$cachedUsers = [])
    {
        if (!isset($cachedUsers[$user_id])) {
            $user = get_userdata($user_id);
            if ($user) {
                $cachedUsers[$user_id] = array(
                    "id" => $user->ID,
                    "username" => $user->user_login,
                    "nicename" => $user->user_nicename,
                    "email" => $user->user_email,
                    "displayname" => $user->display_name,
                    "firstname" => $user->user_firstname,
                    "lastname" => $user->last_name,
                    "nickname" => $user->nickname,
                    "description" => $user->user_description,
                );
            }
        }
        return $cachedUsers[$user_id];
    }

    public function get_transactions($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }
            $page = isset($request['page']) ? $request['page'] : 0;
            $length = isset($request['length']) ? $request['length'] : 10;
            $page = $page * $length;
            $args = array(
                'limit' => "$page, $length",
                'user_id' => $user_id
            );
            $data = get_wallet_transactions($args);

            $cachedUsers = [];
            foreach ($data as &$item) {
                $item->user = $this->getUserInfo($item->user_id, $cachedUsers);
                $item->created_by = $this->getUserInfo($item->created_by, $cachedUsers);
                unset($item->user_id);
            }

            return $data;
        } else {
            return parent::sendError("no_permission", "You need to add User-Cookie in header request", 400);
        }
    }


    public function get_balance($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }
            $data = woo_wallet()->wallet->get_wallet_balance($user_id, 'Edit');
            return $data;
        } else {
            return parent::sendError("no_permission", "You need to add User-Cookie in header request", 400);
        }
    }

    public function transfer($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }

            $json = file_get_contents('php://input');
            $params = json_decode($json, TRUE);
            $user = get_user_by('email', $params['to']);
            if (!$user) {
                return parent::sendError("user_not_found", "The user is not found", 400);
            }
            wp_set_current_user($user_id);
            $_POST['woo_wallet_transfer_user_id'] = $user->id;
            $_POST['woo_wallet_transfer_amount'] = $params['amount'];
            $_POST['woo_wallet_transfer_note'] = sanitize_text_field($params['note']);
            $_POST['woo_wallet_transfer'] = wp_create_nonce('woo_wallet_transfer');


            include_once(WOO_WALLET_ABSPATH . 'includes/class-woo-wallet-frontend.php');
            return Woo_Wallet_Frontend::instance()->do_wallet_transfer();
        } else {
            return parent::sendError("no_permission", "You need to add User-Cookie in header request", 400);
        }
    }

    public function check_recharge($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $json = file_get_contents('php://input');
        $params = json_decode($json, TRUE);
        $_POST['woo_wallet_topup'] = wp_create_nonce('woo_wallet_topup');
        include_once(WOO_WALLET_ABSPATH . 'includes/class-woo-wallet-frontend.php');
        $wallet_product = get_wallet_rechargeable_product();

        $check = Woo_Wallet_Frontend::instance()->is_valid_wallet_recharge_amount($params['amount']);

        if ($check['is_valid'] == false) {
            return $check;
        }
        $api = new WC_REST_Products_Controller();
        $req = new WP_REST_Request('GET');
        $req->set_query_params(["id" => $wallet_product->id]);
        $res = $api->get_item($req);
        if (is_wp_error($res)) {
            return $res;
        } else {
            return $res->get_data();
        }
    }

    public function process_payment($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $json = file_get_contents('php://input');
        $params = json_decode($json, TRUE);
        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }
            wp_set_current_user($user_id);
            $order = wc_get_order($params['order_id']);
            if (($order->get_total('edit') > woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), 'edit')) && apply_filters('woo_wallet_disallow_negative_transaction', (woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), 'edit') <= 0 || $order->get_total('edit') > woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), 'edit')), $order->get_total('edit'), woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), 'edit'))) {
                $error = sprintf(__('Your wallet balance is low. Please add %s to proceed with this transaction.', 'woo-wallet'), $order->get_total('edit') - woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), 'edit'));
                return parent::sendError("wallet_error", $error, 400);
            }
            if($order->get_payment_method() == "wallet"){
				$wallet_response = woo_wallet()->wallet->debit(get_current_user_id(), $order->get_total('edit'), apply_filters('woo_wallet_order_payment_description', __('For order payment #', 'woo-wallet') . $order->get_order_number(), $order));
				if ($wallet_response) {
                    $order->set_transaction_id( $wallet_response );
					do_action( 'woo_wallet_payment_processed', $params['order_id'], $wallet_response );
					$order->save();

                    // Reduce stock levels.
                    wc_reduce_stock_levels( $params['order_id'] );

                    // Complete order payment.
                    $order->payment_complete();
				}else{
                    return parent::sendError("error_debit", "Something went wrong with processing payment please try again.", 400);
                }
			}else{
				$order->payment_complete();
			}

            // Return thankyou redirect
            return array(
                'result' => 'success',
            );
        } else {
            return parent::sendError("no_permission", "You need to add User-Cookie in header request", 400);
        }
    }

    public function partial_payment($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $json = file_get_contents('php://input');
        $params = json_decode($json, TRUE);
        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }
            $order = wc_get_order($params['order_id']);
            if ($order) {
                if ($order->get_customer_id() == $user_id) {
                    wp_set_current_user($user_id);
                    woo_wallet()->wallet->wallet_partial_payment($params['order_id']);
                    return array(
                        'result' => 'success',
                    );
                } else {
                    return parent::sendError("no_permission", "No Permission", 400);
                }
            } else {
                return parent::sendError("not_found", "Order not found", 400);
            }
        } else {
            return parent::sendError("no_permission", "You need to add User-Cookie in header request", 400);
        }
    }

    public function check_email($request)
    {
        if (!is_plugin_active('woo-wallet/woo-wallet.php')) {
            return parent::sendError("invalid_plugin", "You need to install TeraWallet plugin to use this api", 404);
        }

        $json = file_get_contents('php://input');
        $params = json_decode($json, TRUE);
        $cookie = $request->get_header("User-Cookie");
        if (isset($cookie) && $cookie != null) {
            $user_id = validateCookieLogin($cookie);
            if (is_wp_error($user_id)) {
                return $user_id;
            }

            $user = get_user_by('email', $params['email']);
            if ($user) {
                $avatar = get_user_meta($user->ID, 'user_avatar', true);
                if (!isset($avatar) || $avatar == "" || is_bool($avatar)) {
                    $avatar = get_avatar_url($user->ID);
                } else {
                    $avatar = $avatar[0];
                }
                return array(
                    "id" => $user->ID,
                    "username" => $user->user_login,
                    "nicename" => $user->user_nicename,
                    "email" => $user->user_email,
                    "url" => $user->user_url,
                    "displayname" => $user->display_name,
                    "firstname" => $user->user_firstname,
                    "lastname" => $user->last_name,
                    "nickname" => $user->nickname,
                    "description" => $user->user_description,
                    "avatar" => $avatar,
                );
            } else {
                return parent::sendError("not_found", "The user is not found", 400);
            }
        }

    }
}

new FlutterTeraWallet;

Youez - 2016 - github.com/yon3zu
LinuXploit