/**
  * return process api hook, link back to site after payment is made	
  * Note: as Worldpay Gateway doesn't support custom thankyou url redirection, we make use of resultY.html/resultC.html 
  * template html MC_success/MC_error tags to print thankyou page url. The user will need to click the respective links
  * to get redirected back to the site.
  * Check payment form creation for success/error url and parameters details.  
  *
  */
 function process_return()
 {
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // check and show message
     //if((isset($_POST['rawAuthCode']) && !empty($_POST['rawAuthCode'])) || (isset($_POST['M_custom']) && !empty($_POST['M_custom']))){
     if (isset($_POST['rawAuthCode']) && !empty($_POST['rawAuthCode']) || ($_REQUEST['transtatus'] == 'success' && (isset($_REQUEST['M_custom']) && !empty($_REQUEST['M_custom'])) || isset($_REQUEST['transid']) && !empty($_REQUEST['transid']))) {
         if (isset($_REQUEST['M_custom'])) {
             //not sure M_custom is available on thank you page
             $trans_id = $_REQUEST['M_custom'];
         } elseif (isset($_REQUEST['transid'])) {
             $trans_id = mgm_decode_id($_REQUEST['transid']);
         }
         // process notify, internally called
         if (isset($this->setting['shopper_response']) && bool_from_yn($this->setting['shopper_response'])) {
             // track
             $this->webhook_called_by = 'self';
             // process
             $this->process_notify();
         }
         // redirect as success if not already redirected
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($trans_id));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($trans_id);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($trans_id);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // meta redirect for wp only
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode('WorldPay data error')), $this->_get_thankyou_url()));
     }
 }
/**
 * get payment processed page html
 *
 * @param void
 * @return string
 * @since 1.5
 */
