public function task($offset = 0)
 {
     global $ym_sys;
     if (!$ym_sys->email_reminder_enable) {
         echo 'Not Enabled in YM SYS';
         return;
     }
     $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : $offset;
     if (is_null($offset)) {
         $offset = 0;
     }
     if ($offset == -1) {
         // no pagination
         $offset = 0;
         $this->limit = null;
     }
     $this->limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $this->limit;
     // use API Exposed Element for search
     $users = get_users(array('offset' => $offset, 'number' => $this->limit, 'meta_key' => 'ym_status', 'meta_value' => YM_STATUS_EXPIRED, 'meta_compare' => '!='));
     $current_time = time();
     // set to now + days so a future
     $limit_date = time() + $ym_sys->email_reminder_limit * 86400;
     $postarray = array();
     //Drip Feed Email
     if ($ym_sys->email_drip_reminder_enable) {
         global $wpdb;
         //Get all posts
         $args = array('meta_key' => '_ym_account_min_duration', 'post_status' => 'publish');
         $posts = get_posts($args);
         foreach ($posts as $post) {
             $drip = get_post_meta($post->ID, '_ym_account_min_duration', true);
             $new_array = array();
             if ($drip) {
                 $drip = explode(';', $drip);
                 if ($drip) {
                     foreach ($drip as $d) {
                         $array = explode('=', $d);
                         $new_array[$array[0]] = $array[1];
                     }
                 }
             }
             $postarray[$post->ID] = array_filter($new_array);
         }
         $postarray = array_filter($postarray);
     }
     $total = count($users);
     if ($total) {
         $counter = 0;
         foreach ($users as $user) {
             $counter++;
             $user = new YourMember_User($user->ID);
             $expire_date = $user->expire_date;
             // user has expire date
             // user has not been sent a reminder
             // expire_date is less that the limit date
             // expire date is in the future
             if ($user->expire_date && !$user->reminder_email_sent && $user->expire_date < $limit_date && $user->expire_date > $current_time) {
                 // lock
                 $user->update(array('reminder_email_sent' => true), true);
                 // send
                 $subject = $ym_sys->email_reminder_subject;
                 $message = $ym_sys->email_reminder_message;
                 $pack = ym_get_pack_by_id($user->pack_id);
                 if ($pack['num_cycles'] != 1) {
                     // so 0 or many ie recurring
                     $subject = $ym_sys->email_reminder_subject_recur;
                     $message = $ym_sys->email_reminder_message_recur;
                 }
                 $subject = str_replace('[site_name]', get_bloginfo(), $subject);
                 $message = ym_apply_filter_the_content($message);
                 ym_email($user->data->user_email, $subject, $message);
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Email Reminder Sent', 'ym'), $user->ID);
                 do_action('ym_cron_email_reminder_sent', $user->ID);
                 echo '1';
             } else {
                 echo '.';
             }
             if (substr($counter, -1, 1) == '0') {
                 echo ' ' . $counter . '/' . $total . "\n";
             }
             $reminders = array();
             foreach ($postarray as $post => $type) {
                 foreach ($type as $ac_type => $days) {
                     if ($ac_type == $act) {
                         $reminders[$post] = array('post_id' => $post, 'days' => $days);
                     }
                 }
             }
             if ($reminders) {
                 $users_reminders = unserialize(get_user_meta($user->ID, 'drip_email_reminders', true));
                 if (!$users_reminders || !is_array($users_reminders)) {
                     $users_reminders = array();
                 }
                 foreach ($reminders as $reminder) {
                     if (!in_array($reminder['post_id'], $users_reminders)) {
                         //The post ID is not marked as already sent so we may need to send it
                         //need to determine if we should send it.
                         $reg = $user->data->user_registered;
                         if ($sys->post_delay_start == 'pack_join') {
                             if ($pack_join = $user->account_type_join_date) {
                                 $reg = date('Y-m-d', $pack_join);
                             }
                         }
                         $reg = mktime(0, 0, 0, substr($reg, 5, 2), substr($reg, 8, 2), substr($reg, 0, 4));
                         $user_at = $reg + 86400 * $reminder['days'];
                         if ($user_at <= time() && $user_at >= time() - 86400 * 7) {
                             //If the time is not in the future, and no older then 10 days, we should send an email
                             //send email
                             $subject = $ym_sys->email_drip_subject;
                             $message = $ym_sys->email_drip_message;
                             $subject = str_replace('[site_name]', get_bloginfo(), $subject);
                             $message = ym_apply_filter_the_content($message);
                             ym_email($target, $subject, $message);
                             $users_reminders[] = $reminder['post_id'];
                             @ym_log_transaction(USER_STATUS_UPDATE, __('Drip Content Email for post' . $reminder['post_id'], 'ym'), $user->ID);
                             do_action('ym_cron_email_drip_sent', $user->ID, $reminder['post_id']);
                         }
                     }
                 }
                 update_user_meta($user->ID, 'drip_email_reminders', serialize($users_reminders));
             }
         }
         echo ' ' . $counter . '/' . $total . "\n";
         // loop
         echo 'Loop Complete From ' . $offset . "\n";
         if ($this->call_type == 'auto') {
             if ($this->limit != NULL) {
                 echo 'Schedule Next Step' . "\n";
                 wp_schedule_single_event(time(), 'ym_cron_email_reminder', array($offset + $this->limit));
             } else {
                 echo 'Full Call Occured' . "\n";
             }
         } else {
             // reload
             echo 'Sleeping' . "\n";
             echo '<form action="" method="post"><input type="hidden" name="run_cron_job" value="ym_cron_email_reminder" /><input type="hidden" name="offset" value="' . ($offset + $this->limit) . '" /></form>';
             echo '<script type="text/javascript">jQuery(document).ready(function() { setTimeout(\'ym_fire()\', 5000) }); function ym_fire() { jQuery(\'form\').submit(); }</script>';
         }
     } else {
         echo 'Nothing to do Job Complete' . "\n";
         do_action('ym_cron_email_reminder_complete');
     }
 }
