コード例 #1
0
/**
 * generate subscription buttons for first time payment
 *
 * @param array userdata
 * @retun string html output
 */
function mgm_get_subscription_buttons($user = false)
{
    global $wpdb;
    // user
    if ($user === FALSE) {
        // query string
        $user = mgm_get_user_from_querystring();
    }
    // validate
    if (!$user->ID) {
        return __('No such user', 'mgm');
    }
    // packs
    $packs_obj = mgm_get_class('subscription_packs');
    // mgm member
    $member = mgm_get_member($user->ID);
    // check subscription
    if (isset($_GET['subs'])) {
        // init
        $html = '';
        // get
        $subs_pack = mgm_decode_package(strip_tags($_GET['subs']));
        extract($subs_pack);
        // validate
        $pack = $packs_obj->validate_pack($cost, $duration, $duration_type, $membership_type, $pack_id);
        // error
        if ($pack === false) {
            // no more process
            return sprintf(__('Invalid Data Passed. <a href="%1$s">Try again.</a>', 'mgm'), add_query_arg(array('username' => $user->user_login), mgm_get_custom_url('transactions')));
        }
        // is using a coupon ? reset prices
        mgm_get_register_coupon_pack($member, $pack);
        //issue #1468
        $notify_user = isset($_GET['notify_user']) ? $_GET['notify_user'] : false;
        // get
        $system_obj = mgm_get_class('system');
        // check
        if (bool_from_yn($system_obj->get_setting('enable_new_user_email_notifiction_after_user_active')) && !$notify_user) {
            $notify_user = true;
        }
        // get active modules
        $a_payment_modules = mgm_get_class('system')->get_active_modules('payment');
        // free | trial with zero cost | zero coupons |other membership with free module active	-issue #1072 added -manualpay check
        if ((double) $pack['cost'] == 0.0 && (isset($pack['coupon_id']) || in_array($membership_type, array('free', 'trial')) || in_array('mgm_free', (array) $pack['modules']) && !in_array('mgm_manualpay', (array) $pack['modules']))) {
            // payments url
            $payments_url == mgm_get_custom_url('transactions');
            // module
            $modules = array('mgm_' . $membership_type);
            // other
            $modules[] = $membership_type == 'free' ? 'mgm_trial' : 'mgm_free';
            // init
            $module = '';
            // check if mod available
            foreach ($modules as $mod) {
                // check
                if (in_array($mod, $a_payment_modules)) {
                    $module = $mod;
                    break;
                }
            }
            // exit
            if (!$module) {
                // return
                return __('No Free module active, please activate Trial or Free module.', 'mgm');
                exit;
            }
            // redirect
            $redirector = strip_tags($_GET['redirector']);
            // get object
            $mod_obj = mgm_get_module($module, 'payment');
            // tran options
            $tran_options = array('is_registration' => true, 'user_id' => $user->ID, 'notify_user' => $notify_user);
            // is register & purchase
            if (isset($_GET['post_id'])) {
                $tran_options['post_id'] = (int) strip_tags($_GET['post_id']);
            }
            // is register & purchase postpack
            if (isset($_GET['postpack_post_id']) && isset($_GET['postpack_id'])) {
                $tran_options['postpack_post_id'] = (int) strip_tags($_GET['postpack_post_id']);
                $tran_options['postpack_id'] = (int) strip_tags($_GET['postpack_id']);
            }
            // tran id
            $transid = mgm_add_transaction($pack, $tran_options);
            // attempt to redirect to the processor.
            $redirect = add_query_arg(array('method' => 'payment_return', 'module' => $module, 'custom' => $user->ID . '_' . $duration . '_' . $duration_type . '_' . $pack_id, 'redirector' => $redirector, 'transid' => mgm_encode_id($transid)), $payments_url);
            // redirect
            if (!headers_sent()) {
                @header('location: ' . $redirect);
            }
            // js redirect
            $html .= sprintf('<script type="text/javascript">window.location = "%s";</script><div>%s</div>', $redirect, $packs_obj->get_pack_desc($pack));
        } else {
            // paid subscription
            // init
            $payment_modules = array();
            // when active
            if ($a_payment_modules) {
                // loop
                foreach ($a_payment_modules as $payment_module) {
                    // not trial
                    if (in_array($payment_module, array('mgm_free', 'mgm_trial'))) {
                        continue;
                    }
                    // modules
                    if (isset($pack['modules']) && !in_array($payment_module, (array) $pack['modules'])) {
                        continue;
                    }
                    // store
                    $payment_modules[] = $payment_module;
                }
            }
            // check
            if (count($payment_modules) == 0) {
                // error
                $html .= sprintf('<div>%s</div>', __('No active payment module', 'mgm'));
            } else {
                //issue #1072
                if ((double) $pack['cost'] == 0.0 && in_array('mgm_manualpay', (array) $pack['modules'])) {
                    // pack desc
                    $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', $packs_obj->get_pack_desc($pack));
                    // coupon
                    if (isset($member->coupon['id'])) {
                        $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', sprintf(__('Using Coupon "%s" - %s', 'mgm'), $member->coupon['name'], $member->coupon['description']));
                    }
                    // html
                    $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', __('Please Select from Available Payment Gateways', 'mgm'));
                    // tran id
                    $tran_id = 0;
                    // generate modules
                    foreach ($payment_modules as $payment_module) {
                        // check
                        if ($payment_module == 'mgm_manualpay') {
                            // get obj
                            $mod_obj = mgm_get_module($payment_module, 'payment');
                            // create transaction
                            if ($tran_id == 0) {
                                // set
                                // tran options
                                $tran_options = array('is_registration' => true, 'user_id' => $user->ID, 'notify_user' => $notify_user);
                                // is register & purchase
                                if (isset($_GET['post_id'])) {
                                    $tran_options['post_id'] = (int) strip_tags($_GET['post_id']);
                                }
                                // is register & purchase postpack
                                if (isset($_GET['postpack_post_id']) && isset($_GET['postpack_id'])) {
                                    $tran_options['postpack_post_id'] = (int) strip_tags($_GET['postpack_post_id']);
                                    $tran_options['postpack_id'] = (int) strip_tags($_GET['postpack_id']);
                                }
                                // create
                                // $tran_id = $mod_obj->_create_transaction($pack, $tran_options);
                                $tran_id = mgm_add_transaction($pack, $tran_options);
                            }
                            // html
                            $html .= sprintf('<div>%s</div>', $mod_obj->get_button_subscribe(array('pack' => $pack, 'tran_id' => $tran_id)));
                        }
                    }
                } else {
                    // pack desc
                    $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', $packs_obj->get_pack_desc($pack));
                    // coupon
                    if (isset($member->coupon['id'])) {
                        $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', sprintf(__('Using Coupon "%s" - %s', 'mgm'), $member->coupon['name'], $member->coupon['description']));
                    }
                    // html
                    $html .= sprintf('<div class="mgm_get_subs_btn" >%s</div>', __('Please Select from Available Payment Gateways', 'mgm'));
                    // tran id
                    $tran_id = 0;
                    // generate modules
                    foreach ($payment_modules as $payment_module) {
                        // get obj
                        $mod_obj = mgm_get_module($payment_module, 'payment');
                        // create transaction
                        if ($tran_id == 0) {
                            // set
                            // tran options
                            $tran_options = array('is_registration' => true, 'user_id' => $user->ID, 'notify_user' => $notify_user);
                            // is register & purchase
                            if (isset($_GET['post_id'])) {
                                $tran_options['post_id'] = (int) strip_tags($_GET['post_id']);
                            }
                            // is register & purchase postpack
                            if (isset($_GET['postpack_post_id']) && isset($_GET['postpack_id'])) {
                                $tran_options['postpack_post_id'] = (int) strip_tags($_GET['postpack_post_id']);
                                $tran_options['postpack_id'] = (int) strip_tags($_GET['postpack_id']);
                            }
                            // create
                            // $tran_id = $mod_obj->_create_transaction($pack, $tran_options);
                            $tran_id = mgm_add_transaction($pack, $tran_options);
                        }
                        // html
                        $html .= sprintf('<div>%s</div>', $mod_obj->get_button_subscribe(array('pack' => $pack, 'tran_id' => $tran_id)));
                    }
                }
            }
        }
        // return
        return $html;
    }
    // error
    return '';
}
コード例 #2
0
 /**
  * API helper method get credit card page html
  *
  * @param array $user
  * @param array $tran
  * @param string $html_type (div|table)
  * @return string $html
  */
 function _get_ccfields($user = NULL, $tran = NULL, $html_type = 'div')
 {
     // data
     $data = array();
     // name, amount
     $data['name'] = $data['billing_info'] = $purchase_desc = '';
     // address
     $address_fields = array();
     // user id
     if (isset($user->ID) && (int) $user->ID > 0) {
         // name
         $data['name'] = isset($user->first_name) && isset($user->last_name) ? mgm_str_concat($user->first_name, $user->last_name) : $user->display_name;
         // member
         $member = mgm_get_member($user->ID);
         // packs
         $packs_obj = mgm_get_class('subscription_packs');
         //issue #806
         // pack
         if (isset($tran['data']['pack_id']) && !empty($tran['data']['pack_id'])) {
             $pack_id = $tran['data']['pack_id'];
         } elseif (isset($tran['data']['id']) && !empty($tran['data']['id'])) {
             //Issue #1058
             $pack_id = $tran['data']['id'];
         } else {
             $pack_id = $member->pack_id;
         }
         $pack = $packs_obj->get_pack($pack_id);
         // using coupon - issue #1501
         if (isset($tran['data']['subscription_option']) && $tran['data']['subscription_option'] == 'create') {
             mgm_get_register_coupon_pack($member, $pack);
         }
         // pack desc
         $purchase_desc = sprintf('<div class="ccfields_pack_desc">%s</div>', $packs_obj->get_pack_desc($pack));
         // buypost
         if (isset($tran['payment_type']) && $tran['payment_type'] == 'post_purchase') {
             $purchase_desc = $tran['data']['item_name'] . ' [' . $tran['data']['cost'] . ' ' . $tran['data']['currency'] . ']';
         }
     }
     // address fields
     $address_fields = $this->_get_address_fields($user, 'both');
     // cancel
     $data['cancel_url'] = $this->_get_endpoint('cancel');
     // head
     $html = $purchase_desc;
     // billing_info
     if (!empty($address_fields['fields'])) {
         // get mgm_form_fields generator
         $form_fields = new mgm_form_fields();
         // info
         $billing_info = sprintf('<h2>%s</h2><br>', __('Billing Info', 'mgm'));
         // check
         if (isset($address_fields['fields'])) {
             // row template
             $row_template = '';
             $req_tag = "<span class='required'>*</span>";
             // template
             switch ($html_type) {
                 case 'table':
                     $row_template = "<tr>\r\r\n\t\t\t\t\t\t\t\t\t\t\t<td valign='top'><label for='%s'>%s %s</label></td>\r\r\n\t\t\t\t\t\t\t\t\t\t\t<td valign='top'>%s</td>\t\r\r\n\t\t\t\t\t\t\t\t\t\t </tr>";
                     break;
                 case 'div':
                 default:
                     $row_template = "<p><label for='%s'>%s %s</label><br />%s</p>";
                     break;
             }
             // form_html
             $form_html = '';
             // loop
             foreach ($address_fields['fields'] as $field) {
                 // req
                 $req = (bool) $field['attributes']['required'] == true ? $req_tag : '';
                 // value
                 $value = isset($address_fields['captured'][$field['name']]) ? $address_fields['captured'][$field['name']] : '';
                 // type cls
                 $type_class = $field['type'] == 'select' ? 'select' : 'input';
                 // class
                 if ((bool) $field['attributes']['required'] == true) {
                     // append
                     $type_class .= ' {required: true}';
                     // reset to skip default required class
                     $field['attributes']['required'] = false;
                 }
                 // set class
                 $field['attributes']['class'] = $type_class;
                 // elem
                 $elem = $form_fields->get_field_element($field, 'mgm_payment_field', $value);
                 // form
                 $form_html .= sprintf($row_template, $field['name'], $field['label'], $req, $elem);
             }
             // set
             $billing_info .= $form_html;
             // set
             $data['billing_info'] = $billing_info;
         }
     }
     // credit card types: read from settings
     $card_types = array();
     // loop
     foreach ($this->card_types as $type => $label) {
         // check
         if (isset($this->setting['supported_card_types']) && is_array($this->setting['supported_card_types'])) {
             if (in_array($type, $this->setting['supported_card_types'])) {
                 $card_types[$type] = $label;
             }
         }
     }
     // set
     $data['card_types'] = $card_types;
     // code
     $data['code'] = $this->code;
     // html
     $html .= mgm_get_include(MGM_CORE_DIR . sprintf('html/payment_cc_form_%s.php', $html_type), array('data' => $data));
     // cc form
     $cc_form = sprintf("<div id='%s_form_cc' class='ccfields ccfields_block_left'>%s</div>", $this->code, $html);
     // apply filter
     return apply_filters('mgm_cc_form_html', $cc_form, $this->code, $data);
 }
