function rcp_show_user_columns($value, $column_name, $user_id)
{
    if ('rcp_status' == $column_name) {
        return rcp_get_status($user_id);
    }
    if ('rcp_subscription' == $column_name) {
        return rcp_get_subscription($user_id);
    }
    if ('rcp_links' == $column_name) {
        $page = admin_url('/admin.php?page=rcp-members');
        if (rcp_is_active($user_id)) {
            $links = '<a href="' . esc_url($page) . '&edit_member=' . esc_attr(absint($user_id)) . '">' . __('Edit Subscription', 'rcp') . '</a>';
        } else {
            $links = '<a href="' . esc_url($page) . '&edit_member=' . esc_attr(absint($user_id)) . '">' . __('Add Subscription', 'rcp') . '</a>';
        }
        return $links;
    }
    return $value;
}
Exemplo n.º 2
0
	function test_get_status() {

		$this->assertEquals( 'free', $this->member->get_status() );
		$this->assertEquals( 'free', rcp_get_status( 1 ) );

	}
function rcp_print_status( $user_id = 0, $echo = true  ) {

	if( empty( $user_id ) ) {
		$user_id = get_current_user_id();
	}

	$status = rcp_get_status( $user_id );
	switch ( $status ) :

		case 'active';
			$print_status = __( 'Active', 'rcp' );
		break;
		case 'expired';
			$print_status = __( 'Expired', 'rcp' );
		break;
		case 'pending';
			$print_status = __( 'Pending', 'rcp' );
		break;
		case 'cancelled';
			$print_status = __( 'Cancelled', 'rcp' );
		break;
		default:
			$print_status = __( 'Free', 'rcp' );
		break;

	endswitch;

	if( $echo ) {
		echo $print_status;
	}

	return $print_status;
}
/**
 * Get subscriptions to which this user can upgrade
 *
 * @since 2.5
 * @param int $user_id the ID of the user to check
 *
 * @return mixed|void
 */
function rcp_get_upgrade_paths($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    // make sure the user is active and get the subscription ID
    $user_subscription = rcp_is_recurring($user_id) && rcp_is_active($user_id) && 'cancelled' !== rcp_get_status() ? rcp_get_subscription_id($user_id) : '';
    $subscriptions = rcp_get_subscription_levels('active');
    // remove the user's current subscription from the list
    foreach ($subscriptions as $key => $subscription) {
        if ($user_subscription == $subscription->id) {
            unset($subscriptions[$key]);
        }
    }
    return apply_filters('rcp_get_upgrade_paths', array_values($subscriptions), $user_id);
}
/**
 * Triggers an email to the member when a payment is received.
 *
 * @access  public
 * @since   2.3
 * @return  void
 */
function rcp_email_payment_received($payment_id, $args)
{
    global $rcp_options;
    if (isset($rcp_options['disable_payment_received_email'])) {
        return;
    }
    $user_info = get_userdata($args['user_id']);
    if (!$user_info) {
        return;
    }
    $message = !empty($rcp_options['payment_received_email']) ? $rcp_options['payment_received_email'] : false;
    $message = rcp_filter_email_tags($message, $args['user_id'], $user_info->display_name);
    $message = apply_filters('rcp_payment_received_email', $message, $payment_id, $args);
    if (!$message) {
        return;
    }
    $site_name = stripslashes_deep(html_entity_decode(get_bloginfo('name'), ENT_COMPAT, 'UTF-8'));
    $from_name = isset($rcp_options['from_name']) ? $rcp_options['from_name'] : $site_name;
    $from_name = apply_filters('rcp_emails_from_name', $from_name, $args['user_id'], rcp_get_status($args['user_id']));
    $from_email = isset($rcp_options['from_email']) ? $rcp_options['from_email'] : get_option('admin_email');
    $from_email = apply_filters('rcp_emails_from_address', $from_email);
    $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers = apply_filters('rcp_email_headers', $headers, $args['user_id'], rcp_get_status($args['user_id']));
    wp_mail($user_info->user_email, $rcp_options['payment_received_subject'], $message, $headers);
}
Exemplo n.º 6
0
	</a>
</h2>
<table class="form-table">
	<tbody>
		<?php 
do_action('rcp_view_member_before', $user->ID);
?>
		<tr class="form-field">
			<th scope="row" valign="top">
				<?php 
