/**
  * Process registration
  *
  * @since 2.1
  */
 public function process_signup()
 {
     \Stripe\Stripe::setApiKey($this->secret_key);
     $paid = false;
     $member = new RCP_Member($this->user_id);
     $customer_exists = false;
     if (empty($_POST['stripeToken'])) {
         wp_die(__('Missing Stripe token, please try again or contact support if the issue persists.', 'rcp'), __('Error', 'rcp'), array('response' => 400));
     }
     $customer_id = $member->get_payment_profile_id();
     if ($customer_id) {
         $customer_exists = true;
         try {
             // Update the customer to ensure their card data is up to date
             $customer = \Stripe\Customer::retrieve($customer_id);
             if (isset($customer->deleted) && $customer->deleted) {
                 // This customer was deleted
                 $customer_exists = false;
             }
             // No customer found
         } catch (Exception $e) {
             $customer_exists = false;
         }
     }
     if (empty($customer_exists)) {
         try {
             $customer_args = array('card' => $_POST['stripeToken'], 'email' => $this->email);
             $customer = \Stripe\Customer::create(apply_filters('rcp_stripe_customer_create_args', $customer_args, $this));
             // A temporary invoice is created to force the customer's currency to be set to the store currency. See https://github.com/restrictcontentpro/restrict-content-pro/issues/549
             if (!empty($this->signup_fee)) {
                 \Stripe\InvoiceItem::create(array('customer' => $customer->id, 'amount' => 0, 'currency' => rcp_get_currency(), 'description' => 'Setting Customer Currency'));
                 $temp_invoice = \Stripe\Invoice::create(array('customer' => $customer->id));
             }
             $member->set_payment_profile_id($customer->id);
         } catch (Exception $e) {
             $this->handle_processing_error($e);
         }
     } else {
         $customer->source = $_POST['stripeToken'];
     }
     $customer->description = 'User ID: ' . $this->user_id . ' - User Email: ' . $this->email . ' Subscription: ' . $this->subscription_name;
     $customer->metadata = array('user_id' => $this->user_id, 'email' => $this->email, 'subscription' => $this->subscription_name);
     $customer->save();
     if ($this->auto_renew) {
         // process a subscription sign up
         if (!($plan_id = $this->plan_exists($this->subscription_name))) {
             // create the plan if it doesn't exist
             $plan_id = $this->create_plan($this->subscription_name);
         }
         try {
             // Add fees before the plan is updated and charged
             if (!empty($this->signup_fee)) {
                 $customer->account_balance = $customer->account_balance + $this->signup_fee * rcp_stripe_get_currency_multiplier();
                 // Add additional amount to initial payment (in cents)
                 $customer->save();
                 if (isset($temp_invoice)) {
                     $invoice = \Stripe\Invoice::retrieve($temp_invoice->id);
                     $invoice->closed = true;
                     $invoice->save();
                     unset($temp_invoice, $invoice);
                 }
             }
             // clean up any past due or unpaid subscriptions before upgrading/downgrading
             foreach ($customer->subscriptions->all()->data as $subscription) {
                 // check if we are renewing an existing subscription. This should not ever be 'active', if it is Stripe
                 // will do nothing. If it is 'past_due' the most recent invoice will be paid and the subscription will become active
                 if ($subscription->plan->id == $plan_id && in_array($subscription->status, array('active', 'past_due'))) {
                     continue;
                 }
                 // remove any subscriptions that are past_due or inactive
                 if (in_array($subscription->status, array('past_due', 'unpaid'))) {
                     $subscription->cancel();
                 }
             }
             // If the customer has an existing subscription, we need to cancel it
             if ($member->just_upgraded() && rcp_can_member_cancel($member->ID)) {
                 $cancelled = rcp_cancel_member_payment_profile($member->ID, false);
             }
             $sub_args = array('plan' => $plan_id, 'prorate' => false);
             if (!empty($this->discount_code)) {
                 $sub_args['coupon'] = $this->discount_code;
             }
             // Set the customer's subscription in Stripe
             $subscription = $customer->subscriptions->create(array($sub_args));
             $member->set_merchant_subscription_id($subscription->id);
             // subscription payments are recorded via webhook
             $paid = true;
         } catch (\Stripe\Error\Card $e) {
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\InvalidRequest $e) {
             // Invalid parameters were supplied to Stripe's API
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\Authentication $e) {
             // Authentication with Stripe's API failed
             // (maybe you changed API keys recently)
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\ApiConnection $e) {
             // Network communication with Stripe failed
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\Base $e) {
             // Display a very generic error to the user
             $this->handle_processing_error($e);
         } catch (Exception $e) {
             // Something else happened, completely unrelated to Stripe
             $error = '<p>' . __('An unidentified error occurred.', 'rcp') . '</p>';
             $error .= print_r($e, true);
             wp_die($error, __('Error', 'rcp'), array('response' => 401));
         }
     } else {
         // process a one time payment signup
         try {
             $charge = \Stripe\Charge::create(apply_filters('rcp_stripe_charge_create_args', array('amount' => round(($this->amount + $this->signup_fee) * rcp_stripe_get_currency_multiplier(), 0), 'currency' => strtolower($this->currency), 'customer' => $customer->id, 'description' => 'User ID: ' . $this->user_id . ' - User Email: ' . $this->email . ' Subscription: ' . $this->subscription_name, 'receipt_email' => $this->email, 'metadata' => array('email' => $this->email, 'user_id' => $this->user_id, 'level_id' => $this->subscription_id, 'level' => $this->subscription_name, 'key' => $this->subscription_key)), $this));
             $payment_data = array('date' => date('Y-m-d H:i:s', current_time('timestamp')), 'subscription' => $this->subscription_name, 'payment_type' => 'Credit Card One Time', 'subscription_key' => $this->subscription_key, 'amount' => $this->amount + $this->signup_fee, 'user_id' => $this->user_id, 'transaction_id' => $charge->id);
             $rcp_payments = new RCP_Payments();
             $rcp_payments->insert($payment_data);
             $paid = true;
         } catch (\Stripe\Error\Card $e) {
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\InvalidRequest $e) {
             // Invalid parameters were supplied to Stripe's API
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\Authentication $e) {
             // Authentication with Stripe's API failed
             // (maybe you changed API keys recently)
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\ApiConnection $e) {
             // Network communication with Stripe failed
             $this->handle_processing_error($e);
         } catch (\Stripe\Error\Base $e) {
             // Display a very generic error to the user
             $this->handle_processing_error($e);
         } catch (Exception $e) {
             // Something else happened, completely unrelated to Stripe
             $error = '<p>' . __('An unidentified error occurred.', 'rcp') . '</p>';
             $error .= print_r($e, true);
             wp_die($error, __('Error', 'rcp'), array('response' => 401));
         }
     }
     if ($paid) {
         // If this is a one-time signup and the customer has an existing subscription, we need to cancel it
         if (!$this->auto_renew && $member->just_upgraded() && rcp_can_member_cancel($member->ID)) {
             $cancelled = rcp_cancel_member_payment_profile($member->ID, false);
         }
         // set this user to active
         $member->set_status('active');
         $member->set_recurring($this->auto_renew);
         if (!is_user_logged_in()) {
             // log the new user in
             rcp_login_user_in($this->user_id, $this->user_name, $_POST['rcp_user_pass']);
         }
         if (!$this->auto_renew) {
             $member->set_expiration_date($member->calculate_expiration());
         }
         do_action('rcp_stripe_signup', $this->user_id, $this);
     } else {
         wp_die(__('An error occurred, please contact the site administrator: ', 'rcp') . get_bloginfo('admin_email'), __('Error', 'rcp'), array('response' => 401));
     }
     // redirect to the success page, or error page if something went wrong
     wp_redirect($this->return_url);
     exit;
 }
/**
 * Displays stripe checkout form
 *
 * @since 2.5
 * @access public
 *
 * @param $atts
 * @return mixed|void
 */
