/** * Send Email Notification to User * * @uses mgm_mail() * @param string optional $user_email * @param string $subject * @param string $message * @return bool $send */ function mgm_notify_user($user_email = null, $subject = 'You have a notification', $message = 'Notification for User') { // current user email if (!$user_email) { $user_email = mgm_get_current_user_email(); } // log // mgm_log( sprintf('%s, %s, %s', $user_email, $subject, $message), __FUNCTION__ ); // send return @mgm_mail($user_email, $subject, $message); }
/** * Cancel Recurring Subscription * This is not a private function * @param int/string $trans_ref * @param int $user_id * @param int/string $subscr_id * @param int $pack_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)) { if (isset($member->payment_info->subscr_id)) { $subscr_id = $member->payment_info->subscr_id; } else { //check pack is recurring: $pid = $pack_id ? $pack_id : $member->pack_id; if ($pid) { $s_packs = mgm_get_class('subscription_packs'); $sel_pack = $s_packs->get_pack($pid); 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; } } $system_obj = mgm_get_class('system'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); //send email only if setting enabled if ((!empty($subscr_id) || $subscr_id === 0) && !$dge) { $user = get_userdata($user_id); //send notification email to admin: $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm'); $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm'); if ($subscr_id) { $message .= "<br/><br/>" . __('Pay Id: ', 'mgm') . $subscr_id; } if (isset($member->transaction_id)) { $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id; } //admin email: if (!empty($system_obj->setting['admin_email'])) { @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message); } } return true; }
} // send email notification to system administrator if (!$dge && $acknowledge_user) { $subject = "[{$blogname}] {$user->user_email} - {$member->status}"; $message = "\tUser display name: {$user->display_name}\n\n<br />\n\t\t\t\tUser email: {$user->user_email}\n\n<br />\n\t\t\t\tUser ID: {$user->ID}\n\n<br />\n\t\t\t\tMembership Type: {$membership_type}\n\n<br />\n\t\t\t\tNew status: {$member->status}\n\n<br />\n\t\t\t\tStatus message: {$member->status_str}\n\n<br />\n\t\t\t\tSubscription period: {$member->duration} " . $s_packs->get_pack_duration($subs_pack) . "\n\n<br />\n\t\t\t\tSubscription amount: {$member->amount} {$member->currency}\n<br />\n\t\t\t\tPayment Mode: {$member->payment_type}\n\n<br />\n\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); } } // 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 />\n\t\t\tUser email: {$user->user_email}\n\n<br />\n\t\t\tUser ID: {$user->ID}\n\n<br />\n\t\t\tMembership Type: {$membership_type}\n\n<br />\n\t\t\tNew status: {$new_status}\n\n<br />\n\t\t\tStatus message: {$member->status_str}\n\n<br />\t\t\t\t\t\n\t\t\tPayment Mode: Cancelled\n\n<br />\n\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], $subject, $message); } // message $message = "sent a request to url: '" . $notification_url . "'. \n\n <br />\n\t\t\tresponse was: \n\n <br />\n\t\t\t" . $http_response . "\n\n <br />\n\t\t\tpost vars: <br />\n\t\t\t<pre>\n" . print_r($_POST, true) . '</pre>'; // mail mgm_mail($system_obj->setting['admin_email'], 'callback failed', $message);
break; case MGM_STATUS_PENDING: // subject $subject = $system_obj->get_template('payment_pending_email_template_subject', array('blogname' => $blogname), true); // body - issue #1284 $message = $system_obj->get_template('payment_pending_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'email' => $user->user_email, 'reason' => $member->status_str, 'amount' => $member->amount, 'membership_type' => $member->membership_type, 'admin_email' => $system_obj->setting['admin_email']), true); break; case MGM_STATUS_ERROR: // subject $subject = $system_obj->get_template('payment_error_email_template_subject', array('blogname' => $blogname), true); // body $message = $system_obj->get_template('payment_error_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'email' => $user->user_email, 'reason' => $member->status_str, 'admin_email' => $system_obj->setting['admin_email']), true); break; } // notify user if (!$dpne) { if ($acknowledge_user) { //issue #862 $subject = mgm_replace_email_tags($subject, $user_id); $message = mgm_replace_email_tags($message, $user_id); mgm_mail($user->user_email, $subject, $message); //update as email sent $this->update_paymentemail_sent($_POST['custom']); } } // notify admin, only if gateway emails on if (!$dge && $acknowledge_user) { $subject = "[{$blogname}] {$user->user_email} - {$member->status}"; $message = "\tUser display name: {$user->display_name}\n\n<br />\n\t\t\tUser email: {$user->user_email}\n\n<br />\n\t\t\tUser ID: {$user->ID}\n\n<br />\n\t\t\tMembership Type: {$membership_type}\n\n<br />\n\t\t\tNew status: {$member->status}\n\n<br />\n\t\t\tStatus message: {$member->status_str}\n\n<br />\n\t\t\tSubscription period: {$member->duration} " . $s_packs->get_pack_duration($subs_pack) . "\n\n<br />\n\t\t\tSubscription amount: {$member->amount} {$member->currency}\n<br />\n\t\t\tPayment Mode: {$member->payment_type}\n\n<br />\n\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], $subject, $message); }
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; }
$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 />\n\t\t\tUser email: {$user->user_email}\n\n<br />\n\t\t\tUser ID: {$user->ID}\n\n<br />\n\t\t\tMembership Type: {$membership_type}\n\n<br />\n\t\t\tNew status: {$new_status}\n\n<br />\n\t\t\tStatus message: {$member->status_str}\n\n<br />\t\t\t\t\t\n\t\t\tPayment Mode: Cancelled\n\n<br />\n\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], $subject, $message); } $user = get_userdata($user_id); //send notification email to admin: $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm'); $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm'); if ($subscr_id) { $message .= "<br/><br/>" . __('Pay Id: ', 'mgm') . $subscr_id; } if (isset($member->transaction_id)) { $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id; } //admin email: if (!empty($system_obj->setting['admin_email'])) { @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message); }
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); // post if($post_fields){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); } curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, 'Magic Members Membership Software'); curl_setopt($ch, CURLOPT_REFERER, get_option('siteurl')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // auth if($auth){ curl_setopt($ch, CURLOPT_USERPWD, $auth); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); } // buffer $buffer = curl_exec($ch); curl_close($ch); // return return $buffer; } */ if (!$dge) { $message = 'Could not read membership type in the following POST 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($_POST, true) . '</pre>'; mgm_mail($system_obj->setting['admin_email'], 'Error in 2Checkout membership verification', $message); }
/** * Cancel Recurring Subscription * Cancellation includes 2 webservice calls * 1. delete Rebill Event on eWay * 2. delete Rebill Customer on eWay * This is not a private function * @param int/string $trans_ref * @param int $user_id * @param int/string $rebill_id * @param int $pack_id * @return boolean */ function cancel_recurring_subscription($trans_ref = null, $user_id = null, $rebill = 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)) { if (isset($member->payment_info->subscr_id)) { $rebill['rebill_id'] = $member->payment_info->subscr_id; $rebill['rebill_customer_id'] = $member->payment_info->rebill_customerid; } else { //check pack is recurring: $pid = $pack_id ? $pack_id : $member->pack_id; if ($pid) { $s_packs = mgm_get_class('subscription_packs'); $sel_pack = $s_packs->get_pack($pid); if ($sel_pack['num_cycles'] != 1) { $rebill['rebill_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)) { // log mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->module, $this->module . '_cancel'); // return 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; } } //if valid rebill data is found and settings are set if (!empty($rebill['rebill_id']) && !empty($rebill['rebill_customer_id']) && !empty($this->setting['customer_id']) && !empty($this->setting['username']) && !empty($this->setting['password'])) { $gateway_method = 'webservice'; $secure = array('CustomerID' => $this->setting['customer_id'], 'Username' => $this->setting['username'], 'Password' => $this->setting['password']); //data to post //Delete Rebill Event $post_data = array('webservice_action' => 'DeleteRebillEvent', 'RebillCustomerID' => $rebill['rebill_customer_id'], 'RebillID' => $rebill['rebill_id']); $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__); /*$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__); //if rebill event is deleted, delete rebill customer if (isset($this->response['response_status']) && $this->response['response_status'] == 1) { //delete rebill customer: $post_data['webservice_action'] = 'DeleteRebillCustomer'; // filter post data and create soap xml $post_string = $this->_filter_postdata($gateway_method, $post_data); // soap_action $soap_action = sprintf('http://www.eway.com.au/gateway/rebill/manageRebill/%s', $post_data['webservice_action']); // http_headers $http_headers = array_merge($http_headers, array('SOAPAction' => $soap_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__); /*$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']) && $this->response['response_status'] == 1) { //done return true; } } } elseif ($rebill['rebill_id'] === 0) { $system_obj = mgm_get_class('system'); $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails')); //send email only if setting enabled if (!$dge) { $user = get_userdata($user_id); //send notification email to admin: $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm'); $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm'); if (!empty($rebill['rebill_customer_id'])) { $message .= "<br/><br/>" . __('Customer Rebill Id: ', 'mgm') . $rebill['rebill_customer_id']; } if (!empty($rebill['rebill_id'])) { $message .= "<br/><br/>" . __('Rebill Id: ', 'mgm') . $rebill['rebill_id']; } if (isset($member->transaction_id)) { $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id; } //admin email: if (!empty($system_obj->setting['admin_email'])) { @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message); } } //treat as done return true; } return false; }
function send_confirmation() { $todate = new DateTime(); $todate = $todate->format('Y-m-d'); $url = $this->get_endpoint('live'); $fields = array(); // set $this->postfields = array('campaign_name' => $this->setting['category1'], 'campaign_ref' => $this->setting['ref']); $fields = $this->postfields; $this->get_proxy($url); // obj $jsonrpc = new mgm_jsonrpc_client($url); // campaigns $campaigns = $jsonrpc->get_campaigns($fields['campaign_ref'], array('name' => array('EQUALS' => $fields['campaign_name']))); // validate if (is_array($campaigns) && count($campaigns) > 0) { // campaign_id $campaign_id = array_shift(array_keys($campaigns)); foreach ($campaigns as $campaign) { //Contacts from campaigns $contacts = $jsonrpc->get_contacts($fields['campaign_ref'], array('campaigns' => array($campaign_id), 'created_on' => array('AT' => $todate))); if (!empty($contacts)) { $confirm_users = ''; foreach ($contacts as $contact) { if (!empty($contact['name']) && !empty($contact['email'])) { $confirm_users .= $contact['name'] . " [ " . $contact['email'] . "], "; } else { if (!empty($contact['name'])) { $confirm_users .= $contact['name'] . ","; } if (!empty($contact['email'])) { $confirm_users .= $contact['email'] . ","; } } } // contacts $confirm_users = rtrim($confirm_users, ', '); $campaign_name = $campaign['name']; $campaign_admin_email = $campaign['from_email']; $subject = "User(s) confirmed in campaign - {$campaign_name} - Automated mail"; //Mail message $message = "Hi Admin,\n\n<br/><br />"; $message .= "Campaign Name : {$campaign_name}\n\n<br /><br />"; if (strpos($confirm_users, ',') === false && !empty($confirm_users)) { $message .= " Below user has been confirmed today. \n\n<br /><br /> "; $message .= " User : {$confirm_users}\n\n<br /"; } else { if (!empty($confirm_users)) { $message .= " Below users has been confirmed today: \n\n<br /><br /> "; $message .= " Users : {$confirm_users}\n\n<br /"; } } //Sending mail mgm_mail($campaign_admin_email, $subject, $message); } } } }
/** * 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)) { if (isset($member->payment_info->subscr_id)) { $subscr_id = $member->payment_info->subscr_id; } else { //check pack is recurring: $pid = $pack_id ? $pack_id : $member->pack_id; if ($pid) { $s_packs = mgm_get_class('subscription_packs'); $sel_pack = $s_packs->get_pack($pid); 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; } } //ony for subscription_purchase if ($subscr_id) { // end point $endpoint = $this->_get_endpoint('unsubscribe'); // base // add query $url = add_query_arg(array('SUBSCRIPTION_ID' => urlencode($subscr_id), 'MERCHANT_ID' => urlencode($this->setting['merchant_id']), 'ZombaioGWPass' => urlencode($this->setting['gw_pass']), 'ReasonCode' => urlencode(11)), $endpoint); // create curl post //$buffer = $this->_curl_post($url); // headers $http_headers = array(); // fetch $http_response = mgm_remote_post($url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // verify if ($http_response == 1) { return true; } else { // message return $this->_get_cancel_error($http_response); } } elseif ($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')); //send email only if setting enabled if (!$dge) { $user = get_userdata($user_id); //send notification email to admin: $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm'); $message .= "<br/>" . __('Please unsubscribe the user subscription from Gateway Merchant panel.', 'mgm'); if (!empty($member->transaction_id)) { $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id; } //admin email: if (!empty($system_obj->setting['admin_email'])) { @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message); } } return true; } return false; }
function _buy_post() { global $wpdb; // system $system_obj = mgm_get_class('system'); $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($_REQUEST['custom']); // local var extract($custom); // find user if ($user_id) { $user = get_userdata($user_id); } // blog $blogname = get_option('blogname'); //getting purchase post title and & price - issue #981 $post_obj = mgm_get_post($post_id); $purchase_cost = mgm_convert_to_currency($post_obj->purchase_cost); $post = get_post($post_id); $post_title = $post->post_title; // tran $tran_success = false; // status success $tran_success = true; // status $status_str = __('Last payment was successful', 'mgm'); // emails not for guest if ($user_id) { // subject $subject = $system_obj->get_template('payment_success_email_template_subject', array('blogname' => $blogname), true); // body $message = $system_obj->get_template('payment_success_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true); //update coupon usage - issue #1421 do_action('mgm_update_coupon_usage', array('user_id' => $user_id)); } // transation id $transaction_id = $this->_get_transaction_id('custom', $_REQUEST); // hook args $args = array('post_id' => $post_id, 'transaction_id' => $transaction_id); // user purchase if (isset($user_id) && (int) $user_id > 0) { $args['user_id'] = $user_id; } else { // guest purchase $args['guest_token'] = $guest_token; } // after succesful payment hook do_action('mgm_buy_post_transaction_success', $args); // backward compatibility do_action('mgm_post_purchase_payment_success', $args); // new organized name // do action do_action('mgm_return_post_purchase_payment_' . $this->module, array('post_id' => $post_id)); // new, individual do_action('mgm_return_post_purchase_payment', array('post_id' => $post_id)); // new, global // notify user if (!$dpne) { // mail if ($user_id && $this->send_payment_email($_REQUEST['custom'])) { //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 an email to the buyer //update as email sent $this->update_paymentemail_sent($_REQUEST['custom']); } } // mark as purchased if (isset($guest_token)) { // issue #1421 if (isset($coupon_id) && isset($coupon_code)) { do_action('mgm_update_coupon_usage', array('guest_token' => $guest_token, 'coupon_id' => $coupon_id)); $this->_set_purchased(NULL, $post_id, $guest_token, $_REQUEST['custom'], $coupon_code); } else { $this->_set_purchased(NULL, $post_id, $guest_token, $_REQUEST['custom']); } } else { $this->_set_purchased($user_id, $post_id, NULL, $_REQUEST['custom']); } // status $status = __('The post was purchased successfully', 'mgm'); // transaction status mgm_update_transaction_status($_REQUEST['custom'], $status, $status_str); // notify admin, only if gateway emails on if (!$dge) { // not for guest if ($user_id) { // subject $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id; // message $message = "User display name: {$user->display_name}<br />\r\r\n\t\t\t\t\t\t\tUser email: {$user->user_email}<br />\r\r\n\t\t\t\t\t\t\tUser ID: {$user->ID}<br />Status: " . $status . "<br />\r\r\n\t\t\t\t\t\t\tAction: Purchase post:" . $subject . "<br /><br />" . $message; } else { $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id; $message = "Guest Purchase"; } // mail mgm_mail($system_obj->setting['admin_email'], $subject, $message); } }
/** * send reminder mail * * @param object $user * @param array $data * @return bool $has_sent */ function mgm_send_reminder_mail($user, $data, $system_obj) { // format date // issue#: 692 $sformat = mgm_get_date_format('date_format_long_time2'); // $expire_date_fmt = date($sformat,strtotime($data['expire_date'])); // Issue #1178 $expire_date_fmt = mgm_translate_datestring($data['expire_date'], $sformat); // $expire_date_fmt = date('m-d-Y',strtotime($data['expire_date'])); // mail body $data['template_body'] = str_replace(array('[name]', '[expire_date]', '[subscription_type]'), array($user->display_name, $expire_date_fmt, $data['subscription_type']), $data['template_body']); //issue #862 $data['template_subject'] = mgm_replace_email_tags($data['template_subject'], $user->ID); $data['template_body'] = mgm_replace_email_tags($data['template_body'], $user->ID); // @todo add filter $template = apply_filters('mgm_reminder_email_template', array('subject' => $data['template_subject'], 'body' => $data['template_body'])); // send mail return @mgm_mail($user->user_email, $template['subject'], $template['body']); // log // mgm_log('Sending Reminder email:UID:' .$user->ID. ": Date:". date('Y-m-d H:i:s'), __FUNCTION__ ); }
function mgm_reset_password($key, $user) { global $current_site; if (isset($user->ID) && $user->ID > 0) { $new_pass = wp_generate_password(); do_action('password_reset', $user, $new_pass); wp_set_password($new_pass, $user->ID); update_user_option($user->ID, 'default_password_nag', true, true); //Set up the Password change nag. //get custom title/messages $title = apply_filters('password_reset_title', ''); $message = apply_filters('password_reset_message', '', $new_pass); if ($message && !mgm_mail($user->user_email, $title, $message)) { wp_die(__('The e-mail could not be sent.', 'mgm') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.', 'mgm')); } wp_password_change_notification($user); wp_safe_redirect(mgm_get_custom_url('login', false, array('checkemail' => 'newpass'))); exit; } }
function _member_update_status(&$member, $user_id, $system_obj) { // return $return = array('old_status' => $member->status); // set new status $member->status = $return['new_status'] = mgm_post_var('upd_status'); // override_rebill_status_check $override_rebill_status_check = mgm_post_var('override_rebill_status_check'); // disable payment/rebill status check if (bool_from_yn($override_rebill_status_check)) { $member->last_payment_check = 'disabled'; } // active for manualpay if ($member->status == MGM_STATUS_ACTIVE) { // for manual pay if ($member->payment_info->module == 'mgm_manualpay') { // MARK status reset for manual pay upgrade $member->status_reset_on = NULL; // unset unset($member->status_reset_on); // mark as paid $member->status_str = __('Last payment was successful', 'mgm'); // send user notification: issue#: 537 if ($return['old_status'] == MGM_STATUS_PENDING) { // transaction status -issue #1287 mgm_update_transaction_status($member->transaction_id, $member->status, $member->status_str); // userdata $userdata = get_userdata($user_id); $blogname = get_option('blogname'); //issue #1263 if ($member->subscribed == 'Y') { do_action('mgm_return_subscription_payment', array('user_id' => $user_id, 'acknowledge_ar' => true, 'mgm_member' => $member)); } // subject $subject = $system_obj->get_template('payment_active_email_template_subject', array('blogname' => $blogname), true); // param $b_args = array('blogname' => $blogname, 'name' => mgm_stripslashes_deep($userdata->display_name), 'email' => $userdata->user_email, 'admin_email' => $system_obj->get_setting('admin_email')); // body $message = $system_obj->get_template('payment_active_email_template_body', $b_args, true); //issue #862 $subject = mgm_replace_email_tags($subject, $user_id); $message = mgm_replace_email_tags($message, $user_id); // mail mgm_mail($userdata->user_email, $subject, $message); //send an email to the buyer // send notification - issue #1758 if ($system_obj->setting['enable_new_user_email_notifiction_after_user_active'] == 'Y') { $user_pass = mgm_decrypt_password($member->user_password, $user_id); do_action('mgm_register_user_notification', $user_id, $user_pass); } // unset unset($userdata, $message); } } else { // mark as paid $member->status_str = __('Last rebill cycle processed manually', 'mgm'); } } // return return $return; }
/** * retrive/lost password * */ function mgm_retrieve_password() { global $wpdb, $current_site; $errors = new WP_Error(); if (empty($_POST['user_login']) && empty($_POST['user_email'])) { $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.', 'mgm')); } if (strpos($_POST['user_login'], '@')) { $user_data = get_user_by('email', trim($_POST['user_login'])); if (empty($user_data)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'mgm')); } } else { $login = trim($_POST['user_login']); $user_data = get_user_by('login', $login); } do_action('lostpassword_post'); if ($errors->get_error_code()) { return $errors; } if (!$user_data) { $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.', 'mgm')); return $errors; } // redefining user_login ensures we return the right case in the email $user_login = $user_data->user_login; $user_email = $user_data->user_email; do_action('retreive_password', $user_login); // Misspelled and deprecated do_action('retrieve_password', $user_login); $allow = apply_filters('allow_password_reset', true, $user_data->ID); if (!$allow) { return new WP_Error('no_password_reset', __('Password reset is not allowed for this user', 'mgm')); } else { if (is_wp_error($allow)) { return $allow; } } $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM {$wpdb->users} WHERE user_login = %s", $user_login)); if (empty($key)) { // Generate something random for a key... $key = wp_generate_password(20, false); // action do_action('retrieve_password_key', $user_login, $key); //issue #1700 if (mgm_compare_wp_version('3.7', '>=')) { // Now insert the key, hashed, into the DB. if (empty($wp_hasher)) { require_once ABSPATH . 'wp-includes/class-phpass.php'; $wp_hasher = new PasswordHash(8, true); } $key = $wp_hasher->HashPassword($key); } // Now insert the new md5 key into the db $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); } // title source is unknown if (!isset($title)) { $title = __('Get Your Password', 'mgm'); } // apply filter $title = apply_filters('retrieve_password_title', $title); // message source is unknown if (!isset($message)) { $message = __('Password Reset Requested', 'mgm'); } // apply filter $message = apply_filters('retrieve_password_message', $message, $key); // send if (isset($message) && !empty($message) && !mgm_mail($user_email, $title, $message)) { // add $errors->add('empty_username', __('The e-mail could not be sent.', 'mgm') . "<br />" . __('Possible reason: your host may have disabled the mail() function...', 'mgm')); // return return $errors; } // return return true; }