コード例 #3
0
/**
 * register post process
 *
 * @param int $user_id 
 * @return void or int $user_id
 */
function mgm_register($user_id)
{
    global $wpdb, $post;
    // check import in action and skip, tools->import calls mgm_register via "user_register" hook, this will help skip
    if (defined('MGM_DOING_USERS_IMPORT') && MGM_DOING_USERS_IMPORT == TRUE) {
        // return
        return $user_id;
    }
    // get mgm_system
    $system_obj = mgm_get_class('system');
    // hide
    $hide_custom_fields = $system_obj->get_setting('hide_custom_fields');
    // packs
    $packs = mgm_get_class('subscription_packs');
    // members object
    $member = mgm_get_member($user_id);
    // set status
    $member->set_field('status', MGM_STATUS_NULL);
    // get custom fields
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    // mgm_subscription
    $mgm_subscription = mgm_post_var('mgm_subscription');
    // get subs
    $subs_pack = mgm_decode_package($mgm_subscription);
    // extract
    extract($subs_pack);
    // payment_gateways if set:
    $mgm_payment_gateways = mgm_post_var('mgm_payment_gateways');
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = !empty($mgm_payment_gateways) ? $mgm_payment_gateways : NULL;
    // init
    $member_custom_fields = array();
    // wordpress register
    $wordpres_form = mgm_check_wordpress_login();
    // system - issue #1237
    $short_format = !empty($system_obj->setting['date_format_short']) ? $system_obj->setting['date_format_short'] : MGM_DATE_FORMAT_SHORT;
    // loop
    foreach ($cf_register_page as $field) {
        // skip custom fields by settings call
        if ($hide_custom_fields == 'Y' || $hide_custom_fields == 'W' && $wordpres_form || $hide_custom_fields == 'C' && !$wordpres_form) {
            // if($hide_custom_fields && $field['name'] != 'subscription_options') continue;
            if (!in_array($field['name'], array('subscription_options', 'payment_gateways'))) {
                continue;
            }
        }
        //skip if payment_gateways custom field
        if ($field['name'] == 'payment_gateways') {
            continue;
        }
        //
        // do not save html
        if ($field['type'] == 'html' || $field['type'] == 'label') {
            continue;
        }
        // save
        switch ($field['name']) {
            case 'username':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_login'];
                }
                break;
            case 'email':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_email'];
                }
                break;
            case 'password':
                // #739
                // check
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        $user_password = @$_POST[$field['attributes']['capture_field_alias']];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                } else {
                    if (!empty($_POST['user_password'])) {
                        $user_password = $_POST['user_password'];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                }
                break;
            case 'autoresponder':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // checked issue #839
                    // if(in_array(strtolower($_POST[$field['attributes']['capture_field_alias']]), array('y','yes'))){
                    if (!empty($_POST[$field['attributes']['capture_field_alias']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                } else {
                    // checked issue #839
                    // if(in_array(strtolower($_POST['mgm_register_field'][$field['name']]), array('y','yes'))){
                    if (!empty($_POST['mgm_register_field'][$field['name']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        // set to member, to be used on payment
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                }
                break;
            case 'coupon':
                // #739
                // check alias
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // check
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST[$field['attributes']['capture_field_alias']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                } else {
                    // check primary
                    if (isset($_POST['mgm_register_field'][$field['name']]) && !empty($_POST['mgm_register_field'][$field['name']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST['mgm_register_field'][$field['name']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                }
                break;
            case 'birthdate':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    //issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST[$field['attributes']['capture_field_alias']], $short_format);
                } else {
                    //convert from short date format to mysql format - issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST['mgm_register_field'][$field['name']], $short_format);
                }
                break;
            default:
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } elseif ($field['type'] == 'checkbox' && is_array(@$_POST['mgm_register_field'][$field['name']])) {
                    //$member_custom_fields[$field['name']] = implode(" ", @$_POST['mgm_register_field'][$field['name']]);
                    //issue #1070
                    $val = @$_POST['mgm_register_field'][$field['name']];
                    $member_custom_fields[$field['name']] = serialize($val);
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['mgm_register_field'][$field['name']];
                }
                break;
        }
    }
    // end fields save
    // user password not provided
    /*
    	if (!isset( $user_password )){
    		$user_password = (isset($_POST['pass1']) && !empty($_POST['pass1'])) ? trim($_POST['pass1']) : substr(md5(uniqid(microtime())), 0, 7);		
    	}*/
    // user password not provided
    if (!isset($user_password)) {
        // take custom password fields, iss#717, consider BP custom password field
        $password_fields = array('pass1', 'signup_password');
        // loop
        foreach ($password_fields as $password_field) {
            // check if set
            if (isset($_POST[$password_field]) && !empty($_POST[$password_field])) {
                $user_password = trim($_POST[$password_field]);
                break;
            }
        }
    }
    // auto generate if still missing
    if (!isset($user_password)) {
        $user_password = substr(md5(uniqid(microtime())), 0, 7);
    }
    //encrypt password and save in
    $member->user_password = mgm_encrypt_password($user_password, $user_id);
    // md5
    $user_password_hash = wp_hash_password($user_password);
    // db update
    $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->users}` SET `user_pass` = %s WHERE ID = %d", $user_password_hash, $user_id));
    // unset label fields
    if (isset($member_custom_fields['password_conf'])) {
        unset($member_custom_fields['password_conf']);
    }
    // set custom
    $member->set_custom_fields($member_custom_fields);
    // set pack
    if ($pack_id) {
        // pack
        $pack = $packs->get_pack($pack_id);
        // set
        $member->amount = $pack['cost'];
        $member->duration = $pack['duration'];
        $member->duration_type = $pack['duration_type'];
        $member->active_num_cycles = $pack['num_cycles'];
        // set membership type
        $member->membership_type = $membership_type;
        // from mgm_subscription
        // set in member
        $member->pack_id = $pack_id;
        // from mgm_subscription
    }
    // set status
    $member->status = MGM_STATUS_NULL;
    // update option
    $member->save();
    // update user firstname/last name
    mgm_update_default_userdata($user_id);
    // admin check
    $is_admin = is_admin();
    //&& current_user_can('manage_options');
    // send
    $notify_user = true;
    // Block registration emails if Buddypress is enabled and disable_registration_email_bp value is Yes
    $block_reg_email = bool_from_yn(mgm_get_class('system')->get_setting('disable_registration_email_bp'));
    // send notification, bp active, do not send password, #739
    if (!isset($_POST['send_password']) && $is_admin || mgm_is_plugin_active('buddypress/bp-loader.php') && $block_reg_email) {
        $notify_user = false;
    }
    // send notification - issue #1468
    if ($system_obj->setting['enable_new_user_email_notifiction_after_user_active'] == 'N') {
        if ($notify_user) {
            mgm_new_user_notification($user_id, $user_password, $is_admin ? false : true);
        }
        $notify_user = false;
    }
    // hook for other plugin who wishes to use default "user_register"
    do_action('mgm_user_register', $user_id);
    // process payment only when registered from site, not when user added by admin
    if ($is_admin) {
        // unset
        unset($_POST['send_password']);
        //prevent sending user email again
        // assign default pack
        do_action('mgm_admin_user_register', $user_id, $notify_user);
        // return id
        return $user_id;
    }
    // if on wordpress page or custompage
    $post_id = get_the_ID();
    // post custom register
    if ($post_id > 0 && $post->post_type == 'post') {
        $redirect = get_permalink($post_id);
    } else {
        $redirect = mgm_get_custom_url('transactions');
    }
    // if buddypress url replace by register url : issue#: 791
    $redirect = apply_filters('mgm_bp_register_url', $redirect);
    // userdata
    $userdata = get_userdata($user_id);
    // note this fix VERY IMPORTANT, needed for PAYPAL PRO CC POST
    $redirect = add_query_arg(array('username' => urlencode($userdata->user_login)), $redirect);
    // add redirect
    if ($redirector = mgm_request_var('mgm_redirector', mgm_request_var('redirect_to', '', true), true)) {
        $redirect = add_query_arg(array('redirector' => $redirector), $redirect);
    }
    // with subscription
    if ($mgm_subscription) {
        $redirect = add_query_arg(array('subs' => $mgm_subscription, 'method' => 'payment_subscribe'), $redirect);
    }
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // pack
        $packs_obj = mgm_get_class('subscription_packs');
        // validate
        $pack = $packs_obj->validate_pack($cost, $duration, $duration_type, $membership_type, $pack_id);
        // error
        if ($pack != false) {
            // get pack
            mgm_get_register_coupon_pack($member, $pack);
            // cost
            if ((double) $pack['cost'] > 0) {
                //get an object of the payment gateway:
                $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
                // tran options
                $tran_options = array('is_registration' => true, 'user_id' => $user_id, 'notify_user' => $notify_user);
                // is register & purchase
                if (isset($_POST['post_id'])) {
                    $tran_options['post_id'] = (int) $_POST['post_id'];
                }
                // is register & purchase postpack
                if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                    $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                    $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
                }
                // create transaction
                // $tran_id = $mod_obj->_create_transaction($pack, $tran_options);
                $tran_id = mgm_add_transaction($pack, $tran_options);
                //bypass directly to process return if manual payment:
                if ($cf_payment_gateways == 'mgm_manualpay') {
                    // set
                    $_POST['custom'] = $tran_id;
                    // direct call to module return function:
                    $mod_obj->process_return();
                    // exit
                    exit;
                }
                // encode id:
                $tran_id = mgm_encode_id($tran_id);
                // redirect - if on wordpress page or custompage - issue #1648
                if ($post_id > 0 && $post->post_type == 'post') {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', true);
                } else {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', false);
                }
                // if buddypress url replace by register url : issue#: 791
                $redirect = add_query_arg(array('tran_id' => $tran_id), apply_filters('mgm_bp_register_url', $redirect));
            } else {
                // issue #1468
                $redirect = add_query_arg(array('notify_user' => $notify_user), $redirect);
            }
        }
    }
    // ends custom payment gateway bypassing
    // is register & purchase
    if (isset($_POST['post_id'])) {
        $redirect = add_query_arg(array('post_id' => (int) $_POST['post_id']), $redirect);
    }
    // is register & purchase postpack
    if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
        $redirect = add_query_arg(array('postpack_id' => (int) $_POST['postpack_id'], 'postpack_post_id' => (int) $_POST['postpack_post_id']), $redirect);
    }
    // redirect filter, returing a false can stop the redirect
    $redirect = apply_filters('mgm_after_regiter_redirect', mgm_site_url($redirect));
    // redirect
    if ($redirect !== FALSE) {
        // do the redirect to payment
        mgm_redirect($redirect);
        // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
        // exit
        exit;
    }
    // default
    return $user_id;
}