function transition_user_through_subscriptions()
 {
     $relationships = $this->get_expiring_relationships();
     if (!empty($relationships)) {
         membership_debug_log(__('CRON: Loaded relationships', 'membership') . print_r($relationships, true));
         foreach ($relationships as $rel) {
             // Just creating a membership record for this user should automatically
             // start the transition through the subscription
             membership_debug_log(sprintf(__('CRON: Processing member %d', 'membership'), $rel->user_id));
             $member = Membership_Plugin::factory()->get_member($rel->user_id);
         }
     }
 }
Beispiel #2
0
 function load_rules($loadtype = array('public', 'core'))
 {
     global $M_Rules;
     global $M_previous_positive;
     global $M_previous_negative;
     global $M_rule_filters;
     $M_previous_positive = array();
     $M_previous_negative = array();
     $M_rule_filters = array();
     membership_debug_log(__('Loading level - ', 'membership') . $this->level_title());
     $positive = $this->get_rules('positive');
     if (!empty($positive)) {
         $key = 0;
         foreach ((array) $positive as $key => $rule) {
             if (isset($M_Rules[$rule->rule_area]) && class_exists($M_Rules[$rule->rule_area])) {
                 $this->positiverules[$key] = new $M_Rules[$rule->rule_area]($this->id);
                 if ($rule->rule_area == 'pages') {
                     $this->positiverules[$key]->allow_page_cascade = $this->allow_page_cascade;
                 }
                 if (in_array($this->positiverules[$key]->rulearea, $loadtype)) {
                     $this->positiverules[$key]->on_positive(maybe_unserialize($rule->rule_value));
                     $this->positiverules[$key]->set_level_data($this->level->id);
                     $key++;
                 } else {
                     unset($this->positiverules[$key]);
                 }
             }
         }
     }
     $negative = $this->get_rules('negative');
     if (!empty($negative)) {
         $key = 0;
         foreach ((array) $negative as $key => $rule) {
             if ($rule->rule_area == 'pages') {
                 $rule->allow_page_cascade = $this->allow_page_cascade;
             }
             if (isset($M_Rules[$rule->rule_area]) && class_exists($M_Rules[$rule->rule_area])) {
                 $this->negativerules[$key] = new $M_Rules[$rule->rule_area]($this->id);
                 if ($rule->rule_area == 'pages') {
                     $this->negativerules[$key]->allow_page_cascade = $this->allow_page_cascade;
                 }
                 if (in_array($this->negativerules[$key]->rulearea, $loadtype)) {
                     $this->negativerules[$key]->on_negative(maybe_unserialize($rule->rule_value));
                     $this->negativerules[$key]->set_level_data($this->level->id);
                     $key++;
                 } else {
                     unset($this->negativerules[$key]);
                 }
             }
         }
     }
 }
