Since: 2.1
Inheritance: extends WP_User
 /**
  * Process registration
  *
  * @since 2.1
  */
 public function process_signup()
 {
     global $rcp_options;
     $args = array('USER' => $this->username, 'PWD' => $this->password, 'SIGNATURE' => $this->signature, 'VERSION' => '121', 'METHOD' => 'CreateRecurringPaymentsProfile', 'AMT' => $this->amount, 'INITAMT' => 0, 'CURRENCYCODE' => strtoupper($this->currency), 'ITEMAMT' => round($this->amount + $this->signup_fee, 2), 'SHIPPINGAMT' => 0, 'TAXAMT' => 0, 'DESC' => $this->subscription_name, 'SOFTDESCRIPTOR' => get_bloginfo('name') . ': ' . $this->subscription_name, 'SOFTDESCRIPTORCITY' => get_bloginfo('admin_email'), 'CUSTOM' => $this->user_id, 'NOTIFYURL' => add_query_arg('listener', 'EIPN', home_url('index.php')), 'EMAIL' => $this->email, 'CREDITCARDTYPE' => '', 'ACCT' => sanitize_text_field($_POST['rcp_card_number']), 'EXPDATE' => sanitize_text_field($_POST['rcp_card_exp_month'] . $_POST['rcp_card_exp_year']), 'CVV2' => sanitize_text_field($_POST['rcp_card_cvc']), 'ZIP' => sanitize_text_field($_POST['rcp_card_zip']), 'BUTTONSOURCE' => 'EasyDigitalDownloads_SP', 'PROFILESTARTDATE' => date('Y-m-d\\Tg:i:s', strtotime('+' . $this->length . ' ' . $this->length_unit, time())), 'BILLINGPERIOD' => ucwords($this->length_unit), 'BILLINGFREQUENCY' => $this->length, 'FAILEDINITAMTACTION' => 'CancelOnFailure', 'TOTALBILLINGCYCLES' => $this->auto_renew ? 0 : 1);
     $request = wp_remote_post($this->api_endpoint, array('timeout' => 45, 'sslverify' => false, 'body' => $args));
     if (is_wp_error($request)) {
         $error = '<p>' . __('An unidentified error occurred.', 'rcp') . '</p>';
         $error .= '<p>' . $request->get_error_message() . '</p>';
         wp_die($error, __('Error', 'rcp'), array('response' => '401'));
     } elseif (200 == $request['response']['code'] && 'OK' == $request['response']['message']) {
         parse_str($request['body'], $data);
         if ('failure' === strtolower($data['ACK'])) {
             $error = '<p>' . __('PayPal subscription creation failed.', 'rcp') . '</p>';
             $error .= '<p>' . __('Error message:', 'rcp') . ' ' . $data['L_LONGMESSAGE0'] . '</p>';
             $error .= '<p>' . __('Error code:', 'rcp') . ' ' . $data['L_ERRORCODE0'] . '</p>';
             wp_die($error, __('Error', 'rcp'), array('response' => '401'));
         } else {
             // Successful signup
             if ('ActiveProfile' === $data['PROFILESTATUS']) {
                 // Confirm a one-time payment
                 $member = new RCP_Member($this->user_id);
                 $member->renew($this->auto_renew);
                 $member->set_payment_profile_id($data['PROFILEID']);
             }
             wp_redirect(esc_url_raw(rcp_get_return_url()));
             exit;
             exit;
         }
     } else {
         wp_die(__('Something has gone wrong, please try again', 'rcp'), __('Error', 'rcp'), array('back_link' => true, 'response' => '401'));
     }
 }
コード例 #2
0
 /**
  * Process registration
  *
  * @since 2.1
  */
 public function process_signup()
 {
     $member = new RCP_Member($this->user_id);
     $member->renew(false, '');
     // setup the payment info in an array for storage
     $payment_data = array('subscription' => $this->subscription_name, 'payment_type' => 'manual', 'subscription_key' => $this->subscription_key, 'amount' => $this->amount + $this->signup_fee, 'user_id' => $this->user_id, 'transaction_id' => $this->generate_transaction_id());
     $rcp_payments = new RCP_Payments();
     $rcp_payments->insert($payment_data);
     wp_redirect($this->return_url);
     exit;
 }
コード例 #3
0
/**
 * Determine if a member is a Stripe subscriber
 *
 * @since       v2.1
 * @access      public
 * @param       $user_id INT the ID of the user to check
 * @return      bool
*/
function rcp_is_stripe_subscriber($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    $ret = false;
    $member = new RCP_Member($user_id);
    $profile_id = $member->get_payment_profile_id();
    // Check if the member is a Stripe customer
    if (false !== strpos($profile_id, 'cus_')) {
        $ret = true;
    }
    return (bool) apply_filters('rcp_is_stripe_subscriber', $ret, $user_id);
}
コード例 #4
0
/**
 * Determine if a member is a PayPal subscriber
 *
 * @since       v2.0
 * @access      public
 * @param       $user_id INT the ID of the user to check
 * @return      bool
*/
function rcp_is_paypal_subscriber($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    $ret = false;
    $member = new RCP_Member($user_id);
    $profile_id = $member->get_payment_profile_id();
    // Check if the member is a PayPal customer
    if (false !== strpos($profile_id, 'I-')) {
        $ret = true;
    } else {
        // The old way of identifying PayPal subscribers
        $ret = (bool) get_user_meta($user_id, 'rcp_paypal_subscriber', true);
    }
    return (bool) apply_filters('rcp_is_paypal_subscriber', $ret, $user_id);
}
コード例 #5
0
 /**
  * Get the data being exported
  *
  * @access      public
  * @since       1.5
  * @return      array
  */
 public function get_data()
 {
     global $wpdb;
     $data = array();
     $subscription = isset($_POST['rcp-subscription']) ? absint($_POST['rcp-subscription']) : null;
     $status = isset($_POST['rcp-status']) ? sanitize_text_field($_POST['rcp-status']) : 'active';
     $offset = isset($_POST['rcp-offset']) ? absint($_POST['rcp-offset']) : null;
     $number = isset($_POST['rcp-number']) ? absint($_POST['rcp-number']) : null;
     $members = rcp_get_members($status, $subscription, $offset, $number);
     if ($members) {
         foreach ($members as $member) {
             $member = new RCP_Member($member->ID);
             $discounts = get_user_meta($member->ID, 'rcp_user_discounts', true);
             if (!empty($discounts) && is_array($discounts) && !$discounts instanceof stdClass) {
                 foreach ($discounts as $key => $code) {
                     if (!is_string($code)) {
                         unset($discounts[$key]);
                     }
                 }
                 $discounts = implode(' ', $discounts);
             }
             $data[] = array('user_id' => $member->ID, 'user_login' => $member->user_login, 'user_email' => $member->user_email, 'first_name' => $member->first_name, 'last_name' => $member->last_name, 'subscription' => $member->get_subscription_id(), 'subscription_key' => $member->get_subscription_key(), 'expiration' => $member->get_expiration_date(), 'status' => $member->get_status(), 'discount_codes' => $discounts, 'profile_id' => $member->get_payment_profile_id(), 'is_recurring' => $member->is_recurring());
         }
     }
     $data = apply_filters('rcp_export_get_data', $data);
     $data = apply_filters('rcp_export_get_data_' . $this->export_type, $data);
     return $data;
 }
 /**
  * Process registration
  *
  * @since 2.1
  */
 public function process_signup()
 {
     $member = new RCP_Member($this->user_id);
     $old_level = get_user_meta($member->ID, '_rcp_old_subscription_id', true);
     if (!empty($old_level) && $old_level == $this->subscription_id) {
         $expiration = $member->calculate_expiration();
     } else {
         delete_user_meta($member->ID, 'rcp_pending_expiration_date');
         $expiration = $member->calculate_expiration(true);
     }
     $member->renew(false, 'pending', $expiration);
     // setup the payment info in an array for storage
     $payment_data = array('subscription' => $this->subscription_name, 'payment_type' => 'manual', 'subscription_key' => $this->subscription_key, 'amount' => $this->amount + $this->signup_fee, 'user_id' => $this->user_id, 'transaction_id' => $this->generate_transaction_id());
     $rcp_payments = new RCP_Payments();
     $rcp_payments->insert($payment_data);
     wp_redirect($this->return_url);
     exit;
 }
コード例 #7
0
/**
 * Prevents the "Cancel your subscription" link from showing
 * until the member has been subscribed to his or her current
 * subscription for 3 months.
 */