function rcp_register_form_stripe_checkout($atts)
{
    global $rcp_options;
    if (empty($atts['id'])) {
        return '';
    }
    // button is an alias for data-label
    if (isset($atts['button'])) {
        $atts['data-label'] = $atts['button'];
    }
    $key = rcp_is_sandbox() ? $rcp_options['stripe_test_publishable'] : $rcp_options['stripe_live_publishable'];
    $member = new RCP_Member(wp_get_current_user()->ID);
    $subscription = rcp_get_subscription_details($atts['id']);
    $amount = $subscription->price + $subscription->fee;
    if ($member->ID > 0) {
        $amount -= $member->get_prorate_credit_amount();
    }
    if ($amount < 0) {
        $amount = 0;
    }
    $data = wp_parse_args($atts, array('id' => 0, 'data-key' => $key, 'data-name' => get_option('blogname'), 'data-description' => $subscription->description, 'data-label' => sprintf(__('Join %s', 'rcp'), $subscription->name), 'data-panel-label' => __('Register - {{amount}}', 'rcp'), 'data-amount' => $amount * rcp_stripe_get_currency_multiplier(), 'data-locale' => 'auto', 'data-allow-remember-me' => true, 'data-currency' => rcp_get_currency(), 'data-alipay' => isset($rcp_options['stripe_alipay']) && '1' === $rcp_options['stripe_alipay'] && 'USD' === rcp_get_currency() ? 'true' : 'false'));
    if (empty($data['data-email']) && !empty($member->user_email)) {
        $data['data-email'] = $member->user_email;
    }
    if (empty($data['data-image']) && ($image = get_site_icon_url())) {
        $data['data-image'] = $image;
    }
    $data = apply_filters('rcp_stripe_checkout_data', $data);
    if ('USD' !== rcp_get_currency()) {
        unset($data['data-alipay']);
    }
    ob_start();
    if ($member->ID > 0 && $member->get_subscription_id() == $subscription->id && $member->is_active()) {
        ?>

		<div class="rcp-stripe-checkout-notice"><?php 
        _e('You are already subscribed.', 'rcp');
        ?>
</div>

	<?php 
    } else {
        ?>
		<form action="" method="post">
			<?php 
        do_action('register_form_stripe_fields', $data);
        ?>
			<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" <?php 
        foreach ($data as $label => $value) {
            printf(' %s="%s" ', esc_attr($label), esc_attr($value));
        }
        ?>
 ></script>
			<input type="hidden" name="rcp_level" value="<?php 
        echo $subscription->id;
        ?>
" />
			<input type="hidden" name="rcp_register_nonce" value="<?php 
        echo wp_create_nonce('rcp-register-nonce');
        ?>
"/>
			<input type="hidden" name="rcp_gateway" value="stripe_checkout"/>
			<input type="hidden" name="rcp_stripe_checkout" value="1"/>
		</form>
	<?php 
    }
    return apply_filters('register_form_stripe', ob_get_clean(), $atts);
}
 /**
  * Create plan in Stripe
  *
  * @since 2.1
  * @return bool | string - plan_id if successful, false if not
  */
 private function create_plan($plan_name = '')
 {
     global $rcp_options;
     // get all subscription level info for this plan
     $plan = rcp_get_subscription_details_by_name($plan_name);
     $price = round($plan->price * rcp_stripe_get_currency_multiplier(), 0);
     $interval = $plan->duration_unit;
     $interval_count = $plan->duration;
     $name = $plan->name;
     $plan_id = sprintf('%s-%s-%s', strtolower(str_replace(' ', '', $plan_name)), $plan->price, $plan->duration . $plan->duration_unit);
     $currency = strtolower(rcp_get_currency());
     \Stripe\Stripe::setApiKey($this->secret_key);
     try {
         $plan = \Stripe\Plan::create(array("amount" => $price, "interval" => $interval, "interval_count" => $interval_count, "name" => $name, "currency" => $currency, "id" => $plan_id));
         // plann successfully created
         return $plan->id;
     } catch (Exception $e) {
         $this->handle_processing_error($e);
     }
 }
    /**
     * Print fields for this gateway
     *
     * @return string
     */
    public function fields()
    {
        global $rcp_options;
        if (is_user_logged_in()) {
            $email = wp_get_current_user()->user_email;
        } else {
            $email = false;
        }
        $data = apply_filters('rcp_stripe_checkout_form_data', array('key' => $this->publishable_key, 'locale' => 'auto', 'allowRememberMe' => true, 'email' => $email, 'currency' => rcp_get_currency(), 'alipay' => isset($rcp_options['stripe_alipay']) && '1' === $rcp_options['stripe_alipay'] && 'USD' === rcp_get_currency() ? true : false));
        $subscriptions = array();
        foreach (rcp_get_subscription_levels('active') as $subscription) {
            $subscriptions[$subscription->id] = array('description' => $subscription->description, 'name' => $subscription->name, 'panelLabel' => __('Register', 'rcp'));
        }
        $subscriptions = apply_filters('rcp_stripe_checkout_subscription_data', $subscriptions);
        ob_start();
        ?>

		<script>
			var rcp_script_options;
			var rcpSubscriptions = <?php 
        echo json_encode($subscriptions);
        ?>
;
			var checkoutArgs     = <?php 
        echo json_encode($data);
        ?>
;

			// define the token function
			checkoutArgs.token = function(token){ jQuery('body').trigger('rcp_stripe_checkout_submit', token); };

			if( ! checkoutArgs.email ) {
				checkoutArgs.email = jQuery('#rcp_registration_form #rcp_user_email' ).val();
			}

			jQuery('#rcp_registration_form #rcp_submit').val( rcp_script_options.pay_now );

			jQuery('body').on('rcp_level_change', function(event, target) {
				jQuery('#rcp_registration_form #rcp_submit').val(
					jQuery(target).attr('rel') > 0 ? rcp_script_options.pay_now : rcp_script_options.register
				);
			});

			jQuery('body').on('rcp_stripe_checkout_submit', function(e, token){
				jQuery('#rcp_registration_form').append('<input type="hidden" name="stripeToken" value="' + token.id + '" />').submit();
			});

			jQuery('#rcp_registration_form #rcp_user_email' ).focusout(function() {
				checkoutArgs.email = jQuery('#rcp_registration_form #rcp_user_email' ).val();
			});

			var rcpStripeCheckout = StripeCheckout.configure(checkoutArgs);

			jQuery('#rcp_registration_form #rcp_submit').on('click', function(e) {

				if ( jQuery('#rcp_gateway option:selected').val() !== 'stripe_checkout' && jQuery('input[name=rcp_gateway]').val() !== 'stripe_checkout' && jQuery('input[name=rcp_gateway]:checked').val() !== 'stripe_checkout' ) {
					return;
				}

				var $form = jQuery(this).closest('form');
				var $level = $form.find('input[name=rcp_level]:checked');

				var $price = $level.parent().find('.rcp_price').attr('rel') * <?php 
        echo rcp_stripe_get_currency_multiplier();
        ?>
;
				if ( ! $level.length ) {
					$level = $form.find('input[name=rcp_level]');
					$price = $form.find('.rcp_level').attr('rel') * <?php 
        echo rcp_stripe_get_currency_multiplier();
        ?>
;
				}

				if( jQuery('.rcp_gateway_fields').hasClass('rcp_discounted_100') ) {
					return true;
				}

				// Open Checkout with further options
				if ( $price > 0 ) {
					rcpStripeCheckout.open(rcpSubscriptions[$level.val()]);
					e.preventDefault();

					return false;
				}
			});

			// Close Checkout on page navigation
			jQuery(window).on('popstate', function() {
				rcpStripeCheckout.close();
			});
		</script>

		<?php 
        return ob_get_clean();
    }