Beispiel #3
0
 public function move_subscription($fromsub_id, $tosub_id, $tolevel_id, $to_order)
 {
     if (!apply_filters('pre_membership_move_subscription', true, $fromsub_id, $tosub_id, $tolevel_id, $to_order, $this->ID)) {
         return false;
     }
     membership_debug_log(sprintf(__('MEMBER: Moving subscription from %d to %d', 'membership'), $fromsub_id, $tosub_id));
     $factory = Membership_Plugin::factory();
     // Check if existing level matches new one but it is a serial or indefinite level
     $subscription = $factory->get_subscription($tosub_id);
     $nextlevel = $subscription->get_next_level($tolevel_id, $to_order);
     if (!$this->on_level($tolevel_id, true, $to_order) || $this->on_level($tolevel_id, true, $to_order) && ($nextlevel->sub_type == 'serial' || $nextlevel->sub_type == 'indefinite') && $this->on_sub($fromsub_id)) {
         membership_debug_log(sprintf(__('MEMBER: New level to move to %d on order %d', 'membership'), $tolevel_id, $to_order));
         // Get the level for this subscription before removing it
         $fromlevel_id = $this->get_level_for_sub($fromsub_id);
         // grab the level information for this position
         $subscription = $factory->get_subscription($tosub_id);
         $level = $subscription->get_level_at($tolevel_id, $to_order);
         if ($level) {
             $period = 'days';
             $now = current_time('mysql');
             $start = strtotime($now);
             switch ($level->level_period_unit) {
                 case 'd':
                     $period = 'days';
                     break;
                 case 'w':
                     $period = 'weeks';
                     break;
                 case 'm':
                     $period = 'months';
                     break;
                 case 'y':
                     $period = 'years';
                     break;
             }
             //subscription start and end date
             $start_sub = $tosub_id == $fromsub_id ? get_user_meta($this->ID, 'start_current_' . $fromsub_id, true) : $start;
             $expires_sub = $this->get_subscription_expire_date($subscription, $tolevel_id, $fromsub_id, $fromlevel_id);
             //level end date
             $expires = gmdate('Y-m-d H:i:s', strtotime('+' . $level->level_period . ' ' . $period, $start));
             // Update users start and expiry meta
             delete_user_meta($this->ID, 'start_current_' . $fromsub_id);
             delete_user_meta($this->ID, 'expire_current_' . $fromsub_id);
             delete_user_meta($this->ID, 'sent_msgs_' . $fromsub_id);
             // get the gateway and then remove it from the usermeta
             $gateway = get_user_meta($this->ID, 'using_gateway_' . $fromsub_id, true);
             delete_user_meta($this->ID, 'using_gateway_' . $fromsub_id);
             update_user_meta($this->ID, 'start_current_' . $tosub_id, $start_sub);
             update_user_meta($this->ID, 'expire_current_' . $tosub_id, $expires_sub);
             update_user_meta($this->ID, 'using_gateway_' . $tosub_id, $gateway);
             $this->_wpdb->update(MEMBERSHIP_TABLE_RELATIONS, array('sub_id' => $tosub_id, 'level_id' => $tolevel_id, 'updateddate' => $now, 'expirydate' => $expires, 'order_instance' => $level->level_order), array('sub_id' => $fromsub_id, 'user_id' => $this->ID));
             // Update the associated role
             $this->set_role(Membership_Model_Level::get_associated_role($level->level_id));
             membership_debug_log(sprintf(__('MEMBER: Completed move to %d on order %d on sub %d', 'membership'), $tolevel_id, $to_order, $tosub_id));
             do_action('membership_move_subscription', $fromsub_id, $fromlevel_id, $tosub_id, $tolevel_id, $to_order, $this->ID);
         }
     } else {
         membership_debug_log(sprintf(__('MEMBER: Already on level %d on order %d', 'membership'), $tolevel_id, $to_order));
     }
 }
