/**
  * Initialize the object one time
  * @return object
  */
 public static function getInstance()
 {
     if (!self::$c_instance) {
         self::$c_instance = new self();
     }
     return self::$c_instance;
 }
<?php

/**
 * Form posting handler
 */
require_once '../../../wp-load.php';
require_once TMM_PAYPAL_PLUGIN_PATH . '/classes/paypalConfig.php';
require_once TMM_PAYPAL_PLUGIN_PATH . '/classes/paypalApi.php';
if (isset($_POST['func']) && $_POST['func'] === 'start') {
    paypalApi::startExpressCheckout();
} else {
    if (isset($_GET['func']) && $_GET['func'] == 'confirm' && isset($_GET['token']) && isset($_GET['PayerID'])) {
        $message_num = 0;
        $paypal_data = paypalApi::confirmExpressCheckout();
        $config = paypalConfig::getInstance();
        if (isset($paypal_data['ACK']) && ($paypal_data['ACK'] == 'Success' || $paypal_data['ACK'] == 'SuccessWithWarning')) {
            $message_num = TMM_Cardealer_User::user_paid_money($paypal_data);
            header('Location: ' . $config->getItem('success_page'));
        } else {
            $message_num = $paypal_data['L_ERRORCODE0'];
            header('Location: ' . $config->getItem('cancel_page') . '?errorcode=' . $message_num);
        }
    } else {
        header('Location: ' . $config->getItem('cancel_page'));
    }
}
Ejemplo n.º 3
0
 /**
  * @param $fields
  * @return mixed
  */
 static function doCurlRequest($fields)
 {
     if (!function_exists('curl_init')) {
         return false;
     }
     $fields_string = http_build_query($fields);
     $config = paypalConfig::getInstance();
     $ch = curl_init();
     if (get_option('paypal_environment') == 'sandbox') {
         curl_setopt($ch, CURLOPT_URL, $config->getItem('paypal_sandbox_api_url'));
     } elseif (get_option('paypal_environment') == 'live') {
         curl_setopt($ch, CURLOPT_URL, $config->getItem('paypal_live_api_url'));
     }
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //curl_setopt($ch, CURLOPT_VERBOSE, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_CAINFO, $config->getItem('curl_certificate_path'));
     $result = curl_exec($ch);
     curl_close($ch);
     parse_str($result, $result);
     return $result;
 }
    /**
     * Admin interface > payments history
     */
    public static function adminHistory()
    {
        global $wpdb;
        $config = paypalConfig::getInstance();
        $params = array();
        $config_saved = false;
        $allowed_statuses = array('success', 'pending', 'failed');
        if (count($_POST) && isset($_POST['status']) && in_array($_POST['status'], $allowed_statuses) && isset($_POST['id']) && is_numeric($_POST['id']) && $_POST['id'] > 0) {
            $config_saved = TRUE;
            $update_data = array('status' => $_POST['status']);
            $where = array('id' => $_POST['id']);
            $update_format = array('%s');
            $wpdb->update('tmm_cars_hccoder_paypal', $update_data, $where, $update_format);
        }
        if (isset($_GET['action']) && $_GET['action'] == 'details' && is_numeric($_GET['id']) && $_GET['id'] > 0) {
            $details = $wpdb->get_row('SELECT tmm_cars_hccoder_paypal.id,
                                tmm_cars_hccoder_paypal.amount,
                                tmm_cars_hccoder_paypal.currency,
                                tmm_cars_hccoder_paypal.packet_id,
                                tmm_cars_hccoder_paypal.status,
                                tmm_cars_hccoder_paypal.firstname,
                                tmm_cars_hccoder_paypal.lastname,
                                tmm_cars_hccoder_paypal.email,
                                tmm_cars_hccoder_paypal.description,
                                tmm_cars_hccoder_paypal.summary,
                                tmm_cars_hccoder_paypal.created
                              FROM
                                tmm_cars_hccoder_paypal
                              WHERE
                                tmm_cars_hccoder_paypal.id = ' . (int) $_GET['id']);
            $path = 'adminhistorydetails';
            $params['details'] = $details;
        } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id']) && $_GET['id'] > 0) {
            $details = $wpdb->get_row('SELECT
                                tmm_cars_hccoder_paypal.status
                              FROM
                                tmm_cars_hccoder_paypal
                              WHERE
                                tmm_cars_hccoder_paypal.id = ' . (int) $_GET['id']);
            $path = 'adminhistoryedit';
            $params['details'] = $details;
        } else {
            $limit = $config->getItem('history_page_pagination_limit');
            $pagenum = 0;
            if (isset($_REQUEST['paged'])) {
                $pagenum = (int) $_REQUEST['paged'] - 1;
                if ($pagenum < 0) {
                    $pagenum = 0;
                }
            }
            $order = 'DESC';
            if (isset($_REQUEST['order'])) {
                $order = $_REQUEST['order'];
            }
            $orderby = 'created';
            if (isset($_REQUEST['orderby'])) {
                $orderby = $_REQUEST['orderby'];
            }
            $user_email = '';
            if (isset($_REQUEST['user_email'])) {
                $user_email = $_REQUEST['user_email'];
                $_GET['user_email'] = $user_email;
            }
            $year = -1;
            if (isset($_REQUEST['y'])) {
                $year = $_REQUEST['y'];
                $_GET['y'] = $year;
            }
            $month = -1;
            if (isset($_REQUEST['m'])) {
                $month = $_REQUEST['m'];
                $_GET['m'] = $month;
            }
            //***
            $time_from = 0;
            $time_to = 0;
            if ($year > -1 or $month > -1) {
                if ($month > -1 and $year == -1) {
                    $year = intval(date('Y'));
                }
            }
            if ($month == -1) {
                //see for full year
                $time_from = mktime(0, 0, 0, 1, 1, $year);
                $time_to = mktime(0, 0, 0, 12, 31, $year);
            }
            if ($month != -1) {
                //see for full year
                $time_from = mktime(0, 0, 0, $month + 1, 1, $year);
                $time_to = mktime(0, 0, 0, $month + 1, 31, $year);
            }
            $rows_count = $wpdb->get_var('SELECT COUNT(*)
                   FROM tmm_cars_hccoder_paypal
				   WHERE 1=1 ' . ($time_from > 0 ? ' ' . 'AND created>=' . $time_from . ' ' . 'AND created<=' . $time_to : '') . ' ' . (!empty($user_email) ? 'AND email LIKE "%' . $user_email . '%"' : ''));
            $rows = $wpdb->get_results('SELECT tmm_cars_hccoder_paypal.id,
                                tmm_cars_hccoder_paypal.amount,
                                tmm_cars_hccoder_paypal.currency,
                                tmm_cars_hccoder_paypal.packet_id,
                                tmm_cars_hccoder_paypal.status,
                                tmm_cars_hccoder_paypal.firstname,
                                tmm_cars_hccoder_paypal.lastname,
                                tmm_cars_hccoder_paypal.email,
                                tmm_cars_hccoder_paypal.description,
                                tmm_cars_hccoder_paypal.summary,
                                tmm_cars_hccoder_paypal.created
                              FROM
                                tmm_cars_hccoder_paypal WHERE 1=1 ' . ($time_from > 0 ? ' ' . 'AND created>=' . $time_from . ' ' . 'AND created<=' . $time_to : '') . ' ' . (!empty($user_email) ? 'AND email LIKE "%' . $user_email . '%"' : '') . '
                              ORDER BY
                                tmm_cars_hccoder_paypal.' . $orderby . ' ' . $order . ' LIMIT ' . $pagenum * $limit . ',' . $limit);
            $path = 'adminhistory';
            if (isset($details)) {
                $params['details'] = $details;
            }
            $params['limit'] = $limit;
            $params['pagenum'] = $pagenum + 1;
            $params['order'] = $order;
            $params['rows_count'] = $rows_count;
            $params['rows'] = $rows;
            $params['user_email'] = $user_email;
            $params['year'] = $year;
            $params['month'] = $month;
        }
        $params['config_saved'] = $config_saved;
        if (isset($path)) {
            self::includeView($path, $params);
        }
    }
Ejemplo n.º 5
0
/**
 * Check currency.
 * If currency is not supported by Paypal convert it to default
 */
function tmm_paypal_currency($currency, $amount)
{
    $config = paypalConfig::getInstance();
    if (!in_array($currency, $config->getItem('supported_currencies'))) {
        $def_currency = get_option('paypal_currency');
        if ($def_currency) {
            $currency = $def_currency;
            $new_amount = tmm_get_currency_rate($amount, $currency, $def_currency);
            if ((double) $new_amount) {
                $amount = $new_amount;
                $currency = $def_currency;
            }
        }
    }
    return array('currency' => $currency, 'amount' => $amount);
}