function rcp_member_levels_page()
{
    global $rcp_options, $rcp_db_name, $wpdb;
    $page = admin_url('/admin.php?page=rcp-member-levels');
    ?>
	<div class="wrap">
		<?php 
    if (isset($_GET['edit_subscription'])) {
        include 'edit-subscription.php';
    } else {
        ?>
			<h2><?php 
        _e('Subscription Levels', 'rcp');
        ?>
</h2>
			<table class="wp-list-table widefat fixed posts rcp-subscriptions">
				<thead>
					<tr>
						<th scope="col" class="rcp-sub-name-col column-primary"><?php 
        _e('Name', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-desc-col"><?php 
        _e('Description', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-level-col"><?php 
        _e('Access Level', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-duration-col"><?php 
        _e('Duration', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-price-col"><?php 
        _e('Price', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-subs-col"><?php 
        _e('Subscribers', 'rcp');
        ?>
</th>
						<?php 
        do_action('rcp_levels_page_table_header');
        ?>
						<th scope="col" class="rcp-sub-order-col"><?php 
        _e('Order', 'rcp');
        ?>
</th>
					</tr>
				</thead>
				<tbody id="the-list">
				<?php 
        $levels = rcp_get_subscription_levels('all');
        ?>
				<?php 
        if ($levels) {
            $i = 1;
            foreach ($levels as $key => $level) {
                ?>
						<tr id="recordsArray_<?php 
                echo $level->id;
                ?>
" class="rcp-subscription rcp_row <?php 
                if (rcp_is_odd($i)) {
                    echo 'alternate';
                }
                ?>
">
							<td class="rcp-sub-name-col column-primary has-row-actions" data-colname="<?php 
                _e('Name', 'rcp');
                ?>
">
								<strong><a href="<?php 
                echo esc_url(add_query_arg('edit_subscription', $level->id, $page));
                ?>
"><?php 
                echo stripslashes($level->name);
                ?>
</a></strong>
								<?php 
                if (current_user_can('rcp_manage_levels')) {
                    ?>
									<div class="row-actions">
										<span class="rcp-sub-id-col" data-colname="<?php 
                    _e('ID:', 'rcp');
                    ?>
"> <?php 
                    echo __('ID:', 'rcp') . ' ' . $level->id;
                    ?>
 | </span>
										<a href="<?php 
                    echo esc_url(add_query_arg('edit_subscription', $level->id, $page));
                    ?>
"><?php 
                    _e('Edit', 'rcp');
                    ?>
</a> |
										<?php 
                    if ($level->status != 'inactive') {
                        ?>
											<a href="<?php 
                        echo esc_url(add_query_arg('deactivate_subscription', $level->id, $page));
                        ?>
"><?php 
                        _e('Deactivate', 'rcp');
                        ?>
</a> |
										<?php 
                    } else {
                        ?>
											<a href="<?php 
                        echo esc_url(add_query_arg('activate_subscription', $level->id, $page));
                        ?>
"><?php 
                        _e('Activate', 'rcp');
                        ?>
</a> |
										<?php 
                    }
                    ?>
										<a href="<?php 
                    echo esc_url(add_query_arg('delete_subscription', $level->id, $page));
                    ?>
" class="rcp_delete_subscription"><?php 
                    _e('Delete', 'rcp');
                    ?>
</a>
									</div>
								<?php 
                }
                ?>
								<button type="button" class="toggle-row"><span class="screen-reader-text"><?php 
                _e('Show more details', 'rcp');
                ?>
</span></button>
							</td>
							<td class="rcp-sub-desc-col" data-colname="<?php 
                _e('Description', 'rcp');
                ?>
"><?php 
                echo stripslashes($level->description);
                ?>
</td>
							<td class="rcp-sub-level-col" data-colname="<?php 
                _e('Access Level', 'rcp');
                ?>
"><?php 
                echo $level->level != '' ? $level->level : __('none', 'rcp');
                ?>
</td>
							<td class="rcp-sub-duration-col" data-colname="<?php 
                _e('Duration', 'rcp');
                ?>
">
								<?php 
                if ($level->duration > 0) {
                    echo $level->duration . ' ' . rcp_filter_duration_unit($level->duration_unit, $level->duration);
                } else {
                    echo __('unlimited', 'rcp');
                }
                ?>
							</td>
							<td class="rcp-sub-price-col" data-colname="<?php 
                _e('Price', 'rcp');
                ?>
">
								<?php 
                $price = rcp_get_subscription_price($level->id);
                if (!$price) {
                    echo __('Free', 'rcp');
                } else {
                    echo rcp_currency_filter($price);
                }
                ?>
							</td>
							<td class="rcp-sub-subs-col" data-colname="<?php 
                _e('Subscribers', 'rcp');
                ?>
">
								<?php 
                if ($price || $level->duration > 0) {
                    echo rcp_get_subscription_member_count($level->id, 'active');
                } else {
                    echo rcp_get_subscription_member_count($level->id, 'free');
                }
                ?>
							</td>
							<?php 
                do_action('rcp_levels_page_table_column', $level->id);
                ?>
							<td class="rcp-sub-order-col"><a href="#" class="dragHandle"></a></td>
						</tr>
					<?php 
                $i++;
            }
        } else {
            ?>
					<tr><td colspan="9"><?php 
            _e('No subscription levels added yet.', 'rcp');
            ?>
</td></tr>
				<?php 
        }
        ?>
				</tbody>
				<tfoot>
					<tr>
						<th scope="col" class="rcp-sub-name-col column-primary"><?php 
        _e('Name', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-desc-col"><?php 
        _e('Description', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-level-col"><?php 
        _e('Access Level', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-duration-col"><?php 
        _e('Duration', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-price-col"><?php 
        _e('Price', 'rcp');
        ?>
</th>
						<th scope="col" class="rcp-sub-subs-col"><?php 
        _e('Subscribers', 'rcp');
        ?>
</th>
						<?php 
        do_action('rcp_levels_page_table_footer');
        ?>
						<th scope="col" class="rcp-sub-order-col"><?php 
        _e('Order', 'rcp');
        ?>
</th>
					</tr>
				</tfoot>
			</table>
			<?php 
        do_action('rcp_levels_below_table');
        ?>
			<?php 
        if (current_user_can('rcp_manage_levels')) {
            ?>
				<h3><?php 
            _e('Add New Level', 'rcp');
            ?>
</h3>
				<form id="rcp-member-levels" action="" method="post">
					<table class="form-table">
						<tbody>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-name"><?php 
            _e('Name', 'rcp');
            ?>
</label>
								</th>
								<td>
									<input type="text" id="rcp-name" name="name" value="" style="width: 300px;"/>
									<p class="description"><?php 
            _e('The name of the membership level.', 'rcp');
            ?>
</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-description"><?php 
            _e('Description', 'rcp');
            ?>
</label>
								</th>
								<td>
									<textarea id="rcp-description" name="description" style="width: 300px;"></textarea>
									<p class="description"><?php 
            _e('Membership level description. This is shown on the registration form.', 'rcp');
            ?>
</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-level"><?php 
            _e('Access Level', 'rcp');
            ?>
</label>
								</th>
								<td>
									<select id="rcp-level" name="level">
										<?php 
            $access_levels = rcp_get_access_levels();
            foreach ($access_levels as $access) {
                echo '<option value="' . $access . '">' . $access . '</option>';
            }
            ?>
									</select>
									<p class="description">
										<?php 
            _e('Level of access this subscription gives. Leave None for default or you are unsure what this is.', 'rcp');
            ?>
										<span alt="f223" class="rcp-help-tip dashicons dashicons-editor-help" title="<?php 
            _e('<strong>Access Level</strong>: refers to a tiered system where a member\'s ability to view content is determined by the access level assigned to their account. A member with an access level of 5 can view content assigned to access levels of 5 and lower, whereas a member with an access level of 4 can only view content assigned to levels of 4 and lower.', 'rcp');
            ?>
"></span>
									</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-duration"><?php 
            _e('Duration', 'rcp');
            ?>
</label>
								</th>
								<td>
									<input type="text" id="rcp-duration" style="width: 40px;" name="duration" value="0"/>
									<select name="duration_unit" id="rcp-duration-unit">
										<option value="day"><?php 
            _e('Day(s)', 'rcp');
            ?>
</option>
										<option value="month"><?php 
            _e('Month(s)', 'rcp');
            ?>
</option>
										<option value="year"><?php 
            _e('Year(s)', 'rcp');
            ?>
</option>
									</select>
									<p class="description">
										<?php 
            _e('Length of time for this membership level. Enter 0 for unlimited.', 'rcp');
            ?>
										<span alt="f223" class="rcp-help-tip dashicons dashicons-editor-help" title="<?php 
            _e('<strong>Example</strong>: setting this to 1 month would make memberships last 1 month, after which they will renew automatically or be marked as expired.', 'rcp');
            ?>
"></span>
									</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-price"><?php 
            _e('Price', 'rcp');
            ?>
</label>
								</th>
								<td>
									<input type="text" id="rcp-price" name="price" value="0" pattern="^(\d+\.\d{2})|(\d+)$" style="width: 40px;"/>
									<select name="rcp-price-select" id="rcp-price-select">
										<option value="normal"><?php 
            echo rcp_get_currency();
            ?>
</option>
										<option value="free"><?php 
            _e('Free', 'rcp');
            ?>
</option>
									</select>
									<p class="description">
										<?php 
            _e('The price of this membership level. Enter 0 for free.', 'rcp');
            ?>
										<span alt="f223" class="rcp-help-tip dashicons dashicons-editor-help" title="<?php 
            _e('This price refers to the amount paid per duration period. For example, if duration period is set to 1 month, this would be the amount charged each month.', 'rcp');
            ?>
"></span>
									</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-fee"><?php 
            _e('Signup Fee', 'rcp');
            ?>
</label>
								</th>
								<td>
									<input type="text" id="rcp-fee" name="fee" value="0" style="width: 40px;"/>
									<p class="description"><?php 
            _e('Optional signup fee to charge subscribers for the first billing cycle. Enter a negative number to give a discount on the first payment.', 'rcp');
            ?>
</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-status"><?php 
            _e('Status', 'rcp');
            ?>
</label>
								</th>
								<td>
									<select name="status" id="rcp-status">
										<option value="active"><?php 
            _e('Active', 'rcp');
            ?>
</option>
										<option value="inactive"><?php 
            _e('Inactive', 'rcp');
            ?>
</option>
									</select>
									<p class="description"><?php 
            _e('Members may only sign up for active subscription levels.', 'rcp');
            ?>
</p>
								</td>
							</tr>
							<tr class="form-field">
								<th scope="row" valign="top">
									<label for="rcp-role"><?php 
            _e('User Role', 'rcp');
            ?>
</label>
								</th>
								<td>
									<select name="role" id="rcp-role">
										<?php 
            wp_dropdown_roles('subscriber');
            ?>
									</select>
									<p class="description"><?php 
            _e('The user role given to the member after signing up.', 'rcp');
            ?>
</p>
								</td>
							</tr>
							<?php 
            do_action('rcp_add_subscription_form');
            ?>
						</tbody>
					</table>
					<p class="submit">
						<input type="hidden" name="rcp-action" value="add-level"/>
						<input type="submit" value="<?php 
            _e('Add Membership Level', 'rcp');
            ?>
" class="button-primary"/>
					</p>
					<?php 
            wp_nonce_field('rcp_add_level_nonce', 'rcp_add_level_nonce');
            ?>
				</form>
			<?php 
        }
        ?>
		<?php 
    }
    ?>
	</div><!--end wrap-->

	<?php 
}
/**
 * Register a new user
 *
 * @access      public
 * @since       1.0
 */
function rcp_process_registration()
{
    // check nonce
    if (!(isset($_POST["rcp_register_nonce"]) && wp_verify_nonce($_POST['rcp_register_nonce'], 'rcp-register-nonce'))) {
        return;
    }
    global $rcp_options, $rcp_levels_db;
    $subscription_id = rcp_get_registration()->get_subscription();
    $discount = isset($_POST['rcp_discount']) ? sanitize_text_field($_POST['rcp_discount']) : '';
    $price = number_format((double) $rcp_levels_db->get_level_field($subscription_id, 'price'), 2);
    $price = str_replace(',', '', $price);
    $subscription = $rcp_levels_db->get_level($subscription_id);
    $auto_renew = rcp_registration_is_recurring();
    // if both today's total and the recurring total are 0, the there is a full discount
    // if this is not a recurring subscription only check today's total
    $full_discount = $auto_renew ? rcp_get_registration()->get_total() == 0 && rcp_get_registration()->get_recurring_total() == 0 : rcp_get_registration()->get_total() == 0;
    // get the selected payment method/gateway
    if (!isset($_POST['rcp_gateway'])) {
        $gateway = 'paypal';
    } else {
        $gateway = sanitize_text_field($_POST['rcp_gateway']);
    }
    /***********************
     * validate the form
     ***********************/
    do_action('rcp_before_form_errors', $_POST);
    $is_ajax = isset($_POST['rcp_ajax']);
    $user_data = rcp_validate_user_data();
    if (!rcp_is_registration()) {
        // no subscription level was chosen
        rcp_errors()->add('no_level', __('Please choose a subscription level', 'rcp'), 'register');
    }
    if ($subscription_id && $price == 0 && $subscription->duration > 0 && rcp_has_used_trial($user_data['id'])) {
        // this ensures that users only sign up for a free trial once
        rcp_errors()->add('free_trial_used', __('You may only sign up for a free trial once', 'rcp'), 'register');
    }
    if (!empty($discount)) {
        // make sure we have a valid discount
        if (rcp_validate_discount($discount, $subscription_id)) {
            // check if the user has already used this discount
            if ($price > 0 && !$user_data['need_new'] && rcp_user_has_used_discount($user_data['id'], $discount) && apply_filters('rcp_discounts_once_per_user', false, $discount, $subscription_id)) {
                rcp_errors()->add('discount_already_used', __('You can only use the discount code once', 'rcp'), 'register');
            }
        } else {
            // the entered discount code is incorrect
            rcp_errors()->add('invalid_discount', __('The discount you entered is invalid', 'rcp'), 'register');
        }
    }
    // Validate extra fields in gateways with the 2.1+ gateway API
    if (!has_action('rcp_gateway_' . $gateway) && $price > 0 && !$full_discount) {
        $gateways = new RCP_Payment_Gateways();
        $gateway_var = $gateways->get_gateway($gateway);
        $gateway_obj = new $gateway_var['class']();
        $gateway_obj->validate_fields();
    }
    do_action('rcp_form_errors', $_POST);
    // retrieve all error messages, if any
    $errors = rcp_errors()->get_error_messages();
    if (!empty($errors) && $is_ajax) {
        wp_send_json_error(array('success' => false, 'errors' => rcp_get_error_messages_html('register'), 'nonce' => wp_create_nonce('rcp-register-nonce')));
    } elseif ($is_ajax) {
        wp_send_json_success(array('success' => true));
    }
    // only create the user if there are no errors
    if (!empty($errors)) {
        return;
    }
    if ($user_data['need_new']) {
        $user_data['id'] = wp_insert_user(array('user_login' => $user_data['login'], 'user_pass' => $user_data['password'], 'user_email' => $user_data['email'], 'first_name' => $user_data['first_name'], 'last_name' => $user_data['last_name'], 'display_name' => $user_data['first_name'] . ' ' . $user_data['last_name'], 'user_registered' => date('Y-m-d H:i:s')));
    }
    if (empty($user_data['id'])) {
        return;
    }
    // Setup the member object
    $member = new RCP_Member($user_data['id']);
    update_user_meta($user_data['id'], '_rcp_new_subscription', '1');
    $subscription_key = rcp_generate_subscription_key();
    $old_subscription_id = $member->get_subscription_id();
    if ($old_subscription_id) {
        update_user_meta($user_data['id'], '_rcp_old_subscription_id', $old_subscription_id);
    }
    if (!$member->is_active()) {
        update_user_meta($user_data['id'], 'rcp_subscription_level', $subscription_id);
        update_user_meta($user_data['id'], 'rcp_subscription_key', $subscription_key);
        // Ensure no pending level details are set
        delete_user_meta($user_data['id'], 'rcp_pending_subscription_level');
        delete_user_meta($user_data['id'], 'rcp_pending_subscription_key');
        $member->set_status('pending');
    } else {
        // If the member is already active, we need to set these as pending changes
        update_user_meta($user_data['id'], 'rcp_pending_subscription_level', $subscription_id);
        update_user_meta($user_data['id'], 'rcp_pending_subscription_key', $subscription_key);
        // Flag the member as having just upgraded
        update_user_meta($user_data['id'], '_rcp_just_upgraded', current_time('timestamp'));
    }
    $member->set_joined_date('', $subscription_id);
    // Calculate the expiration date for the member
    $member_expires = $member->calculate_expiration($auto_renew);
    update_user_meta($user_data['id'], 'rcp_pending_expiration_date', $member_expires);
    // remove the user's old role, if this is a new user, we need to replace the default role
    $old_role = get_option('default_role', 'subscriber');
    if ($old_subscription_id) {
        $old_level = $rcp_levels_db->get_level($old_subscription_id);
        $old_role = !empty($old_level->role) ? $old_level->role : $old_role;
    }
    $member->remove_role($old_role);
    // Set the user's role
    $role = !empty($subscription->role) ? $subscription->role : 'subscriber';
    $user = new WP_User($user_data['id']);
    $user->add_role(apply_filters('rcp_default_user_level', $role, $subscription_id));
    do_action('rcp_form_processing', $_POST, $user_data['id'], $price);
    // process a paid subscription
    if ($price > '0') {
        if (!empty($discount)) {
            $discounts = new RCP_Discounts();
            $discount_obj = $discounts->get_by('code', $discount);
            // record the usage of this discount code
            $discounts->add_to_user($user_data['id'], $discount);
            // increase the usage count for the code
            $discounts->increase_uses($discount_obj->id);
            // if the discount is 100%, log the user in and redirect to success page
            if ($full_discount) {
                $member->set_expiration_date($member_expires);
                $member->set_status('active');
                rcp_login_user_in($user_data['id'], $user_data['login']);
                wp_redirect(rcp_get_return_url($user_data['id']));
                exit;
            }
        }
        // Remove trialing status, if it exists
        delete_user_meta($user_data['id'], 'rcp_is_trialing');
        // log the new user in
        rcp_login_user_in($user_data['id'], $user_data['login']);
        $redirect = rcp_get_return_url($user_data['id']);
        $subscription_data = array('price' => rcp_get_registration()->get_total(true, false), 'discount' => rcp_get_registration()->get_total_discounts(), 'discount_code' => $discount, 'fee' => rcp_get_registration()->get_total_fees(), 'length' => $subscription->duration, 'length_unit' => strtolower($subscription->duration_unit), 'subscription_id' => $subscription->id, 'subscription_name' => $subscription->name, 'key' => $subscription_key, 'user_id' => $user_data['id'], 'user_name' => $user_data['login'], 'user_email' => $user_data['email'], 'currency' => rcp_get_currency(), 'auto_renew' => $auto_renew, 'return_url' => $redirect, 'new_user' => $user_data['need_new'], 'post_data' => $_POST);
        // if giving the user a credit, make sure the credit does not exceed the first payment
        if ($subscription_data['fee'] < 0 && abs($subscription_data['fee']) > $subscription_data['price']) {
            $subscription_data['fee'] = -1 * $subscription_data['price'];
        }
        update_user_meta($user_data['id'], 'rcp_pending_subscription_amount', $subscription_data['price'] + $subscription_data['fee']);
        // send all of the subscription data off for processing by the gateway
        rcp_send_to_gateway($gateway, apply_filters('rcp_subscription_data', $subscription_data));
        // process a free or trial subscription
    } else {
        // This is a free user registration or trial
        $member->set_expiration_date($member_expires);
        // if the subscription is a free trial, we need to record it in the user meta
        if ($member_expires != 'none') {
            // activate the user's trial subscription
            $member->set_status('active');
            // this is so that users can only sign up for one trial
            update_user_meta($user_data['id'], 'rcp_has_trialed', 'yes');
            update_user_meta($user_data['id'], 'rcp_is_trialing', 'yes');
            rcp_email_subscription_status($user_data['id'], 'trial');
        } else {
            update_user_meta($user_data['id'], 'rcp_subscription_level', $subscription_id);
            update_user_meta($user_data['id'], 'rcp_subscription_key', $subscription_key);
            // Ensure no pending level details are set
            delete_user_meta($user_data['id'], 'rcp_pending_subscription_level');
            delete_user_meta($user_data['id'], 'rcp_pending_subscription_key');
            // set the user's status to free
            $member->set_status('free');
            rcp_email_subscription_status($user_data['id'], 'free');
        }
        if ($user_data['need_new']) {
            if (!isset($rcp_options['disable_new_user_notices'])) {
                // send an email to the admin alerting them of the registration
                wp_new_user_notification($user_data['id']);
            }
            // log the new user in
            rcp_login_user_in($user_data['id'], $user_data['login']);
        }
        // send the newly created user to the redirect page after logging them in
        wp_redirect(rcp_get_return_url($user_data['id']));
        exit;
    }
    // end price check
}
/**
 * Sets the number of decimal places based on the currency.
 *
 * @since  2.5.2
 * @param  int $decimals The number of decimal places. Default is 2.
 * @return int The number of decimal places.
 */
function rcp_currency_decimal_filter($decimals = 2)
{
    $currency = rcp_get_currency();
    if (rcp_is_zero_decimal_currency($currency)) {
        $decimals = 0;
    }
    return apply_filters('rcp_currency_decimal_filter', $decimals, $currency);
}
Example #8
0
function rcp_settings_page()
{
    global $rcp_options;
    $defaults = array('currency_position' => 'before', 'currency' => 'USD', 'registration_page' => 0, 'redirect' => 0, 'redirect_from_premium' => 0, 'login_redirect' => 0);
    $rcp_options = wp_parse_args($rcp_options, $defaults);
    ?>
	<div class="wrap">
		<?php 
    if (!isset($_REQUEST['updated'])) {
        $_REQUEST['updated'] = false;
    }
    ?>

		<h1><?php 
    _e('Restrict Content Pro', 'rcp');
    ?>
</h1>
		<h2 class="nav-tab-wrapper">
			<a href="#general" class="nav-tab"><?php 
    _e('General', 'rcp');
    ?>
</a>
			<a href="#payments" class="nav-tab"><?php 
    _e('Payments', 'rcp');
    ?>
</a>
			<a href="#emails" class="nav-tab"><?php 
    _e('Emails', 'rcp');
    ?>
</a>
			<a href="#invoices" class="nav-tab"><?php 
    _e('Invoices', 'rcp');
    ?>
</a>
			<a href="#misc" class="nav-tab"><?php 
    _e('Misc', 'rcp');
    ?>
</a>
		</h2>
		<?php 
    if (false !== $_REQUEST['updated']) {
        ?>
		<div class="updated fade"><p><strong><?php 
        _e('Options saved', 'rcp');
        ?>
</strong></p></div>
		<?php 
    }
    ?>
		<form method="post" action="options.php" class="rcp_options_form">

			<?php 
    settings_fields('rcp_settings_group');
    ?>

			<?php 
    $pages = get_pages();
    ?>


			<div id="tab_container">

				<div class="tab_content" id="general">
					<table class="form-table">
						<tr valign="top">
							<th colspan=2>
								<h3><?php 
    _e('General', 'rcp');
    ?>
</h3>
							</th>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[license_key]"><?php 
    _e('License Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[license_key]" style="width: 300px;" name="rcp_settings[license_key]" value="<?php 
    if (isset($rcp_options['license_key'])) {
        echo $rcp_options['license_key'];
    }
    ?>
"/>
								<?php 
    $status = get_option('rcp_license_status');
    ?>
								<?php 
    if ($status !== false && $status == 'valid') {
        ?>
									<?php 
        wp_nonce_field('rcp_deactivate_license', 'rcp_deactivate_license');
        ?>
									<input type="submit" class="button-secondary" name="rcp_license_deactivate" value="<?php 
        _e('Deactivate License', 'rcp');
        ?>
"/>
									<span style="color:green;"><?php 
        _e('active', 'rcp');
        ?>
</span>
								<?php 
    } elseif ($status !== 'valid') {
        ?>
									<input type="submit" class="button-secondary" name="rcp_license_activate" value="<?php 
        _e('Activate License', 'rcp');
        ?>
"/>
								<?php 
    }
    ?>
								<p class="description"><?php 
    printf(__('Enter license key for Restrict Content Pro. This is required for automatic updates and <a href="%s">support</a>.', 'rcp'), 'http://restrictcontentpro.com/support');
    ?>
</p>
							</td>
						</tr>
						<?php 
    do_action('rcp_license_settings', $rcp_options);
    ?>
						<tr valign="top">
							<th>
								<label for="rcp_settings[registration_page]"><?php 
    _e('Registration Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[registration_page]" name="rcp_settings[registration_page]">
									<?php 
    if ($pages) {
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['registration_page'], false) . '>';
            $option .= $page->post_title;
            $option .= ' (ID: ' . $page->ID . ')';
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    printf(__('Choose the primary registration page. This must contain the [register_form] short code. Additional registration forms may be added to other pages with [register_form id="x"]. <a href="%s" target="_blank">See documentation</a>.', 'rcp'), 'http://docs.pippinsplugins.com/article/442-registerform');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[redirect]"><?php 
    _e('Success Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[redirect]" name="rcp_settings[redirect]">
									<?php 
    if ($pages) {
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['redirect'], false) . '>';
            $option .= $page->post_title;
            $option .= ' (ID: ' . $page->ID . ')';
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    _e('This is the page users are redirected to after a successful registration.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[account_page]"><?php 
    _e('Account Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[account_page]" name="rcp_settings[account_page]">
									<?php 
    if ($pages) {
        $rcp_options['account_page'] = isset($rcp_options['account_page']) ? absint($rcp_options['account_page']) : 0;
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['account_page'], false) . '>';
            $option .= $page->post_title;
            $option .= ' (ID: ' . $page->ID . ')';
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    printf(__('This page displays the account and membership information for members. Contains <a href="%s" target="_blank">[subscription_details] short code</a>.', 'rcp'), 'http://docs.pippinsplugins.com/article/447-subscriptiondetails');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[edit_profile]"><?php 
    _e('Edit Profile Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[edit_profile]" name="rcp_settings[edit_profile]">
									<?php 
    if ($pages) {
        $rcp_options['edit_profile'] = isset($rcp_options['edit_profile']) ? absint($rcp_options['edit_profile']) : 0;
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['edit_profile'], false) . '>';
            $option .= $page->post_title;
            $option .= ' (ID: ' . $page->ID . ')';
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    printf(__('This page displays a profile edit form for logged-in members. Contains <a href="%s" target="_blank">[rcp_profile_editor] shortcode.', 'rcp'), 'http://docs.pippinsplugins.com/article/446-rcpprofileeditor');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[update_card]"><?php 
    _e('Update Billing Card Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[update_card]" name="rcp_settings[update_card]">
									<?php 
    if ($pages) {
        $rcp_options['update_card'] = isset($rcp_options['update_card']) ? absint($rcp_options['update_card']) : 0;
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['update_card'], false) . '>';
            $option .= $page->post_title;
            $option .= ' (ID: ' . $page->ID . ')';
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    printf(__('This page displays a profile edit form for logged-in members. Contains <a href="%s" target="_blank">[rcp_update_card] short code</a>.', 'rcp'), 'http://docs.pippinsplugins.com/article/820-rcpupdatecard');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[auto_renew]"><?php 
    _e('Auto Renew', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select name="rcp_settings[auto_renew]" id="rcp_settings[auto_renew]">
									<option value="1"<?php 
    selected('1', rcp_get_auto_renew_behavior());
    ?>
><?php 
    _e('Always auto renew', 'rcp');
    ?>
</option>
									<option value="2"<?php 
    selected('2', rcp_get_auto_renew_behavior());
    ?>
><?php 
    _e('Never auto renew', 'rcp');
    ?>
</option>
									<option value="3"<?php 
    selected('3', rcp_get_auto_renew_behavior());
    ?>
><?php 
    _e('Let customer choose whether to auto renew', 'rcp');
    ?>
</option>
								</select>
								<p class="description"><?php 
    _e('Select the auto renew behavior you would like subscription levels to have.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[free_message]"><?php 
    _e('Free Content Message', 'rcp');
    ?>
</label>
							</th>
							<td>
								<?php 
    $free_message = isset($rcp_options['free_message']) ? $rcp_options['free_message'] : '';
    wp_editor($free_message, 'rcp_settings_free_message', array('textarea_name' => 'rcp_settings[free_message]', 'teeny' => true));
    ?>
								<p class="description"><?php 
    _e('This is the message shown to users that do not have privilege to view free, user only content.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[paid_message]"><?php 
    _e('Premium Content Message', 'rcp');
    ?>
</label>
							</th>
							<td>
								<?php 
    $paid_message = isset($rcp_options['paid_message']) ? $rcp_options['paid_message'] : '';
    wp_editor($paid_message, 'rcp_settings_paid_message', array('textarea_name' => 'rcp_settings[paid_message]', 'teeny' => true));
    ?>
								<p class="description"><?php 
    _e('This is the message shown to users that do not have privilege to view premium content.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    do_action('rcp_messages_settings', $rcp_options);
    ?>
					</table>
					<?php 
    do_action('rcp_general_settings', $rcp_options);
    ?>

				</div><!--end #general-->

				<div class="tab_content" id="payments">
					<table class="form-table">
						<tr>
							<th>
								<label fo="rcp_settings[currency]"><?php 
    _e('Currency', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[currency]" name="rcp_settings[currency]">
									<?php 
    $currencies = rcp_get_currencies();
    foreach ($currencies as $key => $currency) {
        echo '<option value="' . esc_attr($key) . '" ' . selected($key, $rcp_options['currency'], false) . '>' . $currency . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    _e('Choose your currency.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[currency_position]"><?php 
    _e('Currency Position', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[currency_position]" name="rcp_settings[currency_position]">
									<option value="before" <?php 
    selected('before', $rcp_options['currency_position']);
    ?>
><?php 
    _e('Before - $10', 'rcp');
    ?>
</option>
									<option value="after" <?php 
    selected('after', $rcp_options['currency_position']);
    ?>
><?php 
    _e('After - 10$', 'rcp');
    ?>
</option>
								</select>
								<p class="description"><?php 
    _e('Show the currency sign before or after the price?', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    $gateways = rcp_get_payment_gateways();
    ?>
						<?php 
    if (count($gateways) > 1) {
        ?>
						<tr valign="top">
							<th>
								<h3><?php 
        _e('Gateways', 'rcp');
        ?>
</h3>
							</th>
							<td>
								<?php 
        _e('Check each of the payment gateways you would like to enable. Configure the selected gateways below.', 'rcp');
        ?>
							</td>
						</tr>
						<tr valign="top">
							<th><span><?php 
        _e('Enabled Gateways', 'rcp');
        ?>
</span></th>
							<td>
								<?php 
        $gateways = rcp_get_payment_gateways();
        foreach ($gateways as $key => $gateway) {
            $label = $gateway;
            if (is_array($gateway)) {
                $label = $gateway['admin_label'];
            }
            echo '<input name="rcp_settings[gateways][' . $key . ']" id="rcp_settings[gateways][' . $key . ']" type="checkbox" value="1" ' . checked(true, isset($rcp_options['gateways'][$key]), false) . '/>&nbsp;';
            echo '<label for="rcp_settings[gateways][' . $key . ']">' . $label . '</label><br/>';
        }
        ?>
							</td>
						</tr>
						<?php 
    }
    ?>
						<tr valign="top">
							<th>
								<label for="rcp_settings[sandbox]"><?php 
    _e('Sandbox Mode', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[sandbox]" id="rcp_settings[sandbox]" <?php 
    if (isset($rcp_options['sandbox'])) {
        checked('1', $rcp_options['sandbox']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Use Restrict Content Pro in Sandbox mode. This allows you to test the plugin with test accounts from your payment processor.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<?php 
    if (!function_exists('rcp_register_stripe_gateway')) {
        ?>
						<tr valign="top">
							<th colspan=2>
								<h3><?php 
        _e('Stripe Settings', 'rcp');
        ?>
</h3>
							</th>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[stripe_test_secret]"><?php 
        _e('Test Secret Key', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[stripe_test_secret]" style="width: 300px;" name="rcp_settings[stripe_test_secret]" value="<?php 
        if (isset($rcp_options['stripe_test_secret'])) {
            echo $rcp_options['stripe_test_secret'];
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your test secret key. Your API keys can be obtained from your <a href="https://dashboard.stripe.com/account/apikeys" target="_blank">Stripe account settings</a>.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[stripe_test_publishable]"><?php 
        _e('Test Publishable Key', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[stripe_test_publishable]" style="width: 300px;" name="rcp_settings[stripe_test_publishable]" value="<?php 
        if (isset($rcp_options['stripe_test_publishable'])) {
            echo $rcp_options['stripe_test_publishable'];
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your test publishable key.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[stripe_live_secret]"><?php 
        _e('Live Secret Key', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[stripe_live_secret]" style="width: 300px;" name="rcp_settings[stripe_live_secret]" value="<?php 
        if (isset($rcp_options['stripe_live_secret'])) {
            echo $rcp_options['stripe_live_secret'];
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your live secret key.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[stripe_live_publishable]"><?php 
        _e('Live Publishable Key', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[stripe_live_publishable]" style="width: 300px;" name="rcp_settings[stripe_live_publishable]" value="<?php 
        if (isset($rcp_options['stripe_live_publishable'])) {
            echo $rcp_options['stripe_live_publishable'];
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your live publishable key.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<?php 
        if ('USD' === rcp_get_currency()) {
            ?>
						<tr>
							<th>
								<label for="rcp_settings[stripe_alipay]"><?php 
            _e('Enable Alipay Support', 'rcp');
            ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[stripe_alipay]" id="rcp_settings[stripe_alipay]" <?php 
            if (isset($rcp_options['stripe_alipay'])) {
                checked('1', $rcp_options['stripe_alipay']);
            }
            ?>
/>
								<span class="description"><?php 
            _e('Check to enable Alipay support in Stripe Checkout. Alipay is only available with Stripe Checkout. It does not work with the standard Stripe gateway.', 'rcp');
            ?>
</span>
							</td>
						</tr>
						<?php 
        }
        ?>
						<tr>
							<th colspan=2>
								<p><strong><?php 
        _e('Note', 'rcp');
        ?>
</strong>: <?php 
        _e('in order for subscription payments made through Stripe to be tracked, you must enter the following URL to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe Webhooks</a> under Account Settings:', 'rcp');
        ?>
</p>
								<p><strong><?php 
        echo esc_url(add_query_arg('listener', 'stripe', home_url()));
        ?>
</strong></p>
							</th>
						</tr>
						<?php 
    }
    ?>
						<tr valign="top">
							<th colspan=2><h3><?php 
    _e('PayPal Settings', 'rcp');
    ?>
</h3></th>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[paypal_email]"><?php 
    _e('PayPal Address', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[paypal_email]" style="width: 300px;" name="rcp_settings[paypal_email]" value="<?php 
    if (isset($rcp_options['paypal_email'])) {
        echo $rcp_options['paypal_email'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your PayPal email address.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr>
							<th><?php 
    _e('PayPal API Credentials', 'rcp');
    ?>
</th>
							<td>
								<p><?php 
    _e('The PayPal API credentials are required in order to use PayPal Express, PayPal Pro, and to support advanced subscription cancellation options in PayPal Standard. Test API credentials can be obtained at <a href="http://docs.pippinsplugins.com/article/826-setting-up-paypal-sandbox-accounts" target="_blank">developer.paypal.com</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    if (!function_exists('rcp_register_paypal_pro_express_gateway')) {
        ?>
						<tr>
							<th>
								<label for="rcp_settings[test_paypal_api_username]"><?php 
        _e('Test API Username', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[test_paypal_api_username]" style="width: 300px;" name="rcp_settings[test_paypal_api_username]" value="<?php 
        if (isset($rcp_options['test_paypal_api_username'])) {
            echo trim($rcp_options['test_paypal_api_username']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your test API username.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[test_paypal_api_password]"><?php 
        _e('Test API Password', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[test_paypal_api_password]" style="width: 300px;" name="rcp_settings[test_paypal_api_password]" value="<?php 
        if (isset($rcp_options['test_paypal_api_password'])) {
            echo trim($rcp_options['test_paypal_api_password']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your test API password.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[test_paypal_api_signature]"><?php 
        _e('Test API Signature', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[test_paypal_api_signature]" style="width: 300px;" name="rcp_settings[test_paypal_api_signature]" value="<?php 
        if (isset($rcp_options['test_paypal_api_signature'])) {
            echo trim($rcp_options['test_paypal_api_signature']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your test API signature.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[live_paypal_api_username]"><?php 
        _e('Live API Username', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[live_paypal_api_username]" style="width: 300px;" name="rcp_settings[live_paypal_api_username]" value="<?php 
        if (isset($rcp_options['live_paypal_api_username'])) {
            echo trim($rcp_options['live_paypal_api_username']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your live API username.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[live_paypal_api_password]"><?php 
        _e('Live API Password', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[live_paypal_api_password]" style="width: 300px;" name="rcp_settings[live_paypal_api_password]" value="<?php 
        if (isset($rcp_options['live_paypal_api_password'])) {
            echo trim($rcp_options['live_paypal_api_password']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your live API password.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr>
							<th>
								<label for="rcp_settings[live_paypal_api_signature]"><?php 
        _e('Live API Signature', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[live_paypal_api_signature]" style="width: 300px;" name="rcp_settings[live_paypal_api_signature]" value="<?php 
        if (isset($rcp_options['live_paypal_api_signature'])) {
            echo trim($rcp_options['live_paypal_api_signature']);
        }
        ?>
"/>
								<p class="description"><?php 
        _e('Enter your live API signature.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<?php 
    }
    ?>
						<tr valign="top">
							<th>
								<label for="rcp_settings[paypal_page_style]"><?php 
    _e('PayPal Page Style', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[paypal_page_style]" style="width: 300px;" name="rcp_settings[paypal_page_style]" value="<?php 
    if (isset($rcp_options['paypal_page_style'])) {
        echo trim($rcp_options['paypal_page_style']);
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the PayPal page style name you wish to use, or leave blank for default.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[disable_curl]"><?php 
    _e('Disable CURL', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[disable_curl]" id="rcp_settings[disable_curl]" <?php 
    if (isset($rcp_options['disable_curl'])) {
        checked('1', $rcp_options['disable_curl']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Only check this option if your host does not allow cURL.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[disable_ipn_verify]"><?php 
    _e('Disable IPN Verification', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[disable_ipn_verify]" id="rcp_settings[disable_ipn_verify]" <?php 
    if (isset($rcp_options['disable_ipn_verify'])) {
        checked('1', $rcp_options['disable_ipn_verify']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Only check this option if your members statuses are not getting changed to "active".', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th colspan=2>
								<h3><?php 
    _e('2Checkout Settings', 'rcp');
    ?>
</h3>
							</th>
						</tr>
						<?php 
    // 2checkout Secret Word
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_secret_word]"><?php 
    _e('Secret Word', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_secret_word]" style="width: 300px;" name="rcp_settings[twocheckout_secret_word]" value="<?php 
    if (isset($rcp_options['twocheckout_secret_word'])) {
        echo $rcp_options['twocheckout_secret_word'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your secret word. This can be obtained from the <a href="https://sandbox.2checkout.com/sandbox/acct/detail_company_info" target="_blank">2Checkout Sandbox</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Test Private Key
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_test_private]"><?php 
    _e('Test Private Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_test_private]" style="width: 300px;" name="rcp_settings[twocheckout_test_private]" value="<?php 
    if (isset($rcp_options['twocheckout_test_private'])) {
        echo $rcp_options['twocheckout_test_private'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your test private key. Your test API keys can be obtained from the <a href="https://sandbox.2checkout.com/sandbox/api" target="_blank">2Checkout Sandbox</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Test Publishable Key
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_test_publishable]"><?php 
    _e('Test Publishable Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_test_publishable]" style="width: 300px;" name="rcp_settings[twocheckout_test_publishable]" value="<?php 
    if (isset($rcp_options['twocheckout_test_publishable'])) {
        echo $rcp_options['twocheckout_test_publishable'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your test publishable key.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Test Seller ID
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_test_seller_id]"><?php 
    _e('Test Seller ID', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_test_seller_id]" style="width: 300px;" name="rcp_settings[twocheckout_test_seller_id]" value="<?php 
    if (isset($rcp_options['twocheckout_test_seller_id'])) {
        echo $rcp_options['twocheckout_test_seller_id'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your live Seller ID. <a href="http://help.2checkout.com/articles/FAQ/Where-is-my-Seller-ID" target="_blank">Where is my Seller ID?</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Live Private Key
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_live_private]"><?php 
    _e('Live Private Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_live_private]" style="width: 300px;" name="rcp_settings[twocheckout_live_private]" value="<?php 
    if (isset($rcp_options['twocheckout_live_private'])) {
        echo $rcp_options['twocheckout_live_private'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your live secret key. Your API keys can be obtained from the <a href="https://pci.trustwave.com/2checkout" target="_blank">2Checkout PCI Program</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Live Publishable Key
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_live_publishable]"><?php 
    _e('Live Publishable Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_live_publishable]" style="width: 300px;" name="rcp_settings[twocheckout_live_publishable]" value="<?php 
    if (isset($rcp_options['twocheckout_live_publishable'])) {
        echo $rcp_options['twocheckout_live_publishable'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your live publishable key.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<?php 
    // 2checkout Live Seller ID
    ?>
						<tr>
							<th>
								<label for="rcp_settings[twocheckout_live_seller_id]"><?php 
    _e('Live Seller ID', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[twocheckout_live_seller_id]" style="width: 300px;" name="rcp_settings[twocheckout_live_seller_id]" value="<?php 
    if (isset($rcp_options['twocheckout_live_seller_id'])) {
        echo $rcp_options['twocheckout_live_seller_id'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter your live Seller ID. <a href="http://help.2checkout.com/articles/FAQ/Where-is-my-Seller-ID" target="_blank">Where is my Seller ID?</a>.', 'rcp');
    ?>
</p>
							</td>
						</tr>
					</table>
					<?php 
    do_action('rcp_payments_settings', $rcp_options);
    ?>

				</div><!--end #payments-->

				<div class="tab_content" id="emails">
					<div id="rcp_email_options">

						<table class="form-table">
							<tr>
								<th colspan=2><h3><?php 
    _e('General', 'rcp');
    ?>
</h3></th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[from_name]"><?php 
    _e('From Name', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[from_name]" style="width: 300px;" name="rcp_settings[from_name]" value="<?php 
    if (isset($rcp_options['from_name'])) {
        echo $rcp_options['from_name'];
    } else {
        echo get_bloginfo('name');
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The name that emails come from. This is usually the name of your business.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[from_email]"><?php 
    _e('From Email', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[from_email]" style="width: 300px;" name="rcp_settings[from_email]" value="<?php 
    if (isset($rcp_options['from_email'])) {
        echo $rcp_options['from_email'];
    } else {
        echo get_bloginfo('admin_email');
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The email address that emails are sent from.', 'rcp');
    ?>
</p>
								</td>
							</tr>

							<tr>
								<th colspan=2><h3><?php 
    _e('Active Subscription Email', 'rcp');
    ?>
</h3></th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_active_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_active_email]" id="rcp_settings[disable_active_email]" <?php 
    checked(true, isset($rcp_options['disable_active_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a member becomes active.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[active_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[active_subject]" style="width: 300px;" name="rcp_settings[active_subject]" value="<?php 
    if (isset($rcp_options['active_subject'])) {
        echo $rcp_options['active_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users when their subscription becomes active.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[active_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[active_email]" style="width: 300px; height: 100px;" name="rcp_settings[active_email]"><?php 
    if (isset($rcp_options['active_email'])) {
        echo $rcp_options['active_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users when their subscription becomes active.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2>
									<h3><?php 
    _e('Cancelled Subscription Email', 'rcp');
    ?>
</h3>
								</th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_cancelled_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_cancelled_email]" id="rcp_settings[disable_cancelled_email]" <?php 
    checked(true, isset($rcp_options['disable_cancelled_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a member is cancelled.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[cancelled_subject]"><?php 
    _e('Subject line', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[cancelled_subject]" style="width: 300px;" name="rcp_settings[cancelled_subject]" value="<?php 
    if (isset($rcp_options['cancelled_subject'])) {
        echo $rcp_options['cancelled_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users when their subscription is cancelled.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[cancelled_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[cancelled_email]" style="width: 300px; height: 100px;" name="rcp_settings[cancelled_email]"><?php 
    if (isset($rcp_options['cancelled_email'])) {
        echo $rcp_options['cancelled_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users when their subscription is cancelled.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2>
									<h3><?php 
    _e('Expired Subscription Email', 'rcp');
    ?>
</h3>
								</th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_expired_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_expired_email]" id="rcp_settings[disable_expired_email]" <?php 
    checked(true, isset($rcp_options['disable_expired_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a member expires.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[expired_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[expired_subject]" style="width: 300px;" name="rcp_settings[expired_subject]" value="<?php 
    if (isset($rcp_options['expired_subject'])) {
        echo $rcp_options['expired_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users when their subscription is expired.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[expired_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[expired_email]" style="width: 300px; height: 100px;" name="rcp_settings[expired_email]"><?php 
    if (isset($rcp_options['expired_email'])) {
        echo $rcp_options['expired_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users when their subscription is expired.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2><h3><?php 
    _e('Expiring Soon Email', 'rcp');
    ?>
</h3></th>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[renewal_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[renewal_subject]" style="width: 300px;" name="rcp_settings[renewal_subject]" value="<?php 
    if (isset($rcp_options['renewal_subject'])) {
        echo $rcp_options['renewal_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users before their subscription expires.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[renew_notice_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[renew_notice_email]" style="width: 300px; height: 100px;" name="rcp_settings[renew_notice_email]"><?php 
    if (isset($rcp_options['renew_notice_email'])) {
        echo $rcp_options['renew_notice_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users before their subscription expires to encourage them to renew.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[renewal_reminder_period]"><?php 
    _e('Reminder Period', 'rcp');
    ?>
</label>
								</th>
								<td>
									<select id="rcp_settings[renewal_reminder_period]" name="rcp_settings[renewal_reminder_period]">
										<?php 
    $periods = rcp_get_renewal_reminder_periods();
    foreach ($periods as $key => $period) {
        $option = '<option value="' . $key . '" ' . selected($key, rcp_get_renewal_reminder_period(), false) . '>' . $period . '</option>';
        echo $option;
    }
    ?>
									</select>
									<p class="description"><?php 
    _e('When should the renewal reminder be sent? These are sent to members that do not have automatically recurring subscriptions.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2>
									<h3><?php 
    _e('Free Subscription Email', 'rcp');
    ?>
</h3>
								</th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_free_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_free_email]" id="rcp_settings[disable_free_email]" <?php 
    checked(true, isset($rcp_options['disable_free_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a free member registers.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[free_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[free_subject]" style="width: 300px;" name="rcp_settings[free_subject]" value="<?php 
    if (isset($rcp_options['free_subject'])) {
        echo $rcp_options['free_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users when they sign up for a free membership.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[free_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[free_email]" style="width: 300px; height: 100px;" name="rcp_settings[free_email]"><?php 
    if (isset($rcp_options['free_email'])) {
        echo $rcp_options['free_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users when they sign up for a free account.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2>
									<h3><?php 
    _e('Trial Subscription Email', 'rcp');
    ?>
</h3>
								</th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_trial_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_trial_email]" id="rcp_settings[disable_trial_email]" <?php 
    checked(true, isset($rcp_options['disable_trial_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a member signs up with a trial.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[trial_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[trial_subject]" style="width: 300px;" name="rcp_settings[trial_subject]" value="<?php 
    if (isset($rcp_options['trial_subject'])) {
        echo $rcp_options['trial_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users when they sign up for a free trial.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[trial_email]"><?php 
    _e('Trial Email Message', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[trial_email]" style="width: 300px; height: 100px;" name="rcp_settings[trial_email]"><?php 
    if (isset($rcp_options['trial_email'])) {
        echo $rcp_options['trial_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users when they sign up for a free trial.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2><h3><?php 
    _e('Payment Received Email', 'rcp');
    ?>
</h3></th>
							</tr>
							<tr>
								<th>
									<label for="rcp_settings[disable_payment_received_email]"><?php 
    _e('Disabled', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_payment_received_email]" id="rcp_settings[disable_payment_received_email]" <?php 
    checked(true, isset($rcp_options['disable_payment_received_email']));
    ?>
/>
									<span><?php 
    _e('Check this to disable the email sent out when a payment is received.', 'rcp');
    ?>
</span>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[payment_received_subject]"><?php 
    _e('Subject', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input class="regular-text" id="rcp_settings[payment_received_subject]" style="width: 300px;" name="rcp_settings[payment_received_subject]" value="<?php 
    if (isset($rcp_options['payment_received_subject'])) {
        echo $rcp_options['payment_received_subject'];
    }
    ?>
"/>
									<p class="description"><?php 
    _e('The subject line for the email sent to users upon a successful payment being received.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[payment_received_email]"><?php 
    _e('Email Body', 'rcp');
    ?>
</label>
								</th>
								<td>
									<textarea id="rcp_settings[payment_received_email]" style="width: 300px; height: 100px;" name="rcp_settings[payment_received_email]"><?php 
    if (isset($rcp_options['payment_received_email'])) {
        echo $rcp_options['payment_received_email'];
    }
    ?>
</textarea>
									<p class="description"><?php 
    _e('This is the email message that is sent to users after a payment has been received from them.', 'rcp');
    ?>
</p>
								</td>
							</tr>
							<tr valign="top">
								<th colspan=2>
									<h3><?php 
    _e('New User Notifications', 'rcp');
    ?>
</h3>
								</th>
							</tr>
							<tr valign="top">
								<th>
									<label for="rcp_settings[disable_new_user_notices]"><?php 
    _e('Disable New User Notifications', 'rcp');
    ?>
</label>
								</th>
								<td>
									<input type="checkbox" value="1" name="rcp_settings[disable_new_user_notices]" id="rcp_settings[disable_new_user_notices]" <?php 
    if (isset($rcp_options['disable_new_user_notices'])) {
        checked('1', $rcp_options['disable_new_user_notices']);
    }
    ?>
/>
									<span class="description"><?php 
    _e('Check this option if you do NOT want to receive emails when new users signup.', 'rcp');
    ?>
</span>
								</td>
							</tr>
						</table>
						<?php 
    do_action('rcp_email_settings', $rcp_options);
    ?>

					</div><!--end #rcp_email_options-->
					<div id="rcp_email_tags">
						<p><strong><?php 
    _e('Available Template Tags', 'rcp');
    ?>
</strong></p>
						<ul>
							<li><em>%blogname%</em> - <?php 
    _e('will be replaced with the name of your site', 'rcp');
    ?>
</li>
							<li><em>%username%</em> - <?php 
    _e('will be replaced with the user name of the person receiving the email', 'rcp');
    ?>
</li>
							<li><em>%useremail%</em> - <?php 
    _e('will be replaced with the email of the person receiving the email', 'rcp');
    ?>
</li>
							<li><em>%firstname%</em> - <?php 
    _e('will be replaced with the first name of the person receiving the email', 'rcp');
    ?>
</li>
							<li><em>%lastname%</em> - <?php 
    _e('will be replaced with the last name of the person receiving the email', 'rcp');
    ?>
</li>
							<li><em>%displayname%</em> - <?php 
    _e('will be replaced with the display name of the person receiving the email', 'rcp');
    ?>
</li>
							<li><em>%expiration%</em> - <?php 
    _e('will be replaced with the expiration date of subscription', 'rcp');
    ?>
</li>
							<li><em>%subscription_name%</em> - <?php 
    _e('will be replaced with the name of the subscription', 'rcp');
    ?>
</li>
							<li><em>%subscription_key%</em> - <?php 
    _e('will be replaced with the unique, 32 character key created when the user is registered', 'rcp');
    ?>
</li>
							<li><em>%amount%</em> - <?php 
    _e('will be replaced with the amount of the users last payment', 'rcp');
    ?>
</li>

							<?php 
    do_action('rcp_available_template_tags');
    ?>

						</ul>
					</div><!--end #rcp_email_tags-->
					<div class="clear"></div>
				</div><!--end #emails-->

				<div class="tab_content" id="invoices">
					<table class="form-table">
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_logo]"><?php 
    _e('Invoice Logo', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text rcp-upload-field" id="rcp_settings[invoice_logo]" style="width: 300px;" name="rcp_settings[invoice_logo]" value="<?php 
    if (isset($rcp_options['invoice_logo'])) {
        echo $rcp_options['invoice_logo'];
    }
    ?>
"/>
								<button class="button-secondary rcp-upload"><?php 
    _e('Choose Logo', 'rcp');
    ?>
</button>
								<p class="description"><?php 
    _e('Upload a logo to display on the invoices.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_company]"><?php 
    _e('Company Name', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_company]" style="width: 300px;" name="rcp_settings[invoice_company]" value="<?php 
    if (isset($rcp_options['invoice_company'])) {
        echo $rcp_options['invoice_company'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the company name that will be shown on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_name]"><?php 
    _e('Name', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_name]" style="width: 300px;" name="rcp_settings[invoice_name]" value="<?php 
    if (isset($rcp_options['invoice_name'])) {
        echo $rcp_options['invoice_name'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the personal name that will be shown on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_address]"><?php 
    _e('Address Line 1', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_address]" style="width: 300px;" name="rcp_settings[invoice_address]" value="<?php 
    if (isset($rcp_options['invoice_address'])) {
        echo $rcp_options['invoice_address'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the first address line that will appear on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_address_2]"><?php 
    _e('Address Line 2', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_address_2]" style="width: 300px;" name="rcp_settings[invoice_address_2]" value="<?php 
    if (isset($rcp_options['invoice_address_2'])) {
        echo $rcp_options['invoice_address_2'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the second address line that will appear on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_city_state_zip]"><?php 
    _e('City, State, and Zip', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_city_state_zip]" style="width: 300px;" name="rcp_settings[invoice_city_state_zip]" value="<?php 
    if (isset($rcp_options['invoice_city_state_zip'])) {
        echo $rcp_options['invoice_city_state_zip'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the city, state and zip/postal code that will appear on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_email]"><?php 
    _e('Email', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_email]" style="width: 300px;" name="rcp_settings[invoice_email]" value="<?php 
    if (isset($rcp_options['invoice_email'])) {
        echo $rcp_options['invoice_email'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the email address that will appear on the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_header]"><?php 
    _e('Header Text', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_header]" style="width: 300px;" name="rcp_settings[invoice_header]" value="<?php 
    if (isset($rcp_options['invoice_header'])) {
        echo $rcp_options['invoice_header'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the message you would like to be shown on the header of the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_notes]"><?php 
    _e('Notes', 'rcp');
    ?>
</label>
							</th>
							<td>
								<textarea id="rcp_settings[invoice_notes]" style="width: 300px; height: 100px;" name="rcp_settings[invoice_notes]"><?php 
    if (isset($rcp_options['invoice_notes'])) {
        echo $rcp_options['invoice_notes'];
    }
    ?>
</textarea>
								<p class="description"><?php 
    _e('Enter additional notes you would like displayed below the invoice totals.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[invoice_footer]"><?php 
    _e('Footer Text', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input class="regular-text" id="rcp_settings[invoice_footer]" style="width: 300px;" name="rcp_settings[invoice_footer]" value="<?php 
    if (isset($rcp_options['invoice_footer'])) {
        echo $rcp_options['invoice_footer'];
    }
    ?>
"/>
								<p class="description"><?php 
    _e('Enter the message you would like to be shown on the footer of the invoice.', 'rcp');
    ?>
</p>
							</td>
						</tr>
					</table>
					<?php 
    do_action('rcp_invoice_settings', $rcp_options);
    ?>
				</div><!--end #invoices-->

				<div class="tab_content" id="misc">
					<table class="form-table">
						<tr valign="top">
							<th>
								<label for="rcp_settings[hide_premium]"><?php 
    _e('Hide Premium Posts', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[hide_premium]" id="rcp_settings[hide_premium]" <?php 
    if (isset($rcp_options['hide_premium'])) {
        checked('1', $rcp_options['hide_premium']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Check this to hide all premium posts from queries when user is not logged in. Note, this will only hide posts that are restricted to paid memberships.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[redirect]">&nbsp;&mdash;&nbsp;<?php 
    _e('Redirect Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[redirect_from_premium]" name="rcp_settings[redirect_from_premium]">
									<?php 
    if ($pages) {
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['redirect_from_premium'], false) . '>';
            $option .= $page->post_title;
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    _e('This is the page non-subscribed users are redirected to when attempting to access a premium post or page.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[hijack_login_url]"><?php 
    _e('Redirect Default Login URL', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[hijack_login_url]" id="rcp_settings[hijack_login_url]" <?php 
    if (isset($rcp_options['hijack_login_url'])) {
        checked('1', $rcp_options['hijack_login_url']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Check this to force the default login URL to redirect to the page specified below.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[redirect]">&nbsp;&mdash;&nbsp;<?php 
    _e('Login Page', 'rcp');
    ?>
</label>
							</th>
							<td>
								<select id="rcp_settings[login_redirect]" name="rcp_settings[login_redirect]">
									<?php 
    if ($pages) {
        foreach ($pages as $page) {
            $option = '<option value="' . $page->ID . '" ' . selected($page->ID, $rcp_options['login_redirect'], false) . '>';
            $option .= $page->post_title;
            $option .= '</option>';
            echo $option;
        }
    } else {
        echo '<option>' . __('No pages found', 'rcp') . '</option>';
    }
    ?>
								</select>
								<p class="description"><?php 
    _e('This is the page the default login URL redirects to, if the option above is checked. This should be the page that contains the [login_form] short code.', 'rcp');
    ?>
</p>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[no_login_sharing]"><?php 
    _e('Prevent Account Sharing', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[no_login_sharing]" id="rcp_settings[no_login_sharing]"<?php 
    checked(true, isset($rcp_options['no_login_sharing']));
    ?>
/>
								<span class="description"><?php 
    _e('Check this if you\'d like to prevent multiple users from logging into the same account simultaneously.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[email_ipn_reports]"><?php 
    _e('Email IPN reports', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[email_ipn_reports]" id="rcp_settings[email_ipn_reports]" <?php 
    if (isset($rcp_options['email_ipn_reports'])) {
        checked('1', $rcp_options['email_ipn_reports']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Check this to send an email each time an IPN request is made with PayPal. The email will contain a list of all data sent. This is useful for debugging in the case that something is not working with the PayPal integration.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[disable_css]"><?php 
    _e('Disable Form CSS', 'rcp');
    ?>
</label><br/>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[disable_css]" id="rcp_settings[disable_css]" <?php 
    if (isset($rcp_options['disable_css'])) {
        checked('1', $rcp_options['disable_css']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Check this to disable all included form styling.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[enable_recaptcha]"><?php 
    _e('Enable reCaptcha', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input type="checkbox" value="1" name="rcp_settings[enable_recaptcha]" id="rcp_settings[enable_recaptcha]" <?php 
    if (isset($rcp_options['enable_recaptcha'])) {
        checked('1', $rcp_options['enable_recaptcha']);
    }
    ?>
/>
								<span class="description"><?php 
    _e('Check this to enable reCaptcha on the registration form.', 'rcp');
    ?>
</span>
							</td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[recaptcha_public_key]"><?php 
    _e('reCaptcha Site Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input id="rcp_settings[recaptcha_public_key]" style="width: 300px;" name="rcp_settings[recaptcha_public_key]" type="text" value="<?php 
    if (isset($rcp_options['recaptcha_public_key'])) {
        echo $rcp_options['recaptcha_public_key'];
    }
    ?>
" />
								<p class="description"><?php 
    _e('This your own personal reCaptcha Site key. Go to', 'rcp');
    ?>
 <a href="https://www.google.com/recaptcha/"><?php 
    _e('your account', 'rcp');
    ?>
</a>, <?php 
    _e('then click on your domain (or add a new one) to find your site key.', 'rcp');
    ?>
</p>
							<td>
						</tr>
						<tr valign="top">
							<th>
								<label for="rcp_settings[recaptcha_private_key]"><?php 
    _e('reCaptcha Secret Key', 'rcp');
    ?>
</label>
							</th>
							<td>
								<input id="rcp_settings[recaptcha_private_key]" style="width: 300px;" name="rcp_settings[recaptcha_private_key]" type="text" value="<?php 
    if (isset($rcp_options['recaptcha_private_key'])) {
        echo $rcp_options['recaptcha_private_key'];
    }
    ?>
" />
								<p class="description"><?php 
    _e('This your own personal reCaptcha Secret key. Go to', 'rcp');
    ?>
 <a href="https://www.google.com/recaptcha/"><?php 
    _e('your account', 'rcp');
    ?>
</a>, <?php 
    _e('then click on your domain (or add a new one) to find your secret key.', 'rcp');
    ?>
</p>
							</td>
						</tr>
					</table>
					<?php 
    do_action('rcp_misc_settings', $rcp_options);
    ?>
				</div><!--end #misc-->

			</div><!--end #tab_container-->

			<!-- save the options -->
			<p class="submit">
				<input type="submit" class="button-primary" value="<?php 
    _e('Save Options', 'rcp');
    ?>
" />
			</p>


		</form>
	</div><!--end wrap-->

	<?php 
}
 /**
  * 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['subscr_id'])) {
             $user_id = rcp_get_member_id_from_profile_id($posted['subscr_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');
         }
         $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($subscription_id), 2);
         $pending_amount = get_user_meta($member->ID, 'rcp_pending_subscription_amount', true);
         $pending_amount = number_format((double) $pending_amount, 2);
         // Check for invalid amounts in the IPN data
         if (!empty($pending_amount) && !empty($amount) && in_array($posted['txn_type'], array('web_accept', 'subscr_payment'))) {
             if ($amount < $pending_amount) {
                 rcp_add_member_note($member->ID, sprintf(__('Incorrect amount received in the IPN. Amount received was %s. The amount should have been %s. PayPal Transaction ID: %s', 'rcp'), $amount, $pending_amount, sanitize_text_field($posted['txn_id'])));
                 die('incorrect amount');
             } else {
                 delete_user_meta($member->ID, 'rcp_pending_subscription_amount');
             }
         }
         // setup the payment info in an array for storage
         $payment_data = array('date' => date('Y-m-d H: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_get_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']);
                 if ($member->just_upgraded() && rcp_can_member_cancel($member->ID)) {
                     $cancelled = rcp_cancel_member_payment_profile($member->ID, false);
                 }
                 $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":
                 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 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':
                         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('');
                             }
                         }
                         // 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');
     }
 }
/**
 * Update a discount in Stripe when a local code is updated
 *
 * @access      private
 * @param       $discount_id int the id of the discount being updated
 * @param       $args array the array of discount args
 *              array(
 *					'name',
 *					'description',
 *					'amount',
 *					'unit',
 *					'code',
 *					'status',
 *					'expiration',
 *					'max_uses',
 *					'subscription_id'
 *				)
 * @since       2.1
 */
function rcp_stripe_update_discount($discount_id, $args)
{
    if (!is_admin()) {
        return;
    }
    // bail if the discount id or args are empty
    if (empty($discount_id) || empty($args)) {
        return;
    }
    if (function_exists('rcp_stripe_add_discount')) {
        return;
        // Old Stripe gateway is active
    }
    if (!rcp_is_gateway_enabled('stripe') && !rcp_is_gateway_enabled('stripe_checkout')) {
        return;
    }
    global $rcp_options;
    if (!class_exists('Stripe\\Stripe')) {
        require_once RCP_PLUGIN_DIR . 'includes/libraries/stripe/init.php';
    }
    if (!empty($_REQUEST['deactivate_discount']) || !empty($_REQUEST['activate_discount'])) {
        return;
    }
    if (rcp_is_sandbox()) {
        $secret_key = trim($rcp_options['stripe_test_secret']);
    } else {
        $secret_key = trim($rcp_options['stripe_live_secret']);
    }
    \Stripe\Stripe::setApiKey($secret_key);
    $discount_details = rcp_get_discount_details($discount_id);
    $discount_name = $discount_details->code;
    if (!rcp_stripe_does_coupon_exists($discount_name)) {
        try {
            if ($args['unit'] == '%') {
                \Stripe\Coupon::create(array("percent_off" => sanitize_text_field($args['amount']), "duration" => "forever", "id" => sanitize_text_field($discount_name), "currency" => strtolower(rcp_get_currency())));
            } else {
                \Stripe\Coupon::create(array("amount_off" => sanitize_text_field($args['amount']) * rcp_stripe_get_currency_multiplier(), "duration" => "forever", "id" => sanitize_text_field($discount_name), "currency" => strtolower(rcp_get_currency())));
            }
        } catch (Exception $e) {
            wp_die('<pre>' . $e . '</pre>', __('Error', 'rcp'));
        }
    } else {
        // first delete the discount in Stripe
        try {
            $cpn = \Stripe\Coupon::retrieve($discount_name);
            $cpn->delete();
        } catch (Exception $e) {
            wp_die('<pre>' . $e . '</pre>', __('Error', 'rcp'));
        }
        // now add a new one. This is a fake "update"
        try {
            if ($args['unit'] == '%') {
                \Stripe\Coupon::create(array("percent_off" => sanitize_text_field($args['amount']), "duration" => "forever", "id" => sanitize_text_field($discount_name), "currency" => strtolower(rcp_get_currency())));
            } else {
                \Stripe\Coupon::create(array("amount_off" => sanitize_text_field($args['amount']) * rcp_stripe_get_currency_multiplier(), "duration" => "forever", "id" => sanitize_text_field($discount_name), "currency" => strtolower(rcp_get_currency())));
            }
        } catch (\Stripe\Error\InvalidRequest $e) {
            // Invalid parameters were supplied to Stripe's API
            $body = $e->getJsonBody();
            $err = $body['error'];
            $error = '<h4>' . __('An error occurred', 'rcp') . '</h4>';
            if (isset($err['code'])) {
                $error .= '<p>' . sprintf(__('Error code: %s', 'rcp'), $err['code']) . '</p>';
            }
            $error .= "<p>Status: " . $e->getHttpStatus() . "</p>";
            $error .= "<p>Message: " . $err['message'] . "</p>";
            wp_die($error, __('Error', 'rcp'), array('response' => 401));
        } catch (\Stripe\Error\Authentication $e) {
            // Authentication with Stripe's API failed
            // (maybe you changed API keys recently)
            $body = $e->getJsonBody();
            $err = $body['error'];
            $error = '<h4>' . __('An error occurred', 'rcp') . '</h4>';
            if (isset($err['code'])) {
                $error .= '<p>' . sprintf(__('Error code: %s', 'rcp'), $err['code']) . '</p>';
            }
            $error .= "<p>Status: " . $e->getHttpStatus() . "</p>";
            $error .= "<p>Message: " . $err['message'] . "</p>";
            wp_die($error, __('Error', 'rcp'), array('response' => 401));
        } catch (\Stripe\Error\ApiConnection $e) {
            // Network communication with Stripe failed
            $body = $e->getJsonBody();
            $err = $body['error'];
            $error = '<h4>' . __('An error occurred', 'rcp') . '</h4>';
            if (isset($err['code'])) {
                $error .= '<p>' . sprintf(__('Error code: %s', 'rcp'), $err['code']) . '</p>';
            }
            $error .= "<p>Status: " . $e->getHttpStatus() . "</p>";
            $error .= "<p>Message: " . $err['message'] . "</p>";
            wp_die($error, __('Error', 'rcp'), array('response' => 401));
        } catch (\Stripe\Error\Base $e) {
            // Display a very generic error to the user
            $body = $e->getJsonBody();
            $err = $body['error'];
            $error = '<h4>' . __('An error occurred', 'rcp') . '</h4>';
            if (isset($err['code'])) {
                $error .= '<p>' . sprintf(__('Error code: %s', 'rcp'), $err['code']) . '</p>';
            }
            $error .= "<p>Status: " . $e->getHttpStatus() . "</p>";
            $error .= "<p>Message: " . $err['message'] . "</p>";
            wp_die($error, __('Error', 'rcp'), array('response' => 401));
        } catch (Exception $e) {
            // Something else happened, completely unrelated to Stripe
            $error = '<p>' . __('An unidentified error occurred.', 'rcp') . '</p>';
            $error .= print_r($e, true);
            wp_die($error, __('Error', 'rcp'), array('response' => 401));
        }
    }
}