Beispiel #4
0
function M_ping_expiresub($sub_id, $from_level, $user_id)
{
    if (!empty($from_level)) {
        M_ping_leftlevel($from_level, $user_id);
    }
    $sub = Membership_Plugin::factory()->get_subscription($sub_id);
    $subleavingping_id = $sub->get_meta('leaving_ping');
    if (!empty($subleavingping_id)) {
        $ping = new M_Ping($subleavingping_id);
        membership_debug_log("M_ping_expiresub: LINE 548" . print_r($ping, true));
        $ping->send_ping($sub_id, false, $user_id);
    }
}
Beispiel #5
0
 /**
  * Checks member permissions and protects current page.
  *
  * @since 3.5
  * @action template_redirect 1
  *
  * @access public
  */
 public function protect_current_page()
 {
     global $post, $M_options;
     if (membership_is_special_page()) {
         if (is_user_logged_in()) {
             if (membership_is_welcome_page() && !Membership_Plugin::current_member()->has_subscription()) {
                 //  Uncomment to make welcome page protected.
                 //	membership_redirect_to_protected();
                 //	exit;
             }
             return;
         } else {
             if (membership_is_account_page()) {
                 membership_redirect_to_protected();
                 exit;
             }
         }
         return;
     }
     if (!Membership_Plugin::current_member()->can_view_current_page()) {
         membership_debug_log(__('Current member can not view current page.', 'membership'));
         membership_redirect_to_protected();
         exit;
     }
     membership_debug_log(__('Current member can view current page.', 'membership'));
 }
 function handle_paypal_return()
 {
     // PayPal IPN handling code
     if ((isset($_POST['payment_status']) || isset($_POST['txn_type'])) && isset($_POST['custom'])) {
         if (get_option($this->gateway . "_paypal_status") == 'live') {
             $domain = 'https://www.paypal.com';
         } else {
             $domain = 'https://www.sandbox.paypal.com';
         }
         membership_debug_log(__('Received PayPal IPN from - ', 'membership') . $domain);
         //Paypal post authenticity verification
         $ipn_data = (array) stripslashes_deep($_POST);
         $ipn_data['cmd'] = '_notify-validate';
         $response = wp_remote_post("{$domain}/cgi-bin/webscr", array('timeout' => 60, 'httpversion' => '1.1', 'sslverify' => false, 'body' => $ipn_data));
         if (!is_wp_error($response) && 200 == $response['response']['code'] && !empty($response['body']) && "VERIFIED" == $response['body']) {
             membership_debug_log('PayPal Transaction Verified');
         } else {
             $error = 'Response Error: Unexpected transaction response';
             membership_debug_log($error);
             membership_debug_log($response);
             echo $error;
             exit;
         }
         // process PayPal response
         $factory = Membership_Plugin::factory();
         switch (filter_input(INPUT_POST, 'payment_status')) {
             case 'Completed':
             case 'Processed':
                 // case: successful payment
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], '');
                 membership_debug_log(__('Processed transaction received - ', 'membership') . print_r($_POST, true));
                 // Added for affiliate system link
                 do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Reversed':
                 // case: charge back
                 $note = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back)', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Reversed transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_reversed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Refunded':
                 // case: refund
                 $note = __('Last transaction has been reversed. Reason: Payment has been refunded', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Refunded transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                 }
                 do_action('membership_payment_refunded', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Denied':
                 // case: denied
                 $note = __('Last transaction has been reversed. Reason: Payment Denied', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Denied transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Pending':
                 // case: payment is pending
                 $pending_str = array('address' => __('Customer did not include a confirmed shipping address', 'membership'), 'authorization' => __('Funds not captured yet', 'membership'), 'echeck' => __('eCheck that has not cleared yet', 'membership'), 'intl' => __('Payment waiting for aproval by service provider', 'membership'), 'multi-currency' => __('Payment waiting for service provider to handle multi-currency process', 'membership'), 'unilateral' => __('Customer did not register or confirm his/her email yet', 'membership'), 'upgrade' => __('Waiting for service provider to upgrade the PayPal account', 'membership'), 'verify' => __('Waiting for service provider to verify his/her PayPal account', 'membership'), '*' => '');
                 $reason = @$_POST['pending_reason'];
                 $note = __('Last transaction is pending. Reason: ', 'membership') . (isset($pending_str[$reason]) ? $pending_str[$reason] : $pending_str['*']);
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 membership_debug_log(__('Pending transaction received - ', 'membership') . print_r($_POST, true));
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
         }
         //check for subscription details
         switch ($_POST['txn_type']) {
             // Simple one-off payment
             case 'web_accept':
                 $amount = $_POST['mc_gross'];
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                     membership_debug_log(sprintf(__('Key does not match for amount - not creating subscription for user %d with key ', 'membership'), $user_id) . $newkey);
                 } else {
                     if ($from_sub) {
                         $member->drop_subscription($from_sub);
                     }
                     // create_subscription
                     $member->create_subscription($sub_id, $this->gateway);
                     membership_debug_log(sprintf(__('Creating subscription %d for user %d', 'membership'), $sub_id, $user_id));
                     do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 }
                 break;
             case 'subscr_signup':
                 // start the subscription
                 $amount = $_POST['mc_amount3'];
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                     membership_debug_log(sprintf(__('Key does not match for amount - not creating subscription for user %d with key ', 'membership'), $user_id) . $newkey);
                 } else {
                     if ($from_sub) {
                         $member->drop_subscription($from_sub);
                     }
                     // create_subscription
                     $member->create_subscription($sub_id, $this->gateway);
                     membership_debug_log(sprintf(__('Creating subscription %d for user %d', 'membership'), $sub_id, $user_id));
                     do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 }
                 break;
             case 'subscr_modify':
                 // modify the subscription
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($from_sub ? $from_sub : $sub_id);
                 $member->create_subscription((int) $_POST['item_number'], $this->gateway);
                 // Timestamp the update
                 update_user_meta($user_id, '_membership_last_upgraded', time());
                 membership_debug_log(sprintf(__('Moved from subscription - %d to subscription %d for user %d', 'membership'), $sub_id, (int) $_POST['item_number'], $user_id));
                 do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 break;
             case 'recurring_payment_profile_canceled':
             case 'subscr_cancel':
                 // mark for removal
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->mark_for_expire($sub_id);
                 membership_debug_log(sprintf(__('Marked for expiration %d on %d', 'membership'), $user_id, $sub_id));
                 do_action('membership_payment_subscr_cancel', $user_id, $sub_id);
                 break;
             case 'recurring_payment_suspended':
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($sub_id);
                 membership_debug_log(sprintf(__('Recurring payment has been suspended - for %d', 'membership'), $user_id));
                 break;
             case 'recurring_payment_suspended_due_to_max_failed_payment':
             case 'recurring_payment_failed':
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($sub_id);
                 membership_debug_log(sprintf(__('Recurring payment failed - the number of attempts to collect payment has exceeded the value specified for "max failed payments" - for %d', 'membership'), $user_id));
                 break;
             case 'new_case':
                 // a dispute
                 if ($_POST['case_type'] == 'dispute') {
                     // immediately suspend the account
                     $member = $factory->get_member($user_id);
                     $member->deactivate();
                     membership_debug_log(sprintf(__('Dispute for %d', 'membership'), $user_id));
                 }
                 do_action('membership_payment_new_case', $user_id, $sub_id, $_POST['case_type']);
                 break;
         }
     } else {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         header('Status: 404 Not Found');
         echo 'Error: Missing POST variables. Identification is not possible.';
         membership_debug_log('Error: Missing POST variables. Identification is not possible.');
         exit;
     }
 }
 function handle_paypal_return()
 {
     // PayPal IPN handling code
     if ((isset($_POST['payment_status']) || isset($_POST['txn_type'])) && isset($_POST['custom'])) {
         if (get_option($this->gateway . "_paypal_status") == 'live') {
             $domain = 'https://www.paypal.com';
         } else {
             $domain = 'https://www.sandbox.paypal.com';
         }
         membership_debug_log(__('Received PayPal IPN from - ', 'membership') . $domain);
         //Paypal post authenticity verification
         $ipn_data = (array) stripslashes_deep($_POST);
         $ipn_data['cmd'] = '_notify-validate';
         $response = wp_remote_post("{$domain}/cgi-bin/webscr", array('timeout' => 60, 'sslverify' => false, 'httpversion' => '1.1', 'body' => $ipn_data));
         if (!is_wp_error($response) && 200 == $response['response']['code'] && !empty($response['body']) && "VERIFIED" == $response['body']) {
             membership_debug_log('PayPal Transaction Verified');
         } else {
             $error = 'Response Error: Unexpected transaction response';
             membership_debug_log($error);
             membership_debug_log($response);
             echo $error;
             exit;
         }
         // handle cases that the system must ignore
         //if ($_POST['payment_status'] == 'In-Progress' || $_POST['payment_status'] == 'Partially-Refunded') exit;
         $new_status = false;
         // process PayPal response
         $factory = Membership_Plugin::factory();
         switch ($_POST['payment_status']) {
             case 'Partially-Refunded':
                 break;
             case 'In-Progress':
                 break;
             case 'Completed':
             case 'Processed':
                 // case: successful payment
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel, $fromsub) = explode(':', $_POST['custom']);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     $member = $factory->get_member($user_id);
                     if ($member) {
                         if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                             $member->deactivate();
                         }
                     }
                 } elseif (!$this->_check_duplicate_transaction($user_id, $sub_id, $timestamp, trim($_POST['txn_id']))) {
                     $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, trim($_POST['txn_id']), $_POST['payment_status'], '');
                     if ($sublevel == '1') {
                         // This is the first level of a subscription so we need to create one if it doesn't already exist
                         $member = $factory->get_member($user_id);
                         if ($member) {
                             $member->create_subscription($sub_id, $this->gateway);
                             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                         }
                     } else {
                         $member = $factory->get_member($user_id);
                         if ($member) {
                             // Mark the payment so that we can move through ok
                             $member->record_active_payment($sub_id, $sublevel, $timestamp);
                         }
                     }
                     // remove any current subs for upgrades
                     $sub_ids = $member->get_subscription_ids();
                     foreach ($sub_ids as $fromsub) {
                         if ($sub_id == $fromsub) {
                             continue;
                         }
                         $member->drop_subscription($fromsub);
                     }
                     // Added for affiliate system link
                     do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 }
                 membership_debug_log(__('Processed transaction received - ', 'membership') . print_r($_POST, true));
                 break;
             case 'Reversed':
                 // case: charge back
                 $note = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back)', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Reversed transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_reversed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Refunded':
                 // case: refund
                 $note = __('Last transaction has been reversed. Reason: Payment has been refunded', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Refunded transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                 }
                 do_action('membership_payment_refunded', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Denied':
                 // case: denied
                 $note = __('Last transaction has been reversed. Reason: Payment Denied', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Denied transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Pending':
                 // case: payment is pending
                 $pending_str = array('address' => __('Customer did not include a confirmed shipping address', 'membership'), 'authorization' => __('Funds not captured yet', 'membership'), 'echeck' => __('eCheck that has not cleared yet', 'membership'), 'intl' => __('Payment waiting for aproval by service provider', 'membership'), 'multi-currency' => __('Payment waiting for service provider to handle multi-currency process', 'membership'), 'unilateral' => __('Customer did not register or confirm his/her email yet', 'membership'), 'upgrade' => __('Waiting for service provider to upgrade the PayPal account', 'membership'), 'verify' => __('Waiting for service provider to verify his/her PayPal account', 'membership'), '*' => '');
                 $reason = @$_POST['pending_reason'];
                 $note = 'Last transaction is pending. Reason: ' . (isset($pending_str[$reason]) ? $pending_str[$reason] : $pending_str['*']);
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Pending transaction received - ', 'membership') . print_r($_POST, true));
                 do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             default:
                 // case: various error cases
         }
         //check for subscription details
         switch ($_POST['txn_type']) {
             case 'new_case':
                 // a dispute
                 if ($_POST['case_type'] == 'dispute') {
                     list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                     // immediately suspend the account
                     $member = $factory->get_member($user_id);
                     if ($member) {
                         $member->deactivate();
                         membership_debug_log(sprintf(__('Dispute for %d', 'membership'), $user_id));
                     }
                 }
                 do_action('membership_payment_new_case', $user_id, $sub_id, $_POST['case_type']);
                 break;
         }
     } else {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         header('Status: 404 Not Found');
         echo 'Error: Missing POST variables. Identification is not possible.';
         membership_debug_log('Error: Missing POST variables. Identification is not possible.');
         exit;
     }
 }