_e('Status', 'rcp');
?>
			</th>
			<td>
				<?php 
echo rcp_get_status($user->ID);
?>
			</td>
		</tr>
		<tr class="form-field">
			<th scope="row" valign="top">
				<?php 
_e('Subscription Level', 'rcp');
?>
			</th>
			<td>
				<?php 
echo rcp_get_subscription($user->ID);
?>
			</td>
		</tr>
Exemplo n.º 7
0
		<tr>
			<td><?php 
rcp_print_status();
?>
</td>
			<td><?php 
echo rcp_get_subscription();
?>
</td>
			<td><?php 
echo rcp_get_expiration_date();
?>
</td>
			<td>
				<?php 
if ((rcp_is_expired($user_ID) || !rcp_is_recurring($user_ID) || rcp_get_status($user_ID) == 'cancelled') && rcp_subscription_upgrade_possible($user_ID)) {
    echo '<a href="' . esc_url(get_permalink($rcp_options['registration_page'])) . '" title="' . __('Renew your subscription', 'rcp') . '" class="rcp_sub_details_renew">' . __('Renew your subscription', 'rcp') . '</a>';
} elseif (!rcp_is_active($user_ID) && rcp_subscription_upgrade_possible($user_ID)) {
    echo '<a href="' . esc_url(get_permalink($rcp_options['registration_page'])) . '" title="' . __('Upgrade your subscription', 'rcp') . '" class="rcp_sub_details_renew">' . __('Upgrade your subscription', 'rcp') . '</a>';
} elseif (rcp_is_active($user_ID) && rcp_is_paypal_subscriber()) {
    echo '<a href="https://www.paypal.com/cgi-bin/customerprofileweb?cmd=_manage-paylist" target="_blank" title="' . __('Cancel your subscription', 'rcp') . '">' . __('Cancel your subscription', 'rcp') . '</a>';
}
do_action('rcp_subscription_details_action_links');
?>
			</td>
		</tr>
	</tbody>
</table>
<table class="rcp-table" id="rcp-payment-history">
	<thead>
		<tr>
