/** * Get the data being exported * * @access public * @since 1.5 * @return array */ public function get_data() { global $wpdb; $data = array(); $subscription = isset($_POST['rcp-subscription']) ? absint($_POST['rcp-subscription']) : null; $status = isset($_POST['rcp-status']) ? sanitize_text_field($_POST['rcp-status']) : 'active'; $offset = isset($_POST['rcp-offset']) ? absint($_POST['rcp-offset']) : null; $number = isset($_POST['rcp-number']) ? absint($_POST['rcp-number']) : null; $members = rcp_get_members($status, $subscription, $offset, $number); if ($members) { foreach ($members as $member) { $member = new RCP_Member($member->ID); $discounts = get_user_meta($member->ID, 'rcp_user_discounts', true); if (!empty($discounts) && is_array($discounts) && !$discounts instanceof stdClass) { foreach ($discounts as $key => $code) { if (!is_string($code)) { unset($discounts[$key]); } } $discounts = implode(' ', $discounts); } $data[] = array('user_id' => $member->ID, 'user_login' => $member->user_login, 'user_email' => $member->user_email, 'first_name' => $member->first_name, 'last_name' => $member->last_name, 'subscription' => $member->get_subscription_id(), 'subscription_key' => $member->get_subscription_key(), 'expiration' => $member->get_expiration_date(), 'status' => $member->get_status(), 'discount_codes' => $discounts, 'profile_id' => $member->get_payment_profile_id(), 'is_recurring' => $member->is_recurring()); } } $data = apply_filters('rcp_export_get_data', $data); $data = apply_filters('rcp_export_get_data_' . $this->export_type, $data); return $data; }
<svg class="icon icon-sort-desc"><use xlink:href="#icon-sort-desc"></use></svg> </div> </td> <th class="holy-ambition"> <div> Holy Ambition </div> </td> </tr> </thead> <tbody> <?php $members = get_users(); foreach ($members as $member) { $sub = new RCP_Member($member->ID); $status = $sub->get_status(); if ($status == 'active') { if (get_user_meta($member->ID, 'rcp_ambition', true) == 1) { ?> <tr class="users"> <td class="last-name"><?php echo get_user_meta($member->ID, 'last_name', true); ?> </td> <td class="first-name"><?php echo get_user_meta($member->ID, 'first_name', true); ?> </td> <td class="email"><?php echo get_userdata($member->ID)->user_email; ?>
/** * Determines if a member can cancel their subscription on site * * @access public * @since 2.1 */ function rcp_can_member_cancel( $user_id = 0 ) { if( empty( $user_id ) ) { $user_id = get_current_user_id(); } $ret = false; $member = new RCP_Member( $user_id ); if( $member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status() ) { $profile_id = $member->get_payment_profile_id(); // Check if the member is a Stripe customer if( false !== strpos( $profile_id, 'cus_' ) ) { $ret = true; } elseif ( rcp_is_paypal_subscriber( $user_id ) && rcp_has_paypal_api_access() ) { $ret = true; } } return apply_filters( 'rcp_member_can_cancel', $ret, $user_id ); }
/** * Determines if a member can cancel their subscription on site * * @access public * @since 2.1 */ function rcp_can_member_cancel($user_id = 0) { if (empty($user_id)) { $user_id = get_current_user_id(); } $ret = false; $member = new RCP_Member($user_id); if ($member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status()) { $profile_id = $member->get_payment_profile_id(); // Check if the member is a Stripe customer if (rcp_is_stripe_subscriber($user_id)) { $ret = true; } elseif (rcp_is_paypal_subscriber($user_id) && rcp_has_paypal_api_access()) { $ret = true; } elseif (rcp_is_2checkout_subscriber($user_id) && defined('TWOCHECKOUT_ADMIN_USER') && defined('TWOCHECKOUT_ADMIN_PASSWORD')) { $ret = true; } } return apply_filters('rcp_member_can_cancel', $ret, $user_id); }
/** * Process PayPal IPN * * @since 2.1 */ public function process_webhooks() { if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'IPN') { return; } global $rcp_options; nocache_headers(); if (!class_exists('IpnListener')) { // instantiate the IpnListener class include RCP_PLUGIN_DIR . 'includes/gateways/paypal/paypal-ipnlistener.php'; } $listener = new IpnListener(); $verified = false; if ($this->test_mode) { $listener->use_sandbox = true; } /* if( isset( $rcp_options['ssl'] ) ) { $listener->use_ssl = true; } else { $listener->use_ssl = false; } */ //To post using the fsockopen() function rather than cURL, use: if (isset($rcp_options['disable_curl'])) { $listener->use_curl = false; } try { $listener->requirePostMethod(); $verified = $listener->processIpn(); } catch (Exception $e) { status_header(402); //die( 'IPN exception: ' . $e->getMessage() ); } /* The processIpn() method returned true if the IPN was "VERIFIED" and false if it was "INVALID". */ if ($verified || isset($_POST['verification_override']) || ($this->test_mode || isset($rcp_options['disable_ipn_verify']))) { status_header(200); $user_id = 0; $posted = apply_filters('rcp_ipn_post', $_POST); // allow $_POST to be modified if (!empty($posted['custom']) && is_numeric($posted['custom'])) { $user_id = absint($posted['custom']); } else { if (!empty($posted['subscr_id'])) { $user_id = rcp_get_member_id_from_profile_id($posted['subscr_id']); } else { if (!empty($posted['payer_email'])) { $user = get_user_by('email', $posted['payer_email']); $user_id = $user ? $user->ID : false; } } } $member = new RCP_Member($user_id); if (!$member || !$member->get_subscription_id()) { die('no member found'); } if (!rcp_get_subscription_details($member->get_subscription_id())) { die('no subscription level found'); } $subscription_name = $posted['item_name']; $subscription_key = $posted['item_number']; $amount = number_format((double) $posted['mc_gross'], 2); $amount2 = number_format((double) $posted['mc_amount3'], 2); $payment_status = $posted['payment_status']; $currency_code = $posted['mc_currency']; $subscription_price = number_format((double) rcp_get_subscription_price($member->get_subscription_id()), 2); // setup the payment info in an array for storage $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'], current_time('timestamp'))), 'subscription' => $posted['item_name'], 'payment_type' => $posted['txn_type'], 'subscription_key' => $subscription_key, 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']); do_action('rcp_valid_ipn', $payment_data, $user_id, $posted); if ($posted['txn_type'] == 'web_accept' || $posted['txn_type'] == 'subscr_payment') { // only check for an existing payment if this is a payment IPD request if (rcp_check_for_existing_payment($posted['txn_type'], $posted['payment_date'], $subscription_key)) { $log_data = array('post_title' => __('Duplicate Payment', 'rcp'), 'post_content' => __('A duplicate payment was detected. The new payment was still recorded, so you may want to check into both payments.', 'rcp'), 'post_parent' => 0, 'log_type' => 'gateway_error'); $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id); $log_entry = WP_Logging::insert_log($log_data, $log_meta); die('duplicate IPN detected'); } if (strtolower($currency_code) != strtolower($rcp_options['currency'])) { // the currency code is invalid $log_data = array('post_title' => __('Invalid Currency Code', 'rcp'), 'post_content' => sprintf(__('The currency code in an IPN request did not match the site currency code. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error'); $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id); $log_entry = WP_Logging::insert_log($log_data, $log_meta); die('invalid currency code'); } } if (isset($rcp_options['email_ipn_reports'])) { wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport()); } /* now process the kind of subscription/payment */ $rcp_payments = new RCP_Payments(); // Subscriptions switch ($posted['txn_type']) { case "subscr_signup": // when a new user signs up // store the recurring payment ID update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); $member->set_payment_profile_id($posted['subscr_id']); do_action('rcp_ipn_subscr_signup', $user_id); die('successful subscr_signup'); break; case "subscr_payment": // when a user makes a recurring payment update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); $member->set_payment_profile_id($posted['subscr_id']); $member->renew(true); // record this payment in the database $rcp_payments->insert($payment_data); do_action('rcp_ipn_subscr_payment', $user_id); die('successful subscr_payment'); break; case "subscr_cancel": // user is marked as cancelled but retains access until end of term $member->set_status('cancelled'); // set the use to no longer be recurring delete_user_meta($user_id, 'rcp_paypal_subscriber'); do_action('rcp_ipn_subscr_cancel', $user_id); die('successful subscr_cancel'); break; case "subscr_failed": do_action('rcp_ipn_subscr_failed'); die('successful subscr_failed'); break; case "subscr_eot": // user's subscription has reached the end of its term if ('cancelled' !== $member->get_status($user_id)) { $member->set_status('expired'); } do_action('rcp_ipn_subscr_eot', $user_id); die('successful subscr_eot'); break; case "web_accept": switch (strtolower($payment_status)) { case 'completed': // set this user to active $member->renew(); $rcp_payments->insert($payment_data); break; case 'denied': case 'expired': case 'failed': case 'voided': $member->set_status('cancelled'); break; } die('successful web_accept'); break; case "cart": case "express_checkout": default: break; } } else { if (isset($rcp_options['email_ipn_reports'])) { // an invalid IPN attempt was made. Send an email to the admin account to investigate wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'rcp'), $listener->getTextReport()); } status_header(400); die('invalid IPN'); } }
/** * Process PayPal IPN * * @since 2.1 */ public function process_webhooks() { if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'EIPN') { return; } $posted = apply_filters('rcp_ipn_post', $_POST); // allow $_POST to be modified $user_id = absint($posted['custom']); $member = new RCP_Member($user_id); if (!$member || !$member->get_subscription_id()) { die('no member found'); } if (!rcp_get_subscription_details($member->get_subscription_id())) { die('no subscription level found'); } $amount = number_format((double) $posted['mc_gross'], 2); // setup the payment info in an array for storage $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'])), 'subscription' => $member->get_subscription_name(), 'payment_type' => $posted['txn_type'], 'subscription_key' => $member->get_subscription_key(), 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']); do_action('rcp_valid_ipn', $payment_data, $user_id, $posted); if (isset($rcp_options['email_ipn_reports'])) { wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport()); } /* now process the kind of subscription/payment */ $rcp_payments = new RCP_Payments(); // Subscriptions switch ($posted['txn_type']) { case "recurring_payment": // when a user makes a recurring payment // record this payment in the database $rcp_payments->insert($payment_data); update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); $member->set_payment_profile_id($posted['recurring_payment_id']); $this->renew_member(true); do_action('rcp_ipn_subscr_payment', $user_id); die('successful recurring_payment'); break; case "recurring_payment_profile_cancel": // user is marked as cancelled but retains access until end of term $member->set_status('cancelled'); // set the use to no longer be recurring delete_user_meta($user_id, 'rcp_paypal_subscriber'); do_action('rcp_ipn_subscr_cancel', $user_id); die('successful recurring_payment_profile_cancel'); break; case "recurring_payment_failed": case "recurring_payment_suspended_due_to_max_failed_payment": if ('cancelled' !== $member->get_status($user_id)) { $member->set_status('expired'); } do_action('rcp_ipn_subscr_failed'); die('successful recurring_payment_failed or recurring_payment_suspended_due_to_max_failed_payment'); break; } }
function rcp_process_data() { if (!is_admin()) { return; } if (!empty($_POST)) { /**************************************** * subscription levels ****************************************/ // add a new subscription level if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-level') { if (!wp_verify_nonce($_POST['rcp_add_level_nonce'], 'rcp_add_level_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } if (empty($_POST['name'])) { $url = admin_url('admin.php?page=rcp-member-levels&rcp_message=level_missing_fields'); wp_safe_redirect(esc_url_raw($url)); exit; } $levels = new RCP_Levels(); $add = $levels->insert($_POST); if ($add) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_added'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_added'; } wp_safe_redirect($url); exit; } // edit a subscription level if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-subscription') { if (!wp_verify_nonce($_POST['rcp_edit_level_nonce'], 'rcp_edit_level_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update($_POST['subscription_id'], $_POST); if ($update) { // clear the cache $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_updated'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_updated'; } wp_safe_redirect($url); exit; } // add a subscription for an existing member if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-subscription') { if (!wp_verify_nonce($_POST['rcp_add_member_nonce'], 'rcp_add_member_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } if (empty($_POST['level']) || empty($_POST['user'])) { wp_die(__('Please fill out all fields.', 'rcp')); } if (isset($_POST['expiration']) && strtotime('NOW', current_time('timestamp')) > strtotime($_POST['expiration'], current_time('timestamp')) && 'none' !== $_POST['expiration']) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_not_added'; header("Location:" . $url); } else { $levels = new RCP_Levels(); $user = get_user_by('login', $_POST['user']); if (!$user) { wp_die(__('You entered a username that does not exist.', 'rcp')); } $member = new RCP_Member($user->ID); $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none'; $level_id = absint($_POST['level']); $subscription = $levels->get_level($level_id); if (!$subscription) { wp_die(__('Please supply a valid subscription level.', 'rcp')); } $member->set_expiration_date($expiration); $new_subscription = get_user_meta($user->ID, '_rcp_new_subscription', true); if (empty($new_subscription)) { update_user_meta($user->ID, '_rcp_new_subscription', '1'); } update_user_meta($user->ID, 'rcp_signup_method', 'manual'); update_user_meta($user->ID, 'rcp_subscription_level', $level_id); $status = $subscription->price == 0 ? 'free' : 'active'; $member->set_status($status); // Add the new user role $role = !empty($subscription->role) ? $subscription->role : 'subscriber'; $user->add_role($role); // Set joined date for the new subscription $member->set_joined_date('', $level_id); if (isset($_POST['recurring'])) { update_user_meta($user->ID, 'rcp_recurring', 'yes'); } else { delete_user_meta($user->ID, 'rcp_recurring'); } $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_added'; header("Location:" . $url); } } // bulk edit members if (isset($_POST['rcp-bulk-action']) && $_POST['rcp-bulk-action']) { if (!wp_verify_nonce($_POST['rcp_bulk_edit_nonce'], 'rcp_bulk_edit_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } if (empty($_POST['member-ids'])) { wp_die(__('Please select at least one member to edit.', 'rcp')); } $member_ids = array_map('absint', $_POST['member-ids']); $action = !empty($_POST['rcp-bulk-action']) ? sanitize_text_field($_POST['rcp-bulk-action']) : false; foreach ($member_ids as $member_id) { $member = new RCP_Member($member_id); if (!empty($_POST['expiration']) && 'delete' !== $action) { $member->set_expiration_date(date('Y-m-d H:i:s', strtotime($_POST['expiration'], current_time('timestamp')))); } if ($action) { switch ($action) { case 'mark-active': $member->set_status('active'); break; case 'mark-expired': $member->set_status('expired'); break; case 'mark-cancelled': $member->set_status('cancelled'); break; } } } wp_redirect(admin_url('admin.php?page=rcp-members&rcp_message=members_updated')); exit; } // edit a member's subscription if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-member') { if (!wp_verify_nonce($_POST['rcp_edit_member_nonce'], 'rcp_edit_member_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $user_id = absint($_POST['user']); $member = new RCP_Member($user_id); $status = sanitize_text_field($_POST['status']); $level_id = absint($_POST['level']); $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none'; $expiration = 'none' !== $expiration ? date('Y-m-d 23:59:59', strtotime($_POST['expiration'], current_time('timestamp'))) : $expiration; if (!empty($_POST['expiration'])) { $member->set_expiration_date($expiration); } if (isset($_POST['level'])) { $current_id = rcp_get_subscription_id($user_id); $new_level = $levels->get_level($level_id); $old_level = $levels->get_level($current_id); if ($current_id != $level_id) { update_user_meta($user_id, 'rcp_subscription_level', $level_id); // Remove the old user role $role = !empty($old_level->role) ? $old_level->role : 'subscriber'; $member->remove_role($role); // Add the new user role $role = !empty($new_level->role) ? $new_level->role : 'subscriber'; $member->add_role($role); // Set joined date for the new subscription $member->set_joined_date('', $level_id); } } if (isset($_POST['recurring'])) { $member->set_recurring(true); } else { $member->set_recurring(false); } if (isset($_POST['trialing'])) { update_user_meta($user_id, 'rcp_is_trialing', 'yes'); } else { delete_user_meta($user_id, 'rcp_is_trialing'); } if (isset($_POST['signup_method'])) { update_user_meta($user_id, 'rcp_signup_method', $_POST['signup_method']); } if (isset($_POST['notes'])) { update_user_meta($user_id, 'rcp_notes', wp_kses($_POST['notes'], array())); } if ($status !== $member->get_status()) { $member->set_status($status); } if (isset($_POST['payment-profile-id'])) { $member->set_payment_profile_id($_POST['payment-profile-id']); } do_action('rcp_edit_member', $user_id); wp_redirect(admin_url('admin.php?page=rcp-members&edit_member=' . $user_id . '&rcp_message=user_updated')); exit; } /**************************************** * discount codes ****************************************/ // add a new discount code if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-discount') { if (!wp_verify_nonce($_POST['rcp_add_discount_nonce'], 'rcp_add_discount_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); // Setup unsanitized data $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => 'active', 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']); $add = $discounts->insert($data); if (is_wp_error($add)) { wp_die($add); } if ($add) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_added'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_not_added'; } wp_safe_redirect($url); exit; } // edit a discount code if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-discount') { if (!wp_verify_nonce($_POST['rcp_edit_discount_nonce'], 'rcp_edit_discount_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); // Setup unsanitized data $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => $_POST['status'], 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']); $update = $discounts->update($_POST['discount_id'], $data); if (is_wp_error($update)) { wp_die($update); } if ($update) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=1'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=0'; } wp_safe_redirect($url); exit; } // add a new manual payment if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-payment') { if (!wp_verify_nonce($_POST['rcp_add_payment_nonce'], 'rcp_add_payment_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $user = get_user_by('login', $_POST['user']); if ($user) { $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'payment_type' => 'manual', 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status'])); $add = $payments->insert($data); } if (!empty($add)) { $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => ''); $cache_key = md5(implode(',', $cache_args)); delete_transient($cache_key); $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_added'); } else { $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_added'); } wp_safe_redirect($url); exit; } // edit a payment if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-payment') { if (!wp_verify_nonce($_POST['rcp_edit_payment_nonce'], 'rcp_edit_payment_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $payment_id = absint($_POST['payment-id']); $user = get_user_by('login', $_POST['user']); if ($user && $payment_id) { $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status'])); $update = $payments->update($payment_id, $data); } if (!empty($update)) { $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => ''); $cache_key = md5(implode(',', $cache_args)); delete_transient($cache_key); $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_updated'); } else { $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_updated'); } wp_safe_redirect($url); exit; } } /************************************* * delete data *************************************/ if (!empty($_GET)) { /* member processing */ if (isset($_GET['cancel_member'])) { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } rcp_cancel_member_payment_profile(urldecode(absint($_GET['cancel_member']))); wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'member_cancelled', 'admin.php?page=rcp-members'))); exit; } /* subscription processing */ if (isset($_GET['delete_subscription']) && $_GET['delete_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $members_of_subscription = rcp_get_members_of_subscription(absint($_GET['delete_subscription'])); // cancel all active members of this subscription if ($members_of_subscription) { foreach ($members_of_subscription as $member) { rcp_set_status($member, 'cancelled'); } } $levels = new RCP_Levels(); $levels->remove($_GET['delete_subscription']); $levels->remove_all_meta_for_level_id($_GET['delete_subscription']); } if (isset($_GET['activate_subscription']) && $_GET['activate_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update(absint($_GET['activate_subscription']), array('status' => 'active')); delete_transient('rcp_subscription_levels'); } if (isset($_GET['deactivate_subscription']) && $_GET['deactivate_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update(absint($_GET['deactivate_subscription']), array('status' => 'inactive')); delete_transient('rcp_subscription_levels'); } /* discount processing */ if (!empty($_GET['delete_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->delete($_GET['delete_discount']); } if (!empty($_GET['activate_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->update($_GET['activate_discount'], array('status' => 'active')); } if (!empty($_GET['deactivate_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->update($_GET['deactivate_discount'], array('status' => 'disabled')); } if (!empty($_GET['rcp-action']) && $_GET['rcp-action'] == 'delete_payment' && wp_verify_nonce($_GET['_wpnonce'], 'rcp_delete_payment_nonce')) { if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $payments->delete(absint($_GET['payment_id'])); wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'payment_deleted', 'admin.php?page=rcp-payments'))); exit; } } }
/** * Process PayPal IPN * * @since 2.1 */ public function process_webhooks() { if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'EIPN') { return; } $user_id = 0; $posted = apply_filters('rcp_ipn_post', $_POST); // allow $_POST to be modified if (!empty($posted['recurring_payment_id'])) { $user_id = rcp_get_member_id_from_profile_id($posted['recurring_payment_id']); } if (empty($user_id) && !empty($posted['custom']) && is_numeric($posted['custom'])) { $user_id = absint($posted['custom']); } if (empty($user_id) && !empty($posted['payer_email'])) { $user = get_user_by('email', $posted['payer_email']); $user_id = $user ? $user->ID : false; } $member = new RCP_Member($user_id); if (!$member || !$member->ID > 0) { die('no member found'); } $subscription_id = $member->get_pending_subscription_id(); if (empty($subscription_id)) { $subscription_id = $member->get_subscription_id(); } if (!$subscription_id) { die('no subscription for member found'); } if (!rcp_get_subscription_details($subscription_id)) { die('no subscription level found'); } $amount = number_format((double) $posted['mc_gross'], 2); // setup the payment info in an array for storage $payment_data = array('date' => date('Y-m-d H:i:s', strtotime($posted['payment_date'])), 'subscription' => $member->get_subscription_name(), 'payment_type' => $posted['txn_type'], 'subscription_key' => $member->get_subscription_key(), 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']); do_action('rcp_valid_ipn', $payment_data, $user_id, $posted); if (isset($rcp_options['email_ipn_reports'])) { wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport()); } /* now process the kind of subscription/payment */ $rcp_payments = new RCP_Payments(); // Subscriptions switch ($posted['txn_type']) { case "recurring_payment_profile_created": if (isset($posted['initial_payment_txn_id'])) { $transaction_id = 'Completed' == $posted['initial_payment_status'] ? $posted['initial_payment_txn_id'] : ''; } else { $transaction_id = $posted['ipn_track_id']; } if (empty($transaction_id) || $rcp_payments->payment_exists($transaction_id)) { break; } // setup the payment info in an array for storage $payment_data = array('date' => date('Y-m-d H:i:s', strtotime($posted['time_created'])), 'subscription' => $member->get_subscription_name(), 'payment_type' => $posted['txn_type'], 'subscription_key' => $member->get_subscription_key(), 'amount' => number_format((double) $posted['initial_payment_amount'], 2), 'user_id' => $user_id, 'transaction_id' => sanitize_text_field($transaction_id)); $rcp_payments->insert($payment_data); $expiration = date('Y-m-d 23:59:59', strtotime($posted['next_payment_date'])); $member->renew($member->is_recurring(), 'active', $expiration); break; case "recurring_payment": // when a user makes a recurring payment update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); $member->set_payment_profile_id($posted['recurring_payment_id']); $member->renew(true); // record this payment in the database $rcp_payments->insert($payment_data); do_action('rcp_ipn_subscr_payment', $user_id); die('successful recurring_payment'); break; case "recurring_payment_profile_cancel": if (!$member->just_upgraded()) { // user is marked as cancelled but retains access until end of term $member->set_status('cancelled'); // set the use to no longer be recurring delete_user_meta($user_id, 'rcp_paypal_subscriber'); do_action('rcp_ipn_subscr_cancel', $user_id); die('successful recurring_payment_profile_cancel'); } break; case "recurring_payment_failed": case "recurring_payment_suspended_due_to_max_failed_payment": if ('cancelled' !== $member->get_status($user_id)) { $member->set_status('expired'); } do_action('rcp_ipn_subscr_failed'); die('successful recurring_payment_failed or recurring_payment_suspended_due_to_max_failed_payment'); break; case "web_accept": switch (strtolower($posted['payment_status'])) { case 'completed': if ($member->just_upgraded() && rcp_can_member_cancel($member->ID)) { $cancelled = rcp_cancel_member_payment_profile($member->ID, false); if ($cancelled) { $member->set_payment_profile_id(''); } } $payment_data = array('date' => date('Y-m-d H:i:s', strtotime($posted['payment_date'])), 'subscription' => $member->get_subscription_name(), 'payment_type' => $posted['txn_type'], 'subscription_key' => $member->get_subscription_key(), 'amount' => number_format((double) $posted['mc_gross'], 2), 'user_id' => $user_id, 'transaction_id' => sanitize_text_field($posted['txn_id'])); $rcp_payments->insert($payment_data); // set this user to active $member->renew(); break; case 'denied': case 'expired': case 'failed': case 'voided': $member->set_status('cancelled'); break; } die('successful web_accept'); break; } }