Beispiel #8
0
 /**
  * Returns current member.
  *
  * @sicne 3.5
  *
  * @access public
  * @global array $M_options The array of the plugin options.
  * @staticvar Membership_Model_Member $member
  * @return Membership_Model_Member Current member.
  */
 public static function current_member()
 {
     global $M_options;
     static $member = null;
     if (is_null($member)) {
         $factory = self::factory();
         $member = $factory->get_member(get_current_user_id());
         if ($member->has_cap(Membership_Model_Member::CAP_MEMBERSHIP_ADMIN) || $member->has_cap('manage_options') || is_super_admin($member->ID)) {
             // member has admin capabilities
             membership_debug_log(__('Current member has admin capabilities.', 'membership'));
             // check whether we need to switch membership level or not
             if (!empty($_COOKIE['membershipuselevel']) && ($membershipuselevel = absint($_COOKIE['membershipuselevel']))) {
                 $member->assign_level($membershipuselevel, true);
                 membership_debug_log(sprintf(__('Switching membership level to %d for current member.', 'membership'), $membershipuselevel));
             }
         } else {
             if ($member->ID > 0) {
                 if ($member->has_levels()) {
                     // load the levels for this member
                     $member->load_levels(true);
                     membership_debug_log(__('Standard levels are loaded for current member.', 'membership'));
                 } elseif (!empty($M_options['freeusersubscription'])) {
                     // load default subscription for registered users
                     $subscription = $factory->get_subscription($M_options['freeusersubscription']);
                     $levels = $subscription->get_levels();
                     if (!empty($levels)) {
                         $member->assign_level($levels[0]->level_id);
                         membership_debug_log(__('Default subscription for registered users is used to assign a level for current member.', 'membership'));
                     }
                 } elseif (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                     $member->assign_level($M_options['strangerlevel']);
                 }
             } elseif (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                 // assign stanger level
                 $member->assign_level($M_options['strangerlevel']);
             }
         }
     }
     return $member;
 }
 function handle_2checkout_return()
 {
     global $M_options;
     // Return handling code
     $timestamp = time();
     if (isset($_REQUEST['key'])) {
         $total = $_REQUEST['total'];
         $sub_id = false;
         $user_id = false;
         list($sub_id, $user_id) = explode(':', $_REQUEST['merchant_order_id']);
         if (esc_attr(get_option($this->gateway . "_twocheckout_status")) == 'test') {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         } else {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         }
         if ($sub_id && $user_id && $_REQUEST['key'] == $hash && $_REQUEST['credit_card_processed'] == 'Y') {
             $this->_record_transaction($user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $timestamp, $_REQUEST['order_number'], 'Credit Card Verified', '');
             // Added for affiliate system link
             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $_REQUEST['order_number']);
             $member = Membership_Plugin::factory()->get_member($user_id);
             if ($member) {
                 $member->create_subscription($sub_id, $this->gateway);
                 membership_debug_log(sprintf(__('Order complete for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
             }
             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
             if (!isset($M_options['registrationcompleted_page']) || 0 >= $M_options['registrationcompleted_page']) {
                 wp_redirect(get_option('home'));
             } else {
                 wp_redirect(M_get_registrationcompleted_permalink());
             }
             exit;
         }
     } else {
         if (isset($_REQUEST['message_type'])) {
             $md5_hash = strtoupper(md5("{$_REQUEST['sale_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . "{$_REQUEST['invoice_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_secret_word"))));
             $sub_id = false;
             $user_id = false;
             //$product_id = $_REQUEST['item_id_1'];
             list($sub_id, $user_id, $from_sub_id) = explode(':', $_REQUEST['vendor_order_id']);
             if ($md5_hash == $_REQUEST['md5_hash']) {
                 switch ($_REQUEST['message_type']) {
                     case 'RECURRING_INSTALLMENT_SUCCESS':
                         if (!$this->_check_duplicate_transaction($user_id, $sub_id, $timestamp, $_POST['invoice_id'])) {
                             $this->_record_transaction($user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 3);
                                 remove_action('membership_add_subscription', 'membership_record_user_subscribe', 10, 4);
                                 if ($from_sub_id) {
                                     $member->drop_subscription($from_sub_id);
                                 }
                                 $member->expire_subscription($sub_id);
                                 $member->create_subscription($sub_id, $this->gateway);
                                 membership_debug_log(sprintf(__('Recurring installment for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                             }
                             // Added for affiliate system link
                             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $_POST['invoice_id']);
                         }
                         break;
                     case 'FRAUD_STATUS_CHANGED':
                     case 'INVOICE_STATUS_CHANGED':
                         // We don't really want to do anything here without pulling out more information
                         break;
                     case 'ORDER_CREATED':
                     case 'RECURRING_RESTARTED':
                         $transaction_amount = !empty($_REQUEST['item_rec_list_amount_1']) ? $_REQUEST['item_rec_list_amount_1'] : $_REQUEST['item_list_amount_1'];
                         $this->_record_transaction($user_id, $sub_id, $transaction_amount, $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             if ($from_sub_id) {
                                 $member->drop_subscription($from_sub_id);
                             }
                             $member->create_subscription($sub_id, $this->gateway);
                             membership_debug_log(sprintf(__('Recurring restarted for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         break;
                     case 'RECURRING_STOPPED':
                     case 'RECURRING_COMPLETE':
                     case 'RECURRING_INSTALLMENT_FAILED':
                     default:
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             $member->mark_for_expire($sub_id);
                             membership_debug_log(sprintf(__('Recurring failed for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         do_action('membership_payment_subscr_cancel', $user_id, $sub_id);
                         break;
                 }
             } else {
                 // MD5 Hash Failed
                 header('Status: 403 Forbidden');
                 echo 'Error: Unexpected Security Value. Verification is not possible.';
                 membership_debug_log('Error: Unexpected Security Value. Verification is not possible.');
                 exit;
             }
             echo "OK";
             membership_debug_log('OK');
             exit;
         } else {
             // Did not find expected POST variables. Possible access attempt from a non PayPal site.
             header('Status: 400 Bad Request');
             echo 'Error: Missing POST variables. Identification is not possible.';
             membership_debug_log('Error: Missing POST variables. Identification is not possible.');
             exit;
         }
     }
 }