function jp_rcp_member_can_cancel($ret, $user_id)
{
    global $rcp_options;
    // Only do this on the Account Page
    if (empty($rcp_options['account_page']) || !is_page($rcp_options['account_page'])) {
        return $ret;
    }
    // Return early if other conditions aren't already met.
    if (!$ret) {
        return false;
    }
    $timezone = get_option('timezone_string');
    $timezone = !empty($timezone) ? $timezone : 'UTC';
    $member = new RCP_Member($user_id);
    $cancel_date = new \DateTime($member->get_joined_date(), new \DateTimeZone($timezone));
    $cancel_date->modify('+3 months');
    // change this if you want a different time period
    $now = new \DateTime('now', new \DateTimeZone($timezone));
    if ($ret && $now < $cancel_date) {
        $ret = false;
    }
    return $ret;
}
 /**
  * Process PayPal IPN
  *
  * @since 2.1
  */
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'IPN') {
         return;
     }
     global $rcp_options;
     nocache_headers();
     if (!class_exists('IpnListener')) {
         // instantiate the IpnListener class
         include RCP_PLUGIN_DIR . 'includes/gateways/paypal/paypal-ipnlistener.php';
     }
     $listener = new IpnListener();
     $verified = false;
     if ($this->test_mode) {
         $listener->use_sandbox = true;
     }
     /*
     if( isset( $rcp_options['ssl'] ) ) {
     	$listener->use_ssl = true;
     } else {
     	$listener->use_ssl = false;
     }
     */
     //To post using the fsockopen() function rather than cURL, use:
     if (isset($rcp_options['disable_curl'])) {
         $listener->use_curl = false;
     }
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         status_header(402);
         //die( 'IPN exception: ' . $e->getMessage() );
     }
     /*
     The processIpn() method returned true if the IPN was "VERIFIED" and false if it
     was "INVALID".
     */
     if ($verified || isset($_POST['verification_override']) || ($this->test_mode || isset($rcp_options['disable_ipn_verify']))) {
         status_header(200);
         $user_id = 0;
         $posted = apply_filters('rcp_ipn_post', $_POST);
         // allow $_POST to be modified
         if (!empty($posted['custom']) && is_numeric($posted['custom'])) {
             $user_id = absint($posted['custom']);
         } else {
             if (!empty($posted['subscr_id'])) {
                 $user_id = rcp_get_member_id_from_profile_id($posted['subscr_id']);
             } else {
                 if (!empty($posted['payer_email'])) {
                     $user = get_user_by('email', $posted['payer_email']);
                     $user_id = $user ? $user->ID : false;
                 }
             }
         }
         $member = new RCP_Member($user_id);
         if (!$member || !$member->get_subscription_id()) {
             die('no member found');
         }
         if (!rcp_get_subscription_details($member->get_subscription_id())) {
             die('no subscription level found');
         }
         $subscription_name = $posted['item_name'];
         $subscription_key = $posted['item_number'];
         $amount = number_format((double) $posted['mc_gross'], 2);
         $amount2 = number_format((double) $posted['mc_amount3'], 2);
         $payment_status = $posted['payment_status'];
         $currency_code = $posted['mc_currency'];
         $subscription_price = number_format((double) rcp_get_subscription_price($member->get_subscription_id()), 2);
         // setup the payment info in an array for storage
         $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'], current_time('timestamp'))), 'subscription' => $posted['item_name'], 'payment_type' => $posted['txn_type'], 'subscription_key' => $subscription_key, 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']);
         do_action('rcp_valid_ipn', $payment_data, $user_id, $posted);
         if ($posted['txn_type'] == 'web_accept' || $posted['txn_type'] == 'subscr_payment') {
             // only check for an existing payment if this is a payment IPD request
             if (rcp_check_for_existing_payment($posted['txn_type'], $posted['payment_date'], $subscription_key)) {
                 $log_data = array('post_title' => __('Duplicate Payment', 'rcp'), 'post_content' => __('A duplicate payment was detected. The new payment was still recorded, so you may want to check into both payments.', 'rcp'), 'post_parent' => 0, 'log_type' => 'gateway_error');
                 $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                 $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                 die('duplicate IPN detected');
             }
             if (strtolower($currency_code) != strtolower($rcp_options['currency'])) {
                 // the currency code is invalid
                 $log_data = array('post_title' => __('Invalid Currency Code', 'rcp'), 'post_content' => sprintf(__('The currency code in an IPN request did not match the site currency code. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error');
                 $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id);
                 $log_entry = WP_Logging::insert_log($log_data, $log_meta);
                 die('invalid currency code');
             }
         }
         if (isset($rcp_options['email_ipn_reports'])) {
             wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport());
         }
         /* now process the kind of subscription/payment */
         $rcp_payments = new RCP_Payments();
         // Subscriptions
         switch ($posted['txn_type']) {
             case "subscr_signup":
                 // when a new user signs up
                 // store the recurring payment ID
                 update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                 $member->set_payment_profile_id($posted['subscr_id']);
                 do_action('rcp_ipn_subscr_signup', $user_id);
                 die('successful subscr_signup');
                 break;
             case "subscr_payment":
                 // when a user makes a recurring payment
                 update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
                 $member->set_payment_profile_id($posted['subscr_id']);
                 $member->renew(true);
                 // record this payment in the database
                 $rcp_payments->insert($payment_data);
                 do_action('rcp_ipn_subscr_payment', $user_id);
                 die('successful subscr_payment');
                 break;
             case "subscr_cancel":
                 // user is marked as cancelled but retains access until end of term
                 $member->set_status('cancelled');
                 // set the use to no longer be recurring
                 delete_user_meta($user_id, 'rcp_paypal_subscriber');
                 do_action('rcp_ipn_subscr_cancel', $user_id);
                 die('successful subscr_cancel');
                 break;
             case "subscr_failed":
                 do_action('rcp_ipn_subscr_failed');
                 die('successful subscr_failed');
                 break;
             case "subscr_eot":
                 // user's subscription has reached the end of its term
                 if ('cancelled' !== $member->get_status($user_id)) {
                     $member->set_status('expired');
                 }
                 do_action('rcp_ipn_subscr_eot', $user_id);
                 die('successful subscr_eot');
                 break;
             case "web_accept":
                 switch (strtolower($payment_status)) {
                     case 'completed':
                         // set this user to active
                         $member->renew();
                         $rcp_payments->insert($payment_data);
                         break;
                     case 'denied':
                     case 'expired':
                     case 'failed':
                     case 'voided':
                         $member->set_status('cancelled');
                         break;
                 }
                 die('successful web_accept');
                 break;
             case "cart":
             case "express_checkout":
             default:
                 break;
         }
     } else {
         if (isset($rcp_options['email_ipn_reports'])) {
             // an invalid IPN attempt was made. Send an email to the admin account to investigate
             wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'rcp'), $listener->getTextReport());
         }
         status_header(400);
         die('invalid IPN');
     }
 }
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtolower($_GET['listener']) != 'stripe') {
         return;
     }
     // Ensure listener URL is not cached by W3TC
     define('DONOTCACHEPAGE', true);
     \Stripe\Stripe::setApiKey($this->secret_key);
     // retrieve the request's body and parse it as JSON
     $body = @file_get_contents('php://input');
     $event_json_id = json_decode($body);
     // for extra security, retrieve from the Stripe API
     if (isset($event_json_id->id)) {
         $rcp_payments = new RCP_Payments();
         $event_id = $event_json_id->id;
         try {
             $event = \Stripe\Event::retrieve($event_id);
             $invoice = $event->data->object;
             if (empty($invoice->customer)) {
                 die('no customer attached');
             }
             // retrieve the customer who made this payment (only for subscriptions)
             $user = rcp_get_member_id_from_profile_id($invoice->customer);
             if (empty($user)) {
                 // Grab the customer ID from the old meta keys
                 global $wpdb;
                 $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_rcp_stripe_user_id' AND meta_value = %s LIMIT 1", $invoice->customer));
             }
             if (empty($user)) {
                 die('no user ID found');
             }
             $member = new RCP_Member($user);
             // check to confirm this is a stripe subscriber
             if ($member) {
                 // successful payment
                 if ($event->type == 'charge.succeeded') {
                     if (!$member->get_subscription_id()) {
                         die('no subscription ID for member');
                     }
                     $payment_data = array('date' => date('Y-m-d g:i:s', $event->created), 'subscription' => $member->get_subscription_name(), 'payment_type' => 'Credit Card', 'subscription_key' => $member->get_subscription_key(), 'amount' => $invoice->amount / 100, 'user_id' => $member->ID, 'transaction_id' => $invoice->id);
                     if (!rcp_check_for_existing_payment($payment_data['payment_type'], $payment_data['date'], $payment_data['subscription_key'])) {
                         // record this payment if it hasn't been recorded yet
                         $rcp_payments->insert($payment_data);
                         $member->renew($member->is_recurring());
                         do_action('rcp_stripe_charge_succeeded', $user, $payment_data);
                         die('rcp_stripe_charge_succeeded action fired successfully');
                     } else {
                         die('duplicate payment found');
                     }
                 }
                 // failed payment
                 if ($event->type == 'charge.failed') {
                     do_action('rcp_stripe_charge_failed', $invoice);
                     die('rcp_stripe_charge_failed action fired successfully');
                 }
                 // Cancelled / failed subscription
                 if ($event->type == 'customer.subscription.deleted') {
                     $member->set_status('cancelled');
                     die('member cancelled successfully');
                 }
                 do_action('rcp_stripe_' . $event->type, $invoice);
             }
         } catch (Exception $e) {
             // something failed
             die('PHP exception: ' . $e->getMessage());
         }
         die('1');
     }
     die('no event ID found');
 }