function ym_shortcode_ym_group_membership_control()
{
    // @TODO: Finish
    global $ym_user, $ym_formgen;
    if ($ym_user->child_ids || $ym_user->child_accounts_allowed) {
        // has children
        $total_kids = count($ym_user->child_ids);
        $action = ym_post('action', false);
        if ($action == 'ym_add_child_user') {
            if ($ym_user->child_accounts_allowed > $total_kids) {
                $email_address = ym_post('email_address');
                $username = ym_post('username', $email_address);
                $password = ym_post('password');
                $c_password = ym_post('c_password');
                if ($email_address && is_email($email_address)) {
                    if (!empty($password) && $password != $c_password) {
                        ym_display_message(__('Passwords do not match', 'ym'), 'error');
                    }
                    $new_user = new YourMember_User();
                    $result = $new_user->create($email_address, false, false, $username, $password);
                    if (is_wp_error($result)) {
                        ym_display_message($result->get_error_message(), 'error');
                    } else {
                        // apply child
                        $data = array('parent_id' => $ym_user->ID);
                        // package type
                        if (count($ym_user->child_accounts_package_types) > 1) {
                            $data['account_type'] = $ym_user->child_accounts_package_types[0];
                        } else {
                            $data['account_type'] = $ym_user->account_type;
                        }
                        $new_user->update($data);
                        $new_user->save();
                        unset($new_user);
                        //garbage collect
                        $child_ids = $ym_user->child_ids;
                        $child_ids[] = $result;
                        $ym_user->update(array('child_ids' => $child_ids));
                        $ym_user->save();
                        // all done
                        ym_display_message(__('Child User was created successfully', 'ym'));
                    }
                } else {
                    ym_display_message(__('The Email Address was Blank or Invalid', 'ym'), 'error');
                }
            } else {
                ym_display_message(__('You have reached the maximum number of accounts', 'ym'), 'error');
            }
        } else {
            if ($action == 'ym_child_package_type_change') {
                $child_id = ym_post('child_id', false);
                if ($child_id) {
                    $ym_child = new YourMember_User($child_id);
                    if ($ym_child->parent_id = $ym_user->ID) {
                        $ym_child->update(array('account_type' => $_POST['package_type']));
                        $ym_child->save();
                        ym_display_message(__('Child account was updated successfully', 'ym'));
                    } else {
                        ym_display_message(__('You are trying to update someone elses child', 'ym'), 'error');
                    }
                }
            }
        }
        $return .= '<table class="form-table">';
        foreach ($ym_user->child_ids as $child) {
            // loop thru kids
            $ym_child = new YourMember_User($child);
            $return .= '<tr>';
            $return .= '<td>' . $ym_child->data->user_login . '</td>';
            $return .= '<td>';
            $return .= $ym_child->account_type;
            $return .= '</td>';
            $return .= '</tr>';
        }
        $return .= '</table>';
        if ($ym_user->child_accounts_allowed > $total_kids) {
            // can add child
            $return .= '<h4>' . __('Create new Group Account', 'ym') . '</h4>';
            $return .= '<form action="" method="post">
	<input type="hidden" name="action" value="ym_add_child_user" />
<table class="form-table">
';
            $ym_formgen->return = true;
            $return .= $ym_formgen->render_form_table_email_row(__('Email Address', 'ym'), 'email_address');
            $return .= $ym_formgen->render_form_table_text_row(__('Username', 'ym'), 'username', '', __('Leave blank to use the email address', 'ym'));
            $return .= $ym_formgen->render_form_table_password_row(__('Password', 'ym'), 'password', '', __('Leave blank to auto generate', 'ym'));
            $return .= $ym_formgen->render_form_table_password_row(__('Confirm Password', 'ym'), 'c_password');
            $ym_formgen->return = false;
            $return .= '<tr><td colspan="2"><p class="submit"><input type="submit" class="button-primary alignright" value="' . __('Create', 'ym') . '" /></p></td></tr>';
            $return .= '</table></form>';
        }
        return $return;
    } else {
        return '<p>' . __('You do not have access to Group Management', 'ym') . '</p>';
    }
}
function wp_ajax_ym_quick_activate_toggle()
{
    ym_ajax_superuser_check();
    $user_id = ym_post('ym_quick_activate_toggle_user_id');
    if ($user_id) {
        $user = new YourMember_User($user_id);
        $target_status = YM_STATUS_NULL;
        $str = __('Suspended', 'ym');
        if ($user->status == $target_status) {
            $target_status = YM_STATUS_ACTIVE;
            $str = __('Manual Update', 'ym');
        }
        $user->update(array('status' => $target_status, 'status_str' => $str), TRUE);
        echo '
<script type="text/javascript">
jQuery(\'.ym_user_status_' . $user_id . '\').html(\'' . $target_status . '<br />' . $str . '\');
</script>
';
    } else {
        echo 0;
    }
    die;
}
Example #4
0
    function invoice_tab()
    {
        $invoice = new ym_invoice();
        global $wpdb;
        if (ym_post('user_id')) {
            $user_id = ym_post('user_id');
            $op = ym_post('op', '');
            $undo = ym_post('undo', FALSE);
            $user = new YourMember_User($user_id);
            if ($undo) {
                $data = array('status' => YM_STATUS_PENDING, 'status_str' => __('Invoice Undo', 'ym'));
                $user->update($data);
                $user->save();
                $packet = array('user_id' => $user_id, 'status' => FALSE);
                do_action('ym_invoice_status_update', $packet);
            } else {
                if ($op == 'resend') {
                    $invoice->generate_invoice($user, $invoice);
                    echo '<div id="message" class="updated"><p>' . __('Inovice Resent', 'ym') . '</p></div>';
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Invoice Resent', 'ym'), $user_id);
                } else {
                    if ($op == 'active') {
                        $data = array('status' => YM_STATUS_ACTIVE, 'status_str' => __('Invoice Paid', 'ym'), 'amount' => intval(ym_post('amount', 0)), 'last_pay_date' => time());
                        $current_status = $user->status;
                        if ($current_status == YM_STATUS_GRACE) {
                            $extend = $user->last_pay_date;
                            $packdata = ym_get_pack_by_id($user->pack_id);
                            $data['expire_date'] = $user->expiry_time($packdata['duration'], $packdata['duration_type'], $extend);
                        }
                        // check for force end
                        if (isset($packdata['force_end_date'])) {
                            $force_end_date = $packdata['force_end_date'];
                            if ($force_end_date > time()) {
                                // greater than now
                                @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $user_id);
                                $data['expire_date'] = $force_end_date;
                            }
                        }
                        $data['amount'] = preg_replace('/[^\\d\\.]/', '', $data['amount']);
                        $data['amount'] = number_format($data['amount'], 2, '.', '');
                        $user->update($data, TRUE);
                        $optional = ym_post('optional');
                        if (!$optional) {
                            $optional = __('Invoice Paid', 'ym');
                        }
                        @ym_log_transaction(YM_IPN, $optional, $user_id);
                        @ym_log_transaction(YM_PAYMENT, $data['amount'], $user_id);
                        @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'], $user_id);
                        echo '<div id="message" class="updated"><p>' . __('Updated and Activated the User', 'ym') . '</p></div>';
                        $packet = array('user_id' => $user_id, 'pack_id' => $user->pack_id, 'status' => TRUE);
                        $invoice = new ym_invoice();
                        $invoice->notify_user($packet);
                        do_action('ym_invoice_status_update', $packet);
                    }
                }
            }
        }
        echo '<div id="poststuff" class="wrap">';
        ym_box_top(__('Invoice Management', 'ym'));
        $search = ym_post('ym_invoice_search', false);
        if ($search) {
            $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->usermeta . ' u
				LEFT JOIN ' . $wpdb->usermeta . ' s ON s.user_id = u.user_id
				LEFT JOIN ' . $wpdb->users . ' us ON us.id = u.user_id
				WHERE
				u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' 
				AND s.meta_key = \'ym_status\'
				AND (
					us.user_login LIKE \'%' . $search . '%\'
					OR
					us.user_email LIKE \'%' . $search . '%\'
				)
				ORDER BY ID DESC
				';
        } else {
            $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->prefix . 'usermeta u
				LEFT JOIN ' . $wpdb->prefix . 'usermeta s ON s.user_id = u.user_id
				WHERE
				u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' 
				AND s.meta_key = \'ym_status\'
				ORDER BY ID DESC
				';
        }
        $results = $wpdb->get_results($query);
        // quick search
        if ($wpdb->num_rows != 0 || $search) {
            // render search form
            echo '
<form action="" method="post" style="float: right;">
<fieldset>
	' . __('Username/Email Search:', 'ym') . '
	<input type="text" name="ym_invoice_search" value="' . $search . '" />
	<input type="submit" value="' . __('Search', 'ym') . '" />
</fieldset>
</form>';
        }
        echo '<p>' . __('Here you can update users based on the honouring of their invoice, you can use the Info to store field to store extra IPN style info such as a Cheque Number', 'ym') . '</p>';
        if ($wpdb->num_rows == 0) {
            echo ym_display_message(__('No Users are Invoice Pending', 'ym'), 'error');
        } else {
            echo '<table class="widefat">';
            echo '<tr>
				<th>' . __('Member', 'ym') . '</th>
				<th>' . __('Invoice Ref', 'ym') . '</th>
				<th>' . __('Purchasing', 'ym') . '</th>
				<th>' . __('Paid/Invoiced On Date', 'ym') . '</th>
				<th>' . __('Member Status', 'ym') . '</th>
				<th>' . __('Payment', 'ym') . '</th>
			</tr>';
            foreach ($results as $row) {
                $user = new YourMember_User($row->ID);
                echo '<tr>';
                echo '<td>(' . $row->ID . ') ' . $user->data->user_email;
                echo '<br />';
                if ($user->data->user_email != $user->data->user_login) {
                    echo $user->data->user_login . ' ';
                }
                echo $user->data->display_name;
                echo '</td>';
                echo '<td>#' . $user->invoice_id . '</td>';
                echo '<td>' . ym_get_pack_label($user->pack_id) . '</td>';
                echo '<td nowrap="nowrap" style="';
                // go red if overdue
                $limit = $user->invoiced_date + 86400 * $invoice->invoice_limit;
                // last pay date is invoiced on date
                // limit is due date for this invoice
                if (time() > $limit && $user->status != YM_STATUS_ACTIVE) {
                    echo 'background: red;';
                } else {
                    if (time() < $limit && $user->status != YM_STATUS_ACTIVE) {
                        echo 'background: #EFEFEF;';
                    }
                }
                echo '">';
                if ($user->status != YM_STATUS_ACTIVE) {
                    echo __('Invoiced', 'ym') . ' ' . date(YM_DATE, $user->invoiced_date);
                    echo '<br />' . __('Due', 'ym') . ' ' . date(YM_DATE, $limit);
                } else {
                    echo date(YM_DATE, $user->last_pay_date);
                }
                echo '</td>';
                echo '<td>' . $user->status . ' - ' . $user->status_str . '</td>';
                echo '<td>
				<form action="" method="post">
				<table><tr><td nowrap="nowrap">
					<input type="hidden" name="search" value="' . $search . '" />
					<input type="hidden" name="user_id" value="' . $row->ID . '" />
					';
                if ($user->status == YM_STATUS_ACTIVE) {
                    echo $user->amount;
                    // last ipn
                    $query = 'SELECT data FROM ' . $wpdb->prefix . 'ym_transaction WHERE action_id = ' . YM_IPN . ' AND user_id = ' . $row->ID . ' ORDER BY id DESC LIMIT 1';
                    $data = $wpdb->get_var($query);
                    if (substr($data, 0, 2) != 'a:') {
                        echo ' - ';
                        echo $data;
                    }
                    echo '</td><td>';
                    echo '</td><td>';
                    echo '
					<input type="hidden" name="undo" value="1" />
					<input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Undo Active', 'ym') . '" />
					';
                } else {
                    echo '
					<label for="amount">' . __('Payment Amount', 'ym') . '</label> 
					<br />
					<label for="optional">' . __('Info to Store', 'ym') . ' 
					</td><td>
					<input type="text" name="amount" id="amount" value="" size="4" />
					<br />
					<input type="text" name="optional" id="optional" value="" size="4" /></label> 
					';
                    echo '</td><td>';
                    echo '
					<input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Payment Recieved - Make Active', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'active\');" />
					';
                    echo '</td><td>';
                    echo '
					<input type="submit" class="button-secondary" style="float: right;" value="' . __('Resend Invoice', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'resend\');" />
					';
                }
                echo '
					<input type="hidden" name="op" id="op_' . $row->ID . '" value="" />
				</td></tr></table>
				</form>
					</td>';
                echo '</tr>';
            }
            echo '</table>';
        }
        ym_box_bottom();
        echo '</div>';
    }
 function do_buy_subscription($subId, $userId, $complete = FALSE)
 {
     global $ym_sys;
     // assumes complete
     @ym_log_transaction(YM_IPN, $_REQUEST, $userId);
     if ($complete) {
         @ym_log_transaction(YM_PACKAGE_PURCHASED, $subId, $userId);
         $pack = ym_get_pack_by_id($subId);
         if (!$pack) {
             // unknown pack
             $complete = 'FALSE';
         } else {
             $user = new YourMember_User($userId);
             // get current
             $current = $user->pack_id;
             $extend = FALSE;
             // extend
             // ONLY extend if same package type (ie better pack for the same type)
             //   SO different Pack IDs
             // - like a switch from a monthly sub to a yearly sub
             // and current status is active
             // if been set inactivate then new sub
             if ($user->account_type == $pack['account_type'] && $user->pack_id != $subId && ($user->status == YM_STATUS_ACTIVE || $user->status == YM_STATUS_GRACE)) {
                 $extend = $user->expire_date;
             }
             // check for pack ID's the same
             // and extend allow
             // make sure expire date in the future
             if ($user->pack_id == $subId && $ym_sys->allow_upgrade_to_same && $user->expire_date > time()) {
                 $extend = $user->expire_date;
             }
             // patch :-P
             $pack['amount'] = $pack['cost'];
             // use magic
             // use an array so can pass to update
             // other wise direct calls to object....
             $data = array();
             // this is crap
             // TODO: takes the whole pack and stores it in the user object.....
             foreach ($user as $key => $value) {
                 if (isset($pack[$key])) {
                     $data[$key] = $pack[$key];
                 }
             }
             // end crap
             // additonal
             $data['pack_id'] = $subId;
             $data['status'] = YM_STATUS_ACTIVE;
             $data['reminder_email_sent'] = FALSE;
             if ($this->code == 'ym_gift') {
                 $data['status_str'] = __('Gift Giving was Successful', 'ym');
             } else {
                 if ($this->code == 'ym_dropdown') {
                     $data['status_str'] = __('DropDown was Successful', 'ym');
                 } else {
                     if ($extend) {
                         $data['status_str'] = __('Subscription Extension Successful', 'ym');
                     } else {
                         $data['status_str'] = __('Last payment was successful', 'ym');
                     }
                 }
             }
             $data['account_type'] = ucwords($pack['account_type']);
             $data['reminder_email_sent'] = FALSE;
             $data['gateway_used'] = $this->code;
             if (!$extend) {
                 $data['account_type_join_date'] = time();
             }
             $data['last_pay_date'] = time();
             // log
             @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $data['account_type'], $userId);
             @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $userId);
             // apply trial?
             $apply = FALSE;
             // if trial enabled and user not taken
             if ($pack['trial_on'] && $user->trial_taken != $subId) {
                 // trial not taken yet then apply trial
                 // does the Gateway Used Support a Trial?
                 if (method_exists($this, 'enable_trial')) {
                     $apply = TRUE;
                 }
             }
             if ($apply) {
                 $data['trial_on'] = TRUE;
                 $data['expire_date'] = $user->expiry_time($data['trial_duration'], $data['trial_duration_type']);
                 $data['trial_taken'] = $subId;
             } else {
                 $data['trial_on'] = FALSE;
                 // most important
                 $data['expire_date'] = $user->expiry_time($data['duration'], $data['duration_type'], $extend);
             }
             @ym_log_transaction(YM_ACCESS_EXTENSION, $data['expire_date'], $userId);
             // check for force end
             if (isset($pack['force_end_date'])) {
                 $force_end_date = $pack['force_end_date'];
                 if ($force_end_date > time()) {
                     // greater than now
                     @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $userId);
                     $data['expire_date'] = $force_end_date;
                 }
             }
             // group membership
             $data['child_accounts_allowed'] = $pack['child_accounts_allowed'];
             $data['child_accounts_package_types'] = $pack['child_accounts_package_types'];
             $data['child_accounts_packages'] = $pack['child_accounts_packages'];
             // admin bar control
             $data['hide_admin_bar'] = $pack['hide_admin_bar'];
             $user->update($data);
             $user->save();
             $user->updaterole($pack['role']);
         }
     }
     if (!$complete) {
         $data = array('new_status' => FALSE);
         if (method_exists($this, 'fail_process')) {
             $data = $this->fail_process();
         } else {
             $new_status = YM_STATUS_ERROR;
             $status_str = sprintf(__('Last Payment Errored and No Handler Found for the Payment Gateway Response', 'ym'));
             $data = array('new_status' => $new_status, 'status_str' => $status_str);
         }
         if (isset($data['new_status']) && $data['new_status']) {
             @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['new_status'] . ' - ' . $data['status_str'], $userId);
             if (isset($data['expiry']) && $data['expiry']) {
                 @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expiry'], $userId);
             }
             $data['status'] = $data['new_status'];
             unset($data['new_status']);
             $user = new YourMember_User($userId);
             $user->update($data);
             $user->save();
         }
     }
     $packet = array('user_id' => $userId, 'pack_id' => $subId, 'status' => $complete);
     if ($complete) {
         do_action('ym_membership_transaction_success', $packet);
         do_action('ym_membership_transaction_success_' . $this->code, $packet);
     } else {
         do_action('ym_membership_transaction_failed', $packet);
         do_action('ym_membership_transaction_failed_' . $this->code, $packet);
     }
     do_action('ym_gateway_return', $packet);
     do_action('ym_gateway_return_' . $this->code, $packet);
     $this->notify_user($packet);
 }
