/** * Specifically check recurring status of each rebill for an expiry date * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { $post_data = '<ARBGetSubscriptionStatusRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>' . $this->setting['loginid'] . '</name> <transactionKey>' . $this->setting['tran_key'] . '</transactionKey> </merchantAuthentication> <subscriptionId>' . $member->payment_info->subscr_id . '</subscriptionId> </ARBGetSubscriptionStatusRequest>'; // end point $endpoint = $this->_get_endpoint($this->status . '_arb'); // test_arb, live_aim etc. // headers $http_headers = array('Content-Type' => 'text/xml'); // create curl post $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // $this->_curl_post($endpoint, $content, array("Content-Type: text/xml") ); // parse response $this->_process_response('subscription_status', $http_response); // check if (isset($this->response['subscription_status'])) { // old status $old_status = $member->status; // set status switch (strtolower($this->response['subscription_status'])) { case 'active': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // get transaction $tran_response = $this->get_transaction_details($member); // last pay date $member->last_pay_date = isset($tran_response['transDate']) && !empty($tran_response['transDate']) ? date('Y-m-d', strtotime($tran_response['transDate'])) : date('Y-m-d'); // expire date if (isset($tran_response['transDate']) && !empty($tran_response['transDate']) && !empty($member->expire_date)) { // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway, if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } //issue #1678 & 1736 - some times proccessing Authorize.net declined transactions so added check here, based on last pay date form gateway $temp_new_expire_date = date('Y-m-d', strtotime($new_expire_date)); $temp_expire_date = date('Y-m-d', strtotime($member->expire_date)); // date mistmatch if (strtotime($temp_new_expire_date) < strtotime($temp_expire_date) || strtotime($temp_new_expire_date) == strtotime($temp_expire_date) && time() > strtotime($member->expire_date)) { /*// set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired','mgm'); //expire date $member->expire_date = $new_expire_date;*/ // #1736 final fix // verify txn id exists again $this->_fetch_merchant_txn_id($member, true); } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // expire on error if (isset($tran_response['response_status']) && (int) $tran_response['response_status'] == 5) { // set as expired $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = sprintf(__('Last payment cycle expired. %s', 'mgm'), $tran_response['message_text']); //expire date $member->expire_date = $member->last_pay_date; } // set eway txn no if (isset($tran_response['transId'])) { $member->payment_info->authorizenet_txn_id = $tran_response['transId']; } // set eway txn no if (isset($tran_response['batchId'])) { $member->payment_info->authorizenet_batch_id = $tran_response['batchId']; } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'canceled': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'suspended': case 'terminated': case 'expired': // set new statis $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired', 'mgm'); // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
function post_purchase_export() { global $wpdb; // data $data = array(); // filter $sql_filter = $data['search_field_name'] = $data['search_field_value'] = ''; $search_field_name = mgm_post_var('search_field_name'); // check if (!empty($search_field_name)) { // post $search_field_value = mgm_post_var('search_field_value'); $search_field_value_two = mgm_post_var('search_field_value_two'); // view data $data['search_field_name'] = $search_field_name; // for display //issue #1281 $data['search_field_value'] = htmlentities($search_field_value, ENT_QUOTES, "UTF-8"); // for display $data['search_field_value_two'] = htmlentities($search_field_value_two, ENT_QUOTES, "UTF-8"); // for display //searc value $search_field_value = esc_sql($search_field_value); // for sql // end date value $search_field_value_two = esc_sql($search_field_value_two); // for sql //current date $curr_date = mgm_get_current_datetime(); $current_date = $curr_date['timestamp']; // by field switch ($search_field_name) { case 'user_login': $sql_filter = " AND (`user_login` LIKE '%{$search_field_value}%' OR `guest_token` LIKE '%{$search_field_value}%')"; break; case 'post_title': $sql_filter = " AND (`post_title` LIKE '%{$search_field_value}%')"; break; case 'is_gift': $sql_filter = " AND (`is_gift` = '{$search_field_value}')"; break; case 'purchase_dt': // date start if (empty($search_field_value)) { $search_field_value = date('Y-m-d', $current_date); } // date end if (empty($search_field_value_two)) { $search_field_value_two = date('Y-m-d', $current_date); } // convert $search_field_value = mgm_format_inputdate_to_mysql($search_field_value); $search_field_value_two = mgm_format_inputdate_to_mysql($search_field_value_two); // set $sql_filter = " AND (DATE_FORMAT(`pp`.`purchase_dt`,'%Y-%m-%d') BETWEEN '{$search_field_value}' AND '{$search_field_value_two}')"; break; } } // order $sql_order = " ORDER BY u.user_login, p.post_title"; // sql $sql = "SELECT SQL_CALC_FOUND_ROWS p.ID AS post_id, p.post_title, pp.purchase_dt, \r\r\n\t\t IF(user_id IS NULL, CONCAT('guest-', guest_token), u.user_login) AS user_login, pp.id,\r\r\n\t\t pp.is_gift,pp.is_expire FROM `" . TBL_MGM_POST_PURCHASES . "` pp \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->posts . " p ON (p.id = pp.post_id) \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->users . " u ON (u.ID = pp.user_id) WHERE 1 \r\r\n\t\t\t\t{$sql_filter} {$sql_order} "; // log // mgm_log($sql); // store $data['post_purchases'] = $wpdb->get_results($sql); // date format $date_format = mgm_get_date_format('date_format'); // init $purchases = array(); // check if (count($data['post_purchases']) > 0) { //purchases foreach ($data['post_purchases'] as $purchase) { // int $row = new stdClass(); // type $type = $purchase->is_gift == 'Y' ? __('Gift', 'mgm') : __('Purchase', 'mgm'); // check is_expiry if ($purchase->is_expire == 'N') { $expiry = __('Indefinite', 'mgm'); } else { $expiry = mgm_get_post($purchase->post_id)->get_access_duration(); $expiry = !$expiry ? __('Indefinite', 'mgm') : date($date_format, 86400 * $expiry + strtotime($purchase->purchase_dt)) . " (" . $expiry . __(' D', 'mgm') . ")"; } // member name if (preg_match('/^guest-/', $purchase->user_login)) { // guest token $guest_token = str_replace('guest-', '', $purchase->user_login); // username $username = __('Guest', 'mgm') . sprintf(' (%s)', $guest_token); } else { // username $username = $purchase->user_login; } //export fields $row->username = $username; $row->post = $purchase->post_title; $row->type = $type; $row->expire_date = $expiry; $row->purchase_or_gift_date = date($date_format, strtotime($purchase->purchase_dt)); // cache $purchases[] = $row; // unset unset($row); } } // default response $response = array('status' => 'error', 'message' => __('Error while exporting post (purchase/gift)s.', 'mgm')); // check if (count($purchases) > 0) { // success $success = count($purchases); // create if (mgm_post_var('export_format') == 'csv') { $filename = mgm_create_csv_file($purchases, 'post_purchases'); } else { $filename = mgm_create_xls_file($purchases, 'post_purchases'); } // src $file_src = MGM_FILES_EXPORT_URL . $filename; // message $message = sprintf(__('Successfully exported %d post %s.', 'mgm'), $success, $success > 1 ? 'purchases' : 'purchase'); // init $response = array('status' => 'success', 'message' => $message, 'src' => $file_src); } // return response echo json_encode($response); exit; }
function _do_import_users() { //test global $wpdb; // extract extract($_POST); // import f*g define('MGM_DOING_USERS_IMPORT', TRUE); // parese $i_response = $this->_parse_import_file(); // log // mgm_log($response, __FUNCTION__); // stop // $response['status'] = 'error'; // process data: if ($i_response['status'] == 'success' && in_array('user_email', $i_response['header'])) { // success // extract $i_users = $i_response['users']; $i_header = $i_response['header']; // object $mgm_packs = mgm_get_class('mgm_subscription_packs'); $mgm_roles = mgm_get_class('mgm_roles'); // types $membership_types = mgm_get_class('membership_types')->get_membership_types(); $memtypes = mgm_get_class('membership_types'); // check users if (!empty($i_users)) { // users found // init $row_count = count($i_users); $col_count = count($i_header); // limits $row_limit = 2000; $user_count = 0; // log // mgm_log(sprintf('Rows: [%d] Cols: [%d]',$row_count, $col_count), __FUNCTION__); // user fields $user_fields = array('first_name', 'last_name', 'user_nicename', 'user_url', 'display_name', 'nickname', 'user_firstname', 'user_lastname', 'user_description', 'user_registered'); // flag $update_count = $user_count = 0; // new users $new_users = array(); $specialchars = array(',', '\'', '"', "\n\r", "\n", '\\', '/', '$', '`', '(', ')', ' ', " "); // custom fields $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true, 'on_profile' => true))); // count $cf_count = count($cf_register_page); // exclude $cf_exclude_names = array('subscription_introduction', 'subscription_options', 'terms_conditions', 'privacy_policy', 'description', 'payment_gateways', 'password_conf', 'autoresponder'); // types $cf_exclude_types = array('html', 'label', 'captcha'); // loop foreach ($i_users as $i_user) { // init $update_user = $insert_user = $is_membership_update = $is_multiple_membership_update = $multiple_membership_exists = $update_role = false; // pack $pack = array(); // increment $user_count++; // remove N/A ? // $i_user = str_ireplace('N/A', '', $i_user); // init // id $id = isset($i_user['ID']) && is_numeric($i_user['ID']) ? $i_user['ID'] : ''; $email = str_replace($specialchars, '', sanitize_email($i_user['user_email'])); $user_login = str_replace($specialchars, '', sanitize_user($i_user['user_login'])); $user_password = isset($i_user['user_password']) ? $i_user['user_password'] : ''; // Issue #1559: Standardize membership type name to use machine name $membership_type = $memtypes->get_type_code($i_user['membership_type']); $pack_id = isset($i_user['pack_id']) ? sanitize_user($i_user['pack_id']) : ''; // log // mgm_log(sprintf('step 1: user_count: [%d] id: [%s] email: [%s] user_login: [%s] user_password: [%s]', $user_count, $id, $email, $user_login, $user_password), __FUNCTION__); // user id not valid if (!is_numeric($id)) { // check login/email if (!empty($user_login) && !empty($email)) { // user $_user = get_user_by('login', $user_login); // if update and different email if (isset($_user->ID) && $_user->user_email != $email) { // log // mgm_log(sprintf('step 2: %s %s', $_user->user_email, $email), __FUNCTION__); // continue continue; } // fresh insert/registration: if (!$_user) { // password $user_password = !empty($user_password) ? $user_password : wp_generate_password(); $user_password = str_replace($specialchars, '', $user_password); // trim $user_password = trim($user_password); // log // mgm_log('step 2.1 user_password: '******'step 3: %s, %s ', $user_password, $id), __FUNCTION__); // check error if (is_wp_error($id)) { // log // mgm_log(sprintf('step 4: %s', print_r($id->get_error_messages(),1)), __FUNCTION__); // unset unset($id); // continue continue; } // set new user $new_users[$id]['email'] = $email; $new_users[$id]['user_login'] = $user_login; // update option update_user_option($id, 'default_password_nag', true, true); // flag $insert_user = true; } else { // set id to user $id = $_user->ID; } // unset unset($_user); } else { // login/email not present // log // mgm_log(sprintf('step 5: %s, %s ', $user_login, $email), __FUNCTION__); // continue continue; //skip the record } } else { // update $update_user = true; } // get User object: $user = new WP_user($id); // log // mgm_log(sprintf('step 6: %s ', print_r($user,1)), __FUNCTION__); //issue #700 $format = mgm_get_date_format('date_format_short'); // ------------------------------------------ // user to mgm member if (isset($user->ID) && $user->ID > 0) { // get mgm object: $member = mgm_get_member($user->ID); // update custom fields: if (!empty($member)) { // update pack id if not supplied and already exists // This is to make pack_id optional: issue#: 807 if (!is_numeric($pack_id) && isset($member->pack_id) && $member->pack_id > 0) { $pack_id = $member->pack_id; } // update misc fields: if (!isset($member->rss_token) || isset($member->rss_token) && empty($member->rss_token)) { $member->rss_token = mgm_create_rss_token(); } // init $user_password_enc = mgm_encrypt_password($user_password, $user->ID, $member->rss_token); // mgm_log($user_password_enc, __FUNCTION__); // check if ($cf_count > 0) { // loop custom fields foreach ($cf_register_page as $field) { // key $key = $field['name']; // mgm_log($key, __FUNCTION__); // skip unwanted fields if (in_array($field['name'], $cf_exclude_names) || in_array($field['type'], $cf_exclude_types)) { // log // mgm_log(sprintf('step 7: %s ', $field['name']), __FUNCTION__); // continue continue; } // init $val = ''; //issue #700 // check if (isset($i_user[$key]) && !empty($i_user[$key]) && preg_match('/date/i', $key)) { // validate date if (mgm_is_valid_date($i_user[$key]) && mgm_format_inputdate_to_mysql($i_user[$key], $format)) { $val = $i_user[$key]; } } elseif ($key == 'email') { // email and username custom fields $val = $email; } elseif ($key == 'username') { // username $val = $user_login; } elseif ($key == 'password') { // password if (!empty($user_password_enc)) { // set $val = $user_password_enc; // log // mgm_log(sprintf('step 7.1: %s ', $user_password_enc), __FUNCTION__); } } else { $val = isset($i_user[$key]) ? $i_user[$key] : ''; } // If checkbox, then serialize the value: Issue #1070 if ($field['type'] == 'checkbox' && !empty($val)) { $val = serialize(explode("|", $val)); } // update fields: if (!empty($val) || !isset($member->custom_fields->{$key})) { // set $member->custom_fields->{$key} = $val; } // unset unset($field, $val); } } // custom fields updated // log // mgm_log(sprintf('step 8: %s ', print_r($member,1)), __FUNCTION__); // update membership: main mgm_member object if (!empty($membership_type) && is_numeric($pack_id)) { // pack if ($pack = $mgm_packs->get_pack($pack_id)) { // valid pack $member->pack_id = $pack_id; } else { // log // mgm_log(sprintf('step 9: %s ', print_r($pack,1)), __FUNCTION__); // error: continue; } // membership types: $sel_type = ''; // loop foreach ($membership_types as $key => $type) { // check if ($membership_type == $key || $membership_type == $type) { // match $sel_type = $key; break; } } // check if (!empty($sel_type)) { $membership_type = $sel_type; } else { // log // mgm_log(sprintf('step 10: %s ', $sel_type), __FUNCTION__); // continue continue; } // to distinguish between primary membership and other membership(Y/N) if (!isset($i_user['other_membership']) || isset($i_user['other_membership']) && $i_user['other_membership'] != 'Y') { // set $member->membership_type = $membership_type; // update current membership: $_response = $this->_update_member_object($member, $pack, $i_user); // check if (!$_response['status']) { // log // mgm_log(sprintf('step 11: %s ', print_r($_response,1)), __FUNCTION__); // skip the row continue; } // set $member = $_response['mgm_member']; // check guest if (strtolower($member->membership_type) == 'guest') { // default $member->other_membership_types = array(); } else { // flag $update_role = true; } } else { // init $multiple_updated = false; // if multiple mgm_member object: if (isset($member->other_membership_types) && !empty($member->other_membership_types)) { // loop foreach ((array) $member->other_membership_types as $key => $member) { // convert $member = mgm_convert_array_to_memberobj($member, $user->ID); // type if ($member->membership_type == $membership_type) { // check $_response = $this->_update_member_object($member, $pack, $i_user); // check if (!$_response['status']) { // log // mgm_log(sprintf('step 12: %s ', print_r($_response,1)), __FUNCTION__); // skip the row: continue; } // make sure array is saved: $_response['mgm_member'] = mgm_convert_memberobj_to_array($_response['mgm_member']); // set $member->other_membership_types[$key] = $_response['mgm_member']; // flag $multiple_updated = true; // break break; } } } //else {mgm_log('skip other_memberships 3', __FUNCTION__);} // add new to mother_membership_types object: if (!$multiple_updated) { // update $_response = $this->_update_member_object(new stdClass(), $pack, $i_user); // check if (!$_response['status']) { // log // mgm_log(sprintf('step 13: %s ', print_r($_response,1)), __FUNCTION__); // skip the row: continue; } // set $_response['mgm_member'] = mgm_convert_memberobj_to_array($_response['mgm_member']); // set $member->other_membership_types[] = $_response['mgm_member']; // flag $update_role = true; } } } // payment type: if (!isset($member->payment_type) || isset($member->payment_type) && empty($member->payment_type)) { $member->payment_type = 'subscription'; } // update password: if (!empty($user_password)) { // issue#: 672 // generate iss#688 /*if(empty($user_password_enc)) { // set $user_password_enc = mgm_encrypt_password($user_password, $user->ID); // log // mgm_log(sprintf('step 7.2: regenarete password: %s ', $user_password_enc), __FUNCTION__); }*/ // set $member->user_password = $user_password_enc; // md5 // $user_password_md5 = wp_hash_password($user_password); //mgm_log($wpdb->prepare("UPDATE ".$wpdb->users." SET user_pass = %s WHERE ID = %d", $user_password_md5, $user->ID), __FUNCTION__); // db update //$wpdb->query( $wpdb->prepare("UPDATE ".$wpdb->users." SET user_pass = %s WHERE ID = %d", $user_password_md5, $user->ID) ); // new user if ($insert_user) { $new_users[$id]['user_password'] = $user_password; } } // save mgm_member object: $member->save(); // update role: if ($update_role) { // update role/change order $mgm_roles->add_user_role($user->ID, $pack['role']); } // log // mgm_log(sprintf('step 14: %s ', print_r($member,1)), __FUNCTION__); } // update other user fields: $user_extra = array(); if (!empty($user_password)) { $user_extra['user_pass'] = $user_password; } // loop foreach ($i_user as $key => $value) { // check if (in_array($key, $user_fields) && !empty($value)) { if ($key == 'user_registered') { if (mgm_is_valid_date($value) && ($mysql_date = mgm_format_inputdate_to_mysql($value))) { $user_extra[$key] = $mysql_date; } } else { // set $user_extra[$key] = $value; } } } // update if (!empty($user_extra)) { // set $user_extra['ID'] = $user->ID; // update wp_update_user($user_extra); } // update $update_count++; // check here: unset($member, $user, $user_extra); } // check limit reached: if ($user_count >= $row_limit) { // check if ($row_count > $row_limit) { // set $response['message'] = sprintf(__('( Import stopped at: %s as limit( %d ) reached. )', 'mgm'), $email, $row_limit); } // break; break; } // ------------------------------------------ // unset unset($i_user); // debug // if(function_exists('gc_collect_cycles')) gc_collect_cycles(); // wait if (!($user_count % 25)) { sleep(1); } } // end imported users loop // mgm_log('IMPORT MEMORY PEAK2.5: ' . memory_get_peak_usage(true)/(1024*1024)); // free unwanted resources unset($cf_register_page, $cf_exclude_names, $user_fields, $mgm_packs, $mgm_roles, $user_count); // debug // if(function_exists('gc_collect_cycles')) gc_collect_cycles(); // done importing, mail and notify if ($update_count) { // unset unset($update_count); // set response $response['status'] = true; $response['users_count'] = count($new_users); // send admin notification: // send to admin if (!empty($new_users)) { $system_obj = mgm_get_class('system'); // message $message = sprintf('(%d) %s %s: <br/><br/>', count($new_users), __('New user registration on your blog', 'mgm'), get_option('blogname')); // loop foreach ($new_users as $user_id => $n_user) { // set $message .= sprintf('%s: %s <br/>', __('Username', 'mgm'), $n_user['user_login']); $message .= sprintf('%s: %s <br/>', __('E-mail', 'mgm'), $n_user['email']); $message .= "-----------------------------------<br/><br/>"; // unset unset($n_user); // send email to the user: // mgm_new_user_notification($user_id, $new['user_password'],false); } // unset unset($new_users); // check if (isset($response['message'])) { // set $message .= $response['message']; $message .= "-----------------------------------<br/><br/>"; } // admin email: @mgm_mail(get_option('admin_email'), sprintf('[%s] %s', __('New User Registration', 'mgm'), get_option('blogname')), $message); // unset unset($message); // debug // if(function_exists('gc_collect_cycles')) gc_collect_cycles(); } } else { // none updated $response['error'] = __('No users imported', 'mgm'); } } else { // no users $response['error'] = __('Empty records', 'mgm'); } } else { // no users $response['error'] = __('Error in processing users', 'mgm'); } // mgm_log('IMPORT MEMORY PEAK3: ' . memory_get_peak_usage(true)/(1024*1024)); // mgm_log('$response:' . mgm_array_dump($response, true)); // return return $response; }
function _cancel_membership($user_id, $redirect = false) { // system $system_obj = mgm_get_class('system'); $s_packs = mgm_get_class('subscription_packs'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails')); //issue #1521 $is_admin = is_super_admin() ? true : false; // find user $user = get_userdata($user_id); $member = mgm_get_member($user_id); // multiple membesrhip level update: $multiple_update = false; // check if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type']) { $multiple_update = true; $member = mgm_get_member_another_purchase($user_id, $_POST['membership_type']); } // get pack if ($member->pack_id) { $subs_pack = $s_packs->get_pack($member->pack_id); } else { $subs_pack = $s_packs->validate_pack($member->amount, $member->duration, $member->duration_type, $member->membership_type); } // reset payment info $member->payment_info->txn_type = 'subscription_cancel'; // types $duration_exprs = $s_packs->get_duration_exprs(); // default expire date $expire_date = $member->expire_date; // if lifetime: if ($member->duration_type == 'l') { $expire_date = date('Y-m-d'); } // if trial on if ($subs_pack['trial_on'] && isset($duration_exprs[$subs_pack['trial_duration_type']])) { // if cancel data is before trial end, set cancel on trial expire_date $trial_expire_date = strtotime("+{$subs_pack['trial_duration']} {$duration_exprs[$subs_pack['trial_duration_type']]}", $member->join_date); // if lower if (time() < $trial_expire_date) { $expire_date = date('Y-m-d', $trial_expire_date); } } // transaction_id $trans_id = $member->transaction_id; // if today if ($expire_date == date('Y-m-d')) { // status $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); // set $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d'); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true); } else { // date $date_format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date))); // set $member->status = $new_status; $member->status_str = $new_status_str; // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // multiple memberhip level update: if ($multiple_update) { mgm_save_another_membership_fields($member, $user_id); } else { $member->save(); } // transaction status mgm_update_transaction_status($trans_id, $new_status, $new_status_str); // send email notification to client $blogname = get_option('blogname'); // notify user if (!$dpne) { // notify user mgm_notify_user_membership_cancellation($blogname, $user, $member, $system_obj, $new_status, $membership_type); } // notify admin if (!$dge) { // notify admin mgm_notify_admin_membership_cancellation($blogname, $user, $member); } // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // redirect only internal if ($redirect) { // message $lformat = mgm_get_date_format('date_format_long'); $message = sprintf(__("You have successfully unsubscribed. Your account has been marked for cancellation on %s", "mgm"), $expire_date == date('Y-m-d') ? 'Today' : date($lformat, strtotime($expire_date))); //issue #1521 if ($is_admin) { mgm_redirect(add_query_arg(array('user_id' => $user_id, 'unsubscribe_errors' => urlencode($message)), admin_url('user-edit.php'))); } // redirect mgm_redirect(mgm_get_custom_url('membership_details', false, array('unsubscribed' => 'true', 'unsubscribe_errors' => urlencode($message)))); } }
/** * get pack description * * @param array $pack * @return string $desc */ function get_pack_desc($pack) { // system $system_obj = mgm_get_class('system'); // format $date_fmt = mgm_get_date_format('date_format_short'); // tpl data $tpl_data = array(); // tpl vars $tpl_vars = array('membership_type', 'cost', 'currency', 'duration', 'duration_period', 'num_cycles', 'trial_cost', 'trial_duration', 'trial_duration_period', 'description', 'currency_sign', 'pack_start_date', 'pack_end_date'); // get template if (!($pack_desc_template = $system_obj->get_template('pack_desc_template', array(), true))) { $pack_desc_template = sprintf('[membership_type] - [cost] [currency] %s [duration] [duration_period] [num_cycles].<br/> [if_trial_on] %s [trial_cost] [currency] %s [trial_duration] [trial_duration_period] [/if_trial_on]', __('per', 'mgm'), __('This pack includes a special, limited trial-offer:', 'mgm'), __('for', 'mgm')); } // lifetime template: if ($pack['duration_type'] == 'l') { // template -issue #988 if (!($pack_desc_template = $system_obj->get_template('pack_desc_lifetime_template', array(), true))) { $pack_desc_template = sprintf('[membership_type] - [cost] [currency] %s', __('for Lifetime', 'mgm')); } } elseif ($pack['duration_type'] == 'dr') { $date_range = ''; // check if (mgm_is_valid_date($pack['duration_range_start_dt'], '-') && mgm_is_valid_date($pack['duration_range_end_dt'], '-')) { $tpl_data['pack_start_date'] = date($date_fmt, strtotime($pack['duration_range_start_dt'])); $tpl_data['pack_end_date'] = date($date_fmt, strtotime($pack['duration_range_end_dt'])); } if (!($pack_desc_template = $system_obj->get_template('pack_desc_date_range_template', array(), true))) { $pack_desc_template = sprintf('[membership_type] - [cost] [currency] starts from [pack_start_date] to [pack_end_date]'); } } // currency - issue #1602 if (!isset($pack['currency']) || empty($pack['currency'])) { $tpl_data['currency'] = $system_obj->get_setting('currency'); } else { $tpl_data['currency'] = $pack['currency']; } // issue #1177 $tpl_data['currency_sign'] = mgm_get_currency_symbols($tpl_data['currency']); // type $tpl_data['membership_type'] = mgm_stripslashes_deep(mgm_get_class('membership_types')->get_type_name($pack['membership_type'])); $tpl_data['duration_period'] = strtolower($this->get_pack_duration($pack)); // transalation issue #950 $tpl_data['text_for'] = __('for', 'mgm'); $tpl_data['num_cycles'] = $pack['num_cycles'] == 0 ? __(' - Ongoing', 'mgm') : sprintf(' - %s %d %s', $tpl_data['text_for'], (int) $pack['num_cycles'], $pack['num_cycles'] == 1 ? __('time', 'mgm') : __('times', 'mgm')); $tpl_data['trial_duration_period'] = strtolower($this->get_pack_duration($pack, true)); // merge rest, overwrite tpl_data if (is_array($pack)) { $tpl_data = array_merge($pack, $tpl_data); } // remove next lines as preg_replace will fail $pack_desc_template = str_replace(array("\r\n", "\n", "\r"), '', $pack_desc_template); // copy template $pack_desc = $pack_desc_template; // replace 0 cost if (isset($tpl_data['cost']) && $tpl_data['cost'] == 0.0) { $pack_desc = str_replace('[cost] [currency]', __('free', 'mgm'), $pack_desc); } // replace 0 trial_cost if (isset($tpl_data['trial_cost']) && $tpl_data['trial_cost'] == 0.0) { $pack_desc = str_replace('[trial_cost] [currency]', __('free', 'mgm'), $pack_desc); } // replace foreach ($tpl_vars as $var) { if (isset($tpl_data[$var])) { $pack_desc = str_replace('[' . $var . ']', $tpl_data[$var], $pack_desc); } } // num cycles if ($pack['num_cycles']) { $pack_desc = preg_replace("'\\[/?\\s?if_num_cycles\\s?\\]'i", '', $pack_desc); } else { $pack_desc = preg_replace("'\\[if_num_cycles\\s?\\](.*)\\[/if_num_cycles\\s?\\]'i", '', $pack_desc); } // trial on if (isset($pack['trial_on']) && (int) $pack['trial_on'] == 1) { $pack_desc = preg_replace("'\\[/?\\s?if_trial_on\\s?\\]'i", '', $pack_desc); } else { $pack_desc = preg_replace("'\\[if_trial_on\\s?\\](.*)\\[/if_trial_on\\s?\\]'i", '', $pack_desc); } // send return $pack_desc; }
/** * Specifically check recurring status of each rebill for an expiry date * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { // id $subscr_id = $member->payment_info->subscr_id; // check if ($this->response = $this->_get_api_notify('get_customer', null, $subscr_id)) { // log mgm_log($this->response, $this->module . '_' . __FUNCTION__); // old status $old_status = $member->status; // check $subscription_status = 'not found'; if (isset($this->response->subscription->status) && !empty($this->response->subscription->status)) { $subscription_status = strtolower($this->response->subscription->status); } // log mgm_log('subscription_status: ' . $subscription_status, $this->module . '_' . __FUNCTION__); // set status switch ($subscription_status) { case 'active': case 'trialing': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // start date $current_period_start = $this->response->subscription->current_period_start; // trial fix if ('trialing' == $subscription_status) { // expire if (empty($member->expire_date)) { $member->expire_date = date('Y-m-d', $this->response->subscription->trial_end); } // start date $current_period_start = $this->response->subscription->trial_start; // status string $member->status_str = __('Last trial cycle processed successfully', 'mgm'); } // last pay date $member->last_pay_date = isset($current_period_start) && !empty($current_period_start) ? date('Y-m-d', $current_period_start) : date('Y-m-d'); // expire date if (isset($current_period_start) && !empty($current_period_start) && !empty($member->expire_date)) { // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway, if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'canceled': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // set reset date $member->cancel_date = date('Y-m-d', $this->response->subscription->canceled_at); // $member->expire_date; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'suspended': case 'terminated': case 'expired': case 'error': case 'not found': case 'past_due': default: // set new statis $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = sprintf(__('Last payment cycle expired, subscription: %s.', 'mgm'), $subscription_status); // save $member->save(); break; } // action if (isset($new_status)) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
/** * add row to users list * * @param mixed $column_data * @param string $column * @param int $user_id * @return void */ function mgm_manage_users_custom_column($column_data, $column, $user_id) { // column switch ($column) { case 'subscription': // nothing for admin if (is_super_admin($user_id)) { return __('n/a', 'mgm'); } // date format $date_format = mgm_get_date_format('date_format'); // user object $user = get_userdata($user_id); // member $member = mgm_get_member($user_id); // packs $packs = mgm_get_class('subscription_packs'); // pack if (isset($member->pack_id)) { $membership = $packs->get_pack_desc($packs->get_pack($member->pack_id)); } else { $membership = __('Guest', 'mgm'); } // set $subscription = sprintf('<div>%s</div>', $membership); $subscription .= sprintf('<div><span class="overline">%s:</span> %s</div>', __('REGISTER', 'mgm'), date($date_format, strtotime($user->user_registered))); $subscription .= sprintf('<div><span class="mgm_color_gray">%s:</span> %s</div>', __('EXPIRY', 'mgm'), empty($member->expire_date) ? __('N/A', 'mgm') : date($date_format, strtotime($member->expire_date))); $subscription .= sprintf('<div><span class="mgm_color_gray">%s:</span> %s</div>', __('PACK JOIN', 'mgm'), empty($member->join_date) ? __('N/A', 'mgm') : date($date_format, $member->join_date)); $subscription .= sprintf('<div><span class="mgm_color_gray">%s:</span> <span class="%s"><b>%s</b></span> %s</div>', __('STATUS', 'mgm'), mgm_get_status_css_class($member->status), esc_html($member->status), !empty($member->status_str) ? '<br />' . esc_html($member->status_str) : ''); $subscription .= sprintf('<div><span class="mgm_color_gray">%s:</span> %s</div>', __('LAST PAY', 'mgm'), empty($member->last_pay_date) ? __('N/A', 'mgm') : date($date_format, strtotime($member->last_pay_date))); // return return $subscription; break; } // return return $column_data; }
function edit() { global $wpdb; extract($_POST); // save if (isset($save_coupon)) { // response $response = array('status' => 'error', 'message' => __('Coupon update failed, Unknown error!', 'mgm')); // check duplicate if (mgm_is_duplicate(TBL_MGM_COUPON, array('name'), "id <> '{$id}'")) { $response['message'] = sprintf(__('Error while updating coupon: %s, same code exists!', 'mgm'), $name); } else { // fields $fields = array('name', 'value', 'description', 'use_limit', 'used_count', 'product', 'expire_dt'); // colums $column_data = $column_null_data = array(); // create value $value = $this->_set_value(); // use limit if (isset($use_limit) && is_numeric($use_limit)) { $use_limit = (int) $use_limit; } else { $use_limit = NULL; } // product if (isset($product)) { $product = json_encode($product); } else { $product = NULL; } // expire dt format if (isset($expire_dt) && !empty($expire_dt)) { $expire_dt = date('Y-m-d H:i:s', strtotime(mgm_format_inputdate_to_mysql($expire_dt, mgm_get_date_format('date_format_short')))); } else { $expire_dt = NULL; } // loop foreach ($fields as $field) { // check if (isset(${$field}) && !is_null(${$field})) { $column_data[$field] = trim(${$field}); } else { $column_null_data[$field] = 'NULL'; // need string to track } } // affected $affected = 0; // update if ($wpdb->update(TBL_MGM_COUPON, $column_data, array('id' => $id))) { $affected++; } // null if (!empty($column_null_data)) { // column_data2 $column_data2_a = mgm_implode_a(',', array_keys($column_null_data), array_values($column_null_data)); // update if ($wpdb->query("UPDATE `" . TBL_MGM_COUPON . "` SET {$column_data2_a} WHERE id='{$id}' ")) { $affected++; } } // save if ($affected) { $response = array('status' => 'success', 'message' => sprintf(__('Successfully updated coupon: "%s"', 'mgm'), $name)); } else { $response = array('status' => 'error', 'message' => sprintf(__('Error while updating coupon: "%s"', 'mgm'), $name)); } } // return response echo json_encode($response); exit; } // data $data = array(); // coupon $data['coupon'] = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . TBL_MGM_COUPON . "` WHERE id=%d", $id)); // parse $data['value_is'] = $this->_get_value($data['coupon']->value); // currency $data['currency'] = mgm_get_class('system')->setting['currency']; // load template view $this->load->template('coupons/edit', array('data' => $data)); }
/** * Specifically check recurring status of each rebill for an expiry date * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { // check pack if (isset($member->pack_id)) { if ($pack = mgm_get_subscription_package($member->pack_id)) { // one time billing cycle if (isset($pack['num_cycles']) && (int) $pack['num_cycles'] == 1) { // log mgm_log('Exit Flag for One time billing', $this->module . '_' . __FUNCTION__); // exit return false; } } } // add internal vars $data = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'TRXTYPE' => 'R', 'TENDER' => 'C', 'ACTION' => 'I', 'ORIGPROFILEID' => $member->payment_info->subscr_id); // log mgm_log($data, $this->module . '_' . __FUNCTION__); // data $data_str = _http_build_query($data, null, '&', '', false); // do not urlencode // post url $post_url = $this->_get_endpoint(); //issue #1508 $url_parsed = parse_url($post_url); // domain/host $domain = $url_parsed['host']; // headers $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n'); // post $http_response = mgm_remote_post($post_url, $data_str, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // respomse $response = array(); // parse parse_str($http_response, $response); // log mgm_log($response, $this->module . '_' . __FUNCTION__); // check if (isset($response['STATUS'])) { // old status $old_status = $member->status; // set status switch ($response['STATUS']) { case 'ACTIVE': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // last pay date $last_pay_date = date('Y-m-d'); // today // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // date to add if (isset($response['NEXTPAYMENT']) && !empty($response['NEXTPAYMENT'])) { // convert to date $response['NEXTPAYMENT'] = $this->_maketime($response['NEXTPAYMENT']); // make time // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $last_pay_date = strtotime(str_replace('+', '-', $date_add), $response['NEXTPAYMENT']); // start date // $response['START'] = $this->_maketime($response['START']); // mmddyyyy // check before start date if ($last_pay_date < $member->join_date) { $last_pay_date = $member->join_date; } // format $last_pay_date = date('Y-m-d', $last_pay_date); } } // last pay date $member->last_pay_date = $last_pay_date; //date('Y-m-d', strtotime($last_pay_date)); // last pay date // $member->last_pay_date = (isset($response['LASTPAYMENTDATE'])) ? date('Y-m-d', strtotime($response['LASTPAYMENTDATE'])) : date('Y-m-d'); // expire date if (isset($response['NEXTPAYMENT']) && !empty($member->expire_date)) { // date to add // $date_add = mgm_get_pack_cycle_date((int)$member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'VENDOR INACTIVE': case 'DEACTIVATED BY MERCHANT': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // set new status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // set new status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'EXPIRED': // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired', 'mgm'); // save $member->save(); break; case 'TOO MANY FAILURES': // set new status $member->status = $new_status = MGM_STATUS_NULL; // status string $member->status_str = __('Last payment cycle failed, too many failed transactions.', 'mgm'); // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
/** * Cancel Recurring Subscription * This is not a private function * @param int/string $trans_ref * @param int $user_id * @param int/string $subscr_id * @return boolean */ function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null) { //if coming form process return after a subscription payment if (!empty($trans_ref)) { $transdata = $this->_get_transaction_passthrough($trans_ref); if ($transdata['payment_type'] != 'subscription_purchase') { return false; } $user_id = $transdata['user_id']; if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') { $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']); } else { $member = mgm_get_member($user_id); } if (isset($member->payment_info->module) && !empty($member->payment_info->module)) { $subscr_id = null; if (!empty($member->payment_info->subscr_id)) { $subscr_id = $member->payment_info->subscr_id; } elseif (!empty($member->pack_id)) { //check the pack is recurring $s_packs = mgm_get_class('subscription_packs'); $sel_pack = $s_packs->get_pack($member->pack_id); if ($sel_pack['num_cycles'] != 1) { $subscr_id = 0; } // 0 stands for a lost subscription id } //check for same module: if not call the same function of the applicale module. if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) { // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code); return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id); } //skip if same pack is updated if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) { return false; } } else { return false; } } // when a subscription found if ($subscr_id) { $user = get_userdata($user_id); $date_format = mgm_get_date_format('date_format'); // post data $post_data = array('USER' => $this->setting['ap_merchant'], 'PASSWORD' => $this->setting['ap_apipassword'], 'SUBSCRIPTIONREFERENCE' => $subscr_id, 'NOTE' => sprintf('Cancellation selected by member: "%s", ID: %d on: %s', $user->user_email, $user->ID, date($date_format)), 'TESTMODE' => $this->status == 'test' ? '1' : '0'); // url $unsubscribe_url = $this->_get_endpoint('unsubscribe'); // headers $http_headers = array(); // create curl post $http_response = mgm_remote_post($unsubscribe_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // parse @parse_str($http_response, $data); // verify if (isset($data['REFERENCENUMBER']) && $data['RETURNCODE'] == 100) { return true; } elseif (isset($data['DESCRIPTION'])) { //error string return $data['DESCRIPTION']; } } elseif (is_null($subscr_id) || $subscr_id === 0) { //send email to admin if subscription Id is absent $system_obj = mgm_get_class('system'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); // check if (!$dge) { // blog $blogname = get_option('blogname'); // user $user = get_userdata($user_id); // notify admin mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member); } // return return true; } // return return false; }
function member_export() { global $wpdb; // error -- use WP_DEBUG with WP_DEBUG_LOG // if(!WP_DEBUG) error_reporting(0); // extract extract($_POST); // log // mgm_log($_POST, __FUNCTION__); // get format $sformat = mgm_get_date_format('date_format_short'); // process if (isset($export_member_info)) { // init $success = 0; // type $membership_type = isset($bk_membership_type) ? $bk_membership_type : 'all'; // status $membership_status = isset($bk_membership_status) ? $bk_membership_status : 'all'; // date $date_start = isset($bk_date_start) ? $bk_date_start : ''; $date_end = isset($bk_date_end) ? $bk_date_end : ''; // query inut $query = ''; // selected only if (isset($bk_only_selected)) { // check if (isset($bk_selected_members) && is_array($bk_selected_members)) { $query = " AND `id` IN(" . mgm_map_for_in($bk_selected_members) . ")"; } } // start date if ($date_start) { // Issue #700 // convert to mysql date $date_start = strtotime(mgm_format_inputdate_to_mysql($date_start, $sformat)); // end date if ($date_end) { // Issue #700 // convert to mysql date $date_end = mgm_format_inputdate_to_mysql($date_end, $sformat); $date_end = strtotime($date_end); // issue#" 492 $query .= " AND UNIX_TIMESTAMP(user_registered) >= '{$date_start}' \r\r\n\t\t\t\t\t AND UNIX_TIMESTAMP(DATE_FORMAT(user_registered, '%Y-%m-%d')) <= '{$date_end}'"; } else { $query .= " AND UNIX_TIMESTAMP(user_registered) >= '{$date_start}'"; } } else { if ($date_end) { // Issue #700 // convert to mysql date $date_end = strtotime(mgm_format_inputdate_to_mysql($date_end, $sformat)); // query $query .= " AND UNIX_TIMESTAMP(DATE_FORMAT(user_registered, '%Y-%m-%d')) <= '{$date_end}' "; } } // all users $sql = 'SELECT ID, user_login, user_email, user_registered, display_name FROM `' . $wpdb->users . '` WHERE ID <> 1 ' . $query . ' ORDER BY `user_registered` ASC'; // users $users = $wpdb->get_results($sql); // filter $export_users = array(); // date $current_date = time(); //issue #844 $skip_fileds = array('subscription_introduction', 'coupon', 'privacy_policy', 'payment_gateways', 'terms_conditions', 'subscription_options', 'autoresponder', 'captcha'); // check - issue #1382 if (isset($bk_users_to_import)) { $custom_fields = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true, 'on_profile' => true))); $import_user_fileds = array('user_login', 'user_email', 'pack_id', 'membership_type'); foreach ($custom_fields as $field) { if (!in_array($field['name'], $skip_fileds)) { $import_user_fileds[] = $field['name']; } } } // Custom fields $cf_profile_pg = mgm_get_class('member_custom_fields'); $to_unserialize = array(); foreach (array_unique($cf_profile_pg->sort_orders) as $id) { foreach ($cf_profile_pg->custom_fields as $field) { // issue #954: show the field only if it is enabled for profile page if ($field['id'] == $id && $field['type'] == 'checkbox') { $to_unserialize[] = $field['name']; } } } // loop foreach ($users as $user) { // user cloned $user_obj = clone $user; // member $member = mgm_get_member($user->ID); // check if (!isset($bk_inactive)) { $bk_inactive = false; } // check search parameters: if ($this->_get_membership_details($member, $bk_msexp_dur_unit, $bk_msexp_dur, $membership_type, $current_date, $bk_inactive, $membership_status)) { // merge if (method_exists($member, 'merge_fields')) { $user = $member->merge_fields($user); } // log // mgm_log($user, __FUNCTION__); // issue #844 foreach ($skip_fileds as $skip_filed) { unset($user->{$skip_filed}); } // format dates $user->user_registered = date($sformat, strtotime($user->user_registered)); $user->last_pay_date = (int) $user->last_pay_date > 0 ? date($sformat, strtotime($user->last_pay_date)) : 'N/A'; $user->expire_date = !empty($user->expire_date) ? date($sformat, strtotime($user->expire_date)) : 'N/A'; $user->join_date = (int) $user->join_date > 0 ? date($sformat, $user->join_date) : 'N/A'; // issue#: 672 // DO not show actual password: #1002 // $user->user_password = mgm_decrypt_password($member->user_password, $user->ID); $user->rss_token = $member->rss_token; // unset password unset($user->password, $user->password_conf); // unserialize checkbox values if (count($to_unserialize)) { foreach ($to_unserialize as $chkname) { if (isset($user->{$chkname}) && !empty($user->{$chkname})) { $chk_val = @unserialize($user->{$chkname}); if (is_array($chk_val)) { $user->{$chkname} = implode("|", $chk_val); } } } } // check - issue #1382 if (isset($bk_users_to_import)) { $importuser = new stdClass(); foreach ($import_user_fileds as $import_user_filed) { if (isset($user->{$import_user_filed})) { $importuser->{$import_user_filed} = $user->{$import_user_filed}; } if ($import_user_filed == 'pack_id') { $importuser->{$import_user_filed} = $member->pack_id; } } $export_users[] = $importuser; unset($importuser); } else { $export_users[] = $user; } } // consider multiple memberships as well: if (isset($member->other_membership_types) && is_array($member->other_membership_types) && count($member->other_membership_types) > 0) { // loop foreach ($member->other_membership_types as $key => $memtypes) { // types if (is_array($memtypes)) { $memtypes = mgm_convert_array_to_memberobj($memtypes, $user->ID); } // check search parameters: if ($this->_get_membership_details($memtypes, $bk_msexp_dur_unit, $bk_msexp_dur, $membership_type, $current_date, $bk_inactive, $membership_status)) { // copy $user_mem = clone $user_obj; // add custom fields as well: if (!empty($member->custom_fields)) { // loop foreach ($member->custom_fields as $index => $val) { // custom field if ($index == 'birthdate' && !empty($val)) { // convert saved date to input field format $val = mgm_get_datepicker_format('date', $val); } // set $user_mem->{$index} = $val; } } // check types if (is_object($memtypes) && method_exists($memtypes, 'merge_fields')) { // merge $user_mem = $memtypes->merge_fields($user_mem); } else { // convert to array $data = mgm_object2array($memtypes); // check payment if (isset($memtypes->payment_info) && count($memtypes->payment_info) > 0) { // loop payments foreach ($memtypes->payment_info as $index => $val) { // set $data['payment_info_' . $index] = str_replace('mgm_', '', $val); } } // loop data foreach ($data as $index => $val) { $user_mem->{$index} = $val; } } //issue #844 foreach ($skip_fileds as $skip_filed) { unset($user->{$skip_filed}); } // format dates $user_mem->user_registered = date($sformat, strtotime($user_mem->user_registered)); $user_mem->last_pay_date = (int) $memtypes->last_pay_date > 0 ? date($sformat, strtotime($memtypes->last_pay_date)) : 'N/A'; $user_mem->expire_date = !empty($memtypes->expire_date) ? date($sformat, strtotime($memtypes->expire_date)) : 'N/A'; $user_mem->join_date = (int) $memtypes->join_date > 0 ? date($sformat, $memtypes->join_date) : 'N/A'; // check - issue #1382 if (isset($bk_users_to_import)) { $importuser = new stdClass(); foreach ($import_user_fileds as $import_user_filed) { if ($user_mem->{$import_user_filed}) { $importuser->{$import_user_filed} = $user_mem->{$import_user_filed}; } if ($import_user_filed == 'pack_id') { $importuser->{$import_user_filed} = $memtypes->pack_id; } } $export_users[] = $importuser; unset($importuser); } else { $export_users[] = $user_mem; } // unset unset($user_mem); } } } } // end for mgm_log('export_users : ' . mgm_array_dump($export_users, true)); // default response $response = array('status' => 'error', 'message' => __('Error while exporting members. Could not find any member with requested search parameters.', 'mgm')); // check if (($expcount = count($export_users)) > 0) { // Issue #1559: standardization of Membership type for ($k = 0; $k < $expcount; $k++) { if (isset($export_users[$k]->membership_type)) { $export_users[$k]->membership_type = strtolower($export_users[$k]->membership_type); } } // success $success = count($export_users); // create if ($bk_export_format == 'csv') { $filename = mgm_create_csv_file($export_users, 'export_users'); } else { $filename = mgm_create_xls_file($export_users, 'export_users'); } // src $file_src = MGM_FILES_EXPORT_URL . $filename; // message $response['message'] = sprintf(__('Successfully exported %d %s.', 'mgm'), $success, $success > 1 ? 'users' : 'user'); $response['status'] = 'success'; $response['src'] = $file_src; // for download iframe } // return response echo json_encode($response); exit; } // data $data = array(); // load template view $this->load->template('members/member/export', array('data' => $data)); }
/** * Specifically check recurring status of each rebill for an expiry date * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id) && !empty($this->setting['searchapi_auth_user']) && !empty($this->setting['searchapi_auth_pass'])) { // end point $endpoint = $this->_get_endpoint('search'); // search // headers $http_headers = array(); //array('Content-Type' => 'text/xml'); // data $query = array('auth_user' => $this->setting['searchapi_auth_user'], 'auth_pass' => $this->setting['searchapi_auth_pass'], 'member_id' => $member->payment_info->subscr_id, 'trans_id' => $member->payment_info->txn_id, 'api_action' => 'search'); //prevcanc // // url $post_url = add_query_arg($query, $endpoint); // create curl post $http_response = mgm_remote_get($post_url, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // init $response = array(); // parse if ($xml = @simplexml_load_string($http_response)) { // dump mgm_log($xml, __FUNCTION__); $response = array(); // status if (isset($xml->Record->Customer->Status)) { $response['status'] = (string) $xml->Record->Customer->Status; } // tarsn date if (isset($xml->Record->Customer->LastTransDate)) { $response['last_trans_date'] = date('Y-m-d', strtotime((string) $xml->Record->Customer->LastTransDate)); } // trans id if (isset($xml->Record->Transactions->Transaction->TransID)) { $response['trans_id'] = (string) $xml->Record->Transactions->Transaction->TransID; } // event type if (isset($xml->Record->Events->Event->EventType)) { $response['event_type'] = (string) $xml->Record->Events->Event->EventType; } // event date if (isset($xml->Record->Events->Event->EventInitdate)) { $response['event_date'] = (string) $xml->Record->Events->Event->EventInitdate; } } // dump mgm_log($response, __FUNCTION__); //return false; // check if (isset($response['status'])) { // old status $old_status = $member->status; // set status switch ($response['status']) { case 'Active Trial': case 'Active Recurring': case 'Active Preview': case 'Active': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // last pay date $member->last_pay_date = isset($response['last_trans_date']) && !empty($response['last_trans_date']) ? $response['last_trans_date'] : date('Y-m-d'); // expire date if (isset($response['last_trans_date']) && !empty($response['last_trans_date']) && !empty($member->expire_date)) { // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway, if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // set eway txn no if (isset($response['trans_id'])) { $member->payment_info->epoch_txn_id = $response['trans_id']; } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'Canceled': case 'Cancelled Recurring': case 'Cancelled Trial': case 'Cancelled Preview': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'Suspended': case 'Terminated': case 'Expired': // set new statis $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired', 'mgm'); // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
/** * expire member: for force expire test */ function mgm_expire_member($user_id, $expire_date) { // get member $member = mgm_get_member($user_id); // if today if ($expire_date == date('Y-m-d')) { $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d'); } else { $format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($format, strtotime($expire_date))); // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // update user // update_user_option($user_id, 'mgm_member', $member, true); $member->save(); }
<div class="cell theadDivCell width100px"> <b><?php _e('Purchase/Gift Date', 'mgm'); ?> </b> </div> <div class="cell theadDivCell width100px"> <b><?php _e('Action', 'mgm'); ?> </b> </div> </div> <?php $date_format = mgm_get_date_format('date_format'); $date_format_time = mgm_get_date_format('date_format_time'); // loop if ($data['post_purchases']) { foreach ($data['post_purchases'] as $purchase) { // check is_expiry if ($purchase->is_expire == 'N') { $expiry = __('Indefinite', 'mgm'); } else { $expiry = mgm_get_post($purchase->post_id)->get_access_duration(); $expiry = !$expiry ? __('Indefinite', 'mgm') : date('d/m/Y', 86400 * $expiry + strtotime($purchase->purchase_dt)) . " (" . $expiry . __(' D', 'mgm') . ")"; } // member name if (preg_match('/^guest-/', $purchase->user_login)) { // guest token $guest_token = str_replace('guest-', '', $purchase->user_login); // member
/** * Admin user edit screen unsubscribe staus button */ function mgm_get_admin_user_unsubscribe_status_button($member, $user) { // init $html = ''; // object $packs_obj = mgm_get_class('subscription_packs'); $pack_name = $packs_obj->get($member->pack_id); // cancelled if ($member->status == MGM_STATUS_CANCELLED) { $html .= '<span class="s-active"><b>' . $pack_name['description'] . '</b></span>'; $html .= '<div class="mgm_margin_bottom_10px s-expired">' . '<h4>' . __('Unsubscribed', 'mgm') . '</h4>' . '<div class="mgm_margin_bottom_10px mgm_color_red">' . __('You have unsubscribed.', 'mgm') . '</div>' . '</div>'; $html .= '<hr/>'; } elseif (isset($member->status_reset_on) && isset($member->status_reset_as) && $member->status == MGM_STATUS_AWAITING_CANCEL) { $lformat = mgm_get_date_format('date_format_long'); $html .= '<span class="s-active"><b>' . $pack_name['description'] . '</b></span>'; $html .= '<div class="mgm_margin_bottom_10px s-expired">' . '<h4>' . __('Unsubscribed', 'mgm') . '</h4>' . '<div class="mgm_margin_bottom_10px mgm_color_red">' . sprintf(__('You have unsubscribed. Your account has been marked for cancellation on <b>%s</b>.', 'mgm'), date($lformat, strtotime($member->status_reset_on))) . '</div>' . '</div>'; $html .= '<hr/>'; } else { // show unsucscribe button if (is_super_admin()) { // check if ($module = $member->payment_info->module) { // if a valid module if ($obj_module = mgm_is_valid_module($module, 'payment', 'object')) { // output button $html .= '<span class="s-active"><b>' . $pack_name['description'] . '</b></span>'; $html .= $obj_module->get_button_unsubscribe(array('user_id' => $user->ID, 'membership_type' => $member->membership_type)); $html .= '<script language="javascript">' . 'confirm_unsubscribe=function(element){' . 'if(confirm("' . __('You are about to unsubscribe. Do you want to proceed?', 'mgm') . '")){' . 'jQuery(element).closest("form").submit();' . '}' . '}' . '</script>'; $html .= '<hr/>'; } } } } return $html; }
function get_earnings($date_start, $date_end, $member_type) { // global global $wpdb; $data = array(); $curr_date = mgm_get_current_datetime(); $current_date = $curr_date['timestamp']; // preparing query based on dates if (!empty($date_start) && !empty($date_end)) { /* $date_end=str_replace('/','-',$date_end); $end_date = date('Y-m-d', strtotime( $date_end)); $date_start=str_replace('/','-',$date_start); $start_date = date('Y-m-d', strtotime( $date_start)); */ //issue #1311 $sformat = mgm_get_date_format('date_format_short'); $start_date = mgm_format_inputdate_to_mysql($date_start, $sformat); $end_date = mgm_format_inputdate_to_mysql($date_end, $sformat); $start_date .= ' 00:00:00'; $end_date .= ' 23:59:59'; //Issue #733 //$condition =" WHERE transaction_dt BETWEEN '$start_date' AND '$end_date'"; $condition = " AND status_text = 'Last payment was successful' AND transaction_dt BETWEEN '{$start_date}' AND '{$end_date}'"; } else { //setting the default end date if (empty($date_end)) { $date_end = $end_date = date('Y-m-d', $current_date); $end_date .= ' 23:59:59'; } //setting the default start date if (empty($date_start)) { $date_start = $start_date = date('Y-m-d', strtotime("{$end_date} - 3 months")); $start_date .= ' 00:00:00'; } //$condition =" WHERE transaction_dt BETWEEN '$start_date' AND '$end_date'"; $condition = " AND status_text = 'Last payment was successful' AND transaction_dt BETWEEN '{$start_date}' AND '{$end_date}'"; //Issue #733 //$condition =" ORDER BY `transaction_dt` DESC LIMIT 10"; //$condition = " AND status_text = 'Last payment was successful' ORDER BY `transaction_dt` DESC LIMIT 10"; } // sql $sql = "SELECT * FROM `" . TBL_MGM_TRANSACTION . "` WHERE 1 {$condition}"; // mgm_log($sql); // row $rows = $wpdb->get_results($sql); // reset data $subscription = array(); $purchase = array(); $d = array(); // looping the results foreach ($rows as $row) { $row->data = json_decode($row->data, true); extract($row->data); // Storing subscription data to array if (trim($row->payment_type) == 'subscription_purchase') { $dt = strtok($row->transaction_dt, " "); if (isset($subscription[$dt])) { if ($membership_type == $member_type || $member_type == 'all') { $subscription[$dt]['date'] = $dt; //issue #1311 if ($trial_on) { $subscription[$dt]['cost'] += $trial_cost; } else { $subscription[$dt]['cost'] += $cost; } //$subscription[$dt]['cost'] +=$cost; $subscription[$dt]['count']++; } } else { if ($membership_type == $member_type || $member_type == 'all') { $d[] = $dt; $subscription[$dt]['date'] = $dt; //issue #1311 if ($trial_on) { $subscription[$dt]['cost'] += $trial_cost; } else { $subscription[$dt]['cost'] += $cost; } //$subscription[$dt]['cost'] =$cost; $subscription[$dt]['count'] = 1; } } } // Storing pay per post data to array if (trim($row->payment_type) == 'post_purchase') { $dt = strtok($row->transaction_dt, " "); if (isset($purchase[$dt])) { // validating membership type if ($membership_type == $member_type || $member_type == 'all') { $purchase[$dt]['date'] = $dt; $purchase[$dt]['cost'] += $cost; $purchase[$dt]['count']++; } } else { // validating membership type if ($membership_type == $member_type || $member_type == 'all') { $d[] = $dt; $purchase[$dt]['date'] = $dt; $purchase[$dt]['cost'] = $cost; $purchase[$dt]['count'] = 1; } } } } //getting recurring earnings and dates $recurring_data = $this->recurring_earnings($date_start, $date_end, $member_type); $d = array_unique($d); $md = array_merge($d, $recurring_data['dates']); $d = array_unique($md); sort($d); $recurring = $recurring_data['recurring']; $dcount = count($d); $data[0]['date_start'] = $date_start; $data[0]['date_end'] = $date_end; $data[0]['member_type'] = $member_type; // Migrating the pay per post,recurring and subscription data to array for ($i = 0; $i < $dcount; $i++) { $udt = $d[$i]; if (!empty($udt)) { $data[$i]['date'] = $udt; if (array_key_exists($udt, $purchase)) { $data[$i]['purchase'] = $purchase[$udt]['cost']; } else { $data[$i]['purchase'] = 0; } if (array_key_exists($udt, $subscription)) { $data[$i]['subscription'] = $subscription[$udt]['cost']; } else { $data[$i]['subscription'] = 0; } if (isset($recurring) && array_key_exists($udt, $recurring)) { $data[$i]['recurring'] = $recurring[$udt]['cost']; } else { $data[$i]['recurring'] = 0; } } } return $data; }
/** * ongoing member expired */ function mgm_ongoing_member_expired($user, $member, $spacks_obj, $data, $other_purchases = false, $process_inactive_users = false) { // only check for Active members iss#645 // if($member->status != MGM_STATUS_ACTIVE) return $member; // find expire date $expire_date = $member->expire_date; // duration exprs $duration_exprs = $spacks_obj->get_duration_exprs(); // active lifetime user: // $non_date_expr = array('l','dr'); $non_date_expr = array_keys($spacks_obj->get_duration_types('non_date_expr')); // log // mgm_log('non_date_expr: '. print_r($non_date_expr, true), __FUNCTION__); // exit lifetime users if (in_array($member->duration_type, $non_date_expr) || empty($expire_date)) { // before exit update life time users if wrongly processed earlier if ($member->duration_type == 'l' && $member->status == MGM_STATUS_EXPIRED) { // set new status $member->status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Life time membership extended', 'mgm'); // save if ($other_purchases) { mgm_save_another_membership_fields($member, $user->ID); } else { $member->save(); } // log // mgm_log(sprintf('life time member %d reactivated: %s', $user->ID, $member->status), __FUNCTION__); } // exit return $member; // lifetime and date_range } // check on expire date // days to expire $date_diff = strtotime($expire_date) - $data['current_timestamp']; $days_to_expire = floor($date_diff / (60 * 60 * 24)); $days_to_expire2 = abs($date_diff / (60 * 60 * 24)); $date_format_time = mgm_get_date_format('date_format_time'); // log /*mgm_log(sprintf('expire users: user: %d, days_to_expire1: %d, days_to_expire2: %d, expire_date: %s, current_date: %s', $user->ID, $days_to_expire, $days_to_expire2, $expire_date, date('Y-m-d H:i:s', $data['current_timestamp'])), (__FUNCTION__ . '_user_' . $user->ID));*/ // days match, support for expired check, negative days // commented the below line because the membership was expiring one day early. if ($days_to_expire <= 0) { // check pack $subs_pack = array(); // get pack if (isset($member->pack_id) && (int) $member->pack_id > 0) { $subs_pack = $spacks_obj->get_pack($member->pack_id); } // check pack if (empty($subs_pack)) { // fetch from old data $subs_pack = $spacks_obj->validate_pack($member->amount, $member->duration, $member->duration_type, $member->membership_type); } // ok if (isset($subs_pack['id'])) { //issue#: 478 $num_cycles = isset($member->active_num_cycles) && !empty($member->active_num_cycles) ? $member->active_num_cycles : $subs_pack['num_cycles']; // lifetime ongoing/fixed cycle ongoing // issue #: 418 if ($num_cycles == 0 || $num_cycles > 1 && (int) $member->rebilled <= (int) $num_cycles) { // 100 to dynamic // make sure scheduler considers it after expiry date only: if ($days_to_expire2 >= 1 && $days_to_expire < 0) { //This will check the next day after expiry date to consider payments happened on expiry date as well // member reached rebill cycle, expire now // set expired status if ($num_cycles > 1 && (int) $member->rebilled == $num_cycles) { // old status $old_status = $member->status; // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // set status $member->status_str = sprintf(__('Membership expired on %s - rebill cycle completed', 'mgm'), date($date_format_time, $data['current_timestamp'])); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user->ID, $member, 'EXPIRE', true); } else { // #767, for ongoing membership, set Inactive members as Active, depends on settings if ($num_cycles == 0) { // change, checking all status to allow expire date extend for Active users // paid users if (!empty($member->last_pay_date)) { // change status for Inactive only if ($member->status == MGM_STATUS_NULL) { // inactive // only when set to process inactive user if ($process_inactive_users == true) { // old status $old_status = $member->status; // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); } } elseif ($member->status == MGM_STATUS_ACTIVE) { // active // current cycle expire date if (!empty($member->expire_date)) { // date add $date_add = sprintf('+ %d %s', $subs_pack['duration'], $duration_exprs[$subs_pack['duration_type']]); // new expire date, calc by cycle so pack is used, $new_expire_date = mgm_get_current_rebill_cycle_expiry_date($member->expire_date, $date_add); // expire date should not overlap, #1223 if (strtotime($new_expire_date) > strtotime($member->expire_date)) { // set $member->expire_date = $new_expire_date; // last pay if (!empty($member->last_pay_date)) { $member->last_pay_date = date('Y-m-d', strtotime(str_replace('+', '-', $date_add), strtotime($member->expire_date))); } // status string $member->status_str = __('Last payment cycle processed successfully - membership expire extended using pack', 'mgm'); } } } // end paid active } else { // unpaid users // old status if ($member->status != MGM_STATUS_NULL) { // copy $old_status = $member->status; // set new status $member->status = $new_status = MGM_STATUS_NULL; // set status $member->status_str = __('Last payment incomplete', 'mgm'); } } // end unpaid } // end ongoing } // update member if ($other_purchases) { mgm_save_another_membership_fields($member, $user->ID); } else { $member->save(); } // action if (isset($new_status)) { do_action('mgm_user_status_change', $user->ID, $new_status, $old_status, 'schedular_reset_ongoing_memberships', $member->pack_id); } } } elseif ((int) $num_cycles == 1 && $data['current_timestamp'] > strtotime($expire_date)) { //one-time billing,double check for date calc bug #1126 // old status $old_status = $member->status; // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // set status $member->status_str = sprintf(__('Membership expired on %s - onetime billing completed', 'mgm'), date($date_format_time, $data['current_timestamp'])); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user->ID, $member, 'EXPIRE', true); // update member if ($other_purchases) { mgm_save_another_membership_fields($member, $user->ID); } else { $member->save(); } // remove role from user: mgm_remove_userroles($user->ID, $member); // action do_action('mgm_user_status_change', $user->ID, $new_status, $old_status, 'schedular_reset_ongoing_memberships', $member->pack_id); } } else { // pack not found manual update, expire users if days negative if (empty($subs_pack) && $days_to_expire <= 0) { // old status $old_status = $member->status; // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // set status $member->status_str = sprintf(__('Membership expired on %s - no pack found', 'mgm'), date($date_format_time, $data['current_timestamp'])); // update member if ($other_purchases) { mgm_save_another_membership_fields($member, $user->ID); } else { $member->save(); } // remove role from user: mgm_remove_userroles($user->ID, $member); // action do_action('mgm_user_status_change', $user->ID, $new_status, $old_status, 'schedular_reset_ongoing_memberships', $member->pack_id); } } } // return return $member; }
/** * Specifically check recurring status of each rebill for an expiry date * Along with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean * @deprecated as not supported by standard */ function query_rebill_status($user_id, $member = NULL) { // check if ($this->setting['rebill_status_query'] == 'disabled') { return false; } // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { // query data $query_data = array(); // add internal vars $secure = array('clientAccnum' => $this->setting['client_acccnum'], 'clientSubacc' => $this->setting['client_subacc'], 'username' => $this->setting['datalink_username'], 'password' => $this->setting['datalink_password']); // merge $query_data = array_merge($query_data, $secure); // overwrite post data array with secure params // method $query_data['action'] = 'viewSubscriptionStatus'; $query_data['subscriptionId'] = $member->payment_info->subscr_id; // xml response $query_data['returnXML'] = 1; // post string $query_string = _http_build_query($query_data, null, '&'); // endpoint $endpoint = $this->_get_endpoint('datalink_sms'); // url $url = $endpoint . '?' . $query_string; // remote get $http_response = mgm_remote_get($url, null, null, false); // log mgm_log($http_response, $this->module . '_' . __FUNCTION__); // subs data $subsdata = array('subscriptionStatus' => 'Error'); // xml if ($xml = @simplexml_load_string($http_response)) { // check if (isset($xml->subscriptionStatus)) { // get status switch ((int) $xml->subscriptionStatus) { case 0: // inactive //$subsdata['subscriptionStatus'] = 'Pending'; //consider expired - got confirmation from ccbill team $subsdata['subscriptionStatus'] = 'Expired'; if ($expirationDate = (string) $xml->expirationDate) { $subsdata['expirationDate'] = strlen($expirationDate) > 8 ? substr($expirationDate, 0, 8) : $expirationDate; } break; case 1: // cancelled $subsdata['subscriptionStatus'] = 'Cancelled'; if ($cancelDate = (string) $xml->cancelDate) { $subsdata['cancelDate'] = strlen($cancelDate) > 8 ? substr($cancelDate, 0, 8) : $cancelDate; } if ($expirationDate = (string) $xml->expirationDate) { $subsdata['expirationDate'] = strlen($expirationDate) > 8 ? substr($expirationDate, 0, 8) : $expirationDate; } break; case 2: // active $subsdata['subscriptionStatus'] = 'Active'; break; default: // error break; } } // next pay if (isset($xml->nextBillingDate)) { if ($nextBillingDate = (string) $xml->nextBillingDate) { $subsdata['nextBillingDate'] = strlen($nextBillingDate) > 8 ? substr($nextBillingDate, 0, 8) : $nextBillingDate; } } } // check if (isset($subsdata['subscriptionStatus'])) { // old status $old_status = $member->status; // date format $date_format = mgm_get_date_format('date_format'); // set status switch ($subsdata['subscriptionStatus']) { case 'Active': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); //Get pack cycle and less form cc-bill nexbilling date to find last pay date. $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // last pay date if ($pack_cycle_format !== false) { $pack_cycle_less = str_replace('+', '-', $pack_cycle_format); $member->last_pay_date = isset($subsdata['nextBillingDate']) ? date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['nextBillingDate']))) : date('Y-m-d'); } else { $member->last_pay_date = isset($subsdata['nextBillingDate']) ? date('Y-m-d', strtotime($subsdata['nextBillingDate'])) : date('Y-m-d'); } // expire date if (isset($subsdata['nextBillingDate']) && !empty($member->expire_date)) { // consider next billing date as expire date from cc bill. $member->expire_date = date('Y-m-d', strtotime($subsdata['nextBillingDate'])); /* // date to add $date_add = mgm_get_pack_cycle_date((int)$member->pack_id, $member); // check if($date_add !== false){ // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway if(strtotime($new_expire_date) > strtotime($member->expire_date)){ $member->expire_date = $new_expire_date; } }else{ // set last pay date if greater than expire date if(strtotime($member->last_pay_date) > strtotime($member->expire_date)){ $member->expire_date = $member->last_pay_date; } } */ } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'Cancelled': // if expire date in future, let as awaiting if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate']) && strtotime($subsdata['expirationDate']) > time()) { // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; //taking expire date from ccbill $member->expire_date = date('Y-m-d', strtotime($subsdata['expirationDate'])); // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string if (isset($subsdata['cancelDate']) && !empty($subsdata['cancelDate'])) { $member->status_str = sprintf(__('Last payment cycle cancelled on %s', 'mgm'), date($date_format, strtotime($subsdata['cancelDate']))); } else { $member->status_str = __('Last payment cycle cancelled', 'mgm'); } } //Before this fix users having wrong last pay date so updating here - issue #1520 if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) { //Get pack cycle and less form cc-bill nexbilling date to find last pay date $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // last pay date if ($pack_cycle_format !== false) { $pack_cycle_less = str_replace('+', '-', $pack_cycle_format); $member->last_pay_date = date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['expirationDate']))); } } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'Expired': // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // status string if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) { $member->status_str = sprintf(__('Last payment cycle expired on %s', 'mgm'), date($date_format, strtotime($subsdata['expirationDate']))); } else { $member->status_str = __('Last payment cycle expired', 'mgm'); } //Before this fix users having wrong last pay date so updating here - issue #1520 if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) { //Get pack cycle and less form cc-bill nexbilling date to find last pay date $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // last pay date if ($pack_cycle_format !== false) { $pack_cycle_less = str_replace('+', '-', $pack_cycle_format); $member->last_pay_date = date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['expirationDate']))); } //taking expire date from ccbill $member->expire_date = date('Y-m-d', strtotime($subsdata['expirationDate'])); } // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; }
echo mgm_make_combo_options($data['levels'], $data['key']->level, MGM_VALUE_ONLY); ?> </select> </div> </div> <div class="row brBottom"> <div class="cell width120px"> <?php _e('Create Date', 'mgm'); ?> </span>: </div> <div class="cell textalignleft"> <?php echo date(mgm_get_date_format('date_format'), strtotime($data['key']->create_dt)); ?> </div> </div> <div class="row brBottom"> <div class="cell width120px"> <div class="floatleft"> <input class="button" type="submit" name="save_key" value="<?php _e('Save', 'mgm'); ?> " /> <input class="button" type="button" name="cancel_save_key" value="<?php _e('Cancel', 'mgm'); ?> " onclick="mgm_load_api_keys()"/>
/** * Specifically check recurring status of each rebill for an expiry date * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { //issue #1602 $pack_id = (int) $member->pack_id; if ($pack_id) { $currency = mgm_get_pack_currency($pack_id); } // post data $post_data = array(); // add internal vars $secure = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '64.0', 'IPADDRESS' => mgm_get_client_ip_address(), 'CURRENCYCODE' => $currency ? $currency : $this->setting['currency']); // merge $post_data = array_merge($post_data, $secure); // overwrite post data array with secure params // method $post_data['METHOD'] = 'GetRecurringPaymentsProfileDetails'; $post_data['PROFILEID'] = $member->payment_info->subscr_id; // endpoint url $end_point = $this->_get_endpoint(); //issue #1508 $url_parsed = parse_url($end_point); // domain/host $domain = $url_parsed['host']; // headers $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n'); // post $http_response = mgm_remote_post($end_point, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // log mgm_log($http_response, __FUNCTION__); // reset $this->response = array(); // parse to array parse_str($http_response, $this->response); // log mgm_log($this->response, __FUNCTION__); // post string // $post_string = mgm_http_build_query($post_data); // create curl post // $buffer = $this->_curl_post($endpoint, $post_string); // parse to array // parse_str($http_response, $this->response); // check if (isset($this->response['STATUS'])) { // old status $old_status = $member->status; // set status switch ($this->response['STATUS']) { case 'Active': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // last pay date $member->last_pay_date = isset($this->response['LASTPAYMENTDATE']) ? date('Y-m-d', strtotime($this->response['LASTPAYMENTDATE'])) : date('Y-m-d'); // expire date if (isset($this->response['LASTPAYMENTDATE']) && !empty($member->expire_date)) { // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'Cancelled': case 'Suspended': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'Expired': // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired', 'mgm'); // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
function _cancel_membership($user_id = null, $redirect = false) { // system $system_obj = mgm_get_class('system'); $s_packs = mgm_get_class('subscription_packs'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails')); //issue #1521 $is_admin = is_super_admin() ? true : false; // get passthrough, stop further process if fails to parse $custom = $this->_get_transaction_passthrough($_POST['COMPLUS']); // local var extract($custom); // currency if (!$currency) { $currency = $this->setting['currency']; } // find user $user = get_userdata($user_id); $member = mgm_get_member($user_id); // multiple membesrhip level update: $multiple_update = false; if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type'] || isset($is_another_membership_purchase) && $is_another_membership_purchase == 'Y') { $multiple_update = true; $multi_memtype = isset($_POST['membership_type']) ? $_POST['membership_type'] : $membership_type; $member = mgm_get_member_another_purchase($user_id, $multi_memtype); } // tracking fields module_field => post_field $tracking_fields = array('txn_type' => 'txn_type', 'subscr_id' => 'subscr_id', 'txn_id' => 'txn_id'); // save tracking fields $this->_save_tracking_fields($tracking_fields, $member); $expire_date = $member->expire_date; // if lifetime: if ($member->duration_type == 'l') { $expire_date = date('Y-m-d'); } // transaction_id $trans_id = $member->transaction_id; // if today if ($expire_date == date('Y-m-d')) { // status $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); // set $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d'); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true); } else { // date $date_format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date))); // set $member->status = $new_status; $member->status_str = $new_status_str; // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // multiple membesrhip level update: if ($multiple_update) { mgm_save_another_membership_fields($member, $user_id); } else { $member->save(); } // transaction status mgm_update_transaction_status($trans_id, $new_status, $new_status_str); // send email notification to client $blogname = get_option('blogname'); // notify user if (!$dpne) { // notify user mgm_notify_user_membership_cancellation($blogname, $user, $member, $system_obj, $new_status, $membership_type); } // notify admin if (!$dge) { // notify admin mgm_notify_admin_membership_cancellation($blogname, $user, $member); } // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // redirect only internal if ($redirect) { // message $lformat = mgm_get_date_format('date_format_long'); $message = sprintf(__("You have successfully unsubscribed. Your account has been marked for cancellation on %s", "mgm"), $expire_date == date('Y-m-d') ? 'Today' : date($lformat, strtotime($expire_date))); //issue #1521 if ($is_admin) { mgm_redirect(add_query_arg(array('user_id' => $user_id, 'unsubscribe_errors' => urlencode($message)), admin_url('user-edit.php'))); } // redirect mgm_redirect(mgm_get_custom_url('membership_details', false, array('unsubscribed' => 'true', 'unsubscribe_errors' => urlencode($message)))); } }
</div> <div class="cell theadDivCell width100px"> <b><?php _e('Create Date', 'mgm'); ?> </b> </div> <div class="cell theadDivCell width100px"> <b><?php _e('Action', 'mgm'); ?> </b> </div> </div> <?php $date_format = mgm_get_date_format('date_format'); ?> <?php if (count($data['keys']) > 0) { foreach ($data['keys'] as $key) { ?> <div class="row <?php echo $alt = $alt == '' ? 'alternate' : ''; ?> " id="row-<?php echo $key->id; ?> "> <div class="cell width100px">
function _cancel_membership($user_id = NULL, $redirect = false) { // system $system_obj = mgm_get_class('system'); $s_packs = mgm_get_class('subscription_packs'); $duration_str = $s_packs->duration_str; $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails')); //issue #1521 $is_admin = is_super_admin() ? true : false; // if passthrough provided if (isset($_REQUEST['extra'])) { // get passthrough, stop further process if fails to parse $custom = $this->_get_transaction_passthrough($_REQUEST['extra']); // local var extract($custom); } elseif (isset($_REQUEST['SUBSCRIPTION_ID']) || isset($_REQUEST['SubscriptionID'])) { // get tran $tran = mgm_get_transaction_by_option('zombaio_subscription_id', isset($_REQUEST['SUBSCRIPTION_ID']) ? $_REQUEST['SUBSCRIPTION_ID'] : $_REQUEST['SubscriptionID']); // local var extract($tran['data']); } elseif (isset($_REQUEST['TRANSACTION_ID'])) { // get tran $tran = mgm_get_transaction_by_option('zombaio_transaction_id', $_REQUEST['TRANSACTION_ID']); // local var extract($tran['data']); } elseif (isset($_REQUEST['username'])) { // get user if ($user = get_user_by('login', $_REQUEST['username'])) { $user_id = $user->ID; } } // log // mgm_log($user_id, ($this->module . '_' . __FUNCTION__)); // no user id if (!$user_id) { // message $message = 'Could not read member in the following REQUEST data. Please debug or contact magic members to fix the problem making sure to pass on the following data. <br /><br /><pre>' . "\n\n" . print_r($_REQUEST, true) . '</pre>'; // notify admin, only if gateway emails on if (!$dge) { // mail mgm_mail($system_obj->get_setting('admin_email'), 'Error in Zombaio membership cancellation', $message); } else { // log mgm_log($message, $this->module . '_' . __FUNCTION__); } // exit exit; } // find user $user = get_userdata($user_id); $member = mgm_get_member($user_id); // multiple membesrhip level update: $multiple_update = false; // check if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type'] || isset($membership_type) && $member->membership_type != $membership_type) { $multiple_update = true; $member = mgm_get_member_another_purchase($user_id, $_POST['membership_type']); } // get pack if ($member->pack_id) { $subs_pack = $s_packs->get_pack($member->pack_id); } else { $subs_pack = $s_packs->validate_pack($member->amount, $member->duration, $member->duration_type, $member->membership_type); } // tracking fields module_field => post_field $tracking_fields = array('txn_type' => 'Action', 'subscr_id' => array('SUBSCRIPTION_ID', 'SubscriptionID'), 'txn_id' => 'TRANSACTION_ID'); // save tracking fields $this->_save_tracking_fields($tracking_fields, $member, $_REQUEST); // types $duration_exprs = $s_packs->get_duration_exprs(); // default expire date $expire_date = $member->expire_date; // if lifetime: if ($member->duration_type == 'l') { $expire_date = date('Y-m-d'); } // if trial on if ($subs_pack['trial_on'] && isset($duration_exprs[$subs_pack['trial_duration_type']])) { // if cancel data is before trial end, set cancel on trial expire_date $trial_expire_date = strtotime("+{$subs_pack['trial_duration']} {$duration_exprs[$subs_pack['trial_duration_type']]}", $member->join_date); // if lower if (time() < $trial_expire_date) { $expire_date = date('Y-m-d', $trial_expire_date); } } // transaction_id $trans_id = $member->transaction_id; // log // mgm_log($member, ($this->module . '_' . __FUNCTION__)); // mgm_log($expire_date . ' ' . date('Y-m-d H:i:s'), ($this->module . '_' . __FUNCTION__)); // if today if (time() >= strtotime($expire_date)) { // status $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); // set $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d H:i:s'); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true); } else { // date $date_format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date))); // set $member->status = $new_status; $member->status_str = $new_status_str; // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // log // mgm_log($member, ($this->module . '_' . __FUNCTION__)); // update user // multiple membesrhip level update: if ($multiple_update) { mgm_save_another_membership_fields($member, $user_id); } else { $member->save(); } // transaction status mgm_update_transaction_status($trans_id, $new_status, $new_status_str); // send email notification to client $blogname = get_option('blogname'); // subject $subject = $system_obj->get_template('subscription_cancelled_email_template_subject', array('blogname' => $blogname), true); // body $message = $system_obj->get_template('subscription_cancelled_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true); // send email notification to user if (!$dpne) { //issue #862 $subject = mgm_replace_email_tags($subject, $user_id); $message = mgm_replace_email_tags($message, $user_id); // mail mgm_mail($user->user_email, $subject, $message); } // notify admin, only if gateway emails on if (!$dge) { $subject = "[{$blogname}] {$user->user_email} - {$new_status}"; $message = "\tUser display name: {$user->display_name}\n\n<br />\r\r\n\t\t\t\t\tUser email: {$user->user_email}\n\n<br />\r\r\n\t\t\t\t\tUser ID: {$user->ID}\n\n<br />\r\r\n\t\t\t\t\tMembership Type: {$membership_type}\n\n<br />\r\r\n\t\t\t\t\tNew status: {$new_status}\n\n<br />\r\r\n\t\t\t\t\tStatus message: {$member->status_str}\n\n<br />\t\t\t\t\t\r\r\n\t\t\t\t\tPayment Mode: Cancelled\n\n<br />\r\r\n\t\t\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], $subject, $message); } // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // redirect if ($redirect) { // message $lformat = mgm_get_date_format('date_format_long'); $message = sprintf(__("You have successfully unsubscribed. Your account has been marked for cancellation on %s", "mgm"), $expire_date == date('Y-m-d') ? 'Today' : date($lformat, strtotime($expire_date))); //issue #1521 if ($is_admin) { mgm_redirect(add_query_arg(array('user_id' => $user_id, 'unsubscribe_errors' => urlencode($message)), admin_url('user-edit.php'))); } // redirect mgm_redirect(mgm_get_custom_url('membership_details', false, array('unsubscribed' => 'true', 'unsubscribe_errors' => urlencode($message)))); } }
<?php mgm_box_top('Earnings Report. '); $sformat = mgm_get_date_format('date_format_short'); ?> <form name="frmEarnings" id="frmEarnings" method="POST" action="" class="marginpading0px"> <div class="table form-table widefat" id="earnings-table"> <div class="row"> <div class="cell"> <b><?php _e('Date Range:', 'mgm'); ?> </b> </div> <div class="cell"> <?php _e('Start', 'mgm'); ?> : <input type="text" name="bk_date_start" size="10" value="<?php if (isset($data[0]['date_start'])) { echo $data[0]['date_start']; } ?> "/> <?php _e('End', 'mgm'); ?> <input type="text" name="bk_date_end" size="10" value="<?php if (isset($data[0]['date_end'])) {
/** * Specifically check recurring status of each rebill for an expiry date * As Eway doesn't have an IPN post mechanism for rebills, the module will need to specifically request for the rebill status * @param int $user_id * @param object $member * @return boolean */ function query_rebill_status($user_id, $member = NULL) { // check if (isset($member->payment_info->rebill_customerid) && !empty($member->payment_info->rebill_customerid) && isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) { //if settings are blank if (empty($this->setting['username']) || empty($this->setting['password']) || empty($this->setting['customer_id'])) { return false; } // eway time $eway_time = $this->_datetime_to_eway_serverdatetime(date('Y-m-d H:i:s')); // check rebill start date if (!isset($member->payment_info->rebill_start_date) || isset($member->payment_info->rebill_start_date) && strtotime($eway_time) <= strtotime($member->payment_info->rebill_start_date)) { // log mgm_log(sprintf('Exit flag since rebill start date not reached Eway Time Today: %s, Rebill Start Date: %s', $eway_time, $member->payment_info->rebill_start_date), $this->module . '_' . __FUNCTION__); // return return false; } // setup $gateway_method = 'webservice'; $secure = array('CustomerID' => $this->setting['customer_id'], 'Username' => $this->setting['username'], 'Password' => $this->setting['password']); // packs $s_packs = mgm_get_class('subscription_packs'); // pack $pack = $s_packs->get_pack((int) $member->pack_id); // durations $duration_exprs = $s_packs->get_duration_exprs(); // time $time = time(); // start date is last pay date as per pack $start_date = date('Y-m-d', strtotime(sprintf('- %d %s', $pack['duration'], $duration_exprs[$pack['duration_type']]), $time)); // end date is today $end_date = date('Y-m-d', $time); //data to post $post_data = array('Option1' => $member->payment_info->txn_id, 'webservice_action' => 'QueryTransactions', 'RebillCustomerID' => $member->payment_info->rebill_customerid, 'RebillID' => $member->payment_info->subscr_id, 'startDate' => $start_date, 'endDate' => $end_date); // merge $post_data = array_merge($post_data, $secure); // filter post data and create soap xml $post_string = $this->_filter_postdata($gateway_method, $post_data); // endpoint $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method); // test_webservice / live_webservice // headers $http_headers = $this->_get_http_headers($gateway_method, $post_data['webservice_action']); // log mgm_log('Request Headers [' . $post_data['webservice_action'] . ']' . mgm_pr($http_headers, true), __FUNCTION__); // log mgm_log('Request [' . $post_data['webservice_action'] . ']' . $post_string, __FUNCTION__); // create curl post $http_response = mgm_remote_post($endpoint, $post_string, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // log mgm_log('Response [' . $post_data['webservice_action'] . ']' . $http_response, __FUNCTION__); /*// header $http_header = array('User-Agent: NuSOAP/0.9.5 (1.123)', 'Content-Type: text/xml; charset=ISO-8859-1', sprintf('SOAPAction: "http://www.eway.com.au/gateway/rebill/manageRebill/%s"', $post_data['webservice_action']));*/ // post soap data // $buffer = $this->_curl_post($endpoint, $post_string, $http_header); // parse response $this->_process_response($gateway_method, $http_response, $post_data['webservice_action']); // log mgm_log('Response Parsed [' . $post_data['webservice_action'] . ']' . mgm_pr($this->response, true), __FUNCTION__); // check if (isset($this->response['response_status'])) { // old status $old_status = $member->status; // get response code $response_code = $this->_get_response_code($this->response['response_status'], 'status'); // log mgm_log('Response Code' . $response_code, __FUNCTION__); // process on response code switch ($response_code) { case 'Approved': // set new status $member->status = $new_status = MGM_STATUS_ACTIVE; // status string $member->status_str = __('Last payment cycle processed successfully', 'mgm'); // last pay date $member->last_pay_date = isset($this->response['transactiondate']) ? date('Y-m-d', strtotime($this->response['transactiondate'])) : date('Y-m-d'); // expire date if (isset($this->response['transactiondate']) && !empty($member->expire_date)) { // date to add $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member); // check if ($date_add !== false) { // new expire date should be later than current expire date, #1223 $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date))); // apply on last pay date so the calc always treat last pay date form gateway if (strtotime($new_expire_date) > strtotime($member->expire_date)) { $member->expire_date = $new_expire_date; } } else { // set last pay date if greater than expire date if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) { $member->expire_date = $member->last_pay_date; } } } // set eway txn no if (isset($this->response['transactionnumber'])) { $member->payment_info->eway_txn_id = $this->response['transactionnumber']; } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // transaction_id $transaction_id = $member->transaction_id; // hook args $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id); // after succesful payment hook do_action('mgm_membership_transaction_success', $args); // backward compatibility do_action('mgm_subscription_purchase_payment_success', $args); // new organized name // } break; case 'Cancelled': // if expire date in future, let as awaiting if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) { // date format $date_format = mgm_get_date_format('date_format'); // status $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL; // status string $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date))); // set reset date $member->status_reset_on = $member->expire_date; // reset as $member->status_reset_as = MGM_STATUS_CANCELLED; } else { // set cancelled // status $member->status = $new_status = MGM_STATUS_CANCELLED; // status string $member->status_str = __('Last payment cycle cancelled', 'mgm'); } // save $member->save(); // only run in cron, other wise too many tracking will be added // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){ // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); // } break; case 'Expired': // set new status $member->status = $new_status = MGM_STATUS_EXPIRED; // status string $member->status_str = __('Last payment cycle expired', 'mgm'); // save $member->save(); break; } // action if (isset($new_status) && $new_status != $old_status) { // user status change do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id); // rebill status change do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query'); // query or notify } // return as a successful rebill return true; } } // return return false; //default to false to skip normal modules }
function _cancel_membership() { // system $system_obj = mgm_get_class('system'); $s_packs = mgm_get_class('subscription_packs'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails')); // get passthrough, stop further process if fails to parse $custom = $this->_get_transaction_passthrough($_POST['M_custom']); // local var extract($custom); // find user $user = get_userdata($user_id); $member = mgm_get_member($user_id); // multiple membesrhip level update: $multiple_update = false; // check if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type'] || isset($is_another_membership_purchase) && $is_another_membership_purchase == 'Y') { $multiple_update = true; $multi_memtype = isset($_POST['membership_type']) ? $_POST['membership_type'] : $membership_type; $member = mgm_get_member_another_purchase($user_id, $multi_memtype); } // get pack if ($member->pack_id) { $subs_pack = $s_packs->get_pack($member->pack_id); } else { $subs_pack = $s_packs->validate_pack($member->amount, $member->duration, $member->duration_type, $member->membership_type); } // tracking fields module_field => post_field $tracking_fields = array('txn_type' => 'futurePayStatusChange', 'subscr_id' => 'futurePayId', 'txn_id' => 'ctransreceipt'); // save tracking fields $this->_save_tracking_fields($tracking_fields, $member); // types $duration_exprs = $s_packs->get_duration_exprs(); // default expire date $expire_date = $member->expire_date; // if lifetime: if ($member->duration_type == 'l') { $expire_date = date('Y-m-d'); } // if trial on if ($subs_pack['trial_on'] && isset($duration_exprs[$subs_pack['trial_duration_type']])) { // if cancel data is before trial end, set cancel on trial expire_date $trial_expire_date = strtotime("+{$subs_pack['trial_duration']} {$duration_exprs[$subs_pack['trial_duration_type']]}", $member->join_date); // if lower if (time() < $trial_expire_date) { $expire_date = date('Y-m-d', $trial_expire_date); } } // transaction_id $trans_id = $member->transaction_id; // if today if ($expire_date == date('Y-m-d')) { // status $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); // set $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d'); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true); } else { // date $date_format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date))); // set $member->status = $new_status; $member->status_str = $new_status_str; // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // multiple membesrhip level update: if ($multiple_update) { mgm_save_another_membership_fields($member, $user_id); } else { $member->save(); } // transaction status mgm_update_transaction_status($trans_id, $new_status, $new_status_str); // send email notification to client $blogname = get_option('blogname'); // subject $subject = $system_obj->get_template('subscription_cancelled_email_template_subject', array('blogname' => $blogname), true); // body $message = $system_obj->get_template('subscription_cancelled_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true); // send email notification to user if (!$dpne) { //issue #862 $subject = mgm_replace_email_tags($subject, $user_id); $message = mgm_replace_email_tags($message, $user_id); // mail mgm_mail($user->user_email, $subject, $message); } // send email notification to system administrator if (!$dge) { $subject = "[{$blogname}] {$user->user_email} - {$new_status}"; $message = "\tUser display name: {$user->display_name}\n\n<br />\r\r\n\t\t\t\t\tUser email: {$user->user_email}\n\n<br />\r\r\n\t\t\t\t\tUser ID: {$user->ID}\n\n<br />\r\r\n\t\t\t\t\tMembership Type: {$membership_type}\n\n<br />\r\r\n\t\t\t\t\tNew status: {$new_status}\n\n<br />\r\r\n\t\t\t\t\tStatus message: {$member->status_str}\n\n<br />\t\t\t\t\t\r\r\n\t\t\t\t\tPayment Mode: Cancelled\n\n<br />\r\r\n\t\t\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], $subject, $message); } // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); }
function purchase_export() { global $wpdb; // data $data = array(); // filter $sql_filter = $data['search_field_name'] = $data['search_field_value'] = ''; $search_field_name = mgm_post_var('search_field_name'); // check if (!empty($search_field_name)) { // post $search_field_value = mgm_post_var('search_field_value'); $search_field_value_two = mgm_post_var('search_field_value_two'); // view data $data['search_field_name'] = $search_field_name; // for display //issue #1281 $data['search_field_value'] = htmlentities($search_field_value, ENT_QUOTES, "UTF-8"); // for display $data['search_field_value_two'] = htmlentities($search_field_value_two, ENT_QUOTES, "UTF-8"); // for display //searc value $search_field_value = esc_sql($search_field_value); // for sql // end date value $search_field_value_two = esc_sql($search_field_value_two); // for sql //current date $curr_date = mgm_get_current_datetime(); $current_date = $curr_date['timestamp']; // by field switch ($search_field_name) { case 'user_login': $sql_filter = " AND (`user_login` LIKE '%{$search_field_value}%')"; break; case 'addon_option': $sql_filter = " AND (`option` LIKE '%{$search_field_value}%')"; break; case 'purchase_dt': // date start if (empty($search_field_value)) { $search_field_value = date('Y-m-d', $current_date); } // date end if (empty($search_field_value_two)) { $search_field_value_two = date('Y-m-d', $current_date); } // convert $search_field_value = mgm_format_inputdate_to_mysql($search_field_value); $search_field_value_two = mgm_format_inputdate_to_mysql($search_field_value_two); // set $sql_filter = " AND (DATE_FORMAT(`purchase_dt`,'%Y-%m-%d') BETWEEN '{$search_field_value}' AND '{$search_field_value_two}')"; break; } } // order $sql_order = " ORDER BY `user_login`, `purchase_dt`"; // sql $sql = "SELECT SQL_CALC_FOUND_ROWS A.id, A.purchase_dt, B.option AS addon_option, C.user_login\r\r\n\t\t FROM `" . TBL_MGM_ADDON_PURCHASES . "` A \r\r\n\t\t\t\tLEFT JOIN " . TBL_MGM_ADDON_OPTION . " B ON (B.id = A.addon_option_id) \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->users . " C ON (C.ID = A.user_id) WHERE 1 \r\r\n\t\t\t\t{$sql_filter} {$sql_order} "; // store $data['addon_purchases'] = $wpdb->get_results($sql); // date format $date_format = mgm_get_date_format('date_format'); // init $purchases = array(); // check if (count($data['addon_purchases']) > 0) { //purchases foreach ($data['addon_purchases'] as $purchase) { // int $row = new stdClass(); // export fields $row->username = $purchase->user_login; $row->addon_option = $purchase->addon_option; $row->purchase_date = date($date_format, strtotime($purchase->purchase_dt)); // cache $purchases[] = $row; // unset unset($row); } } // default response $response = array('status' => 'error', 'message' => __('Error while exporting addon purchases.', 'mgm')); // check if (count($purchases) > 0) { // success $success = count($purchases); // create if (mgm_post_var('export_format') == 'csv') { $filename = mgm_create_csv_file($purchases, 'addon_purchases'); } else { $filename = mgm_create_xls_file($purchases, 'addon_purchases'); } // src $file_src = MGM_FILES_EXPORT_URL . $filename; // message $message = sprintf(__('Successfully exported %d addon %s.', 'mgm'), $success, $success > 1 ? 'purchases' : 'purchase'); // init $response = array('status' => 'success', 'message' => $message, 'src' => $file_src); } // return response echo json_encode($response); exit; }
/** * status widget : multiple instance * front end instance * * @param array $args * @param array $widget_args * @return void * @since 1.0 */ function mgm_sidebar_widget_status($args, $widget_args = 1) { global $wpdb, $user_ID, $current_user, $mgm_sidebar_widget; extract($args, EXTR_SKIP); if (is_numeric($widget_args)) { $widget_args = array('number' => $widget_args); } $widget_args = wp_parse_args($widget_args, array('number' => -1)); extract($widget_args, EXTR_SKIP); $options = $mgm_sidebar_widget->status_widget; if (!isset($options[$number])) { return; } $title = isset($options[$number]['title']) ? $options[$number]['title'] : __('Magic Members', 'mgm'); $logged_out_intro = isset($options[$number]['logged_out_intro']) ? stripslashes($options[$number]['logged_out_intro']) : $mgm_sidebar_widget->default_text['logged_out_intro']; $hide_logged_out = isset($options[$number]['hide_logged_out']) ? stripslashes($options[$number]['hide_logged_out']) : false; // packs -issue#: 714 $packs = mgm_get_class('subscription_packs'); if ($user_ID) { echo $before_widget; if (trim($title)) { echo $before_title . $title . $after_title; } //issue#: 539 $member = mgm_get_member($user_ID); // check pack - issue#: 714 $subs_pack = null; if ($member->pack_id) { $subs_pack = $packs->get_pack($member->pack_id); } $uat = $member->membership_type; if (!$uat) { $uat = 'free'; } $user_status = $member->status; if ($user_status != MGM_STATUS_ACTIVE || strtolower($uat) == 'free') { $inactive_intro = isset($options[$number]['inactive_intro']) ? $options[$number]['inactive_intro'] : $mgm_sidebar_widget->default_text['inactive_intro']; echo $inactive_intro; mgm_sidebar_register_links(); } else { if ($expiry = $member->expire_date) { //issue#: 692 $sformat = mgm_get_date_format('date_format_short'); $expiry = date($sformat, strtotime($expiry)); //$date = explode('-', $expiry); //$expiry = date(get_option('date_format'), mktime(0,0,0,$date[1], $date[2], $date[0])); } else { $expiry = __('None', 'mgm'); } $active_intro = $mgm_sidebar_widget->default_text['active_intro']; if (isset($options[$number]['active_intro'])) { $active_intro = $options[$number]['active_intro']; } $active_intro = str_replace('[membership_type]', mgm_get_class('membership_types')->get_type_name($uat), $active_intro); $active_intro = str_replace('[expiry_date]', $expiry, $active_intro); // check hidden subscription pack - issue#: 714 if (isset($subs_pack['hidden']) && $subs_pack['hidden'] != 1 || !isset($subs_pack['hidden'])) { echo $active_intro; } mgm_render_my_purchased_posts($user_ID); } echo $after_widget; } else { if (!$hide_logged_out) { echo $before_widget; if (trim($title)) { echo $before_title . $title . $after_title; } echo $logged_out_intro; echo mgm_get_login_register_links(); echo $after_widget; } } }
function _cancel_membership() { // system $system_obj = mgm_get_class('system'); $s_packs = mgm_get_class('subscription_packs'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails')); // get passthrough, stop further process if fails to parse $custom = $this->_get_transaction_passthrough($_POST['custom']); // local var extract($custom); // currency if (!$currency) { $currency = $this->setting['currency']; } // find user $user = get_userdata($user_id); $member = mgm_get_member($user_id); $multiple_update = false; // multiple membesrhip level update: if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type'] || isset($is_another_membership_purchase) && $is_another_membership_purchase == 'Y') { $multiple_update = true; $multi_memtype = isset($_POST['membership_type']) ? $_POST['membership_type'] : $membership_type; $member = mgm_get_member_another_purchase($user_id, $multi_memtype); } // tracking fields module_field => post_field $tracking_fields = array('txn_type' => 'rec_payment_type', 'subscr_id' => 'customer_id', 'txn_id' => 'rec_payment_id'); // save tracking fields $this->_save_tracking_fields($tracking_fields, $member); // expire $expire_date = $member->expire_date; // if lifetime: if ($member->duration_type == 'l') { $expire_date = date('Y-m-d'); } // transaction_id $trans_id = $member->transaction_id; // if today if ($expire_date == date('Y-m-d')) { // status $new_status = MGM_STATUS_CANCELLED; $new_status_str = __('Subscription cancelled', 'mgm'); // set $member->status = $new_status; $member->status_str = $new_status_str; $member->expire_date = date('Y-m-d'); // reassign expiry membership pack if exists: issue#: 535 $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true); } else { // date $date_format = mgm_get_date_format('date_format'); // status $new_status = MGM_STATUS_AWAITING_CANCEL; $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date))); // set $member->status = $new_status; $member->status_str = $new_status_str; // set reset date $member->status_reset_on = $expire_date; $member->status_reset_as = MGM_STATUS_CANCELLED; } // multiple membesrhip level update: if ($multiple_update) { mgm_save_another_membership_fields($member, $user_id); } else { $member->save(); } // transaction status mgm_update_transaction_status($trans_id, $new_status, $new_status_str); // send email notification to client $blogname = get_option('blogname'); // notify user if (!$dpne) { // notify user mgm_notify_user_membership_cancellation($blogname, $user, $member, $system_obj, $new_status, $membership_type); } // notify admin if (!$dge) { // notify admin mgm_notify_admin_membership_cancellation($blogname, $user, $member); } // after cancellation hook do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id)); }