コード例 #10
0
/**
 * 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);
}
コード例 #11
0
<?php

if (isset($_GET['edit_member'])) {
    $member_id = absint($_GET['edit_member']);
} elseif (isset($_GET['view_member'])) {
    $member_id = absint($_GET['view_member']);
}
$member = new RCP_Member($member_id);
?>
<h2>
	<?php 
_e('Edit Member:', 'rcp');
echo ' ' . $member->display_name;
?>
</h2>
<?php 
if ($switch_to_url = rcp_get_switch_to_url($member->ID)) {
    ?>
	<a href="<?php 
    echo esc_url($switch_to_url);
    ?>
" class="rcp_switch"><?php 
    _e('Switch to User', 'rcp');
    ?>
</a>
<?php 
}
?>
<form id="rcp-edit-member" action="" method="post">
	<table class="form-table">
		<tbody>
コード例 #12
0
<?php

$member = new RCP_Member(get_current_user_id());
?>
<form id="rcp_update_card_form" class="rcp_form" action="" method="POST">

	<?php 
$cards = $member->get_card_details();
?>

	<?php 
if (!empty($cards)) {
    ?>
		<h3><?php 
    _e('Your Cards', 'rcp');
    ?>
</h3>
		<?php 
    foreach ($cards as $card) {
        ?>
			<fieldset class="rcp_current_cards_fieldset">
				<p>
					<span class="rcp_card_details_name"><?php 
        _e('Name:', 'rcp');
        ?>
 <?php 
        echo $card['name'];
        ?>
</span>
					<span class="rcp_card_details_type"><?php 
        _e('Type:', 'rcp');
コード例 #13
0
/**
 * Get the prorate amount for this member
 *
 * @since 2.5
 * @param int $user_id
 *
 * @return int
 */
function rcp_get_member_prorate_credit($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    $member = new RCP_Member($user_id);
    return $member->get_prorate_credit_amount();
}
コード例 #14
0
/**
 * Register a new user
 *
 * @access      public
 * @since       1.0
 */