Example #6
0
    function do_process()
    {
        // IPN Handler
        $eventType = ym_request('eventType');
        $acc_num = ym_request('clientAccnum');
        $sub_num = ym_request('clientSubacc');
        if (!$eventType) {
            header('HTTP/1.1 403 Forbidden');
            echo 'Error in IPN. No Idea what the hell your trying to do';
            exit;
        }
        if ($acc_num != $this->clientAccnum || $sub_num != $this->clientSubacc) {
            header('HTTP/1.1 403 Forbidden');
            echo 'Error in IPN. Client Account Numbers';
            exit;
        }
        global $wpdb;
        $subscriptionId = ym_post('subscriptionId');
        switch ($eventType) {
            case 'NewSaleSuccess':
            case 'NewSaleFailure':
                $digest = ym_post('dynamicPricingValidationDigest', false);
                // got something to validate?
                if (ym_post('failureCode')) {
                    // failed
                    $validate = md5(ym_post('subscriptionId') . 0 . $this->md5salt);
                    $complete = false;
                } else {
                    // complete
                    $validate = md5(ym_post('subscriptionId') . 1 . $this->md5salt);
                    $complete = true;
                }
                // validate
                if ($digest != $validate) {
                    header('HTTP/1.1 403 Forbidden');
                    echo 'Error in IPN. Bad Digest';
                    exit;
                }
                // initial purchase
                list($buy, $what, $id, $user_id) = explode('_', ym_post('X-custom'));
                update_user_meta($user_id, 'ym_ccbill_subscription_id', ym_post('subscriptionId'));
                $this->common_process(ym_post('X-custom'), ym_post('billedInitialPrice'), $complete);
                break;
            case 'Cancellation':
                // cancellation
                // load user by sub id
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $ym_user = new YourMember_User($user_id);
                    $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_CANCEL, 'status_str' => ym_post('reason'));
                    $ym_user->update($data);
                    // do expire check (for drop down)
                    $ym_user->expire_check();
                    $ym_user->save();
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            case 'RenewalSuccess':
                // success renewal
                // load user by sub id
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $pack = new YourMember_User($user_id);
                    $code = 'buy_subscription_' . $pack->pack_id . '_' . $user_id;
                    $this->common_process($code, ym_post('billedRecurringPrice'), true);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            case 'RenewalFailure':
                // fail renewal
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $ym_user = new YourMember_User($user_id);
                    $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_ERROR, 'status_str' => ym_post('failureReason'));
                    $ym_user->update($data);
                    // do expire check (for drop down)
                    $ym_user->expire_check();
                    $ym_user->save();
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            default:
                // something we dont want to handle
                @ym_log_transaction(YM_IPN, $_REQUEST, 0);
        }
    }