function mgm_get_payment_processed_page_html()
{
    // home url
    $home_url = trailingslashit(get_option('siteurl'));
    // current module
    $module = mgm_request_var('module', '', true);
    // check
    if (!mgm_is_valid_module($module) || empty($module)) {
        // redirect
        mgm_redirect($home_url);
    }
    // init
    $html = '';
    // refresh wait time
    $refresh_wait_time = 5;
    //in seconds
    // redirect url
    $redirect_url = '';
    // redirect
    $do_redirect = true;
    // refresh header for post redirecr
    if (isset($_GET['post_redirect'])) {
        // redirect url
        $redirect_url = strip_tags($_GET['post_redirect']);
    } elseif (isset($_GET['register_redirect'])) {
        // redirect url, if 1/true, redirect to profile, else its register & redirect url
        if ($_GET['register_redirect'] != 1) {
            $redirect_url = strip_tags($_GET['register_redirect']);
        } else {
            // auto login
            $system_obj = mgm_get_class('system');
            //issue# 1392
            $current_user_id = get_current_user_id();
            // check if set
            if ($autologin_redirect_url = $system_obj->get_setting('autologin_redirect_url')) {
                $page_title = '';
                $redirect_url = $autologin_redirect_url;
                //short code support
                if (!empty($current_user_id)) {
                    $user = get_userdata($current_user_id);
                    $redirect_url = str_replace('[username]', $user->user_login, $redirect_url);
                }
            } elseif (mgm_get_user_package_redirect_url($current_user_id) && $current_user_id) {
                $page_title = '';
                $redirect_url = mgm_get_user_package_redirect_url($current_user_id);
            } else {
                $page_title = 'Profile';
                $redirect_url = mgm_get_custom_url('profile');
            }
        }
        // check not logged in, #948 paypal fails to redirect
        if (!is_user_logged_in()) {
            // user login
            if (isset($_GET['trans_ref'])) {
                // re construct redirect url
                $redirect_url = mgm_get_custom_url('login', false, array('trans_ref' => strip_tags($_GET['trans_ref']), 'auto_login' => true, 'redirect_to' => $redirect_url));
            }
        }
    }
    // check and set
    if (!empty($redirect_url) && $do_redirect) {
        // alter
        $redirect_url = apply_filters('mgm_register_redirect', $redirect_url);
        // no headers
        if (!headers_sent()) {
            @header(sprintf('Refresh: %d;url=%s', $refresh_wait_time, $redirect_url));
        } else {
            $html .= sprintf('<script language="javascript">window.setTimeout(function(){window.location.href="%s";}, %d)</script>', $redirect_url, (int) $refresh_wait_time * 5);
        }
    }
    // module object
    $module_object = mgm_get_module($module, 'payment');
    // [domain]/subscribe/?method=payment_processed&module=mgm_paypal&status=success
    // [domain]/subscribe/?method=payment_processed&module=mgm_paypal&status=cancel
    // status and message
    $arr_shortcodes = array('transaction_amount' => '');
    // check
    if (!isset($_GET['status']) || $_GET['status'] == 'success') {
        // mgm_replace_oldlinks_with_tag is a patch for replacing the old link
        $message = $module_object->setting['success_message'] ? mgm_replace_oldlinks_with_tag($module_object->setting['success_message'], 'payment_success_message') : $system_obj->get_template('payment_success_message', array(), true);
        // get price
        if (isset($_GET['trans_ref'])) {
            // tarns
            $_GET['trans_ref'] = mgm_decode_id(strip_tags($_GET['trans_ref']));
            // get transaction data
            $trans = mgm_get_transaction($_GET['trans_ref']);
            // set amount
            if ($trans['module'] == 'manualpay') {
                $arr_shortcodes['transaction_amount'] = $trans['data']['cost'] . ' ' . $trans['data']['currency'];
            }
            // update googe analytics:
            $html .= apply_filters('mgm_payment_processed_page_analytics', $trans);
            // @todo, callback in template function
            // mgm_update_google_analytics($trans);	deprecated, use hook
        }
    } else {
        if (!isset($_GET['status']) || $_GET['status'] == 'cancel') {
            // set message
            $message = __('You have cancelled the transaction.', 'mgm');
        } else {
            // mgm_replace_oldlinks_with_tag is a patch for replacing the old link
            $message = $module_object->setting['failed_message'] ? mgm_replace_oldlinks_with_tag($module_object->setting['failed_message'], 'payment_failed_message') : $system_obj->get_template('payment_failed_message', array(), true);
        }
    }
    // parse short codes:
    // [transaction_amount] = amount paid
    foreach ($arr_shortcodes as $code => $value) {
        $message = str_replace('[' . $code . ']', $value, $message);
    }
    // html
    $html .= mgm_stripslashes_deep(mgm_get_message_template($message));
    // get error
    if (isset($_GET['errors'])) {
        // get errors
        $errors = explode('|', strip_tags($_GET['errors']));
        // html
        $html .= sprintf('<h3> %s </h3><div><ul>', __('Messages', 'mgm'));
        // loop
        foreach ($errors as $error) {
            $html .= sprintf('<li> %s </li>', $error);
        }
        // end
        $html .= '</ul></div>';
    }
    // auto redirect to post purchased
    if (isset($_GET['post_redirect'])) {
        // message
        $m = sprintf(__('You will be automatically redirected to the post you purchased within %d seconds. Please <a href="%s"> click here </a> to go to the page. ', 'mgm'), $refresh_wait_time, strip_tags($_GET['post_redirect']));
        // set
        $html .= sprintf('<b>%s</b>', $m);
    } elseif (isset($_GET['register_redirect'])) {
        // auto login redirect
        // message
        $m = sprintf(__('You will be automatically redirected to your %s page within %d seconds. Please <a href="%s"> click here </a> to go to the page. ', 'mgm'), $_GET['register_redirect'] == 1 ? __($page_title, 'mgm') : __('Post', 'mgm'), $refresh_wait_time, $redirect_url);
        // set
        $html .= sprintf('<b>%s</b>', $m);
    }
    // return
    return apply_filters('mgm_payment_processed_page_html', $html);
}
Esempio n. 3
0
 function process_return()
 {
     // log
     // mgm_log('process_return free REQUEST : '.print_r($_REQUEST,true));
     //mgm_pr($_REQUEST); die;
     // only save once success, there may be multiple try
     if (isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) {
         // id
         $transid = mgm_decode_id(mgm_get_var('transid', '', true));
         // process
         $this->process_notify($transid);
         // query arg
         $query_arg = array('status' => 'success');
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_REQUEST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // log
         mgm_log($query_arg, __FUNCTION__);
         // login autoredirection
         if (is_numeric($transid)) {
             // update transaction
             mgm_update_transaction_status($transid, MGM_STATUS_ACTIVE, '');
             // is a register redirect?
             $register_redirect = $this->_auto_login($transid);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
         }
         // log
         mgm_log($query_arg, __FUNCTION__);
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // teat as error
         $errors = 'error in processing your request';
         // redirect
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
     }
 }
 /**
  * read transacrion id from get/post
  */
 function _read_transaction_id()
 {
     // check post
     if (isset($_POST['tran_id']) && (int) $_POST['tran_id'] > 0) {
         // set
         return $tran_id = (int) $_POST['tran_id'];
     } else {
         if (isset($_GET['tran_id'])) {
             // encoded
             // set
             return $tran_id = mgm_decode_id(strip_tags($_GET['tran_id']));
         } else {
             if (isset($_GET['trans_ref'])) {
                 // encoded
                 // set
                 return $tran_id = mgm_decode_id(strip_tags($_GET['trans_ref']));
             }
         }
     }
     // error
     return false;
 }
/**
 * try auto login if bypassed
 */
function mgm_try_auto_login()
{
    // check
    if (isset($_GET['auto_login']) && isset($_GET['trans_ref']) && isset($_GET['redirect_to'])) {
        // read transaction id
        if ($id = mgm_decode_id(strip_tags($_GET['trans_ref']))) {
            // process login
            if (mgm_auto_login($id)) {
                // no headers
                if (!headers_sent()) {
                    @header(sprintf('Refresh: %d;url=%s', 5, strip_tags($_GET['redirect_to'])));
                } else {
                    return sprintf('<script language="javascript">window.setTimeout(function(){window.location.href="%s";}, %d)</script>', strip_tags($_GET['redirect_to']), 5 * 5);
                }
                // exit;
                exit;
            }
        }
    }
}