function rcp_process_registration()
{
    if (isset($_POST["rcp_register_nonce"]) && wp_verify_nonce($_POST['rcp_register_nonce'], 'rcp-register-nonce')) {
        global $rcp_options, $user_ID;
        $full_discount = false;
        $subscription_id = isset($_POST['rcp_level']) ? absint($_POST['rcp_level']) : false;
        $discount = isset($_POST['rcp_discount']) ? sanitize_text_field($_POST['rcp_discount']) : '';
        $discount_valid = false;
        $price = number_format((double) rcp_get_subscription_price($subscription_id), 2);
        $price = str_replace(',', '', $price);
        $base_price = $price;
        // Used for discount calculations later
        $expiration = rcp_get_subscription_length($subscription_id);
        $subscription = rcp_get_subscription_details($subscription_id);
        // 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 (!$subscription_id) {
            // no subscription level was chosen
            rcp_errors()->add('no_level', __('Please choose a subscription level', 'rcp'), 'register');
        }
        if ($subscription_id) {
            if ($price == 0 && $expiration->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)) {
            if (rcp_validate_discount($discount, $subscription_id)) {
                $discount_valid = true;
            } else {
                // the entered discount code is incorrect
                rcp_errors()->add('invalid_discount', __('The discount you entered is invalid', 'rcp'), 'register');
            }
            if ($discount_valid && $price > 0) {
                if (!$user_data['need_new'] && rcp_user_has_used_discount($user_data['id'], $discount) && apply_filters('rcp_discounts_once_per_user', false)) {
                    $discount_valid = false;
                    rcp_errors()->add('discount_already_used', __('You can only use the discount code once', 'rcp'), 'register');
                }
                if ($discount_valid) {
                    $discounts = new RCP_Discounts();
                    $discount_obj = $discounts->get_by('code', $discount);
                    if (is_object($discount_obj)) {
                        // calculate the after-discount price
                        $discounted_price = $discounts->calc_discounted_price($base_price, $discount_obj->amount, $discount_obj->unit);
                        if (0 == $discounted_price) {
                            $full_discount = true;
                        }
                    }
                }
            }
        }
        // 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) || $is_ajax) {
            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')));
        }
        // Setup the member object
        $member = new RCP_Member($user_data['id']);
        if ($user_data['id']) {
            update_user_meta($user_data['id'], '_rcp_new_subscription', '1');
            $subscription_key = rcp_generate_subscription_key();
            if (!rcp_is_active($user_data['id'])) {
                rcp_set_status($user_data['id'], 'pending');
                update_user_meta($user_data['id'], 'rcp_subscription_level', $subscription_id);
                update_user_meta($user_data['id'], 'rcp_subscription_key', $subscription_key);
            } 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);
            }
            // Calculate the expiration date for the member
            $member_expires = $member->calculate_expiration();
            // 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)) {
                    // record the usage of this discount code
                    $discounts->add_to_user($user_data['id'], $discount);
                    // incrase 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) {
                        rcp_set_expiration_date($user_data['id'], $member_expires);
                        rcp_set_status($user_data['id'], 'active');
                        rcp_login_user_in($user_data['id'], $user_data['login']);
                        wp_redirect(rcp_get_return_url($user_data['id']));
                        exit;
                    }
                }
                // Determine auto renew behavior
                if ('3' == rcp_get_auto_renew_behavior() && isset($_POST['rcp_auto_renew'])) {
                    $auto_renew = true;
                } elseif ('1' == rcp_get_auto_renew_behavior()) {
                    $auto_renew = true;
                } else {
                    $auto_renew = false;
                }
                // 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' => !empty($discounted_price) ? $discounted_price : $price, 'discount' => !empty($discounted_price) ? $base_price - $discounted_price : 0, 'discount_code' => $discount, 'fee' => !empty($subscription->fee) ? number_format($subscription->fee, 2) : 0, 'length' => $expiration->duration, 'length_unit' => strtolower($expiration->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_options['currency'], 'auto_renew' => $auto_renew, 'return_url' => $redirect, 'new_user' => $user_data['need_new'], 'post_data' => $_POST);
                // 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
                rcp_set_expiration_date($user_data['id'], $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
                    rcp_set_status($user_data['id'], '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 {
                    // set the user's status to free
                    rcp_set_status($user_data['id'], '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
        }
        // end if new user id
    }
    // end nonce check
}
コード例 #15
0
function rcp_process_data()
{
    if (!is_admin()) {
        return;
    }
    if (!empty($_POST)) {
        /****************************************
         * subscription levels
         ****************************************/
        // add a new subscription level
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-level') {
            if (!current_user_can('rcp_manage_levels')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $levels = new RCP_Levels();
            $add = $levels->insert($_POST);
            if ($add) {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_added';
            } else {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_added';
            }
            wp_safe_redirect($url);
            exit;
        }
        // edit a subscription level
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-subscription') {
            if (!current_user_can('rcp_manage_levels')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $levels = new RCP_Levels();
            $update = $levels->update($_POST['subscription_id'], $_POST);
            if ($update) {
                // clear the cache
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_updated';
            } else {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_updated';
            }
            wp_safe_redirect($url);
            exit;
        }
        // add a subscription for an existing member
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-subscription') {
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            if (isset($_POST['expiration']) && strtotime('NOW') > strtotime($_POST['expiration']) && 'none' !== $_POST['expiration']) {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_not_added';
                header("Location:" . $url);
            } else {
                $levels = new RCP_Levels();
                $user = get_user_by('login', $_POST['user']);
                $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none';
                $level_id = absint($_POST['level']);
                rcp_set_expiration_date($user->ID, $expiration);
                rcp_set_status($user->ID, 'active');
                update_user_meta($user->ID, 'rcp_signup_method', 'manual');
                // Add a role, if needed, to the user
                $subscription = $levels->get_level($level_id);
                update_user_meta($user->ID, 'rcp_subscription_level', $level_id);
                // Add the new user role
                $role = !empty($subscription->role) ? $subscription->role : 'subscriber';
                $user->add_role($role);
                if (isset($_POST['recurring'])) {
                    update_user_meta($user->ID, 'rcp_recurring', 'yes');
                } else {
                    delete_user_meta($user->ID, 'rcp_recurring');
                }
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_added';
                header("Location:" . $url);
            }
        }
        // bulk edit members
        if (isset($_POST['rcp-bulk-action']) && $_POST['rcp-bulk-action']) {
            if (!wp_verify_nonce($_POST['rcp_bulk_edit_nonce'], 'rcp_bulk_edit_nonce')) {
                wp_die(__('Nonce verification failed.', 'rcp'));
            }
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            if (empty($_POST['member-ids'])) {
                wp_die(__('Please select at least one member to edit.', 'rcp'));
            }
            $member_ids = array_map('absint', $_POST['member-ids']);
            $action = !empty($_POST['rcp-bulk-action']) ? sanitize_text_field($_POST['rcp-bulk-action']) : false;
            foreach ($member_ids as $member_id) {
                $member = new RCP_Member($member_id);
                if (!empty($_POST['expiration']) && 'delete' !== $action) {
                    $member->set_expiration_date(date('Y-m-d H:i:s', strtotime($_POST['expiration'])));
                }
                if ($action) {
                    switch ($action) {
                        case 'mark-active':
                            $member->set_status('active');
                            break;
                        case 'mark-expired':
                            $member->set_status('expired');
                            break;
                        case 'mark-cancelled':
                            $member->set_status('cancelled');
                            break;
                        case 'delete':
                            wp_delete_user($member->ID);
                            break;
                    }
                }
            }
            wp_redirect(admin_url('admin.php?page=rcp-members&rcp_message=members_updated'));
            exit;
        }
        // edit a member's subscription
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-member') {
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $levels = new RCP_Levels();
            $user_id = absint($_POST['user']);
            $member = new RCP_Member($user_id);
            $status = sanitize_text_field($_POST['status']);
            $level_id = absint($_POST['level']);
            $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none';
            $expiration = 'none' !== $expiration ? date('Y-m-d 23:59:59', strtotime($_POST['expiration'])) : $expiration;
            if (!empty($_POST['expiration'])) {
                $member->set_expiration_date($expiration);
            }
            if (isset($_POST['level'])) {
                $current_id = rcp_get_subscription_id($user_id);
                $new_level = $levels->get_level($level_id);
                $old_level = $levels->get_level($current_id);
                if ($current_id != $level_id) {
                    update_user_meta($user_id, 'rcp_subscription_level', $level_id);
                    // Remove the old user role
                    $role = !empty($old_level->role) ? $old_level->role : 'subscriber';
                    $member->remove_role($role);
                    // Add the new user role
                    $role = !empty($new_level->role) ? $new_level->role : 'subscriber';
                    $member->add_role($role);
                }
            }
            if (isset($_POST['recurring'])) {
                $member->set_recurring(true);
            } else {
                $member->set_recurring(false);
            }
            if (isset($_POST['trialing'])) {
                update_user_meta($user_id, 'rcp_is_trialing', 'yes');
            } else {
                delete_user_meta($user_id, 'rcp_is_trialing');
            }
            if (isset($_POST['signup_method'])) {
                update_user_meta($user_id, 'rcp_signup_method', $_POST['signup_method']);
            }
            if (isset($_POST['notes'])) {
                update_user_meta($user_id, 'rcp_notes', wp_kses($_POST['notes'], array()));
            }
            if (isset($_POST['status'])) {
                rcp_set_status($user_id, $status);
            }
            if (isset($_POST['payment-profile-id'])) {
                $member->set_payment_profile_id($_POST['payment-profile-id']);
            }
            do_action('rcp_edit_member', $user_id);
            wp_redirect(admin_url('admin.php?page=rcp-members&edit_member=' . $user_id . '&rcp_message=user_updated'));
            exit;
        }
        /****************************************
         * discount codes
         ****************************************/
        // add a new discount code
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-discount') {
            if (!current_user_can('rcp_manage_discounts')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $discounts = new RCP_Discounts();
            // Setup unsanitized data
            $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => 'active', 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']);
            $add = $discounts->insert($data);
            if ($add) {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_added';
            } else {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_not_added';
            }
            wp_safe_redirect($url);
            exit;
        }
        // edit a discount code
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-discount') {
            if (!current_user_can('rcp_manage_discounts')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $discounts = new RCP_Discounts();
            // Setup unsanitized data
            $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => $_POST['status'], 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']);
            $update = $discounts->update($_POST['discount_id'], $data);
            if ($update) {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=1';
            } else {
                $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=0';
            }
            wp_safe_redirect($url);
            exit;
        }
        // add a new manual payment
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-payment') {
            if (!current_user_can('rcp_manage_payments')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $payments = new RCP_Payments();
            $user = get_user_by('login', $_POST['user']);
            if ($user) {
                $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'payment_type' => 'manual', 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status']));
                $add = $payments->insert($data);
            }
            if (!empty($add)) {
                $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => '');
                $cache_key = md5(implode(',', $cache_args));
                delete_transient($cache_key);
                $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_added');
            } else {
                $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_added');
            }
            wp_safe_redirect($url);
            exit;
        }
        // edit a payment
        if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-payment') {
            if (!current_user_can('rcp_manage_payments')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $payments = new RCP_Payments();
            $payment_id = absint($_POST['payment-id']);
            $user = get_user_by('login', $_POST['user']);
            if ($user && $payment_id) {
                $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status']));
                $update = $payments->update($payment_id, $data);
            }
            if (!empty($update)) {
                $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => '');
                $cache_key = md5(implode(',', $cache_args));
                delete_transient($cache_key);
                $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_updated');
            } else {
                $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_updated');
            }
            wp_safe_redirect($url);
            exit;
        }
    }
    /*************************************
     * delete data
     *************************************/
    if (!empty($_GET)) {
        /* member processing */
        if (isset($_GET['revoke_access'])) {
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            rcp_set_status(urldecode(absint($_GET['revoke_access'])), 'cancelled');
        }
        if (isset($_GET['activate_member'])) {
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            rcp_set_status(urldecode(absint($_GET['activate_member'])), 'active');
        }
        if (isset($_GET['cancel_member'])) {
            if (!current_user_can('rcp_manage_members')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            rcp_cancel_member_payment_profile(urldecode(absint($_GET['cancel_member'])));
            wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'member_cancelled', 'admin.php?page=rcp-members')));
            exit;
        }
        /* subscription processing */
        if (isset($_GET['delete_subscription']) && $_GET['delete_subscription'] > 0) {
            if (!current_user_can('rcp_manage_levels')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $members_of_subscription = rcp_get_members_of_subscription(absint($_GET['delete_subscription']));
            // cancel all active members of this subscription
            if ($members_of_subscription) {
                foreach ($members_of_subscription as $member) {
                    rcp_set_status($member, 'cancelled');
                }
            }
            $levels = new RCP_Levels();
            $levels->remove($_GET['delete_subscription']);
        }
        if (isset($_GET['activate_subscription']) && $_GET['activate_subscription'] > 0) {
            if (!current_user_can('rcp_manage_levels')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $levels = new RCP_Levels();
            $update = $levels->update(absint($_GET['activate_subscription']), array('status' => 'active'));
            delete_transient('rcp_subscription_levels');
        }
        if (isset($_GET['deactivate_subscription']) && $_GET['deactivate_subscription'] > 0) {
            if (!current_user_can('rcp_manage_levels')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $levels = new RCP_Levels();
            $update = $levels->update(absint($_GET['deactivate_subscription']), array('status' => 'inactive'));
            delete_transient('rcp_subscription_levels');
        }
        /* discount processing */
        if (!empty($_GET['delete_discount'])) {
            if (!current_user_can('rcp_manage_discounts')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $discounts = new RCP_Discounts();
            $discounts->delete($_GET['delete_discount']);
        }
        if (!empty($_GET['activate_discount'])) {
            if (!current_user_can('rcp_manage_discounts')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $discounts = new RCP_Discounts();
            $discounts->update($_GET['activate_discount'], array('status' => 'active'));
        }
        if (!empty($_GET['deactivate_discount'])) {
            if (!current_user_can('rcp_manage_discounts')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $discounts = new RCP_Discounts();
            $discounts->update($_GET['deactivate_discount'], array('status' => 'disabled'));
        }
        if (!empty($_GET['rcp-action']) && $_GET['rcp-action'] == 'delete_payment' && wp_verify_nonce($_GET['_wpnonce'], 'rcp_delete_payment_nonce')) {
            if (!current_user_can('rcp_manage_payments')) {
                wp_die(__('You do not have permission to perform this action.', 'rcp'));
            }
            $payments = new RCP_Payments();
            $payments->delete(absint($_GET['payment_id']));
            wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'payment_deleted', 'admin.php?page=rcp-payments')));
            exit;
        }
    }
}
コード例 #16
0
<?php

if (isset($_GET['edit_member'])) {
    $member_id = absint($_GET['edit_member']);
} elseif (isset($_GET['view_member'])) {
    $member_id = absint($_GET['view_member']);
}
$member = new RCP_Member($member_id);
?>
<h2>
	<?php 
_e('Edit Member:', 'rcp');
echo ' ' . $member->display_name;
?>
 - 
	<a href="<?php 
echo admin_url('/admin.php?page=rcp-members');
?>
" class="button-secondary">
		<?php 
_e('Cancel', 'rcp');
?>
	</a>
</h2>
<?php 
if ($switch_to_url = rcp_get_switch_to_url($member->ID)) {
    ?>
	<a href="<?php 
    echo esc_url($switch_to_url);
    ?>
" class="rcp_switch"><?php 
コード例 #17
0
function rcp_members_page()
{
    global $rcp_options, $rcp_db_name, $wpdb;
    $current_page = admin_url('/admin.php?page=rcp-members');
    ?>
	<div class="wrap" id="rcp-members-page">

		<?php 
    if (isset($_GET['edit_member']) || isset($_GET['view_member'])) {
        include 'edit-member.php';
    } else {
        ?>
			<h2><?php 
        _e(' Paid Subscribers', 'rcp');
        ?>
</h2>
			<?php 
        $subscription_id = isset($_GET['subscription']) && $_GET['subscription'] != 'all' ? urldecode($_GET['subscription']) : null;
        $status = !empty($_GET['status']) ? urldecode($_GET['status']) : 'active';
        $order = !empty($_GET['order']) ? urldecode($_GET['order']) : 'DESC';
        $search = !empty($_GET['s']) ? urldecode($_GET['s']) : '';
        $base_url = admin_url('admin.php?page=rcp-members');
        if ($search) {
            $base_url = add_query_arg('s', $search, $base_url);
        }
        // Get subscriber count
        if (!empty($search) || !empty($subscription_id)) {
            // Query counts
            $active_count = rcp_count_members($subscription_id, 'active', null, $search);
            $pending_count = rcp_count_members($subscription_id, 'pending', null, $search);
            $expired_count = rcp_count_members($subscription_id, 'expired', null, $search);
            $cancelled_count = rcp_count_members($subscription_id, 'cancelled', null, $search);
            $free_count = rcp_count_members($subscription_id, 'free', null, $search);
            $current_count = rcp_count_members($subscription_id, $status, null, $search);
        } else {
            // Retrieve static counts
            $active_count = rcp_get_member_count('active');
            $pending_count = rcp_get_member_count('pending');
            $expired_count = rcp_get_member_count('expired');
            $cancelled_count = rcp_get_member_count('cancelled');
            $free_count = rcp_get_member_count('free');
            $current_count = rcp_get_member_count($status);
        }
        // pagination variables
        $page = isset($_GET['p']) ? absint($_GET['p']) : 1;
        $user = get_current_user_id();
        $screen = get_current_screen();
        $screen_option = $screen->get_option('per_page', 'option');
        $per_page = get_user_meta($user, $screen_option, true);
        if (empty($per_page) || $per_page < 1) {
            $per_page = $screen->get_option('per_page', 'default');
        }
        $total_pages = 1;
        $offset = $per_page * ($page - 1);
        $total_pages = ceil($current_count / $per_page);
        ?>
			<ul class="subsubsub">
				<li><?php 
        _e('Status: ', 'rcp');
        ?>
</li>
				<li>
					<a href="<?php 
        echo esc_url(add_query_arg('status', 'active', $base_url));
        ?>
" title="<?php 
        _e('View all active subscribers', 'rcp');
        ?>
" <?php 
        echo isset($_GET['status']) && $_GET['status'] == 'active' || !isset($_GET['status']) ? 'class="current"' : '';
        ?>
>
					<?php 
        _e('Active', 'rcp');
        ?>
					</a>(<?php 
        echo $active_count;
        ?>
)
				</li>
				<li>
					<a href="<?php 
        echo esc_url(add_query_arg('status', 'pending', $base_url));
        ?>
" title="<?php 
        _e('View all pending subscribers', 'rcp');
        ?>
" <?php 
        echo isset($_GET['status']) && $_GET['status'] == 'pending' ? 'class="current"' : '';
        ?>
>
						<?php 
        _e('Pending', 'rcp');
        ?>
					</a>(<?php 
        echo $pending_count;
        ?>
)
				</li>
				<li>
					<a href="<?php 
        echo esc_url(add_query_arg('status', 'expired', $base_url));
        ?>
" title="<?php 
        _e('View all expired subscribers', 'rcp');
        ?>
" <?php 
        echo isset($_GET['status']) && $_GET['status'] == 'expired' ? 'class="current"' : '';
        ?>
>
						<?php 
        _e('Expired', 'rcp');
        ?>
					</a>(<?php 
        echo $expired_count;
        ?>
)
				</li>
				<li>
					<a href="<?php 
        echo esc_url(add_query_arg('status', 'cancelled', $base_url));
        ?>
" title="<?php 
        _e('View all cancelled subscribers', 'rcp');
        ?>
" <?php 
        echo isset($_GET['status']) && $_GET['status'] == 'cancelled' ? 'class="current"' : '';
        ?>
>
						<?php 
        _e('Cancelled', 'rcp');
        ?>
					</a>(<?php 
        echo $cancelled_count;
        ?>
)
				</li>
				<li>
					<a href="<?php 
        echo esc_url(add_query_arg('status', 'free', $base_url));
        ?>
" title="<?php 
        _e('View all free members', 'rcp');
        ?>
" <?php 
        echo isset($_GET['status']) && $_GET['status'] == 'free' ? 'class="current"' : '';
        ?>
>
						<?php 
        _e('Free', 'rcp');
        ?>
					</a>(<?php 
        echo $free_count;
        ?>
)
				</li>
				<?php 
        do_action('rcp_members_page_statuses');
        ?>
			</ul>
			<form id="rcp-member-search" method="get" action="<?php 
        menu_page_url('rcp-members');
        ?>
">
				<label class="screen-reader-text" for="rcp-member-search-input"><?php 
        _e('Search Members', 'rcp');
        ?>
</label>
				<input type="search" id="rcp-member-search-input" name="s" value="<?php 
        echo esc_attr($search);
        ?>
"/>
				<input type="hidden" name="page" value="rcp-members"/>
				<input type="hidden" name="status" value="<?php 
        echo esc_attr($status);
        ?>
"/>
				<input type="submit" name="" id="rcp-member-search-submit" class="button" value="<?php 
        _e('Search members', 'rcp');
        ?>
"/>
			</form>
			<form id="members-filter" action="" method="get">
				<?php 
        $levels = rcp_get_subscription_levels('all');
        if ($levels) {
            ?>
					<select name="subscription" id="rcp-subscription">
						<option value="all"><?php 
            _e('All Subscriptions', 'rcp');
            ?>
</option>
						<?php 
            foreach ($levels as $level) {
                echo '<option value="' . $level->id . '" ' . selected($subscription_id, $level->id, false) . '>' . $level->name . '</option>';
            }
            ?>
					</select>
				<?php 
        }
        ?>
				<select name="order" id="rcp-order">
					<option value="DESC" <?php 
        selected($order, 'DESC');
        ?>
><?php 
        _e('Newest First', 'rcp');
        ?>
</option>
					<option value="ASC" <?php 
        selected($order, 'ASC');
        ?>
><?php 
        _e('Oldest First', 'rcp');
        ?>
</option>
				</select>
				<input type="hidden" name="page" value="rcp-members"/>
				<input type="hidden" name="status" value="<?php 
        echo isset($_GET['status']) ? $_GET['status'] : 'active';
        ?>
"/>
				<input type="submit" class="button-secondary" value="<?php 
        _e('Filter', 'rcp');
        ?>
"/>
			</form>
			<?php 
        do_action('rcp_members_above_table');
        ?>
			<form id="rcp-members-form" action="<?php 
        echo esc_attr(admin_url('admin.php?page=rcp-members'));
        ?>
" method="post">
				<div id="rcp-bulk-action-options" class="tablenav top">
					<label for="rcp-bulk-member-action" class="screen-reader-text"><?php 
        _e('Select bulk action', 'rcp');
        ?>
</label>
					<select name="rcp-bulk-action" id="rcp-bulk-member-action">
						<option value="-1"><?php 
        _e('Bulk Actions', 'rcp');
        ?>
</option>
						<option value="mark-active"><?php 
        _e('Mark as Active', 'rcp');
        ?>
</option>
						<option value="mark-expired"><?php 
        _e('Mark as Expired', 'rcp');
        ?>
</option>
						<option value="mark-cancelled"><?php 
        _e('Revoke Access', 'rcp');
        ?>
</option>
					</select>
					<input type="text" class="rcp-datepicker" name="expiration" placeholder="<?php 
        esc_attr_e('New Expiration Date', 'rcp');
        ?>
" id="rcp-bulk-expiration" value=""/>
					<input type="submit" id="rcp-submit-bulk-action" class="button action" value="<?php 
        _e('Apply', 'rcp');
        ?>
"/>
				</div>
				<?php 
        wp_nonce_field('rcp_bulk_edit_nonce', 'rcp_bulk_edit_nonce');
        ?>
				<table class="wp-list-table widefat">
					<thead>
						<tr>
							<td id="cb" class="manage-column column-cb check-column">
								<label class="screen-reader-text" for="cb-select-all-1"><?php 
        _e('Select All', 'rcp');
        ?>
</label>
								<input id="cb-select-all-1" type="checkbox">
							</td>
							<th scope="col" class="rcp-user-col manage-column column-primary"><?php 
        _e('User', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-sub-col manage-column"><?php 
        _e('Subscription', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-status-col manage-column"><?php 
        _e('Status', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-recurring-col manage-column"><?php 
        _e('Recurring', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-expiration-col manage-column"><?php 
        _e('Expiration', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-role-col manage-column"><?php 
        _e('User Role', 'rcp');
        ?>
</th>
							<?php 
        do_action('rcp_members_page_table_header');
        ?>
						</tr>
					</thead>
					<tbody id="the-list">
					<?php 
        if (isset($_GET['signup_method'])) {
            $method = $_GET['signup_method'] == 'live' ? 'live' : 'manual';
            $members = get_users(array('meta_key' => 'rcp_signup_method', 'meta_value' => $method, 'number' => 999999));
            $per_page = 999999;
        } else {
            $members = rcp_get_members($status, $subscription_id, $offset, $per_page, $order, null, $search);
        }
        if ($members) {
            $i = 1;
            foreach ($members as $key => $member) {
                $rcp_member = new RCP_Member($member->ID);
                // Show pending expiration date for members with a pending status. See https://github.com/restrictcontentpro/restrict-content-pro/issues/708.
                if ('pending' === $status) {
                    $expiration = $rcp_member->get_expiration_date(true, true);
                } else {
                    $expiration = $rcp_member->get_expiration_date(true, false);
                }
                ?>
							<tr class="rcp_row <?php 
                do_action('rcp_member_row_class', $member);
                if (rcp_is_odd($i)) {
                    echo ' alternate';
                }
                ?>
">
								<th scope="row" class="check-column">
									<input type="checkbox" class="rcp-member-cb" name="member-ids[]" value="<?php 
                echo absint($member->ID);
                ?>
"/>
								</th>
								<td class="has-row-actions column-primary" data-colname="<?php 
                _e('User', 'rcp');
                ?>
">
									<strong>
										<a href="<?php 
                echo esc_url(add_query_arg('edit_member', $member->ID, $current_page));
                ?>
" title="<?php 
                _e('Edit Member', 'rcp');
                ?>
"><?php 
                echo $member->user_login;
                ?>
</a>
										<?php 
                if ($member->user_login != $member->user_email) {
                    ?>
											<?php 
                    echo '&nbsp;&ndash;&nbsp;' . $member->user_email;
                    ?>
										<?php 
                }
                ?>
									</strong>
									<?php 
                if (current_user_can('rcp_manage_members')) {
                    ?>
										<div class="row-actions">
											<span class="edit">
												<a href="<?php 
                    echo esc_url(add_query_arg('edit_member', $member->ID, $current_page));
                    ?>
"><?php 
                    _e('Edit Member', 'rcp');
                    ?>
</a>
												<span class="rcp-separator"> | </span>
												<a href="<?php 
                    echo esc_url(add_query_arg('user_id', $member->ID, admin_url('user-edit.php')));
                    ?>
" title="<?php 
                    _e('View User\'s Profile', 'rcp');
                    ?>
"><?php 
                    _e('Edit User Account', 'rcp');
                    ?>
</a>
											</span>
											<?php 
                    if (rcp_can_member_cancel($member->ID)) {
                        ?>
												<span> | <a href="<?php 
                        echo wp_nonce_url(add_query_arg('cancel_member', $member->ID, $current_page), 'rcp-cancel-nonce');
                        ?>
" class="trash rcp_cancel"><?php 
                        _e('Cancel', 'rcp');
                        ?>
</a></span>
											<?php 
                    }
                    ?>
											<?php 
                    if ($switch_to_url = rcp_get_switch_to_url($member->ID)) {
                        ?>
												<span> | <a href="<?php 
                        echo esc_url($switch_to_url);
                        ?>
" class="rcp_switch"><?php 
                        _e('Switch to User', 'rcp');
                        ?>
</a></span>
											<?php 
                    }
                    ?>
											<span class="rcp-separator"> | </span>
											<span class="id rcp-member-id"><?php 
                    echo __('ID:', 'rcp') . ' ' . $member->ID;
                    ?>
</span>
											<?php 
                    do_action('rcp_member_row_actions', $member->ID);
                    ?>
										</div>
									<?php 
                }
                ?>
									<button type="button" class="toggle-row"><span class="screen-reader-text"><?php 
                _e('Show more details', 'rcp');
                ?>
</span></button>
								</td>
								<td data-colname="<?php 
                _e('Subscription', 'rcp');
                ?>
"><?php 
                echo rcp_get_subscription($member->ID);
                ?>
</td>
								<td data-colname="<?php 
                _e('Status', 'rcp');
                ?>
"><?php 
                echo rcp_print_status($member->ID, false);
                ?>
</td>
								<td data-colname="<?php 
                _e('Recurring', 'rcp');
                ?>
"><?php 
                echo rcp_is_recurring($member->ID) ? __('yes', 'rcp') : __('no', 'rcp');
                ?>
</td>
								<td data-colname="<?php 
                _e('Expiration', 'rcp');
                ?>
"><?php 
                echo $expiration;
                ?>
</td>
								<td data-colname="<?php 
                _e('User Role', 'rcp');
                ?>
"><?php 
                echo rcp_get_user_role($member->ID);
                ?>
</td>
								<?php 
                do_action('rcp_members_page_table_column', $member->ID);
                ?>
							</tr>
						<?php 
                $i++;
            }
        } else {
            ?>
						<tr><td colspan="6"><?php 
            _e('No subscribers found', 'rcp');
            ?>
</td></tr>
					<?php 
        }
        ?>
					</tbody>
					<tfoot>
						<tr>
							<td id="cb" class="manage-column column-cb check-column">
								<label class="screen-reader-text" for="cb-select-all-1"><?php 
        _e('Select All', 'rcp');
        ?>
</label>
								<input id="cb-select-all-1" type="checkbox">
							</td>
							<th scope="col" class="rcp-user-col manage-column column-primary"><?php 
        _e('User', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-sub-col manage-column"><?php 
        _e('Subscription', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-status-col manage-column"><?php 
        _e('Status', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-recurring-col manage-column"><?php 
        _e('Recurring', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-expiration-col manage-column"><?php 
        _e('Expiration', 'rcp');
        ?>
</th>
							<th scope="col" class="rcp-role-col manage-column"><?php 
        _e('User Role', 'rcp');
        ?>
</th>
							<?php 
        do_action('rcp_members_page_table_footer');
        ?>
						</tr>
					</tfoot>
				</table>
			</form>
			<?php 
        if ($total_pages > 1 && !isset($_GET['signup_method'])) {
            ?>
				<div class="tablenav bottom">
					<div class="tablenav-pages alignright">
						<?php 
            $query_string = $_SERVER['QUERY_STRING'];
            $base = 'admin.php?' . remove_query_arg('p', $query_string) . '%_%';
            echo paginate_links(array('base' => $base, 'format' => '&p=%#%', 'prev_text' => __('&laquo; Previous', 'rcp'), 'next_text' => __('Next &raquo;', 'rcp'), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5));
            ?>
					</div>
				</div><!--end .tablenav-->
			<?php 
        }
        ?>
			<?php 
        do_action('rcp_members_below_table');
        ?>
			<h3>
				<?php 
        _e('Add New Subscription (for existing user)', 'rcp');
        ?>
				<span alt="f223" class="rcp-help-tip dashicons dashicons-editor-help" title="<?php 
        _e('If you wish to create a brand new account, that may be done from Users &rarr; Add New. <br/><strong>Note</strong>: this will not create a payment profile for the member. That must be done manually through your merchant account.', 'rcp');
        ?>
"></span>
			</h3>
			<form id="rcp-add-new-member" action="" method="post">
				<table class="form-table">
					<tbody>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="rcp-username"><?php 
        _e('Username', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input type="text" name="user" id="rcp-user" autocomplete="off" class="regular-text rcp-user-search" style="width: 120px;"/>
								<img class="rcp-ajax waiting" src="<?php 
        echo admin_url('images/wpspin_light.gif');
        ?>
" style="display: none;"/>
								<div id="rcp_user_search_results"></div>
								<p class="description"><?php 
        _e('Begin typing the user name to add a subscription to.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="rcp-level"><?php 
        _e('Subscription Level', 'rcp');
        ?>
</label>
							</th>
							<td>
								<select name="level" id="rcp-level">
									<option value="choose"><?php 
        _e('--choose--', 'rcp');
        ?>
</option>
									<?php 
        foreach (rcp_get_subscription_levels() as $level) {
            echo '<option value="' . $level->id . '">' . $level->name . '</option>';
        }
        ?>
								</select>
								<span alt="f223" class="rcp-help-tip dashicons dashicons-editor-help" title="<?php 
        _e('The subscription level determines the content the member has access to. <strong>Note</strong>: adding a subscription level to a member will not create a payment profile in your merchant account.', 'rcp');
        ?>
"></span>
								<p class="description"><?php 
        _e('Choose the subscription level for this user.', 'rcp');
        ?>
</p>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="rcp-expiration"><?php 
        _e('Expiration date', 'rcp');
        ?>
</label>
							</th>
							<td>
								<input name="expiration" id="rcp-expiration" type="text" style="width: 120px;" class="rcp-datepicker"/>
								<label for="rcp-unlimited">
									<input name="unlimited" id="rcp-unlimited" type="checkbox"/>
									<span class="description"><?php 
        _e('Never expires?', 'rcp');
        ?>
</span>
								</label>
								<p class="description"><?php 
        _e('Enter the expiration date for this user in the format of yyyy-mm-dd', 'rcp');
        ?>
</p>
							</td>
						</tr>
					</tbody>
				</table>
				<p class="submit">
					<input type="hidden" name="rcp-action" value="add-subscription"/>
					<input type="submit" value="<?php 
        _e('Add User Subscription', 'rcp');
        ?>
" class="button-primary"/>
				</p>
				<?php 
        wp_nonce_field('rcp_add_member_nonce', 'rcp_add_member_nonce');
        ?>
			</form>

		<?php 
    }
    ?>

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

	<?php 
}
コード例 #18
0
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtolower($_GET['listener']) != 'stripe') {
         return;
     }
     // Ensure listener URL is not cached by W3TC
     if (!defined('DONOTCACHEPAGE')) {
         define('DONOTCACHEPAGE', true);
     }
     \Stripe\Stripe::setApiKey($this->secret_key);
     // retrieve the request's body and parse it as JSON
     $body = @file_get_contents('php://input');
     $event_json_id = json_decode($body);
     $expiration = '';
     // for extra security, retrieve from the Stripe API
     if (isset($event_json_id->id)) {
         $rcp_payments = new RCP_Payments();
         $event_id = $event_json_id->id;
         try {
             $event = \Stripe\Event::retrieve($event_id);
             $payment_event = $event->data->object;
             if (empty($payment_event->customer)) {
                 die('no customer attached');
             }
             // retrieve the customer who made this payment (only for subscriptions)
             $user = rcp_get_member_id_from_profile_id($payment_event->customer);
             if (empty($user)) {
                 // Grab the customer ID from the old meta keys
                 global $wpdb;
                 $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_rcp_stripe_user_id' AND meta_value = %s LIMIT 1", $payment_event->customer));
             }
             if (empty($user)) {
                 die('no user ID found');
             }
             $member = new RCP_Member($user);
             // check to confirm this is a stripe subscriber
             if ($member) {
                 if (!$member->get_subscription_id()) {
                     die('no subscription ID for member');
                 }
                 if ($event->type == 'charge.succeeded' || $event->type == 'invoice.payment_succeeded') {
                     // setup payment data
                     $payment_data = array('date' => date_i18n('Y-m-d g:i:s', $event->created), 'payment_type' => 'Credit Card', 'user_id' => $member->ID, 'amount' => '', 'transaction_id' => '');
                     if ($event->type == 'charge.succeeded') {
                         // Successful one-time payment
                         if (empty($payment_event->invoice)) {
                             $payment_data['amount'] = $payment_event->amount / rcp_stripe_get_currency_multiplier();
                             $payment_data['transaction_id'] = $payment_event->id;
                             // Successful subscription payment
                         } else {
                             $invoice = \Stripe\Invoice::retrieve($payment_event->invoice);
                             $payment_data['amount'] = $invoice->amount_due / rcp_stripe_get_currency_multiplier();
                             $payment_data['transaction_id'] = $payment_event->id;
                         }
                         // Successful subscription paid made with account credit where no charge is created
                     } elseif ($event->type == 'invoice.payment_succeeded' && empty($payment_event->charge)) {
                         $payment_data['amount'] = $payment_event->amount_due / rcp_stripe_get_currency_multiplier();
                         $payment_data['transaction_id'] = $payment_event->id;
                         $invoice = $payment_event;
                     }
                     if (!empty($payment_data['transaction_id']) && !$rcp_payments->payment_exists($payment_data['transaction_id'])) {
                         if (!empty($invoice->subscription)) {
                             $customer = \Stripe\Customer::retrieve($member->get_payment_profile_id());
                             $subscription = $customer->subscriptions->retrieve($invoice->subscription);
                             if (!empty($subscription)) {
                                 $expiration = date('Y-m-d 23:59:59', $subscription->current_period_end);
                                 $member->set_recurring();
                             }
                             $member->set_merchant_subscription_id($subscription->id);
                         }
                         $member->renew($member->is_recurring(), 'active', $expiration);
                         // These must be retrieved after the status is set to active in order for upgrades to work properly
                         $payment_data['subscription'] = $member->get_subscription_name();
                         $payment_data['subscription_key'] = $member->get_subscription_key();
                         // record this payment if it hasn't been recorded yet
                         $rcp_payments->insert($payment_data);
                         do_action('rcp_stripe_charge_succeeded', $user, $payment_data);
                         die('rcp_stripe_charge_succeeded action fired successfully');
                     } else {
                         die('duplicate payment found');
                     }
                 }
                 // failed payment
                 if ($event->type == 'charge.failed') {
                     do_action('rcp_stripe_charge_failed', $invoice);
                     die('rcp_stripe_charge_failed action fired successfully');
                 }
                 // Cancelled / failed subscription
                 if ($event->type == 'customer.subscription.deleted') {
                     if (!$member->just_upgraded()) {
                         $member->set_status('cancelled');
                         die('member cancelled successfully');
                     }
                 }
                 do_action('rcp_stripe_' . $event->type, $payment_event);
             }
         } catch (Exception $e) {
             // something failed
             die('PHP exception: ' . $e->getMessage());
         }
         die('1');
     }
     die('no event ID found');
 }
コード例 #19
0
 public function renew_member($recurring = false, $status = 'active')
 {
     $member = new RCP_Member($this->user_id);
     $member->renew($recurring, $status);
 }
 /**
  * Proccess webhooks
  *
  * @since 2.3
  */
 public function process_webhooks()
 {
     if (isset($_GET['listener']) && $_GET['listener'] == '2checkout') {
         global $wpdb;
         $hash = strtoupper(md5($_POST['sale_id'] . $this->seller_id . $_POST['invoice_id'] . $this->secret_word));
         if (!hash_equals($hash, $_POST['md5_hash'])) {
             die('-1');
         }
         if (empty($_POST['message_type'])) {
             die('-2');
         }
         if (empty($_POST['vendor_id'])) {
             die('-3');
         }
         $subscription_key = sanitize_text_field($_POST['vendor_order_id']);
         $member_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'rcp_subscription_key' AND meta_value = %s LIMIT 1", $subscription_key));
         if (!$member_id) {
             die('-4');
         }
         $member = new RCP_Member($member_id);
         if (!rcp_is_2checkout_subscriber($member->ID)) {
             return;
         }
         $payments = new RCP_Payments();
         switch (strtoupper($_POST['message_type'])) {
             case 'ORDER_CREATED':
                 break;
             case 'REFUND_ISSUED':
                 $payment = $payments->get_payment_by('transaction_id', $_POST['invoice_id']);
                 $payments->update($payment->id, array('status' => 'refunded'));
                 if (!empty($_POST['recurring'])) {
                     $member->cancel();
                     $member->add_note(__('Subscription cancelled via refund 2Checkout', 'rcp'));
                 }
                 break;
             case 'RECURRING_INSTALLMENT_SUCCESS':
                 $payment_data = array('date' => date('Y-m-d H:i:s', strtotime($_POST['timestamp'], current_time('timestamp'))), 'subscription' => $member->get_subscription_name(), 'payment_type' => sanitize_text_field($_POST['payment_type']), 'subscription_key' => $subscription_key, 'amount' => sanitize_text_field($_POST['item_list_amount_1']), 'user_id' => $member->ID, 'transaction_id' => sanitize_text_field($_POST['invoice_id']));
                 $recurring = !empty($_POST['recurring']);
                 $member->renew($recurring);
                 $payments->insert($payment_data);
                 $member->add_note(__('Subscription renewed in 2Checkout', 'rcp'));
                 break;
             case 'RECURRING_INSTALLMENT_FAILED':
                 break;
             case 'RECURRING_STOPPED':
                 if (!$member->just_upgraded()) {
                     $member->cancel();
                     $member->add_note(__('Subscription cancelled in 2Checkout', 'rcp'));
                 }
                 break;
             case 'RECURRING_COMPLETE':
                 break;
             case 'RECURRING_RESTARTED':
                 $member->set_status('active');
                 $member->add_note(__('Subscription restarted in 2Checkout', 'rcp'));
                 break;
             case 'FRAUD_STATUS_CHANGED':
                 switch ($_POST['fraud_status']) {
                     case 'pass':
                         break;
                     case 'fail':
                         $member->set_status('pending');
                         $member->add_note(__('Payment flagged as fraudulent in 2Checkout', 'rcp'));
                         break;
                     case 'wait':
                         break;
                 }
                 break;
         }
         do_action('rcp_2co_' . strtolower($_POST['message_type']) . '_ins', $member);
         die('success');
     }
 }
コード例 #21
0
/**
 * 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)) {
                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_options['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
}
コード例 #22
0
/**
 * Wrapper for RCP_Member->get_switch_to_url()
 *
 * @access public
 * @since 2.1
 */
function rcp_get_switch_to_url( $user_id = 0 ) {

	if( empty( $user_id ) ) {
		return;
	}

	$member = new RCP_Member( $user_id );
	return $member->get_switch_to_url();

}
 /**
  * Process PayPal IPN
  *
  * @since 2.1
  */
 public function process_webhooks()
 {
     if (!isset($_GET['listener']) || strtoupper($_GET['listener']) != 'EIPN') {
         return;
     }
     $posted = apply_filters('rcp_ipn_post', $_POST);
     // allow $_POST to be modified
     $user_id = absint($posted['custom']);
     $member = new RCP_Member($user_id);
     if (!$member || !$member->get_subscription_id()) {
         die('no member found');
     }
     if (!rcp_get_subscription_details($member->get_subscription_id())) {
         die('no subscription level found');
     }
     $amount = number_format((double) $posted['mc_gross'], 2);
     // setup the payment info in an array for storage
     $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'])), 'subscription' => $member->get_subscription_name(), 'payment_type' => $posted['txn_type'], 'subscription_key' => $member->get_subscription_key(), 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']);
     do_action('rcp_valid_ipn', $payment_data, $user_id, $posted);
     if (isset($rcp_options['email_ipn_reports'])) {
         wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport());
     }
     /* now process the kind of subscription/payment */
     $rcp_payments = new RCP_Payments();
     // Subscriptions
     switch ($posted['txn_type']) {
         case "recurring_payment":
             // when a user makes a recurring payment
             // record this payment in the database
             $rcp_payments->insert($payment_data);
             update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']);
             $member->set_payment_profile_id($posted['recurring_payment_id']);
             $this->renew_member(true);
             do_action('rcp_ipn_subscr_payment', $user_id);
             die('successful recurring_payment');
             break;
         case "recurring_payment_profile_cancel":
             // user is marked as cancelled but retains access until end of term
             $member->set_status('cancelled');
             // set the use to no longer be recurring
             delete_user_meta($user_id, 'rcp_paypal_subscriber');
             do_action('rcp_ipn_subscr_cancel', $user_id);
             die('successful recurring_payment_profile_cancel');
             break;
         case "recurring_payment_failed":
         case "recurring_payment_suspended_due_to_max_failed_payment":
             if ('cancelled' !== $member->get_status($user_id)) {
                 $member->set_status('expired');
             }
             do_action('rcp_ipn_subscr_failed');
             die('successful recurring_payment_failed or recurring_payment_suspended_due_to_max_failed_payment');
             break;
     }
 }
コード例 #24
0
ファイル: page-list.php プロジェクト: CmdTab/primemovers
													<svg class="icon icon-sort-asc"><use xlink:href="#icon-sort-asc"></use></svg>
													<svg class="icon icon-sort-desc"><use xlink:href="#icon-sort-desc"></use></svg>
												</div>
											</td>
											<th class="holy-ambition">
												<div>
													Holy Ambition
												</div>
											</td>
										</tr>
									</thead>
									<tbody>
										<?php 
        $members = get_users();
        foreach ($members as $member) {
            $sub = new RCP_Member($member->ID);
            $status = $sub->get_status();
            if ($status == 'active') {
                if (get_user_meta($member->ID, 'rcp_ambition', true) == 1) {
                    ?>
											<tr class="users">
												<td class="last-name"><?php 
                    echo get_user_meta($member->ID, 'last_name', true);
                    ?>
</td>
												<td class="first-name"><?php 
                    echo get_user_meta($member->ID, 'first_name', true);
                    ?>
</td>
												<td class="email"><?php 
                    echo get_userdata($member->ID)->user_email;
 public function get_checkout_details($token = '')
 {
     $args = array('USER' => $this->username, 'PWD' => $this->password, 'SIGNATURE' => $this->signature, 'VERSION' => '124', 'METHOD' => 'GetExpressCheckoutDetails', 'TOKEN' => $token);
     $request = wp_remote_get(add_query_arg($args, $this->api_endpoint), array('timeout' => 45, 'sslverify' => false, 'httpversion' => '1.1'));
     $body = wp_remote_retrieve_body($request);
     $code = wp_remote_retrieve_response_code($request);
     $message = wp_remote_retrieve_response_message($request);
     if (is_wp_error($request)) {
         return $request;
     } elseif (200 == $code && 'OK' == $message) {
         if (is_string($body)) {
             wp_parse_str($body, $body);
         }
         $member = new RCP_Member(absint($_GET['user_id']));
         $subscription_id = $member->get_pending_subscription_id();
         if (empty($subscription_id)) {
             $subscription_id = $member->get_subscription_id();
         }
         $body['subscription'] = (array) rcp_get_subscription_details($subscription_id);
         return $body;
     }
     return false;
 }