function expire_check()
 {
     global $ym_sys;
     if (!isset($this->ID)) {
         return;
     }
     $ID = $this->ID;
     // check for parent
     if ($this->parent_id != FALSE) {
         // has a parent account
         $parent_user = new YourMember_User($this->parent_id);
         $not_expired = $parent_user->expire_check();
         if ($not_expired) {
             // check special case expires
             if ($this->status == YM_STATUS_PARENT_CANCEL) {
                 return FALSE;
             }
             // check user is is in parents child account list ie is orphaned
             if (!in_array($ID, $parent_user->child_ids)) {
                 // orphaned transistion to a normal account
                 // which is pending a sub payment
                 $this->status = YM_STATUS_EXPIRED;
                 //explict active set to clear child account status
                 $this->parent_id = false;
                 $this->save();
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Child Account Orphaned: Expired', 'ym'), $ID);
                 return FALSE;
             }
             // if the account type is blank
             // and parent only allows a single package type
             // set the child to that package type
             if (!$this->account_type) {
                 $allowed_types = count($parent_user->child_accounts_package_types);
                 $allowed_packs = count($parent_user->child_accounts_packages);
                 $error = FALSE;
                 if ($allowed_types >= 1 && $allowed_packs >= 1) {
                     // well f**k
                     $error = TRUE;
                 } else {
                     if ($allowed_types == 1) {
                         $this->account_type = $parent_user->child_accounts_package_types[0];
                         @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $this->account_type, $ID);
                     } else {
                         if ($allowed_packs == 1) {
                             ym_group_apply_package($parent_user->child_accounts_packages[0]);
                             // go drop for status check.....
                         } else {
                             // if drop thru well deny. Account not configured
                             $error = TRUE;
                         }
                     }
                 }
                 if ($error) {
                     $this->status = YM_STATUS_PARENT_CONFIG;
                     $this->save();
                     return FALSE;
                 }
             }
             if ($this->status != $parent_user->status) {
                 $this->status = $parent_user->status;
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             }
             // if expose expire date to child
             // update expiry
             $this->save();
             return TRUE;
         }
         // check for status update at this point the child account should be expired
         // but the parent account can be of any status (such as pending)
         if ($this->account_type != YM_STATUS_PARENT_EXPIRED) {
             $this->status = YM_STATUS_PARENT_EXPIRED;
             @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             $this->save();
         }
         return FALSE;
     }
     if (ym_superuser($ID)) {
         return TRUE;
     }
     $current_status = $this->status;
     if ($current_status === false) {
         return TRUE;
     }
     if ($current_status == YM_STATUS_EXPIRED || $current_status == YM_STATUS_TRIAL_EXPIRED) {
         return FALSE;
     }
     $grace_limit_user = $ym_sys->grace_limit;
     $grace_limit_user = apply_filters('ym_user_grace_limit_adjust', $grace_limit_user, $this);
     $new = FALSE;
     $reg_date = get_userdata($ID);
     $reg_date = strtotime($reg_date->user_registered);
     if ($reg_date > time() - 86400 * $grace_limit_user) {
         $new = TRUE;
     }
     if ($current_status == YM_STATUS_ACTIVE || $current_status == YM_STATUS_GRACE) {
         // time
         $expire = $this->expire_date;
         if ($expire > time()) {
             // expire is in the future
             // safe/not expired
             return TRUE;
         }
         // expired
         if ($this->ym_expiry_sub_dropdown_check()) {
             return;
         }
         if ($this->trial_on) {
             $user_status = YM_STATUS_TRIAL_EXPIRED;
         } else {
             $user_status = YM_STATUS_EXPIRED;
         }
         @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $ID);
         @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status, $ID);
         $data = array('status' => $user_status, 'status_str' => __('User has expired', 'ym'));
         $data = apply_filters('ym_user_expire_check_into_expire', $data, $this);
         $this->update($data);
         $this->save();
         do_action('ym_user_is_expired', $ID, $data);
         return FALSE;
     } else {
         if ($current_status == YM_STATUS_PENDING && $ym_sys->grace_enable && !$new) {
             // grace is only applied to pending users
             // eligable
             $last_pay_date = $this->last_pay_date;
             $limit = time() - 86400 * $grace_limit_user;
             if ($last_pay_date > $limit) {
                 // lets put them into grace
                 $data = array('status' => YM_STATUS_GRACE, 'status_str' => __('User is entering Grace', 'ym'), 'expire_date' => time() + 86400 * $grace_limit_user);
                 @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expire_date'], $ID);
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'], $ID);
                 $data = apply_filters('ym_user_expire_check_into_grace', $data, $this);
                 $this->update($data);
                 $this->save();
                 do_action('ym_user_is_in_grace', $ID, $data);
                 // recheck
                 return $this->expire_check();
             } else {
                 // not eligable
                 return FALSE;
             }
         }
     }
     return FALSE;
 }
 public function task($offset = 0)
 {
     $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' => '!='));
     $total = count($users);
     if ($total) {
         echo 'Loop Begin From ' . $offset . "\n";
         $counter = 0;
         foreach ($users as $user) {
             $counter++;
             echo $counter . '/' . $total . ' ';
             if (ym_superuser($user->ID)) {
                 echo 'SuperUser ' . $user->ID;
             } else {
                 echo 'Checking ' . $user->ID . ' ';
                 $user = new YourMember_User($user->ID);
                 $user->expire_check();
                 echo $user->status;
             }
             echo "\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_inactives', 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_inactives" /><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_inactives_complete');
     }
 }
Exemple #3
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);
        }
    }
Exemple #4
0
function ym_authenticate($user = null, $return_bool = false)
{
    // CL. TN changed to empty() as a more reliable check and mimics WordPress method
    if (empty($user->ID)) {
        return $return_bool ? true : $user;
    }
    global $ym_user;
    if (!isset($ym_user->ID)) {
        $ym_user = new YourMember_User($user->ID);
    }
    // returns true if not expired
    $not_expired = $ym_user->expire_check();
    if ($not_expired) {
        return $return_bool ? true : $user;
    }
    //if the function hasnt returned by this point then theres an error
    if ($return_bool) {
        return false;
    }
    global $ym_res;
    $error_messages = array(YM_STATUS_NULL => $ym_res->login_errmsg_null, YM_STATUS_TRIAL_EXPIRED => $ym_res->login_errmsg_trial_expired, YM_STATUS_EXPIRED => $ym_res->login_errmsg_expired, YM_STATUS_PENDING => $ym_res->login_errmsg_pending, YM_STATUS_PARENT_EXPIRED => $ym_res->login_errmsg_parent_expired, YM_STATUS_PARENT_CANCEL => $ym_res->login_errmsg_parent_cancel, '*' => $ym_res->login_errmsg_default);
    //	$block_access = add_filter('ym_authenticate', TRUE, )
    $user_status = $ym_user->status;
    $error = isset($error_messages[$user_status]) ? $error_messages[$user_status] : $error_messages['*'];
    $error = str_replace('[[USERNAME]]', $user->user_login, $error);
    $err = new WP_Error();
    $err->add('ym_login_error', $error);
    return $err;
}
    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;
        }
    }