Example #7
0
             } else {
                 // reload
                 $new_user = new YourMember_User($result);
                 // ok
                 $new_user->update(array('status_str' => __('User Create: Applied', 'ym')), TRUE);
                 $result_message = sprintf(__('User Created, ID: %s', 'ym'), $result);
             }
         } else {
             $new_user = new YourMember_User();
             $result = $new_user->create($email, false, $smflag, $username, $password);
             if (is_wp_error($result)) {
                 // error
                 ym_display_message($result->get_error_message(), 'error');
             } else {
                 // ok apply stuff
                 $new_user->update(array('account_type' => $package_type, 'status' => $status, 'status_str' => __('User Create: Applied', 'ym')), TRUE);
                 $result_message = sprintf(__('User Created, ID: %s', 'ym'), $result);
             }
         }
     }
     if (!$result_message) {
         break;
     }
     $_POST['filter_by_option'] = '';
 case 'change_filters':
 case 'change_order':
     // load filters
     $filters = get_option('ym_admin_ym_members_filters', array());
     $filters['by_option'] = isset($filters['by_option']) ? $filters['by_option'] : '';
     $filters['by_text'] = isset($filters['by_text']) ? $filters['by_text'] : '';
     $filters['order_by'] = isset($filters['order_by']) ? $filters['order_by'] : 'login';
