/**
  * Get things going
  *
  * @since 2.1
  */
 public function init()
 {
     global $rcp_options;
     $this->supports[] = 'one-time';
     $this->supports[] = 'recurring';
     $this->supports[] = 'fees';
     if ($this->test_mode) {
         $this->api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
         $this->checkout_url = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
     } else {
         $this->api_endpoint = 'https://api-3t.paypal.com/nvp';
         $this->checkout_url = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
     }
     if (rcp_has_paypal_api_access()) {
         $creds = rcp_get_paypal_api_credentials();
         $this->username = $creds['username'];
         $this->password = $creds['password'];
         $this->signature = $creds['signature'];
     }
 }
/**
 * Determines if a member can cancel their subscription on site
 *
 * @access      public
 * @since       2.1
 */
function rcp_can_member_cancel( $user_id = 0 ) {

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

	$ret    = false;
	$member = new RCP_Member( $user_id );

	if( $member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status() ) {

		$profile_id = $member->get_payment_profile_id();

		// Check if the member is a Stripe customer
		if( false !== strpos( $profile_id, 'cus_' ) ) {

			$ret = true;

		} elseif ( rcp_is_paypal_subscriber( $user_id ) && rcp_has_paypal_api_access() ) {

			$ret = true;

		}

	}

	return apply_filters( 'rcp_member_can_cancel', $ret, $user_id );
}
/**
 * Determines if a member can update the credit / debit card attached to their account
 *
 * @access      public
 * @since       2.1
 */
function rcp_member_can_update_billing_card($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    $ret = false;
    // Check if the member is a Stripe customer
    if (rcp_is_stripe_subscriber($user_id)) {
        $ret = true;
    } elseif (rcp_is_paypal_subscriber($user_id) && rcp_has_paypal_api_access()) {
        $ret = true;
    }
    return apply_filters('rcp_member_can_update_billing_card', $ret, $user_id);
}
 /**
  * Validate additional fields during registration submission
  *
  * @since 2.1
  */
 public function validate_fields()
 {
     if (!rcp_has_paypal_api_access()) {
         $this->add_error('no_paypal_api', __('You have not configured PayPal API access. Please configure it in Restrict → Settings', 'rcp'));
     }
     if (empty($_POST['rcp_card_number'])) {
         $this->add_error('missing_card_number', __('The card number you have entered is invalid', 'rcp'));
     }
     if (empty($_POST['rcp_card_cvc'])) {
         $this->add_error('missing_card_code', __('The security code you have entered is invalid', 'rcp'));
     }
     if (empty($_POST['rcp_card_zip'])) {
         $this->add_error('missing_card_zip', __('The zip / postal code you have entered is invalid', 'rcp'));
     }
     if (empty($_POST['rcp_card_name'])) {
         $this->add_error('missing_card_name', __('The card holder name you have entered is invalid', 'rcp'));
     }
     if (empty($_POST['rcp_card_exp_month'])) {
         $this->add_error('missing_card_exp_month', __('The card expiration month you have entered is invalid', 'rcp'));
     }
     if (empty($_POST['rcp_card_exp_year'])) {
         $this->add_error('missing_card_exp_year', __('The card expiration year you have entered is invalid', 'rcp'));
     }
 }
 /**
  * Validate additional fields during registration submission
  *
  * @since 2.1
  */
 public function validate_fields()
 {
     if (!rcp_has_paypal_api_access()) {
         rcp_errors()->add('no_paypal_api', __('You have not configured PayPal API access. Please configure it in Restrict → Settings', 'rcp'), 'register');
     }
 }
/**
 * Determines if a member can cancel their subscription on site
 *
 * @access      public
 * @since       2.1
 */
function rcp_can_member_cancel($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    $ret = false;
    $member = new RCP_Member($user_id);
    if ($member->is_recurring() && $member->is_active() && 'cancelled' !== $member->get_status()) {
        $profile_id = $member->get_payment_profile_id();
        // Check if the member is a Stripe customer
        if (rcp_is_stripe_subscriber($user_id)) {
            $ret = true;
        } elseif (rcp_is_paypal_subscriber($user_id) && rcp_has_paypal_api_access()) {
            $ret = true;
        } elseif (rcp_is_2checkout_subscriber($user_id) && defined('TWOCHECKOUT_ADMIN_USER') && defined('TWOCHECKOUT_ADMIN_PASSWORD')) {
            $ret = true;
        }
    }
    return apply_filters('rcp_member_can_cancel', $ret, $user_id);
}