Exemplo n.º 8
0
function rcp_check_ipn()
{
    global $rcp_options;
    if (!class_exists('IpnListener')) {
        // instantiate the IpnListener class
        include RCP_PLUGIN_DIR . 'includes/gateways/paypal/ipnlistener.php';
    }
    $listener = new IpnListener();
    if (isset($rcp_options['sandbox'])) {
        $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) {
        //exit(0);
    }
    /*
    The processIpn() method returned true if the IPN was "VERIFIED" and false if it
    was "INVALID".
    */
    if ($verified || isset($_POST['verification_override']) || (isset($rcp_options['sandbox']) || isset($rcp_options['disable_ipn_verify']))) {
        $posted = apply_filters('rcp_ipn_post', $_POST);
        // allow $_POST to be modified
        $user_id = $posted['custom'];
        $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_id = rcp_get_subscription_id($user_id);
        $subscription_price = number_format((double) rcp_get_subscription_price(rcp_get_subscription_id($user_id)), 2);
        $user_data = get_userdata($user_id);
        if (!$user_data || !$subscription_id) {
            return;
        }
        if (!rcp_get_subscription_details($subscription_id)) {
            return;
        }
        // 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' => $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);
                return;
                // this IPN request has already been processed
            }
            /* do some quick checks to make sure all necessary data validates */
            if ($amount < $subscription_price && $amount2 < $subscription_price) {
                /*
                				// the subscription price doesn't match, so lets check to see if it matches with a discount code
                				if( ! rcp_check_paypal_return_price_after_discount( $subscription_price, $amount, $amount2, $user_id ) ) {
                	$log_data = array(
                					    'post_title'    => __( 'Price Mismatch', 'rcp' ),
                					    'post_content'  =>  sprintf( __( 'The price in an IPN request did not match the subscription price. 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 );
                	//return;
                				}
                */
            }
            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);
                return;
            }
        }
        if (isset($rcp_options['email_ipn_reports'])) {
            wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport());
        }
        if (rcp_get_subscription_key($user_id) != $subscription_key) {
            // the subscription key is invalid
            $log_data = array('post_title' => __('Subscription Key Mismatch', 'rcp'), 'post_content' => sprintf(__('The subscription key in an IPN request did not match the subscription key recorded for the user. 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);
            return;
        }
        /* 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']);
                // set the user's status to active
                rcp_set_status($user_id, 'active');
                if (!isset($rcp_options['disable_new_user_notices'])) {
                    wp_new_user_notification($user_id);
                }
                // send welcome email
                rcp_email_subscription_status($user_id, 'active');
                update_user_meta($user_id, 'rcp_recurring', 'yes');
                do_action('rcp_ipn_subscr_signup', $user_id);
                break;
            case "subscr_payment":
                // when a user makes a recurring payment
                // record this payment in the database
                $rcp_payments->insert($payment_data);
                $subscription = rcp_get_subscription_details(rcp_get_subscription_id($user_id));
                // update the user's expiration to correspond with the new payment
                $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59'));
                rcp_set_expiration_date($user_id, $member_new_expiration);
                update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                // make sure the user's status is active
                rcp_set_status($user_id, 'active');
                update_user_meta($user_id, 'rcp_recurring', 'yes');
                delete_user_meta($user_id, '_rcp_expired_email_sent');
                do_action('rcp_ipn_subscr_payment', $user_id);
                break;
            case "subscr_cancel":
                // user is marked as cancelled but retains access until end of term
                rcp_set_status($user_id, 'cancelled');
                // set the use to no longer be recurring
                delete_user_meta($user_id, 'rcp_recurring');
                delete_user_meta($user_id, 'rcp_paypal_subscriber');
                // send sub cancelled email
                rcp_email_subscription_status($user_id, 'cancelled');
                do_action('rcp_ipn_subscr_cancel', $user_id);
                break;
            case "subscr_failed":
                do_action('rcp_ipn_subscr_failed');
                break;
            case "subscr_eot":
                // user's subscription has reach the end of its term
                // set the use to no longer be recurring
                delete_user_meta($user_id, 'rcp_recurring');
                if ('cancelled' !== rcp_get_status($user_id)) {
                    rcp_set_status($user_id, 'expired');
                    // send expired email
                    rcp_email_subscription_status($user_id, 'expired');
                }
                do_action('rcp_ipn_subscr_eot', $user_id);
                break;
            case "cart":
                return;
                // get out of here
            // get out of here
            case "express_checkout":
                return;
                // get out of here
            // get out of here
            case "web_accept":
                switch (strtolower($payment_status)) {
                    case 'completed':
                        if (isset($_POST['verification_override'])) {
                            // this is a method for providing a new expiration if it doesn't exist
                            $subscription = rcp_get_subscription_details_by_name($payment_data['subscription']);
                            // update the user's expiration to correspond with the new payment
                            $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59'));
                            rcp_set_expiration_date($user_id, $member_new_expiration);
                        }
                        // set this user to active
                        rcp_set_status($user_id, 'active');
                        $rcp_payments->insert($payment_data);
                        rcp_email_subscription_status($user_id, 'active');
                        if (!isset($rcp_options['disable_new_user_notices'])) {
                            // send welcome email here
                            wp_new_user_notification($user_id);
                        }
                        delete_user_meta($user_id, '_rcp_expired_email_sent');
                        break;
                    case 'denied':
                    case 'expired':
                    case 'failed':
                    case 'voided':
                        rcp_set_status($user_id, 'cancelled');
                        // send cancelled email here
                        break;
                }
                break;
            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());
        }
    }
}
Exemplo n.º 9
0
do_action('rcp_edit_member_before', $member->ID);
?>
			<tr valign="top">
				<th scope="row" valign="top">
					<label for="rcp-status"><?php 
_e('Status', 'rcp');
?>
</label>
				</th>
				<td>
					<select name="status" id="rcp-status">
						<?php 
$statuses = array('active', 'expired', 'cancelled', 'pending', 'free');
$current_status = rcp_get_status($member->ID);
foreach ($statuses as $status) {
    echo '<option value="' . esc_attr($status) . '"' . selected($status, rcp_get_status($member->ID), false) . '>' . ucwords($status) . '</option>';
}
?>
					</select>
					<p class="description"><?php 
_e('The status of this user\'s subscription', 'rcp');
?>
</p>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row" valign="top">
					<label for="rcp-level"><?php 
_e('Subscription Level', 'rcp');
?>
</label>