function ym_group_membership_create_child($email_address, $username, $password, $c_password, $sub_id, $package_type = false, $message = FALSE, $parent_id = FALSE)
{
    if ($parent_id) {
        $ym_user = new YourMember_User($parent_id);
    } else {
        global $ym_user;
    }
    $current_counts = ym_group_membership_get_counts($ym_user);
    if (count($ym_user->child_ids) >= $ym_user->child_accounts_allowed) {
        if ($message) {
            ym_display_message(__('You are out of Child Accounts', 'ym'), 'error');
        }
        return FALSE;
    } else {
        if ($email_address && is_email($email_address)) {
            if (!empty($password) && $password != $c_password) {
                ym_display_message(__('Passwords do not match', 'ym'), 'error');
            }
            if ($sub_id) {
                if (!in_array($sub_id, $ym_user->child_accounts_packages)) {
                    if ($message) {
                        ym_display_message(__('You do not have access to this pacakge', 'ym'), 'error');
                    }
                    return FALSE;
                }
                $pack = ym_get_pack_by_id($sub_id);
            } else {
                if ($package_type) {
                    $pack = array();
                    $pack['account_type'] = $package_type;
                } else {
                    // inherit mode
                    $pack = array();
                    $pack['account_type'] = $ym_user->account_type;
                }
            }
            $inherit = true;
            foreach ($ym_user->child_accounts_package_types as $type => $type_count) {
                if ($type_count) {
                    $inherit = false;
                }
            }
            //			if ($inherit) {
            //				$pack['account_type'] = '';
            //			}
            if ($pack['account_type'] && $ym_user->child_accounts_package_types[$pack['account_type']] > $current_counts[$pack['account_type']] || $inherit && $ym_user->child_accounts_allowed > count($ym_user->child_ids)) {
                $new_user = new YourMember_User();
                $result = $new_user->create($email_address, $sub_id, FALSE, $username, $password);
                if (is_wp_error($result)) {
                    ym_display_message($result->get_error_message(), 'error');
                } else {
                    // apply child
                    $data = array('parent_id' => $ym_user->ID, 'account_type' => $pack['account_type'], 'status_str' => __('Child Account', 'ym'));
                    if (!$sub_id) {
                        // the child has inherited they won't have a role!
                        $new_user->updaterole('subscriber');
                    }
                    $new_user->update($data);
                    $new_user->save();
                    unset($new_user);
                    //garbage collect
                    $child_ids = $ym_user->child_ids;
                    $child_ids[] = $result;
                    $ym_user->update(array('child_ids' => $child_ids));
                    $ym_user->save();
                    @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, __('Child', 'ym') . ' ' . $data['account_type'], $result);
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $result);
                    // all done
                    if ($message) {
                        ym_display_message(__('Child User was created successfully', 'ym'));
                    }
                    return TRUE;
                }
            } else {
                if ($message) {
                    ym_display_message(__('Total for this package type has been reached', 'ym'), 'error');
                }
                return FALSE;
            }
        } else {
            if ($message) {
                ym_display_message(__('The Email Address was Blank or Invalid', 'ym'), 'error');
            }
            return FALSE;
        }
    }
}
Example #9
0
    function ym_profile_unsubscribe_button($return = FALSE)
    {
        if (!$this->access_token) {
            return;
        }
        global $ym_user;
        $id = get_user_meta($ym_user->ID, 'ym_gocardless_active_subscription', TRUE);
        if (!$id) {
            return;
        }
        if (ym_post('gocardless_cancel')) {
            $data = $this->subscriptionCancel($id);
            $html = '<div style="margin-bottom: 10px;">
				<h4>' . __('GoCardless UnSubscribe', 'ym') . '</h4>
				<div style="margin-bottom: 10px;">';
            if ($data) {
                $html .= '<p>' . __('You have UnSubscribed Successfully', 'ym');
                // fire expire
                $user = new YourMember_User($current_user->ID);
                // set time to now
                $data = array('expire_date' => time() - 1);
                $user->update($data);
                // do expire check (for drop down)
                $user->expire_check();
                $user->save();
            } else {
                $html .= '<p>' . __('An error occured whilst attempting to UnSubscribe you', 'ym') . '</p>';
            }
            $html .= '</div></div>';
        } else {
            $html = '<div style="margin-bottom: 10px;">
				<h4>' . __('GoCardless UnSubscribe', 'ym') . '</h4>
				<div style="margin-bottom: 10px;">' . __('If you wish to unsubscribe you can click the following link.', 'ym') . '</div>
				<div>
					<form action="" method="post">
						<input type="submit" name="gocardless_cancel" value="' . __('Cancel Subscription', 'ym') . '" class="button-secondary" />
					</form>
				</div>
			</div>
			';
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }