/** * Handles processing of Pro-Form billing updates. * * @package s2Member\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` */ public static function stripe_update() { if (!empty($_POST['s2member_pro_stripe_update']['nonce']) && ($nonce = $_POST['s2member_pro_stripe_update']['nonce']) && wp_verify_nonce($nonce, 's2member-pro-stripe-update')) { $GLOBALS['ws_plugin__s2member_pro_stripe_update_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__s2member_pro_stripe_update_response']; $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST['s2member_pro_stripe_update'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__s2member_pro_stripe_update_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars = c_ws_plugin__s2member_utils_captchas::recaptcha_post_vars($post_vars); // Collect reCAPTCHA™ post vars. if (!c_ws_plugin__s2member_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__s2member_pro_stripe_responses::stripe_form_submission_validation_errors('update', $post_vars))) { if (is_user_logged_in() && ($user = wp_get_current_user()) && ($user_id = $user->ID)) { if (($cur__subscr_cid = get_user_option('s2member_subscr_cid')) && ($cur__subscr_id = get_user_option('s2member_subscr_id'))) { if (is_object($stripe_subscription = c_ws_plugin__s2member_pro_stripe_utilities::get_customer_subscription($cur__subscr_cid, $cur__subscr_id)) && !preg_match('/^canceled$/i', $stripe_subscription->status) && !$stripe_subscription->cancel_at_period_end) { unset($_POST['s2member_pro_stripe_update']['source_token']); // These are good one-time only. unset($_POST['s2member_pro_stripe_update']['source_token_summary']); if (is_object($set_customer_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($cur__subscr_cid, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => _x('<strong>Confirmed.</strong> Your billing information has been updated.', 's2member-front', 's2member')); if ($post_vars['attr']['success'] && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $post_vars['attr']['success'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } else { $global_response = array('response' => $set_customer_source, 'error' => TRUE); } } else { $global_response = array('response' => _x('<strong>Unable to update.</strong> You have NO recurring fees. Or, your billing profile is no longer active. Please contact Support if you need assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } else { $global_response = array('response' => _x('<strong>Oops.</strong> No Customer|Subscr. ID. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } else { $global_response = array('response' => _x('You\'re <strong>NOT</strong> logged in.', 's2member-front', 's2member'), 'error' => TRUE); } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }
/** * Handles processing of Pro-Form checkouts. * * @package s2Member\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` */ public static function stripe_checkout() { if (!empty($_POST['s2member_pro_stripe_checkout']['nonce']) && ($nonce = $_POST['s2member_pro_stripe_checkout']['nonce']) && wp_verify_nonce($nonce, 's2member-pro-stripe-checkout')) { $GLOBALS['ws_plugin__s2member_pro_stripe_checkout_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__s2member_pro_stripe_checkout_response']; $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST['s2member_pro_stripe_checkout'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__s2member_pro_stripe_checkout_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars['name'] = trim($post_vars['first_name'] . ' ' . $post_vars['last_name']); $post_vars['email'] = apply_filters('user_registration_email', sanitize_email(@$post_vars['email']), get_defined_vars()); $post_vars['username'] = is_multisite() ? strtolower(@$post_vars['username']) : @$post_vars['username']; // Force lowercase. $post_vars['username'] = sanitize_user($post_vars['_o_username'] = $post_vars['username'], is_multisite()); $post_vars = c_ws_plugin__s2member_utils_captchas::recaptcha_post_vars($post_vars); // Collect reCAPTCHA™ post vars. if (!c_ws_plugin__s2member_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__s2member_pro_stripe_responses::stripe_form_submission_validation_errors('checkout', $post_vars))) { unset($_POST['s2member_pro_stripe_checkout']['source_token']); // Good one-time only. unset($_POST['s2member_pro_stripe_checkout']['source_token_summary']); // Good one-time only. $is_bitcoin = !empty($post_vars['source_token']) && stripos($post_vars['source_token'], 'btcrcv_') === 0; $cp_attr = c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($post_vars['attr'], $post_vars['coupon'], 'attr', array('affiliates-silent-post')); $cost_calculations = c_ws_plugin__s2member_pro_stripe_utilities::cost($cp_attr['ta'], $cp_attr['ra'], $post_vars['state'], $post_vars['country'], $post_vars['zip'], $cp_attr['cc'], $cp_attr['desc'], $is_bitcoin); if ($cost_calculations['total'] <= 0 && $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0) { $post_vars['attr']['tp'] = '0'; // Ditch the trial period completely. $cost_calculations['sub_total'] = $cost_calculations['trial_sub_total']; // Use as regular sub-total (ditch trial sub-total). $cost_calculations['tax'] = $cost_calculations['trial_tax']; // Use as regular tax (ditch trial tax). $cost_calculations['tax_per'] = $cost_calculations['trial_tax_per']; // Use as regular tax (ditch trial tax). $cost_calculations['total'] = $cost_calculations['trial_total']; // Use as regular total (ditch trial). $cost_calculations['trial_sub_total'] = '0.00'; // Ditch the initial total (using as grand total). $cost_calculations['trial_tax'] = '0.00'; // Ditch this calculation now also. $cost_calculations['trial_tax_per'] = ''; // Ditch this calculation now also. $cost_calculations['trial_total'] = '0.00'; // Ditch this calculation now also. } $use_subscription = $post_vars['attr']['rr'] === 'BN' || !$post_vars['attr']['tp'] && !$post_vars['attr']['rr'] ? FALSE : TRUE; $is_independent_ccaps_sale = $post_vars['attr']['level'] === '*' ? TRUE : FALSE; // Selling Independent Custom Capabilities? if ($use_subscription && $cost_calculations['trial_total'] <= 0 && $cost_calculations['total'] <= 0) { if (!$post_vars['attr']['rr'] && $post_vars['attr']['rt'] !== 'L') { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 1) { $post_vars['attr']['level_ccaps_eotper'] .= ':' . $post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']; } else { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 0) { $post_vars['attr']['level_ccaps_eotper'] .= '::' . $post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']; } } } else { if ($post_vars['attr']['rr'] && $post_vars['attr']['rrt'] && $post_vars['attr']['rt'] !== 'L') { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 1) { $post_vars['attr']['level_ccaps_eotper'] .= ':' . $post_vars['attr']['rp'] * $post_vars['attr']['rrt'] . ' ' . $post_vars['attr']['rt']; } else { if (substr_count($post_vars['attr']['level_ccaps_eotper'], ':') === 0) { $post_vars['attr']['level_ccaps_eotper'] .= '::' . $post_vars['attr']['rp'] * $post_vars['attr']['rrt'] . ' ' . $post_vars['attr']['rt']; } } } } } if ($use_subscription && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { $plan_attr = $cp_attr; // For the subscription plan. $plan_attr['ta'] = $cost_calculations['trial_total']; $plan_attr['ra'] = $cost_calculations['total']; $plan_attr['desc'] = $cost_calculations['desc']; update_user_meta($user_id, 'first_name', $post_vars['first_name']); update_user_meta($user_id, 'last_name', $post_vars['last_name']); $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars['attr']['tp'] . ' ' . $post_vars['attr']['tt']); $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']); $start_time = $post_vars['attr']['tp'] ? c_ws_plugin__s2member_pro_stripe_utilities::start_time($period1) : c_ws_plugin__s2member_pro_stripe_utilities::start_time($period3); // Or next billing cycle. if (!$global_response) { if ($post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 || !$post_vars['attr']['tp'] && $cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 ? $cost_calculations['trial_total'] : $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc'], array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_plan = c_ws_plugin__s2member_pro_stripe_utilities::get_plan($plan_attr))) { $global_response = array('response' => $stripe_plan, 'error' => TRUE); } else { if ((empty($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if ((empty($stripe_customer_with_source) || !is_object($stripe_customer_with_source)) && !is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_subscription = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_subscription($stripe_customer->id, $stripe_plan->id, array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_subscription, 'error' => TRUE); } else { $new__subscr_cid = $stripe_customer->id; $new__subscr_id = $stripe_subscription->id; } } } } if ($global_response && !empty($new__txn_id)) { $global_response = array(); $stripe_subscription_failed_charge_succeeded = TRUE; } } } if (!$global_response) { $old__subscr_cid = get_user_option('s2member_subscr_cid'); $old__subscr_id = get_user_option('s2member_subscr_id'); $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id(); if (empty($new__subscr_cid)) { $new__subscr_cid = strtoupper('free-' . uniqid()); } if (empty($new__subscr_id)) { $new__subscr_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'subscr_signup'; $ipn['subscr_cid'] = $new__subscr_cid; $ipn['subscr_id'] = $new__subscr_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['txn_cid'] = !empty($new__txn_cid) ? $new__txn_cid : $new__subscr_cid; $ipn['txn_id'] = !empty($new__txn_id) ? $new__txn_id : $new__subscr_id; $ipn['period1'] = $period1; $ipn['period3'] = $period3; $ipn['mc_amount1'] = $cost_calculations['trial_total']; $ipn['mc_amount3'] = $cost_calculations['total']; $ipn['mc_gross'] = preg_match('/^[1-9]/', $ipn['period1']) ? $ipn['mc_amount1'] : $ipn['mc_amount3']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['recurring'] = $post_vars['attr']['rr'] ? '1' : ''; $ipn['payer_email'] = $user->user_email; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $old__subscr_or_wp_id; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_use'] .= $ipn['mc_gross'] > 0 ? ',subscr-signup-as-subscr-payment' : ''; $ipn['s2member_paypal_proxy_coupon'] = array('coupon_code' => $cp_attr['_coupon_code'], 'full_coupon_code' => $cp_attr['_full_coupon_code'], 'affiliate_id' => $cp_attr['_coupon_affiliate_id']); $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); $ipn['s2member_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['s2member_stripe_proxy_return_url'] = trim(c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20))); if (!empty($stripe_subscription_failed_charge_succeeded)) { update_user_option($user_id, 's2member_auto_eot_time', $start_time); } if ($old__subscr_cid && $old__subscr_id && apply_filters('s2member_pro_cancels_old_rp_before_new_rp', TRUE, get_defined_vars())) { c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($old__subscr_cid, $old__subscr_id, FALSE); } c_ws_plugin__s2member_list_servers::process_list_servers_against_current_user((bool) @$post_vars['custom_fields']['opt_in'], TRUE, TRUE); setcookie('s2member_tracking', $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_tracking'] = $s2member_tracking); $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been updated :-)', 's2member-front', 's2member'), esc_attr(wp_login_url()))); if ($post_vars['attr']['success'] && substr($ipn['s2member_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['s2member_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } } else { if ($use_subscription && !is_user_logged_in()) { $plan_attr = $cp_attr; // For the subscription plan. $plan_attr['ta'] = $cost_calculations['trial_total']; $plan_attr['ra'] = $cost_calculations['total']; $plan_attr['desc'] = $cost_calculations['desc']; $period1 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period1($post_vars['attr']['tp'] . ' ' . $post_vars['attr']['tt']); $period3 = c_ws_plugin__s2member_paypal_utilities::paypal_pro_period3($post_vars['attr']['rp'] . ' ' . $post_vars['attr']['rt']); $start_time = $post_vars['attr']['tp'] ? c_ws_plugin__s2member_pro_stripe_utilities::start_time($period1) : c_ws_plugin__s2member_pro_stripe_utilities::start_time($period3); // Or next billing cycle. if (!$global_response) { if ($post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 || !$post_vars['attr']['tp'] && $cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $post_vars['attr']['tp'] && $cost_calculations['trial_total'] > 0 ? $cost_calculations['trial_total'] : $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc'], array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_plan = c_ws_plugin__s2member_pro_stripe_utilities::get_plan($plan_attr))) { $global_response = array('response' => $stripe_plan, 'error' => TRUE); } else { if ((empty($stripe_customer) || !is_object($stripe_customer)) && !is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if ((empty($stripe_customer_with_source) || !is_object($stripe_customer_with_source)) && !is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_subscription = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_subscription($stripe_customer->id, $stripe_plan->id, array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_subscription, 'error' => TRUE); } else { $new__subscr_cid = $stripe_customer->id; $new__subscr_id = $stripe_subscription->id; } } } } if ($global_response && !empty($new__txn_id)) { $global_response = array(); $stripe_subscription_failed_charge_succeeded = TRUE; } } } if (!$global_response) { if (empty($new__subscr_cid)) { $new__subscr_cid = strtoupper('free-' . uniqid()); } if (empty($new__subscr_id)) { $new__subscr_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'subscr_signup'; $ipn['subscr_cid'] = $new__subscr_cid; $ipn['subscr_id'] = $new__subscr_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['txn_cid'] = !empty($new__txn_cid) ? $new__txn_cid : $new__subscr_cid; $ipn['txn_id'] = !empty($new__txn_id) ? $new__txn_id : $new__subscr_id; $ipn['period1'] = $period1; $ipn['period3'] = $period3; $ipn['mc_amount1'] = $cost_calculations['trial_total']; $ipn['mc_amount3'] = $cost_calculations['total']; $ipn['mc_gross'] = preg_match('/^[1-9]/', $ipn['period1']) ? $ipn['mc_amount1'] : $ipn['mc_amount3']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['recurring'] = $post_vars['attr']['rr'] ? '1' : ''; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_use'] .= $ipn['mc_gross'] > 0 ? ',subscr-signup-as-subscr-payment' : ''; $ipn['s2member_paypal_proxy_coupon'] = array('coupon_code' => $cp_attr['_coupon_code'], 'full_coupon_code' => $cp_attr['_full_coupon_code'], 'affiliate_id' => $cp_attr['_coupon_affiliate_id']); $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); $ipn['s2member_paypal_proxy_return_url'] = $post_vars['attr']['success']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_user_pass1'] = @$post_vars['password1']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_first_name'] = $post_vars['first_name']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_last_name'] = $post_vars['last_name']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_opt_in'] = @$post_vars['custom_fields']['opt_in']; if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($post_vars['custom_fields'][$field_var])) { $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_' . $field_var] = $post_vars['custom_fields'][$field_var]; } } } $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway'] = 'stripe'; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid'] = $new__subscr_cid; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_id'] = $new__subscr_id; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_level'] = $post_vars['attr']['level']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_ccaps'] = $post_vars['attr']['ccaps']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_custom'] = $post_vars['attr']['custom']; @(list($level, $ccaps, $eotper) = preg_split('/\\:/', $post_vars['attr']['level_ccaps_eotper'], 3)); if (!empty($eotper)) { $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time'] = date('Y-m-d H:i:s', c_ws_plugin__s2member_utils_time::auto_eot_time('', '', '', $eotper)); } $create_user['user_email'] = $post_vars['email']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_login'] = $post_vars['username']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_pass'] = wp_generate_password(); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`. $has_custom_password = !empty($post_vars['password1']) && $post_vars['password1'] === $create_user['user_pass']; if ((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user['user_login'], $create_user['user_email'], $create_user['user_pass'])) || ($new__user_id = wp_create_user($create_user['user_login'], $create_user['user_pass'], $create_user['user_email']))) && !is_wp_error($new__user_id)) { update_user_option($new__user_id, 'default_password_nag', $has_custom_password ? FALSE : TRUE, TRUE); wp_new_user_notification($new__user_id, $create_user['user_pass']); if (!empty($stripe_subscription_failed_charge_succeeded)) { update_user_option($new__user_id, 's2member_auto_eot_time', $start_time); } $ipn['s2member_stripe_proxy_return_url'] = trim(c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('s2member_tracking', $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__subscr_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_tracking'] = $s2member_tracking); if ($has_custom_password) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">log in</a>.', 's2member-front', 's2member'), esc_attr(wp_login_url()))); } else { $global_response = array('response' => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', 's2member-front', 's2member')); } if ($post_vars['attr']['success'] && substr($ipn['s2member_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['s2member_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } else { c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20)); $global_response = array('response' => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { if (!$use_subscription && is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { update_user_meta($user_id, 'first_name', $post_vars['first_name']); update_user_meta($user_id, 'last_name', $post_vars['last_name']); if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer($user_id, $user->user_email, $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc'], array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { $old__subscr_cid = get_user_option('s2member_subscr_cid'); $old__subscr_id = get_user_option('s2member_subscr_id'); $old__subscr_or_wp_id = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id(); if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $user->user_email; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $old__subscr_or_wp_id; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_coupon'] = array('coupon_code' => $cp_attr['_coupon_code'], 'full_coupon_code' => $cp_attr['_full_coupon_code'], 'affiliate_id' => $cp_attr['_coupon_affiliate_id']); $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); $ipn['s2member_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['s2member_stripe_proxy_return_url'] = trim(c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20))); if (!$is_independent_ccaps_sale) { // Independent? if ($old__subscr_cid && $old__subscr_id && apply_filters('s2member_pro_cancels_old_rp_before_new_rp', TRUE, get_defined_vars())) { c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($old__subscr_cid, $old__subscr_id, FALSE); } } c_ws_plugin__s2member_list_servers::process_list_servers_against_current_user((bool) @$post_vars['custom_fields']['opt_in'], TRUE, TRUE); setcookie('s2member_tracking', $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_tracking'] = $s2member_tracking); $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been updated :-)', 's2member-front', 's2member'), esc_attr(wp_login_url()))); if ($post_vars['attr']['success'] && substr($ipn['s2member_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['s2member_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } } else { if (!$use_subscription && !is_user_logged_in()) { if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer(0, $post_vars['email'], $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars, $post_vars['attr']['reject_prepaid']))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc'], array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['level_ccaps_eotper']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_coupon'] = array('coupon_code' => $cp_attr['_coupon_code'], 'full_coupon_code' => $cp_attr['_full_coupon_code'], 'affiliate_id' => $cp_attr['_coupon_affiliate_id']); $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); $ipn['s2member_paypal_proxy_return_url'] = $post_vars['attr']['success']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_user_pass1'] = @$post_vars['password1']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_first_name'] = $post_vars['first_name']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_last_name'] = $post_vars['last_name']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_opt_in'] = @$post_vars['custom_fields']['opt_in']; if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (isset($post_vars['custom_fields'][$field_var])) { $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_' . $field_var] = $post_vars['custom_fields'][$field_var]; } } } $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_gateway'] = 'stripe'; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_cid'] = $new__txn_cid; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_subscr_id'] = $new__txn_id; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_level'] = $post_vars['attr']['level']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_ccaps'] = $post_vars['attr']['ccaps']; $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_custom'] = $post_vars['attr']['custom']; @(list($level, $ccaps, $eotper) = preg_split('/\\:/', $post_vars['attr']['level_ccaps_eotper'], 3)); if (!empty($eotper)) { $GLOBALS['ws_plugin__s2member_registration_vars']['ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time'] = date('Y-m-d H:i:s', c_ws_plugin__s2member_utils_time::auto_eot_time('', '', '', $eotper)); } $create_user['user_email'] = $post_vars['email']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_login'] = $post_vars['username']; // Copy this into a separate array for `wp_create_user()`. $create_user['user_pass'] = wp_generate_password(); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`. $has_custom_password = !empty($post_vars['password1']) && $post_vars['password1'] === $create_user['user_pass']; if ((is_multisite() && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user($create_user['user_login'], $create_user['user_email'], $create_user['user_pass'])) || ($new__user_id = wp_create_user($create_user['user_login'], $create_user['user_pass'], $create_user['user_email']))) && !is_wp_error($new__user_id)) { update_user_option($new__user_id, 'default_password_nag', $has_custom_password ? FALSE : TRUE, TRUE); wp_new_user_notification($new__user_id, $create_user['user_pass']); $ipn['s2member_stripe_proxy_return_url'] = trim(c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('s2member_tracking', $s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('s2member_tracking', $s2member_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_tracking'] = $s2member_tracking); if ($has_custom_password) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your account has been approved.<br />— Please <a href="%s" rel="nofollow">log in</a>.', 's2member-front', 's2member'), esc_attr(wp_login_url()))); } else { $global_response = array('response' => _x('<strong>Thank you.</strong> Your account has been approved.<br />— You\'ll receive an email momentarily.', 's2member-front', 's2member')); } if ($post_vars['attr']['success'] && substr($ipn['s2member_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['s2member_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } else { c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20)); $global_response = array('response' => _x('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { $global_response = array('response' => _x('<strong>Unknown error.</strong> Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }
/** * Handles processing of Pro-Forms for Specific Post/Page checkout. * * @package s2Member\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` * * @return null Or exits script execution after a custom URL redirection. */ public static function stripe_sp_checkout() { if (!empty($_POST['s2member_pro_stripe_sp_checkout']['nonce']) && ($nonce = $_POST['s2member_pro_stripe_sp_checkout']['nonce']) && wp_verify_nonce($nonce, 's2member-pro-stripe-sp-checkout')) { $GLOBALS['ws_plugin__s2member_pro_stripe_sp_checkout_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__s2member_pro_stripe_sp_checkout_response']; $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST['s2member_pro_stripe_sp_checkout'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__s2member_pro_stripe_sp_checkout_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars['name'] = trim($post_vars['first_name'] . ' ' . $post_vars['last_name']); $post_vars['email'] = apply_filters('user_registration_email', sanitize_email($post_vars['email']), get_defined_vars()); $post_vars['recaptcha_challenge_field'] = isset($_POST['recaptcha_challenge_field']) ? trim(stripslashes($_POST['recaptcha_challenge_field'])) : ''; $post_vars['recaptcha_response_field'] = isset($_POST['recaptcha_response_field']) ? trim(stripslashes($_POST['recaptcha_response_field'])) : ''; if (!c_ws_plugin__s2member_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__s2member_pro_stripe_responses::stripe_form_submission_validation_errors('sp-checkout', $post_vars))) { unset($_POST['s2member_pro_stripe_sp_checkout']['source_token']); // Good one-time only. unset($_POST['s2member_pro_stripe_sp_checkout']['source_token_summary']); // Good one-time only. $is_bitcoin = !empty($post_vars['source_token']) && stripos($post_vars['source_token'], 'btcrcv_') === 0; $cp_attr = c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($post_vars['attr'], $post_vars['coupon'], 'attr', array('affiliates-silent-post')); $cost_calculations = c_ws_plugin__s2member_pro_stripe_utilities::cost(NULL, $cp_attr['ra'], $post_vars['state'], $post_vars['country'], $post_vars['zip'], $cp_attr['cc'], $cp_attr['desc'], $is_bitcoin); if (!$global_response) { if ($cost_calculations['total'] > 0) { if (!is_object($stripe_customer = c_ws_plugin__s2member_pro_stripe_utilities::get_customer(get_current_user_id(), $post_vars['email'], $post_vars['first_name'], $post_vars['last_name'], array(), $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_customer = $stripe_customer_with_source = c_ws_plugin__s2member_pro_stripe_utilities::set_customer_source($stripe_customer->id, $post_vars['source_token'], $post_vars))) { $global_response = array('response' => $stripe_customer, 'error' => TRUE); } else { if (!is_object($stripe_charge = c_ws_plugin__s2member_pro_stripe_utilities::create_customer_charge($stripe_customer->id, $cost_calculations['total'], $cost_calculations['cur'], $cost_calculations['desc'], array(), $post_vars, $cost_calculations))) { $global_response = array('response' => $stripe_charge, 'error' => TRUE); } else { $new__txn_cid = $stripe_customer->id; $new__txn_id = $stripe_charge->id; } } } } } if (!$global_response) { if (empty($new__txn_cid)) { $new__txn_cid = strtoupper('free-' . uniqid()); } if (empty($new__txn_id)) { $new__txn_id = strtoupper('free-' . uniqid()); } $ipn['txn_type'] = 'web_accept'; $ipn['txn_cid'] = $new__txn_cid; $ipn['txn_id'] = $new__txn_id; $ipn['custom'] = $post_vars['attr']['custom']; $ipn['mc_gross'] = $cost_calculations['total']; $ipn['mc_currency'] = $cost_calculations['cur']; $ipn['tax'] = $cost_calculations['tax']; $ipn['payer_email'] = $post_vars['email']; $ipn['first_name'] = $post_vars['first_name']; $ipn['last_name'] = $post_vars['last_name']; if (is_user_logged_in() && ($referencing = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id())) { $ipn['option_name1'] = 'Referencing Customer ID'; $ipn['option_selection1'] = $referencing; } else { $ipn['option_name1'] = 'Originating Domain'; $ipn['option_selection1'] = $_SERVER['HTTP_HOST']; } $ipn['option_name2'] = 'Customer IP Address'; $ipn['option_selection2'] = $_SERVER['REMOTE_ADDR']; $ipn['item_name'] = $cost_calculations['desc']; $ipn['item_number'] = $post_vars['attr']['sp_ids_exp']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_coupon'] = array('coupon_code' => $cp_attr['_coupon_code'], 'full_coupon_code' => $cp_attr['_full_coupon_code'], 'affiliate_id' => $cp_attr['_coupon_affiliate_id']); $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); $ipn['s2member_paypal_proxy_return_url'] = $post_vars['attr']['success']; $ipn['s2member_stripe_proxy_return_url'] = trim(c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20))); setcookie('s2member_sp_tracking', $s2member_sp_tracking = c_ws_plugin__s2member_utils_encryption::encrypt($new__txn_id), time() + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie('s2member_sp_tracking', $s2member_sp_tracking, time() + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE['s2member_sp_tracking'] = $s2member_sp_tracking); if ($sp_access_url = c_ws_plugin__s2member_sp_access::sp_access_link_gen($post_vars['attr']['ids'], $post_vars['attr']['exp'])) { $global_response = array('response' => sprintf(_x('<strong>Thank you.</strong> Your purchase has been approved.<br />— Please <a href="%s" rel="nofollow">click here</a> to proceed.', 's2member-front', 's2member'), esc_attr($sp_access_url))); if ($post_vars['attr']['success'] && substr($ipn['s2member_stripe_proxy_return_url'], 0, 2) === substr($post_vars['attr']['success'], 0, 2) && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $ipn['s2member_stripe_proxy_return_url'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } else { $global_response = array('response' => _x('<strong>Oops.</strong> Unable to generate Access Link. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }
/** * Validates different kinds of form submissions. * * Free Registration Forms do NOT require API Credentials. * * @package s2Member\Stripe * @since 140617 * * @param string $form The type of Pro-Form being submitted. * @param array $s An array of data submitted through the Pro-Form. * * @return null|array Null if there are no errors, else a response array. */ public static function stripe_form_submission_validation_errors($form, $s = array()) { $cp_attr = c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($s['attr'], $s['coupon'], 'attr'); $is_free_checkout = in_array($form, array('sp-checkout', 'checkout'), TRUE) && $cp_attr['ta'] <= 0 && $cp_attr['ra'] <= 0; $is_bitcoin_checkout = !$is_free_checkout && in_array($form, array('sp-checkout', 'checkout'), TRUE) && stripos($s['source_token'], 'btcrcv_') === 0; if ($form === 'registration' || !($response = c_ws_plugin__s2member_pro_stripe_responses::stripe_form_api_validation_errors())) { if ($form === 'cancellation') { if (!is_user_logged_in()) { $response = array('response' => sprintf(_x('You must <a href="%s" rel="nofollow">log in</a> to cancel your account.', 's2member-front', 's2member'), esc_attr(wp_login_url($_SERVER['REQUEST_URI']))), 'error' => TRUE); } else { if ($s['attr']['captcha'] && (empty($s['recaptcha_challenge_field']) || empty($s['recaptcha_response_field']) || !c_ws_plugin__s2member_utils_captchas::recaptcha_code_validates($s['recaptcha_challenge_field'], $s['recaptcha_response_field']))) { $response = array('response' => _x('Missing or invalid Security Verification. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (is_object($user = wp_get_current_user()) && $user->ID && $user->has_cap('administrator')) { $response = array('response' => _x('Unable to process. You are an Administrator. Stopping here for security. Otherwise, an Administrator could lose access.', 's2member-admin', 's2member'), 'error' => TRUE); } } } } else { if ($form === 'update') { if (!is_user_logged_in()) { $response = array('response' => sprintf(_x('You must <a href="%s" rel="nofollow">log in</a> to update your billing information.', 's2member-front', 's2member'), esc_attr(wp_login_url($_SERVER['REQUEST_URI']))), 'error' => TRUE); } else { if (is_object($user = wp_get_current_user()) && $user->ID && $user->has_cap('administrator')) { $response = array('response' => _x('Unable to process. You are an Administrator. Stopping here for security. Otherwise, an Administrator could lose access.', 's2member-admin', 's2member'), 'error' => TRUE); } else { if (empty($s['source_token']) || !is_string($s['source_token'])) { $response = array('response' => _x('Missing Billing Info. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ($s['attr']['captcha'] && (empty($s['recaptcha_challenge_field']) || empty($s['recaptcha_response_field']) || !c_ws_plugin__s2member_utils_captchas::recaptcha_code_validates($s['recaptcha_challenge_field'], $s['recaptcha_response_field']))) { $response = array('response' => _x('Missing or invalid Security Verification. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } else { if ($form === 'registration') { /** @var $_errors \WP_Error For IDEs. This variable is used below in at least one place. */ if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] && (empty($s['first_name']) || !is_string($s['first_name']))) { $response = array('response' => _x('Missing First Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] && (empty($s['last_name']) || !is_string($s['last_name']))) { $response = array('response' => _x('Missing Last Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['email']) || !is_string($s['email'])) { $response = array('response' => _x('Missing or invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_email($s['email'])) { $response = array('response' => _x('Invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (email_exists($s['email']) && (!is_multisite() || !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog(@$s['username'], $s['email']))) { $response = array('response' => _x('That Email Address is already in use. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['username']) || !is_string($s['username']) || empty($s['_o_username']) || !is_string($s['_o_username'])) { $response = array('response' => _x('Missing or invalid Username. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!validate_username($s['username']) || !validate_username($s['_o_username'])) { $response = array('response' => _x('Invalid Username. Please try again. Use ONLY lowercase alphanumerics.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (username_exists($s['username']) && (!is_multisite() || !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog($s['username'], $s['email']))) { $response = array('response' => _x('That Username is already in use. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (is_multisite() && !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog($s['username'], $s['email']) && ($_response = wpmu_validate_user_signup($s['username'], $s['email'])) && is_wp_error($_errors = $_response['errors']) && $_errors->get_error_message()) { $response = array('response' => $_errors->get_error_message(), 'error' => TRUE); } else { if ((empty($s['password1']) || !is_string($s['password1'])) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Missing Password. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ((empty($s['password1']) || strlen($s['password1']) < c_ws_plugin__s2member_user_securities::min_password_length()) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => sprintf(_x('Invalid Password. Must be at least %1$s characters. Please try again.', 's2member-front', 's2member'), c_ws_plugin__s2member_user_securities::min_password_length()), 'error' => TRUE); } else { if (!empty($s['password1']) && strlen($s['password1']) > 64 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Invalid Password. Max length is 64 characters. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ((empty($s['password2']) || $s['password2'] !== $s['password1']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Password fields do NOT match. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ($custom_field_validation_errors = c_ws_plugin__s2member_custom_reg_fields::validation_errors(isset($s['custom_fields']) ? $s['custom_fields'] : array(), c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($s['attr']['level'], 'registration', TRUE))) { $response = array('response' => array_shift($custom_field_validation_errors), 'error' => TRUE); } else { if ($s['attr']['captcha'] && (empty($s['recaptcha_challenge_field']) || empty($s['recaptcha_response_field']) || !c_ws_plugin__s2member_utils_captchas::recaptcha_code_validates($s['recaptcha_challenge_field'], $s['recaptcha_response_field']))) { $response = array('response' => _x('Missing or invalid Security Verification. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } } } } } } } } } } } } else { if ($form === 'sp-checkout') { if (empty($s['first_name']) || !is_string($s['first_name'])) { $response = array('response' => _x('Missing First Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['last_name']) || !is_string($s['last_name'])) { $response = array('response' => _x('Missing Last Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['email']) || !is_string($s['email'])) { $response = array('response' => _x('Missing or invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_email($s['email'])) { $response = array('response' => _x('Invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['source_token']) || !is_string($s['source_token'])) { // Token = `free` for free checkouts. $response = array('response' => _x('Missing Billing Info. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['state']) || !is_string($s['state'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing State/Province. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['country']) || !is_string($s['country'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing Country. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['zip']) || !is_string($s['zip'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing Postal/Zip Code. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ($s['attr']['captcha'] && (empty($s['recaptcha_challenge_field']) || empty($s['recaptcha_response_field']) || !c_ws_plugin__s2member_utils_captchas::recaptcha_code_validates($s['recaptcha_challenge_field'], $s['recaptcha_response_field']))) { $response = array('response' => _x('Missing or invalid Security Verification. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } } } } } } else { if ($form === 'checkout') { /** @var $_errors \WP_Error For IDEs. This variable is used below in at least one place. */ if ($s['attr']['modify'] && !is_user_logged_in()) { $response = array('response' => sprintf(_x('You must <a href="%s" rel="nofollow">log in</a> to modify your billing plan.', 's2member-front', 's2member'), esc_attr(wp_login_url($_SERVER['REQUEST_URI']))), 'error' => TRUE); } else { if ($s['attr']['level'] === '*' && !is_user_logged_in()) { $response = array('response' => sprintf(_x('You must <a href="%s" rel="nofollow">log in</a> before making this purchase.', 's2member-front', 's2member'), esc_attr(wp_login_url($_SERVER['REQUEST_URI']))), 'error' => TRUE); } else { if (is_user_logged_in() && is_object($user = wp_get_current_user()) && $user->ID && $user->has_cap('administrator')) { $response = array('response' => _x('Unable to process. You are an Administrator. Stopping here for security. Otherwise, an Administrator could lose access.', 's2member-admin', 's2member'), 'error' => TRUE); } else { if (empty($s['first_name']) || !is_string($s['first_name'])) { $response = array('response' => _x('Missing First Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (empty($s['last_name']) || !is_string($s['last_name'])) { $response = array('response' => _x('Missing Last Name. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && (empty($s['email']) || !is_string($s['email']))) { $response = array('response' => _x('Missing or invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && !is_email($s['email'])) { $response = array('response' => _x('Invalid Email Address. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && email_exists($s['email']) && (!is_multisite() || !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog(@$s['username'], $s['email']))) { $response = array('response' => _x('That Email Address is already in use. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && (empty($s['username']) || !is_string($s['username']) || empty($s['_o_username']) || !is_string($s['_o_username']))) { $response = array('response' => _x('Missing or invalid Username. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && (!validate_username($s['username']) || !validate_username($s['_o_username']))) { $response = array('response' => _x('Invalid Username. Please try again. Use ONLY lowercase alphanumerics.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && username_exists($s['username']) && (!is_multisite() || !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog($s['username'], $s['email']))) { $response = array('response' => _x('That Username is already in use. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && is_multisite() && !c_ws_plugin__s2member_utils_users::ms_user_login_email_can_join_blog($s['username'], $s['email']) && ($_response = wpmu_validate_user_signup($s['username'], $s['email'])) && is_wp_error($_errors = $_response['errors']) && $_errors->get_error_message()) { $response = array('response' => $_errors->get_error_message(), 'error' => TRUE); } else { if (!is_user_logged_in() && (empty($s['password1']) || !is_string($s['password1'])) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Missing Password. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && (empty($s['password1']) || strlen($s['password1']) < c_ws_plugin__s2member_user_securities::min_password_length()) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => sprintf(_x('Invalid Password. Must be at least %1$s characters. Please try again.', 's2member-front', 's2member'), c_ws_plugin__s2member_user_securities::min_password_length()), 'error' => TRUE); } else { if (!is_user_logged_in() && !empty($s['password1']) && strlen($s['password1']) > 64 && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Invalid Password. Max length is 64 characters. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && (empty($s['password2']) || $s['password2'] !== $s['password1']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password']) { $response = array('response' => _x('Password fields do NOT match. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!is_user_logged_in() && ($custom_field_validation_errors = c_ws_plugin__s2member_custom_reg_fields::validation_errors(isset($s['custom_fields']) ? $s['custom_fields'] : array(), c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($s['attr']['level'] === '*' ? 'auto-detection' : $s['attr']['level'], 'registration', TRUE)))) { $response = array('response' => array_shift($custom_field_validation_errors), 'error' => TRUE); } else { if (empty($s['source_token']) || !is_string($s['source_token'])) { // Token = `free` for free checkouts. $response = array('response' => _x('Missing Billing Method. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['state']) || !is_string($s['state'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing State/Province. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['country']) || !is_string($s['country'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing Country. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if (!$is_free_checkout && !$is_bitcoin_checkout && (empty($s['zip']) || !is_string($s['zip'])) && c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply()) { $response = array('response' => _x('Missing Postal/Zip Code. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } else { if ($s['attr']['captcha'] && (empty($s['recaptcha_challenge_field']) || empty($s['recaptcha_response_field']) || !c_ws_plugin__s2member_utils_captchas::recaptcha_code_validates($s['recaptcha_challenge_field'], $s['recaptcha_response_field']))) { $response = array('response' => _x('Missing or invalid Security Verification. Please try again.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } } } } } } } } } } } } } } } } } } } else { // Else we are dealing with an unknown form submission type. $response = array('response' => _x('Unknown form submission type. Please contact Support.', 's2member-front', 's2member'), 'error' => TRUE); } } } } } } return apply_filters('ws_plugin__s2member_pro_stripe_form_submission_validation_response', empty($response) ? NULL : $response, $form, $s); }
/** * Handles the return of Tax for Pro-Forms, via AJAX; through a JSON object. * * @package s2Member\Stripe * @since 140617 */ public static function stripe_ajax_tax() { if (!empty($_POST['ws_plugin__s2member_pro_stripe_ajax_tax']) && ($nonce = $_POST['ws_plugin__s2member_pro_stripe_ajax_tax']) && (wp_verify_nonce($nonce, 'ws-plugin--s2member-pro-stripe-ajax-tax') || c_ws_plugin__s2member_utils_encryption::decrypt($nonce) === 'ws-plugin--s2member-pro-stripe-ajax-tax')) { status_header(200); // Send a 200 OK status header. header('Content-Type: text/plain; charset=UTF-8'); // Content-Type text/plain with UTF-8. while (@ob_end_clean()) { } // Clean any existing output buffers. if (!empty($_POST['ws_plugin__s2member_pro_stripe_ajax_tax_vars']) && is_array($_p_tax_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST['ws_plugin__s2member_pro_stripe_ajax_tax_vars'])))) { if (is_array($attr = !empty($_p_tax_vars['attr']) ? unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($_p_tax_vars['attr'])) : FALSE)) { $attr = !empty($attr['coupon']) ? c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($attr, $attr['coupon']) : $attr; $trial = $attr['rr'] !== 'BN' && $attr['tp'] ? TRUE : FALSE; // Is there a trial? $sub_total_today = $trial ? $attr['ta'] : $attr['ra']; // What is the sub-total today? $state = strip_tags($_p_tax_vars['state']); $country = strip_tags($_p_tax_vars['country']); $zip = strip_tags($_p_tax_vars['zip']); $currency = $attr['cc']; $desc = $attr['desc']; /* Trial is `null` in this function call. We only need to return what it costs today. However, we do tag on a 'trial' element in the array so the ajax routine will know about this. */ $a = c_ws_plugin__s2member_pro_stripe_utilities::cost(NULL, $sub_total_today, $state, $country, $zip, $currency, $desc); echo json_encode(array('trial' => $trial, 'sub_total' => $a['sub_total'], 'tax' => $a['tax'], 'tax_per' => $a['tax_per'], 'total' => $a['total'], 'cur' => $a['cur'], 'cur_symbol' => $a['cur_symbol'], 'desc' => $a['desc'])); } } exit; // Clean exit. } }
/** * Shortcode `[s2Member-Pro-Stripe-Form /]`. * * @package s2Member\Stripe * @since 140617 * * @attaches-to ``add_shortcode('s2Member-Pro-Stripe-Form');`` * * @param array $attr An array of Attributes. * @param string $content Content inside the Shortcode. * @param string $shortcode The actual Shortcode name itself. * * @return string The resulting Form Code, HTML markup. */ public static function sc_stripe_form($attr, $content = '', $shortcode = '') { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_before_sc_stripe_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. c_ws_plugin__s2member_no_cache::no_cache_constants(TRUE); $attr = c_ws_plugin__s2member_utils_strings::trim_qts_deep((array) $attr); $options = array(); // Initialize options to an empty array. $option_selections = ''; // Initialize w/ no options. if ($content && ($content = strip_tags($content))) { // This allows for nested Pro-Form Shortcodes as options. $content = str_replace('s2Member-Pro-Stripe-Form ', 's2Member-Pro-Stripe-xFormOption ', $content); } if ($content && ($content_options = do_shortcode($content))) { foreach (preg_split('/\\s*\\|\\:\\:\\|\\s*/', $content_options, NULL, PREG_SPLIT_NO_EMPTY) as $_content_option_key => $_content_option) { $_content_option_id = $_content_option_key + 1; $options[$_content_option_id] = maybe_unserialize(trim($_content_option)); if (!is_array($options[$_content_option_id])) { unset($options[$_content_option_id]); continue; // Invalid option. } if (!empty($_REQUEST['s2p-option']) && (int) $_REQUEST['s2p-option'] === $_content_option_id) { $options[$_content_option_id]['selected'] = TRUE; } } unset($_content_option_key, $_content_option, $_content_option_id); // Housekeeping. foreach ($options as $_option_id => $_option) { if (!empty($_option['selected'])) { $attr = array_merge($attr, $_option); $_selected_option_id = $_option_id; } } unset($_option_id, $_option); // Housekeeping. if (empty($_selected_option_id)) { foreach ($options as $_option_id => $_option) { $attr = array_merge($attr, $_option); break; // Force a selected option (default). } } unset($_option_id, $_option, $_selected_option_id); // Housekeeping. foreach ($options as $_option_id => $_option) { // Build option selections. $option_selections .= '<option value="' . esc_attr($_option_id) . '"' . (!empty($_option['selected']) ? ' selected="selected"' : '') . '>' . esc_html($_option['desc']) . '</option>'; } unset($_option_id, $_option); // Housekeeping. } $attr = shortcode_atts(array('ids' => '0', 'exp' => '72', 'level' => @$attr['register'] ? '0' : '1', 'ccaps' => '', 'desc' => '', 'cc' => 'USD', 'custom' => $_SERVER['HTTP_HOST'], 'ta' => '0', 'tp' => '0', 'tt' => 'D', 'ra' => '0.50', 'rp' => '1', 'rt' => 'M', 'rr' => '1', 'rrt' => '', 'modify' => '0', 'cancel' => '0', 'unsub' => '0', 'sp' => '0', 'register' => '0', 'update' => '0', 'accept' => $GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_stripe_api_accept_bitcoin'] ? 'bitcoin' : '', 'coupon' => '', 'accept_coupons' => '0', 'default_country_code' => 'US', 'captcha' => '', 'template' => '', 'success' => ''), $attr); $attr['tt'] = strtoupper($attr['tt']); // Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). $attr['rt'] = strtoupper($attr['rt']); // Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). $attr['rr'] = strtoupper($attr['rr']); // Must be provided in upper-case format. Numerical, or BN value. Only after running shortcode_atts(). $attr['cc'] = strtoupper($attr['cc']); // Must be provided in upper-case format. Only after running shortcode_atts(). $attr['ccaps'] = strtolower($attr['ccaps']); // Custom Capabilities must be typed in lower-case format. Only after running shortcode_atts(). $attr['ccaps'] = str_replace(' ', '', $attr['ccaps']); // Custom Capabilities should not have spaces. $attr['rr'] = $attr['rt'] === 'L' ? 'BN' : $attr['rr']; // Lifetime Subscriptions require Buy Now. Only after running shortcode_atts(). $attr['rr'] = $attr['level'] === '*' ? 'BN' : $attr['rr']; // Independent Ccaps require Buy Now. Only after running shortcode_atts(). $attr['rr'] = !$attr['tp'] && !$attr['rr'] ? 'BN' : $attr['rr']; // No Trial / non-recurring. Only after running shortcode_atts(). $attr['default_country_code'] = strtoupper($attr['default_country_code']); // This MUST be in uppercase format. $attr['success'] = c_ws_plugin__s2member_utils_urls::n_amps($attr['success']); // Normalize ampersands. $attr['coupon'] = !empty($_GET['s2p-coupon']) ? trim(strip_tags(stripslashes($_GET['s2p-coupon']))) : $attr['coupon']; $attr['singular'] = get_the_ID(); // Collect the Singular ID for this Post/Page. $attr['accept'] = trim($attr['accept']) ? preg_split('/[;,]+/', preg_replace('/[' . "\r\n\t" . '\\s]+/', '', trim(strtolower($attr['accept'])))) : array(); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_before_sc_stripe_form_after_shortcode_atts', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. if ($attr['cancel']) { $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); $response = c_ws_plugin__s2member_pro_stripe_responses::stripe_cancellation_response($attr); $_p = $response['response'] && !$response['error'] ? array() : $_p; if ($attr['captcha']) { $captcha = '<div id="s2member-pro-stripe-cancellation-form-captcha-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-cancellation-form-section s2member-pro-stripe-form-captcha-section s2member-pro-stripe-cancellation-form-captcha-section">' . "\n"; $captcha .= '<div id="s2member-pro-stripe-cancellation-form-captcha-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-cancellation-form-section-title s2member-pro-stripe-form-captcha-section-title s2member-pro-stripe-cancellation-form-captcha-section-title">' . "\n"; $captcha .= _x('Security Code', 's2member-front', 's2member') . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '<div id="s2member-pro-stripe-cancellation-form-captcha-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-cancellation-form-div s2member-pro-stripe-form-captcha-div s2member-pro-stripe-cancellation-form-captcha-div">' . "\n"; $captcha .= '<label id="s2member-pro-stripe-cancellation-form-captcha-label" class="s2member-pro-stripe-form-captcha-label s2member-pro-stripe-cancellation-form-captcha-label">' . "\n"; $captcha .= c_ws_plugin__s2member_utils_captchas::recaptcha_script_tag($attr['captcha'], 10) . "\n"; $captcha .= '</label>' . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '</div>' . "\n"; } else { $captcha = ''; } // Not applicable. $hidden_inputs = '<input type="hidden" name="s2member_pro_stripe_cancellation[nonce]" id="s2member-pro-stripe-cancellation-nonce" value="' . esc_attr(wp_create_nonce('s2member-pro-stripe-cancellation')) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_cancellation[attr]" id="s2member-pro-stripe-cancellation-attr" value="' . esc_attr(c_ws_plugin__s2member_utils_encryption::encrypt(serialize($attr))) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2p-option" value="' . esc_attr((string) @$_REQUEST['s2p-option']) . '" />'; $custom_template = is_file(TEMPLATEPATH . '/stripe-cancellation-form.php') ? TEMPLATEPATH . '/stripe-cancellation-form.php' : ''; $custom_template = is_file(get_stylesheet_directory() . '/stripe-cancellation-form.php') ? get_stylesheet_directory() . '/stripe-cancellation-form.php' : $custom_template; $custom_template = $attr['template'] && is_file(TEMPLATEPATH . '/' . $attr['template']) ? TEMPLATEPATH . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(get_stylesheet_directory() . '/' . $attr['template']) ? get_stylesheet_directory() . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(WP_CONTENT_DIR . '/' . $attr['template']) ? WP_CONTENT_DIR . '/' . $attr['template'] : $custom_template; $code = trim(file_get_contents($custom_template ? $custom_template : dirname(dirname(dirname(dirname(__FILE__)))) . '/templates/forms/stripe-cancellation-form.php')); $code = trim(!$custom_template || !is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site() ? c_ws_plugin__s2member_utilities::evl($code) : $code); $code = preg_replace('/%%action%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr($_SERVER['REQUEST_URI'])), $code); $code = preg_replace('/%%response%%/', c_ws_plugin__s2member_utils_strings::esc_refs($response['response']), $code); $code = preg_replace('/%%description%%/', c_ws_plugin__s2member_utils_strings::esc_refs($attr['desc']), $code); $code = preg_replace('/%%captcha%%/', c_ws_plugin__s2member_utils_strings::esc_refs($captcha), $code); $code = preg_replace('/%%hidden_inputs%%/', c_ws_plugin__s2member_utils_strings::esc_refs($hidden_inputs), $code); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_during_sc_stripe_cancellation_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. } else { if ($attr['register']) { $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); $response = c_ws_plugin__s2member_pro_stripe_responses::stripe_registration_response($attr); $_p = $response['response'] && !$response['error'] ? array() : $_p; $custom_fields = ''; // Initialize custom fields. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { // Only display Custom Fields if configured. if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($attr['level'], 'registration')) { $tabindex = 99; // Start tabindex at 99 ( +1 below = 100 ). $custom_fields = '<div id="s2member-pro-stripe-registration-form-custom-fields-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-registration-form-section s2member-pro-stripe-form-custom-fields-section s2member-pro-stripe-registration-form-custom-fields-section">' . "\n"; $custom_fields .= '<div id="s2member-pro-stripe-registration-form-custom-fields-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-registration-form-section-title s2member-pro-stripe-form-custom-fields-section-title s2member-pro-stripe-registration-form-custom-fields-section-title">' . "\n"; $custom_fields .= _x('Additional Info', 's2member-front', 's2member') . "\n"; $custom_fields .= '</div>' . "\n"; foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { if (in_array($field['id'], $fields_applicable)) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (!empty($field['section']) && $field['section'] === 'yes') { // Starts a new section? $custom_fields .= '<div id="s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-divider-section" class="s2member-pro-stripe-form-div s2member-pro-stripe-registration-form-div s2member-pro-stripe-form-custom-reg-field-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . ' s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . ' s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . '">' . (!empty($field['sectitle']) ? $field['sectitle'] : '') . '</div>'; } $custom_fields .= '<div id="s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-registration-form-div s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-div s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-div">' . "\n"; $custom_fields .= '<label for="s2member-pro-stripe-registration-custom-reg-field-' . esc_attr($field_id_class) . '" id="s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-label" class="s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-label s2member-pro-stripe-registration-form-custom-reg-field-' . $field_id_class . '-label">' . "\n"; $custom_fields .= '<span' . (preg_match('/^(checkbox|pre_checkbox)$/', $field['type']) ? ' style="display:none;"' : '') . '>' . $field['label'] . ($field['required'] === 'yes' ? ' *' : '') . '</span></label>' . (preg_match('/^(checkbox|pre_checkbox)$/', $field['type']) ? '' : '<br />') . "\n"; $custom_fields .= c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, 's2member_pro_stripe_registration[custom_fields][', 's2member-pro-stripe-registration-custom-reg-field-', 's2member-pro-stripe-custom-reg-field-' . $field_id_class . ' s2member-pro-stripe-registration-custom-reg-field-' . $field_id_class, '', $tabindex = $tabindex + 1, '', @$_p['s2member_pro_stripe_registration'], @$_p['s2member_pro_stripe_registration']['custom_fields'][$field_var], 'registration'); $custom_fields .= '</div>' . "\n"; } } $custom_fields .= '</div>' . "\n"; } } if ($attr['captcha']) { $captcha = '<div id="s2member-pro-stripe-registration-form-captcha-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-registration-form-section s2member-pro-stripe-form-captcha-section s2member-pro-stripe-registration-form-captcha-section">' . "\n"; $captcha .= '<div id="s2member-pro-stripe-registration-form-captcha-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-registration-form-section-title s2member-pro-stripe-form-captcha-section-title s2member-pro-stripe-registration-form-captcha-section-title">' . "\n"; $captcha .= _x('Security Code', 's2member-front', 's2member') . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '<div id="s2member-pro-stripe-registration-form-captcha-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-registration-form-div s2member-pro-stripe-form-captcha-div s2member-pro-stripe-registration-form-captcha-div">' . "\n"; $captcha .= '<label id="s2member-pro-stripe-registration-form-captcha-label" class="s2member-pro-stripe-form-captcha-label s2member-pro-stripe-registration-form-captcha-label">' . "\n"; $captcha .= c_ws_plugin__s2member_utils_captchas::recaptcha_script_tag($attr['captcha'], 200) . "\n"; $captcha .= '</label>' . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '</div>' . "\n"; } else { $captcha = ''; } // Not applicable. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] && c_ws_plugin__s2member_list_servers::list_servers_integrated()) { $opt_in = '<div id="s2member-pro-stripe-registration-form-custom-reg-field-opt-in-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-registration-form-div s2member-pro-stripe-form-custom-reg-field-opt-in-div s2member-pro-stripe-registration-form-custom-reg-field-opt-in-div">' . "\n"; $opt_in .= '<label for="s2member-pro-stripe-registration-form-custom-reg-field-opt-in" id="s2member-pro-stripe-registration-form-custom-reg-field-opt-in-label" class="s2member-pro-stripe-form-custom-reg-field-opt-in-label s2member-pro-stripe-registration-form-custom-reg-field-opt-in-label">' . "\n"; $opt_in .= '<input type="checkbox" name="s2member_pro_stripe_registration[custom_fields][opt_in]" id="s2member-pro-stripe-registration-form-custom-reg-field-opt-in" class="s2member-pro-stripe-form-custom-reg-field-opt-in s2member-pro-stripe-registration-form-custom-reg-field-opt-in" value="1"' . (empty($_p['s2member_pro_stripe_registration']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] == 1 || @$_p['s2member_pro_stripe_registration']['custom_fields']['opt_in'] ? ' checked="checked"' : '') . ' tabindex="300" />' . "\n"; $opt_in .= $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in_label'] . "\n"; $opt_in .= '</label>' . "\n"; $opt_in .= '</div>' . "\n"; } else { $opt_in = ''; } // Not applicable. $hidden_inputs = '<input type="hidden" name="s2member_pro_stripe_registration[nonce]" id="s2member-pro-stripe-registration-nonce" value="' . esc_attr(wp_create_nonce('s2member-pro-stripe-registration')) . '" />'; $hidden_inputs .= !$GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_names'] ? '<input type="hidden" id="s2member-pro-stripe-registration-names-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= !$GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password'] ? '<input type="hidden" id="s2member-pro-stripe-registration-password-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_registration[attr]" id="s2member-pro-stripe-registration-attr" value="' . esc_attr(c_ws_plugin__s2member_utils_encryption::encrypt(serialize($attr))) . '" />'; $custom_template = is_file(TEMPLATEPATH . '/stripe-registration-form.php') ? TEMPLATEPATH . '/stripe-registration-form.php' : ''; $custom_template = is_file(get_stylesheet_directory() . '/stripe-registration-form.php') ? get_stylesheet_directory() . '/stripe-registration-form.php' : $custom_template; $custom_template = $attr['template'] && is_file(TEMPLATEPATH . '/' . $attr['template']) ? TEMPLATEPATH . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(get_stylesheet_directory() . '/' . $attr['template']) ? get_stylesheet_directory() . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(WP_CONTENT_DIR . '/' . $attr['template']) ? WP_CONTENT_DIR . '/' . $attr['template'] : $custom_template; $code = trim(file_get_contents($custom_template ? $custom_template : dirname(dirname(dirname(dirname(__FILE__)))) . '/templates/forms/stripe-registration-form.php')); $code = trim(!$custom_template || !is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site() ? c_ws_plugin__s2member_utilities::evl($code) : $code); $code = preg_replace('/%%action%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr($_SERVER['REQUEST_URI'])), $code); $code = preg_replace('/%%response%%/', c_ws_plugin__s2member_utils_strings::esc_refs($response['response']), $code); $code = preg_replace('/%%options%%/', c_ws_plugin__s2member_utils_strings::esc_refs($option_selections), $code); $code = preg_replace('/%%description%%/', c_ws_plugin__s2member_utils_strings::esc_refs($attr['desc']), $code); $code = preg_replace('/%%first_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_registration']['first_name'])), $code); $code = preg_replace('/%%last_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_registration']['last_name'])), $code); $code = preg_replace('/%%email_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_registration']['email'])), $code); $code = preg_replace('/%%username_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_registration']['username'])), $code); $code = preg_replace('/%%password1_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_registration']['password1'])), $code); $code = preg_replace('/%%password2_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_registration']['password2'])), $code); $code = preg_replace('/%%custom_fields%%/', c_ws_plugin__s2member_utils_strings::esc_refs($custom_fields), $code); $code = preg_replace('/%%captcha%%/', c_ws_plugin__s2member_utils_strings::esc_refs($captcha), $code); $code = preg_replace('/%%opt_in%%/', c_ws_plugin__s2member_utils_strings::esc_refs($opt_in), $code); $code = preg_replace('/%%hidden_inputs%%/', c_ws_plugin__s2member_utils_strings::esc_refs($hidden_inputs), $code); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_during_sc_stripe_registration_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. } else { if ($attr['update']) { $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); $response = c_ws_plugin__s2member_pro_stripe_responses::stripe_update_response($attr); $_p = $response['response'] && !$response['error'] ? array() : $_p; if ($attr['captcha']) { $captcha = '<div id="s2member-pro-stripe-update-form-captcha-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-update-form-section s2member-pro-stripe-form-captcha-section s2member-pro-stripe-update-form-captcha-section">' . "\n"; $captcha .= '<div id="s2member-pro-stripe-update-form-captcha-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-update-form-section-title s2member-pro-stripe-form-captcha-section-title s2member-pro-stripe-update-form-captcha-section-title">' . "\n"; $captcha .= _x('Security Code', 's2member-front', 's2member') . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '<div id="s2member-pro-stripe-update-form-captcha-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-update-form-div s2member-pro-stripe-form-captcha-div s2member-pro-stripe-update-form-captcha-div">' . "\n"; $captcha .= '<label id="s2member-pro-stripe-update-form-captcha-label" class="s2member-pro-stripe-form-captcha-label s2member-pro-stripe-update-form-captcha-label">' . "\n"; $captcha .= c_ws_plugin__s2member_utils_captchas::recaptcha_script_tag($attr['captcha'], 200) . "\n"; $captcha .= '</label>' . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '</div>' . "\n"; } else { $captcha = ''; } // Not applicable. $hidden_inputs = '<input type="hidden" name="s2member_pro_stripe_update[nonce]" id="s2member-pro-stripe-update-nonce" value="' . esc_attr(wp_create_nonce('s2member-pro-stripe-update')) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_update[source_token]" id="s2member-pro-stripe-update-source-token" value="' . esc_attr(@$_p['s2member_pro_stripe_update']['source_token']) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_update[source_token_summary]" id="s2member-pro-stripe-update-source-token-summary" value="' . esc_attr(@$_p['s2member_pro_stripe_update']['source_token_summary']) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_update[attr]" id="s2member-pro-stripe-update-attr" value="' . esc_attr(c_ws_plugin__s2member_utils_encryption::encrypt(serialize($attr))) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2p-option" value="' . esc_attr((string) @$_REQUEST['s2p-option']) . '" />'; $custom_template = is_file(TEMPLATEPATH . '/stripe-update-form.php') ? TEMPLATEPATH . '/stripe-update-form.php' : ''; $custom_template = is_file(get_stylesheet_directory() . '/stripe-update-form.php') ? get_stylesheet_directory() . '/stripe-update-form.php' : $custom_template; $custom_template = $attr['template'] && is_file(TEMPLATEPATH . '/' . $attr['template']) ? TEMPLATEPATH . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(get_stylesheet_directory() . '/' . $attr['template']) ? get_stylesheet_directory() . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(WP_CONTENT_DIR . '/' . $attr['template']) ? WP_CONTENT_DIR . '/' . $attr['template'] : $custom_template; $custom_template_contents = $custom_template ? trim(file_get_contents($custom_template)) : ''; if ($custom_template_contents && stripos($custom_template_contents, '%%source_token_summary%%') === FALSE) { $custom_template_contents = ''; } // Custom template must be up-to-date. $code = $custom_template_contents ? $custom_template_contents : trim(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/templates/forms/stripe-update-form.php')); $code = trim(!$custom_template_contents || !is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site() ? c_ws_plugin__s2member_utilities::evl($code) : $code); $code = preg_replace('/%%action%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr($_SERVER['REQUEST_URI'])), $code); $code = preg_replace('/%%response%%/', c_ws_plugin__s2member_utils_strings::esc_refs($response['response']), $code); $code = preg_replace('/%%description%%/', c_ws_plugin__s2member_utils_strings::esc_refs($attr['desc']), $code); $code = preg_replace('/%%source_token%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_update']['source_token'])), $code); $code = preg_replace('/%%source_token_summary%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_update']['source_token_summary'])), $code); $code = preg_replace('/%%captcha%%/', c_ws_plugin__s2member_utils_strings::esc_refs($captcha), $code); $code = preg_replace('/%%hidden_inputs%%/', c_ws_plugin__s2member_utils_strings::esc_refs($hidden_inputs), $code); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_during_sc_stripe_update_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. } else { if ($attr['sp']) { $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); $attr['sp_ids_exp'] = 'sp:' . $attr['ids'] . ':' . $attr['exp']; // Combined `sp:ids:expiration hours`. $attr['coupon'] = !empty($_p['s2member_pro_stripe_sp_checkout']['coupon']) ? $_p['s2member_pro_stripe_sp_checkout']['coupon'] : $attr['coupon']; $response = c_ws_plugin__s2member_pro_stripe_responses::stripe_sp_checkout_response($attr); $_p = $response['response'] && !$response['error'] ? array() : $_p; $tax_may_apply = c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply(); // Tax may apply? $cp_attr = $cp_buy_now_attr = c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($attr, $attr['coupon']); // ↑ The discounted amounts, but before any tax calculations occur during checkout. $is_buy_now = TRUE; // Always true for Specific Post/Page Access transactions. $is_buy_now_amount = $is_buy_now && $cp_buy_now_attr['ra'] > 0 ? number_format($cp_buy_now_attr['ra'], 2, '.', '') : '0.00'; $is_buy_now_currency = $is_buy_now ? $cp_buy_now_attr['cc'] : ''; // Note that Bitcoin can only be charged in USD at the present time. $is_buy_now_amount_in_cents = $is_buy_now && $is_buy_now_amount > 0 ? (string) c_ws_plugin__s2member_pro_stripe_utilities::dollar_amount_to_cents($is_buy_now_amount, $is_buy_now_currency) : '0'; $is_buy_now_desc = $is_buy_now ? $cp_buy_now_attr['desc'] : ''; // This description is used for Bitcoin transaction; description for receiver. $is_buy_now_bitcoin_accepted = $is_buy_now && $is_buy_now_amount_in_cents > 0 && $is_buy_now_currency === 'USD' && in_array('bitcoin', $cp_buy_now_attr['accept'], TRUE); $country_default_by_currency = !@$_p['s2member_pro_stripe_sp_checkout']['country'] && $attr['cc'] === 'USD' ? 'US' : ''; $country_default_by_currency = !@$_p['s2member_pro_stripe_sp_checkout']['country'] && $attr['cc'] === 'CAD' ? 'CA' : $country_default_by_currency; $country_default_by_currency = !@$_p['s2member_pro_stripe_sp_checkout']['country'] && $attr['cc'] === 'GBP' ? 'GB' : $country_default_by_currency; $country_default_by_currency = apply_filters('ws_plugin__s2member_pro_stripe_default_country', $country_default_by_currency, get_defined_vars()); $default_country_v = $attr['default_country_code'] ? $attr['default_country_code'] : $country_default_by_currency; $country_options = '<option value=""></option>'; // Start with an empty option value. foreach (preg_split('/[' . "\r\n" . ']+/', file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/iso-3166-1.txt')) as $country) { list($country_l, $country_v) = preg_split('/;/', $country, 2); if ($country_l && $country_v) { // Here we also check on the default pre-selected country; as determined above; based on currency. $country_options .= '<option value="' . esc_attr(strtoupper($country_v)) . '"' . (@$_p['s2member_pro_stripe_sp_checkout']['country'] === $country_v || $default_country_v === $country_v ? ' selected="selected"' : '') . '>' . esc_html(ucwords(strtolower($country_l))) . '</option>'; } } if ($attr['captcha']) { $captcha = '<div id="s2member-pro-stripe-sp-checkout-form-captcha-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-sp-checkout-form-section s2member-pro-stripe-form-captcha-section s2member-pro-stripe-sp-checkout-form-captcha-section">' . "\n"; $captcha .= '<div id="s2member-pro-stripe-sp-checkout-form-captcha-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-sp-checkout-form-section-title s2member-pro-stripe-form-captcha-section-title s2member-pro-stripe-sp-checkout-form-captcha-section-title">' . "\n"; $captcha .= _x('Security Code', 's2member-front', 's2member') . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '<div id="s2member-pro-stripe-sp-checkout-form-captcha-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-sp-checkout-form-div s2member-pro-stripe-form-captcha-div s2member-pro-stripe-sp-checkout-form-captcha-div">' . "\n"; $captcha .= '<label id="s2member-pro-stripe-sp-checkout-form-captcha-label" class="s2member-pro-stripe-form-captcha-label s2member-pro-stripe-sp-checkout-form-captcha-label">' . "\n"; $captcha .= c_ws_plugin__s2member_utils_captchas::recaptcha_script_tag($attr['captcha'], 300) . "\n"; $captcha .= '</label>' . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '</div>' . "\n"; } else { $captcha = ''; } // Not applicable. /* Build the opt-in checkbox. */ if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] && c_ws_plugin__s2member_list_servers::list_servers_integrated()) { $opt_in = '<div id="s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-sp-checkout-form-div s2member-pro-stripe-form-custom-reg-field-opt-in-div s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in-div">' . "\n"; $opt_in .= '<label for="s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in" id="s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in-label" class="s2member-pro-stripe-form-custom-reg-field-opt-in-label s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in-label">' . "\n"; $opt_in .= '<input type="checkbox" name="s2member_pro_stripe_sp_checkout[custom_fields][opt_in]" id="s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in" class="s2member-pro-stripe-form-custom-reg-field-opt-in s2member-pro-stripe-sp-checkout-form-custom-reg-field-opt-in" value="1"' . (empty($_p['s2member_pro_stripe_sp_checkout']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] == 1 || @$_p['s2member_pro_stripe_sp_checkout']['custom_fields']['opt_in'] ? ' checked="checked"' : '') . ' tabindex="400" />' . "\n"; $opt_in .= $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in_label'] . "\n"; $opt_in .= '</label>' . "\n"; $opt_in .= '</div>' . "\n"; } else { $opt_in = ''; } // Not applicable. $hidden_inputs = '<input type="hidden" name="s2member_pro_stripe_sp_checkout[nonce]" id="s2member-pro-stripe-sp-checkout-nonce" value="' . esc_attr(wp_create_nonce('s2member-pro-stripe-sp-checkout')) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_sp_checkout[source_token]" id="s2member-pro-stripe-sp-checkout-source-token" value="' . esc_attr(@$_p['s2member_pro_stripe_sp_checkout']['source_token']) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_sp_checkout[source_token_summary]" id="s2member-pro-stripe-sp-checkout-source-token-summary" value="' . esc_attr(@$_p['s2member_pro_stripe_sp_checkout']['source_token_summary']) . '" />'; $hidden_inputs .= !$attr['accept_coupons'] ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-coupons-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= !$tax_may_apply ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-tax-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= $is_buy_now_amount <= 0 ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-payment-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= $is_buy_now_amount > 0 ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-is-buy-now-amount" value="' . esc_attr($is_buy_now_amount) . '" />' : ''; $hidden_inputs .= $is_buy_now_amount_in_cents > 0 ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-is-buy-now-amount-in-cents" value="' . esc_attr($is_buy_now_amount_in_cents) . '" />' : ''; $hidden_inputs .= $is_buy_now_currency ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-is-buy-now-currency" value="' . esc_attr($is_buy_now_currency) . '" />' : ''; $hidden_inputs .= $is_buy_now_desc ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-is-buy-now-desc" value="' . esc_attr($is_buy_now_desc) . '" />' : ''; $hidden_inputs .= $is_buy_now_bitcoin_accepted ? '<input type="hidden" id="s2member-pro-stripe-sp-checkout-is-buy-now-bitcoin-accepted" value="1" />' : ''; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_sp_checkout[attr]" id="s2member-pro-stripe-sp-checkout-attr" value="' . esc_attr(c_ws_plugin__s2member_utils_encryption::encrypt(serialize($attr))) . '" />'; $custom_template = is_file(TEMPLATEPATH . '/stripe-sp-checkout-form.php') ? TEMPLATEPATH . '/stripe-sp-checkout-form.php' : ''; $custom_template = is_file(get_stylesheet_directory() . '/stripe-sp-checkout-form.php') ? get_stylesheet_directory() . '/stripe-sp-checkout-form.php' : $custom_template; $custom_template = $attr['template'] && is_file(TEMPLATEPATH . '/' . $attr['template']) ? TEMPLATEPATH . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(get_stylesheet_directory() . '/' . $attr['template']) ? get_stylesheet_directory() . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(WP_CONTENT_DIR . '/' . $attr['template']) ? WP_CONTENT_DIR . '/' . $attr['template'] : $custom_template; $custom_template_contents = $custom_template ? trim(file_get_contents($custom_template)) : ''; if ($custom_template_contents && stripos($custom_template_contents, '%%source_token_summary%%') === FALSE) { $custom_template_contents = ''; } // Custom template must be up-to-date. $code = $custom_template_contents ? $custom_template_contents : trim(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/templates/forms/stripe-sp-checkout-form.php')); $code = trim(!$custom_template_contents || !is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site() ? c_ws_plugin__s2member_utilities::evl($code) : $code); $code = preg_replace('/%%action%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr($_SERVER['REQUEST_URI'])), $code); $code = preg_replace('/%%response%%/', c_ws_plugin__s2member_utils_strings::esc_refs($response['response']), $code); $code = preg_replace('/%%options%%/', c_ws_plugin__s2member_utils_strings::esc_refs($option_selections), $code); $code = preg_replace('/%%description%%/', c_ws_plugin__s2member_utils_strings::esc_refs($attr['desc']), $code); $code = preg_replace('/%%coupon_response%%/', c_ws_plugin__s2member_utils_strings::esc_refs(c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($attr, $attr['coupon'], 'response', array('affiliates-1px-response'))), $code); $code = preg_replace('/%%coupon_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit($attr['coupon'])), $code); $code = preg_replace('/%%first_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_sp_checkout']['first_name'])), $code); $code = preg_replace('/%%last_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_sp_checkout']['last_name'])), $code); $code = preg_replace('/%%email_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_sp_checkout']['email'])), $code); $code = preg_replace('/%%source_token%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_sp_checkout']['source_token'])), $code); $code = preg_replace('/%%source_token_summary%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_sp_checkout']['source_token_summary'])), $code); $code = preg_replace('/%%state_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_sp_checkout']['state'])), $code); $code = preg_replace('/%%country_options%%/', c_ws_plugin__s2member_utils_strings::esc_refs($country_options), $code); $code = preg_replace('/%%zip_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_sp_checkout']['zip'])), $code); $code = preg_replace('/%%captcha%%/', c_ws_plugin__s2member_utils_strings::esc_refs($captcha), $code); $code = preg_replace('/%%opt_in%%/', c_ws_plugin__s2member_utils_strings::esc_refs($opt_in), $code); $code = preg_replace('/%%hidden_inputs%%/', c_ws_plugin__s2member_utils_strings::esc_refs($hidden_inputs), $code); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_pro_during_sc_stripe_sp_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. } else { $_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST)); $attr['level_ccaps_eotper'] = $attr['rr'] === 'BN' && $attr['rt'] !== 'L' ? $attr['level'] . ':' . $attr['ccaps'] . ':' . $attr['rp'] . ' ' . $attr['rt'] : $attr['level'] . ':' . $attr['ccaps']; $attr['level_ccaps_eotper'] = rtrim($attr['level_ccaps_eotper'], ':'); // Clean any trailing separators from this string. $attr['coupon'] = !empty($_p['s2member_pro_stripe_checkout']['coupon']) ? $_p['s2member_pro_stripe_checkout']['coupon'] : $attr['coupon']; $response = c_ws_plugin__s2member_pro_stripe_responses::stripe_checkout_response($attr); $_p = $response['response'] && !$response['error'] ? array() : $_p; $tax_may_apply = c_ws_plugin__s2member_pro_stripe_utilities::tax_may_apply(); // Tax may apply? $cp_attr = $cp_buy_now_attr = c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($attr, $attr['coupon']); // ↑ The discounted amounts, but before any tax calculations occur during checkout. if ($cp_buy_now_attr['ra'] <= 0 && $cp_buy_now_attr['tp'] && $cp_buy_now_attr['ta'] > 0) { $cp_buy_now_attr['tp'] = '0'; // Ditch the trial period completely. $cp_buy_now_attr['ra'] = $cp_buy_now_attr['ta']; // Use as regular amount. $cp_buy_now_attr['ta'] = '0.00'; // Ditch this calculation now. } $is_buy_now = $cp_buy_now_attr['rr'] === 'BN' || !$cp_buy_now_attr['tp'] && !$cp_buy_now_attr['rr']; $is_buy_now_amount = $is_buy_now && $cp_buy_now_attr['ra'] > 0 ? number_format($cp_buy_now_attr['ra'], 2, '.', '') : '0.00'; $is_buy_now_currency = $is_buy_now ? $cp_buy_now_attr['cc'] : ''; // Note that Bitcoin can only be charged in USD at the present time. $is_buy_now_amount_in_cents = $is_buy_now && $is_buy_now_amount > 0 ? (string) c_ws_plugin__s2member_pro_stripe_utilities::dollar_amount_to_cents($is_buy_now_amount, $is_buy_now_currency) : '0'; $is_buy_now_desc = $is_buy_now ? $cp_buy_now_attr['desc'] : ''; // This description is used for Bitcoin transaction; description for receiver. $is_buy_now_bitcoin_accepted = $is_buy_now && $is_buy_now_amount_in_cents > 0 && $is_buy_now_currency === 'USD' && in_array('bitcoin', $cp_buy_now_attr['accept'], TRUE); $country_default_by_currency = !@$_p['s2member_pro_stripe_checkout']['country'] && $attr['cc'] === 'USD' ? 'US' : ''; $country_default_by_currency = !@$_p['s2member_pro_stripe_checkout']['country'] && $attr['cc'] === 'CAD' ? 'CA' : $country_default_by_currency; $country_default_by_currency = !@$_p['s2member_pro_stripe_checkout']['country'] && $attr['cc'] === 'GBP' ? 'GB' : $country_default_by_currency; $country_default_by_currency = apply_filters('ws_plugin__s2member_pro_stripe_default_country', $country_default_by_currency, get_defined_vars()); $default_country_v = $attr['default_country_code'] ? $attr['default_country_code'] : $country_default_by_currency; $country_options = '<option value=""></option>'; // Start with an empty option value. foreach (preg_split('/[' . "\r\n" . ']+/', file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/iso-3166-1.txt')) as $country) { list($country_l, $country_v) = preg_split('/;/', $country, 2); if ($country_l && $country_v) { // Here we also check on the default pre-selected country; as determined above; based on currency. $country_options .= '<option value="' . esc_attr(strtoupper($country_v)) . '"' . (@$_p['s2member_pro_stripe_checkout']['country'] === $country_v || $default_country_v === $country_v ? ' selected="selected"' : '') . '>' . esc_html(ucwords(strtolower($country_l))) . '</option>'; } } $custom_fields = ''; // Initialize custom fields. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields']) { // Only display Custom Fields if configured. if ($fields_applicable = c_ws_plugin__s2member_custom_reg_fields::custom_fields_configured_at_level($attr['level'] === '*' ? 'auto-detection' : $attr['level'], 'registration')) { $tabindex = 99; // Start tabindex at 99 (+1 below = 100). $custom_fields = '<div id="s2member-pro-stripe-checkout-form-custom-fields-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-checkout-form-section s2member-pro-stripe-form-custom-fields-section s2member-pro-stripe-checkout-form-custom-fields-section">' . "\n"; $custom_fields .= '<div id="s2member-pro-stripe-checkout-form-custom-fields-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-checkout-form-section-title s2member-pro-stripe-form-custom-fields-section-title s2member-pro-stripe-checkout-form-custom-fields-section-title">' . "\n"; $custom_fields .= _x('Additional Info', 's2member-front', 's2member') . "\n"; $custom_fields .= '</div>' . "\n"; foreach (json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], TRUE) as $field) { if (in_array($field['id'], $fields_applicable)) { $field_var = preg_replace('/[^a-z0-9]/i', '_', strtolower($field['id'])); $field_id_class = preg_replace('/_/', '-', $field_var); if (!empty($field['section']) && $field['section'] === 'yes') { // Starts a new section? $custom_fields .= '<div id="s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-divider-section" class="s2member-pro-stripe-form-div s2member-pro-stripe-checkout-form-div s2member-pro-stripe-form-custom-reg-field-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . ' s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . ' s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-divider-section' . (!empty($field['sectitle']) ? '-title' : '') . '">' . (!empty($field['sectitle']) ? $field['sectitle'] : '') . '</div>'; } $custom_fields .= '<div id="s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-checkout-form-div s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-div s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-div">' . "\n"; $custom_fields .= '<label for="s2member-pro-stripe-checkout-custom-reg-field-' . esc_attr($field_id_class) . '" id="s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-label" class="s2member-pro-stripe-form-custom-reg-field-' . $field_id_class . '-label s2member-pro-stripe-checkout-form-custom-reg-field-' . $field_id_class . '-label">' . "\n"; $custom_fields .= '<span' . (preg_match('/^(checkbox|pre_checkbox)$/', $field['type']) ? ' style="display:none;"' : '') . '>' . $field['label'] . ($field['required'] === 'yes' ? ' *' : '') . '</span></label>' . (preg_match('/^(checkbox|pre_checkbox)$/', $field['type']) ? '' : '<br />') . "\n"; $custom_fields .= c_ws_plugin__s2member_custom_reg_fields::custom_field_gen(__FUNCTION__, $field, 's2member_pro_stripe_checkout[custom_fields][', 's2member-pro-stripe-checkout-custom-reg-field-', 's2member-pro-stripe-custom-reg-field-' . $field_id_class . ' s2member-pro-stripe-checkout-custom-reg-field-' . $field_id_class, '', $tabindex = $tabindex + 1, '', @$_p['s2member_pro_stripe_checkout'], @$_p['s2member_pro_stripe_checkout']['custom_fields'][$field_var], 'registration'); $custom_fields .= '</div>' . "\n"; } } $custom_fields .= '</div>' . "\n"; } } if ($attr['captcha']) { $captcha = '<div id="s2member-pro-stripe-checkout-form-captcha-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-checkout-form-section s2member-pro-stripe-form-captcha-section s2member-pro-stripe-checkout-form-captcha-section">' . "\n"; $captcha .= '<div id="s2member-pro-stripe-checkout-form-captcha-section-title" class="s2member-pro-stripe-form-section-title s2member-pro-stripe-checkout-form-section-title s2member-pro-stripe-form-captcha-section-title s2member-pro-stripe-checkout-form-captcha-section-title">' . "\n"; $captcha .= _x('Security Code', 's2member-front', 's2member') . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '<div id="s2member-pro-stripe-checkout-form-captcha-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-checkout-form-div s2member-pro-stripe-form-captcha-div s2member-pro-stripe-checkout-form-captcha-div">' . "\n"; $captcha .= '<label id="s2member-pro-stripe-checkout-form-captcha-label" class="s2member-pro-stripe-form-captcha-label s2member-pro-stripe-checkout-form-captcha-label">' . "\n"; $captcha .= c_ws_plugin__s2member_utils_captchas::recaptcha_script_tag($attr['captcha'], 400) . "\n"; $captcha .= '</label>' . "\n"; $captcha .= '</div>' . "\n"; $captcha .= '</div>' . "\n"; } else { $captcha = ''; } // Not applicable. if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] && c_ws_plugin__s2member_list_servers::list_servers_integrated()) { $opt_in = '<div id="s2member-pro-stripe-checkout-form-custom-reg-field-opt-in-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-checkout-form-div s2member-pro-stripe-form-custom-reg-field-opt-in-div s2member-pro-stripe-checkout-form-custom-reg-field-opt-in-div">' . "\n"; $opt_in .= '<label for="s2member-pro-stripe-checkout-form-custom-reg-field-opt-in" id="s2member-pro-stripe-checkout-form-custom-reg-field-opt-in-label" class="s2member-pro-stripe-form-custom-reg-field-opt-in-label s2member-pro-stripe-checkout-form-custom-reg-field-opt-in-label">' . "\n"; $opt_in .= '<input type="checkbox" name="s2member_pro_stripe_checkout[custom_fields][opt_in]" id="s2member-pro-stripe-checkout-form-custom-reg-field-opt-in" class="s2member-pro-stripe-form-custom-reg-field-opt-in s2member-pro-stripe-checkout-form-custom-reg-field-opt-in" value="1"' . (empty($_p['s2member_pro_stripe_checkout']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in'] == 1 || @$_p['s2member_pro_stripe_checkout']['custom_fields']['opt_in'] ? ' checked="checked"' : '') . ' tabindex="500" />' . "\n"; $opt_in .= $GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_opt_in_label'] . "\n"; $opt_in .= '</label>' . "\n"; $opt_in .= '</div>' . "\n"; } else { $opt_in = ''; } // Not applicable. $hidden_inputs = '<input type="hidden" name="s2member_pro_stripe_checkout[nonce]" id="s2member-pro-stripe-checkout-nonce" value="' . esc_attr(wp_create_nonce('s2member-pro-stripe-checkout')) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_checkout[source_token]" id="s2member-pro-stripe-checkout-source-token" value="' . esc_attr(@$_p['s2member_pro_stripe_checkout']['source_token']) . '" />'; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_checkout[source_token_summary]" id="s2member-pro-stripe-checkout-source-token-summary" value="' . esc_attr(@$_p['s2member_pro_stripe_checkout']['source_token_summary']) . '" />'; $hidden_inputs .= !$attr['accept_coupons'] ? '<input type="hidden" id="s2member-pro-stripe-checkout-coupons-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= !$GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_password'] ? '<input type="hidden" id="s2member-pro-stripe-checkout-password-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= !$tax_may_apply ? '<input type="hidden" id="s2member-pro-stripe-checkout-tax-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= $cp_attr['ta'] <= 0 && $cp_attr['ra'] <= 0 ? '<input type="hidden" id="s2member-pro-stripe-checkout-payment-not-required-or-not-possible" value="1" />' : ''; $hidden_inputs .= $is_buy_now_amount > 0 ? '<input type="hidden" id="s2member-pro-stripe-checkout-is-buy-now-amount" value="' . esc_attr($is_buy_now_amount) . '" />' : ''; $hidden_inputs .= $is_buy_now_amount_in_cents > 0 ? '<input type="hidden" id="s2member-pro-stripe-checkout-is-buy-now-amount-in-cents" value="' . esc_attr($is_buy_now_amount_in_cents) . '" />' : ''; $hidden_inputs .= $is_buy_now_currency ? '<input type="hidden" id="s2member-pro-stripe-checkout-is-buy-now-currency" value="' . esc_attr($is_buy_now_currency) . '" />' : ''; $hidden_inputs .= $is_buy_now_desc ? '<input type="hidden" id="s2member-pro-stripe-checkout-is-buy-now-desc" value="' . esc_attr($is_buy_now_desc) . '" />' : ''; $hidden_inputs .= $is_buy_now_bitcoin_accepted ? '<input type="hidden" id="s2member-pro-stripe-checkout-is-buy-now-bitcoin-accepted" value="1" />' : ''; $hidden_inputs .= '<input type="hidden" name="s2member_pro_stripe_checkout[attr]" id="s2member-pro-stripe-checkout-attr" value="' . esc_attr(c_ws_plugin__s2member_utils_encryption::encrypt(serialize($attr))) . '" />'; $custom_template = is_file(TEMPLATEPATH . '/stripe-checkout-form.php') ? TEMPLATEPATH . '/stripe-checkout-form.php' : ''; $custom_template = is_file(get_stylesheet_directory() . '/stripe-checkout-form.php') ? get_stylesheet_directory() . '/stripe-checkout-form.php' : $custom_template; $custom_template = $attr['template'] && is_file(TEMPLATEPATH . '/' . $attr['template']) ? TEMPLATEPATH . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(get_stylesheet_directory() . '/' . $attr['template']) ? get_stylesheet_directory() . '/' . $attr['template'] : $custom_template; $custom_template = $attr['template'] && is_file(WP_CONTENT_DIR . '/' . $attr['template']) ? WP_CONTENT_DIR . '/' . $attr['template'] : $custom_template; $custom_template_contents = $custom_template ? trim(file_get_contents($custom_template)) : ''; if ($custom_template_contents && stripos($custom_template_contents, '%%source_token_summary%%') === FALSE) { $custom_template_contents = ''; } // Custom template must be up-to-date. $code = $custom_template_contents ? $custom_template_contents : trim(file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/templates/forms/stripe-checkout-form.php')); $code = trim(!$custom_template_contents || !is_multisite() || !c_ws_plugin__s2member_utils_conds::is_multisite_farm() || is_main_site() ? c_ws_plugin__s2member_utilities::evl($code) : $code); $code = preg_replace('/%%action%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr($_SERVER['REQUEST_URI'])), $code); $code = preg_replace('/%%response%%/', c_ws_plugin__s2member_utils_strings::esc_refs($response['response']), $code); $code = preg_replace('/%%options%%/', c_ws_plugin__s2member_utils_strings::esc_refs($option_selections), $code); $code = preg_replace('/%%description%%/', c_ws_plugin__s2member_utils_strings::esc_refs($attr['desc']), $code); $code = preg_replace('/%%coupon_response%%/', c_ws_plugin__s2member_utils_strings::esc_refs(c_ws_plugin__s2member_pro_stripe_utilities::apply_coupon($attr, $attr['coupon'], 'response', array('affiliates-1px-response'))), $code); $code = preg_replace('/%%coupon_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit($attr['coupon'])), $code); $code = preg_replace('/%%first_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_checkout']['first_name'])), $code); $code = preg_replace('/%%last_name_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_attr(@$_p['s2member_pro_stripe_checkout']['last_name'])), $code); $code = preg_replace('/%%email_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['email'])), $code); $code = preg_replace('/%%username_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['username'])), $code); $code = preg_replace('/%%password1_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['password1'])), $code); $code = preg_replace('/%%password2_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['password2'])), $code); $code = preg_replace('/%%custom_fields%%/', c_ws_plugin__s2member_utils_strings::esc_refs($custom_fields), $code); $code = preg_replace('/%%source_token%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_checkout']['source_token'])), $code); $code = preg_replace('/%%source_token_summary%%/', c_ws_plugin__s2member_utils_strings::esc_refs(esc_html(@$_p['s2member_pro_stripe_checkout']['source_token_summary'])), $code); $code = preg_replace('/%%state_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['state'])), $code); $code = preg_replace('/%%country_options%%/', c_ws_plugin__s2member_utils_strings::esc_refs($country_options), $code); $code = preg_replace('/%%zip_value%%/', c_ws_plugin__s2member_utils_strings::esc_refs(format_to_edit(@$_p['s2member_pro_stripe_checkout']['zip'])), $code); $code = preg_replace('/%%captcha%%/', c_ws_plugin__s2member_utils_strings::esc_refs($captcha), $code); $code = preg_replace('/%%opt_in%%/', c_ws_plugin__s2member_utils_strings::esc_refs($opt_in), $code); $code = preg_replace('/%%hidden_inputs%%/', c_ws_plugin__s2member_utils_strings::esc_refs($hidden_inputs), $code); foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } $attr['modify'] ? do_action('ws_plugin__s2member_pro_during_sc_stripe_modification_form', get_defined_vars()) : do_action('ws_plugin__s2member_pro_during_sc_stripe_form', get_defined_vars()); unset($__refs, $__v); // Ditch these temporary vars. } } } } return apply_filters('ws_plugin__s2member_pro_sc_stripe_form', $code, get_defined_vars()); }
/** * Auto EOT time, else NPR (next payment time). * * @package s2Member\Utilities * @since 150713 * * @param int|string $user_id Optional. Defaults to the current User's ID. * @param bool $check_gateway Defaults to a true value. If this is false, it is only possible to return a fixed EOT time. * In other words, if this is false and there is no EOT time, empty values will be returned. Be careful with this, because not checking * the payment gateway can result in an inaccurate return value. Only set to false if you want to limit the check to a fixed hard-coded EOT time. * @param string $favor Defaults to a value of `fixed`; i.e., if a fixed EOT time is available, that is returned in favor of a next payment time. * You can set this to `next` if you'd like to favor a next payment time (when applicable) instead of returning a fixed EOT time. * * @return array An associative array of EOT details; with the following elements. * * - `type` One of `fixed` (a fixed EOT time), `next` (next payment time; i.e., an ongoing recurring subscription); or an empty string if there is no EOT for the user. * - `time` The timestamp (UTC time) that represents the EOT (End Of Term); else `0` if there is no EOT time. * - `tense` If time is now (or earlier) this will be `past`. If time is in the future, this will be `future`. If there is no time, this is an empty string. * - `debug` A string of details that explain to a developer what was returned. For debugging only. */ public static function get_user_eot($user_id = 0, $check_gateway = TRUE, $favor = 'fixed') { if (!($user_id = (int) $user_id)) { // Empty user ID in this call? $user_id = get_current_user_id(); } // Assume current user. if (!$favor || !in_array($favor, array('fixed', 'next'), TRUE)) { $favor = 'fixed'; } // Default behavior. $now = time(); // Current timestamp. $grace_time = (int) $GLOBALS['WS_PLUGIN__']['s2member']['o']['eot_grace_time']; $grace_time = (int) apply_filters('ws_plugin__s2member_eot_grace_time', $grace_time); $demotion_role = c_ws_plugin__s2member_option_forces::force_demotion_role('subscriber'); $empty_response = array('type' => '', 'time' => 0, 'tense' => '', 'debug' => ''); if (!$user_id || !($user = new WP_User($user_id)) || !$user->ID) { return array_merge($empty_response, array('debug' => 'Invalid user ID.')); } $ipn_signup_vars = self::get_user_ipn_signup_vars($user->ID); $subscr_gateway = (string) get_user_option('s2member_subscr_gateway', $user->ID); $subscr_id = (string) get_user_option('s2member_subscr_id', $user->ID); $subscr_cid = (string) get_user_option('s2member_subscr_cid', $user->ID); $last_auto_eot_time = (int) get_user_option('s2member_last_auto_eot_time', $user->ID); $auto_eot_time = (int) get_user_option('s2member_auto_eot_time', $user->ID); if ($auto_eot_time) { // They have a hard-coded EOT time at present? return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is a fixed EOT time recorded by s2Member. It can be altered in the WordPress Dashboard for this user.'); } if (!$subscr_gateway && !$subscr_id && !$subscr_cid && $last_auto_eot_time && (!user_can($user->ID, 'access_s2member_level1') || c_ws_plugin__s2member_user_access::user_access_role($user) === $demotion_role) && !c_ws_plugin__s2member_user_access::user_access_ccaps($user)) { return array('type' => 'fixed', 'time' => $last_auto_eot_time, 'tense' => $last_auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is an archived/fixed EOT time recorded by s2Member; i.e., the date this customer\'s access expired.'); } if (!$subscr_gateway || !$subscr_id || !is_array($ipn_signup_vars) || !$ipn_signup_vars) { return array_merge($empty_response, array('debug' => 'This user has no subscription; i.e., missing `subscr_id`, `subscr_gateway` or `ipn_signup_vars`.')); } if (empty($ipn_signup_vars['txn_type']) || $ipn_signup_vars['txn_type'] !== 'subscr_signup') { return array_merge($empty_response, array('debug' => 'This user has no subscription; i.e., `txn_type` != `subscr_signup`.')); } $auto_eot_time = c_ws_plugin__s2member_utils_time::auto_eot_time($user->ID, $ipn_signup_vars['period1'], $ipn_signup_vars['period3']); if ($check_gateway) { switch ($subscr_gateway) { case 'paypal': // PayPal (PayPal Pro only). if (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !class_exists('c_ws_plugin__s2member_pro_paypal_utilities') || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['paypal_api_username'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['paypal_api_password'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['paypal_api_signature']) { return array_merge($empty_response, array('debug' => 'PayPal Pro API credentials missing in your s2Member configuration.')); } if ($GLOBALS['WS_PLUGIN__']['s2member']['o']['paypal_payflow_api_username']) { if (!($api_response = c_ws_plugin__s2member_pro_paypal_utilities::payflow_get_profile($subscr_id)) || !empty($api_response['__error'])) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the PayPal Pro API says there is no subscription for this user.')); } if (preg_match('/^(?:Pending|PendingProfile)$/i', $api_response['STATUS'])) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the PayPal Pro API says the subscription for this user is currently pending changes. Unable to determine at this moment. Please try again in 15 minutes.')); } if (!preg_match('/^(?:Active|ActiveProfile)$/i', $api_response['STATUS'])) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The PayPal Pro API says this subscription is no longer active, and thus, access should be terminated at this time.'); } if ($api_response['TERM'] > 0 && $api_response['PAYMENTSLEFT'] <= 0) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The PayPal Pro API says this subscription has reached its last payment, and thus, access should be terminated at this time.'); } if ($api_response['TERM'] <= 0 || $api_response['PAYMENTSLEFT'] > 0) { if ($api_response['NEXTPAYMENT'] && strlen($api_response['NEXTPAYMENT']) === 8) { // MMDDYYYY format is not `strtotime()` compatible. if (($time = strtotime(substr($api_response['NEXTPAYMENT'], -4) . '-' . substr($api_response['NEXTPAYMENT'], 0, 2) . '-' . substr($api_response['NEXTPAYMENT'], 2, 2))) > $now) { return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The PayPal Pro API says this is the next payment time.'); } } } } else { $api_args = array('METHOD' => 'GetRecurringPaymentsProfileDetails', 'PROFILEID' => $subscr_id); if (!($api_response = c_ws_plugin__s2member_paypal_utilities::paypal_api_response($api_args)) || !empty($api_response['__error'])) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the PayPal Pro API says there is no subscription for this user.')); } if (preg_match('/^(?:Pending|PendingProfile)$/i', $api_response['STATUS'])) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the PayPal Pro API says the subscription for this user is currently pending changes. Unable to determine at this moment. Please try again in 15 minutes.')); } if (!preg_match('/^(?:Active|ActiveProfile)$/i', $api_response['STATUS'])) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The PayPal Pro API says this subscription is no longer active, and thus, access should be terminated at this time.'); } if ($api_response['TOTALBILLINGCYCLES'] > 0 && $api_response['NUMCYCLESREMAINING'] <= 0) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The PayPal Pro API says this subscription has reached its last payment, and thus, access should be terminated at this time.'); } if ($api_response['TOTALBILLINGCYCLES'] <= 0 || $api_response['NUMCYCLESREMAINING'] > 0) { if ($api_response['NEXTBILLINGDATE'] && ($time = strtotime($api_response['NEXTBILLINGDATE'])) > $now) { return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The PayPal Pro API says this is the next payment time.'); } } } return array_merge($empty_response, array('debug' => 'No fixed EOT, and there are no more payments needed from this user.')); break; // Break switch. // Break switch. case 'authnet': // Authorize.Net (EOT only; w/ limited functionality). if (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !class_exists('c_ws_plugin__s2member_pro_authnet_utilities') || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_authnet_api_login_id'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_authnet_api_trans_key']) { return array_merge($empty_response, array('debug' => 'Authorize.Net API credentials missing in your s2Member configuration.')); } $api_args = array('x_method' => 'status', 'x_subscription_id' => $subscr_id); if (!($api_response = c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response($api_args)) || !empty($api_response['__error'])) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the Authorize.Net API says there is no subscription for this user.')); } if (!preg_match('/^(?:active)$/i', $api_response['subscription_status'])) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The Authorize.Net API says this subscription is no longer active, and thus, access should be terminated at this time.'); } // Next payment time not possible with Authorize.Net at this time. // Fixed recurring intervals not possible to query with Authorize.Net at this time. return array_merge($empty_response, array('debug' => 'Partially-supported payment gateway; unable to determine.')); break; // Break switch. // Break switch. case 'stripe': // Stripe payment gateway (best). if (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !class_exists('c_ws_plugin__s2member_pro_stripe_utilities') || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_stripe_api_publishable_key'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_stripe_api_secret_key']) { return array_merge($empty_response, array('debug' => 'Stripe API credentials missing in your s2Member configuration.')); } if (!$subscr_cid) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and no `subscr_cid` on file. Unable to determine.')); } if (!is_object($stripe_subscription = c_ws_plugin__s2member_pro_stripe_utilities::get_customer_subscription($subscr_cid, $subscr_id)) || empty($stripe_subscription->id)) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the Stripe API says there is no subscription for this user.')); } if ((int) $stripe_subscription->ended_at > 0) { $time = $stripe_subscription->ended_at + $grace_time; return array('type' => 'fixed', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this subscription reached an expiration on this date + grace time.'); } if (in_array($stripe_subscription->status, array('canceled', 'unpaid'), TRUE) || $stripe_subscription->cancel_at_period_end) { $time = $stripe_subscription->current_period_end + $grace_time; return array('type' => 'fixed', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this subscription was cancelled, and thus, should EOT on this date + grace time.'); } if (isset($stripe_subscription->plan->metadata->recurring, $stripe_subscription->plan->metadata->recurring_times) && !$stripe_subscription->plan->metadata->recurring) { $time = (int) $stripe_subscription->start; $time += $stripe_subscription->plan->trial_period_days * DAY_IN_SECONDS; switch ($stripe_subscription->plan->interval) { case 'day': // Every X days in this case. $time += DAY_IN_SECONDS * $stripe_subscription->plan->interval_count * 1; break; // Break switch now. // Break switch now. case 'week': // Every X weeks in this case. $time += WEEK_IN_SECONDS * $stripe_subscription->plan->interval_count * 1; break; // Break switch now. // Break switch now. case 'month': // Every X months in this case. $time += WEEK_IN_SECONDS * 4 * $stripe_subscription->plan->interval_count * 1; break; // Break switch now. // Break switch now. case 'year': // Every X years in this case. $time += YEAR_IN_SECONDS * $stripe_subscription->plan->interval_count * 1; break; // Break switch now. } if ($favor === 'next' && $stripe_subscription->current_period_end + 1 < $time) { if ($stripe_subscription->current_period_end + 1 > $now) { $time = $stripe_subscription->current_period_end + 1; return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this is the next payment time.'); } return array_merge($empty_response, array('debug' => 'Stripe says no more payments needed from this user.')); } $time += $grace_time; // Now add grace to the final EOT time. return array('type' => 'fixed', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this subscription will be completely over on this date + grace time.'); } if (isset($stripe_subscription->plan->metadata->recurring, $stripe_subscription->plan->metadata->recurring_times) && $stripe_subscription->plan->metadata->recurring && $stripe_subscription->plan->metadata->recurring_times <= 0) { if ($stripe_subscription->current_period_end + 1 > $now) { $time = $stripe_subscription->current_period_end + 1; return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this is the next payment time.'); } return array_merge($empty_response, array('debug' => 'Stripe says no more payments needed from this user.')); } if (isset($stripe_subscription->plan->metadata->recurring, $stripe_subscription->plan->metadata->recurring_times) && $stripe_subscription->plan->metadata->recurring && $stripe_subscription->plan->metadata->recurring_times > 0) { $time = (int) $stripe_subscription->start; $time += $stripe_subscription->plan->trial_period_days * DAY_IN_SECONDS; switch ($stripe_subscription->plan->interval) { case 'day': // Every X days in this case. $time += DAY_IN_SECONDS * $stripe_subscription->plan->interval_count * $stripe_subscription->plan->metadata->recurring_times; break; // Break switch now. // Break switch now. case 'week': // Every X weeks in this case. $time += WEEK_IN_SECONDS * $stripe_subscription->plan->interval_count * $stripe_subscription->plan->metadata->recurring_times; break; // Break switch now. // Break switch now. case 'month': // Every X months in this case. $time += WEEK_IN_SECONDS * 4 * $stripe_subscription->plan->interval_count * $stripe_subscription->plan->metadata->recurring_times; break; // Break switch now. // Break switch now. case 'year': // Every X years in this case. $time += YEAR_IN_SECONDS * $stripe_subscription->plan->interval_count * $stripe_subscription->plan->metadata->recurring_times; break; // Break switch now. } if ($favor === 'next' && $stripe_subscription->current_period_end + 1 < $time) { if ($stripe_subscription->current_period_end + 1 > $now) { $time = $stripe_subscription->current_period_end + 1; return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this is the next payment time.'); } return array_merge($empty_response, array('debug' => 'Stripe says no more payments needed from this user.')); } $time += $grace_time; // Now add grace to the final EOT time. return array('type' => 'fixed', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this subscription will be completely over on this date + grace time.'); } if ($stripe_subscription->current_period_end + 1 > $now) { $time = $stripe_subscription->current_period_end + 1; return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The Stripe API says this is the next payment time.'); } return array_merge($empty_response, array('debug' => 'No fixed EOT, and Stripe says there are no more payments needed from this user.')); break; // Break switch. // Break switch. case 'clickbank': // ClickBank (limited functionality). if (!c_ws_plugin__s2member_utils_conds::pro_is_installed() || !class_exists('c_ws_plugin__s2member_pro_clickbank_utilities') || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_clickbank_username'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_clickbank_clerk_key'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_clickbank_developer_key'] || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_clickbank_secret_key']) { return array_merge($empty_response, array('debug' => 'ClickBank API credentials missing in your s2Member configuration.')); } if (empty($ipn_signup_vars['txn_id'])) { // ClickBank receipt number. return array_merge($empty_response, array('debug' => 'No fixed EOT, and no `txn_id` on file. Unable to determine.')); } if (!($api_response = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_api_order($ipn_signup_vars['txn_id']))) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the ClickBank API says there is no subscription for this user.')); } if (!preg_match('/^(?:TEST_)?SALE$/i', $api_response['txnType']) || !$api_response['recurring']) { return array_merge($empty_response, array('debug' => 'No fixed EOT, and the ClickBank API says there is no recurring subscription for this user.')); } if (strcasecmp($api_response['status'], 'active') !== 0 || $api_response['futurePayments'] <= 0) { return array('type' => 'fixed', 'time' => $auto_eot_time, 'tense' => $auto_eot_time <= $now ? 'past' : 'future', 'debug' => 'This is the estimated EOT time. The ClickBank API says this subscription no longer active, or it has reached its last payment, and thus, access should be terminated at this time.'); } if ($api_response['nextPaymentDate'] && ($time = strtotime($api_response['nextPaymentDate'])) > $now) { return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future', 'debug' => 'The ClickBank API says this is the next payment time.'); } return array_merge($empty_response, array('debug' => 'No fixed EOT, and there are no more payments needed from this user.')); break; // Break switch. // Break switch. default: // Default case handler. return array_merge($empty_response, array('debug' => 'Partially-supported payment gateway; unable to determine.')); } } return array_merge($empty_response, array('debug' => 'Payment gateway check disabled; unable to determine.')); }
/** * Handles processing of Pro-Form cancellations. * * @package s2Member\Stripe * @since 140617 * * @attaches-to ``add_action('init');`` */ public static function stripe_cancellation() { if (!empty($_POST['s2member_pro_stripe_cancellation']['nonce']) && ($nonce = $_POST['s2member_pro_stripe_cancellation']['nonce']) && wp_verify_nonce($nonce, 's2member-pro-stripe-cancellation')) { $GLOBALS['ws_plugin__s2member_pro_stripe_cancellation_response'] = array(); // This holds the global response details. $global_response =& $GLOBALS['ws_plugin__s2member_pro_stripe_cancellation_response']; $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST['s2member_pro_stripe_cancellation'])); $post_vars['attr'] = !empty($post_vars['attr']) ? (array) unserialize(c_ws_plugin__s2member_utils_encryption::decrypt($post_vars['attr'])) : array(); $post_vars['attr'] = apply_filters('ws_plugin__s2member_pro_stripe_cancellation_post_attr', $post_vars['attr'], get_defined_vars()); $post_vars['recaptcha_challenge_field'] = isset($_POST['recaptcha_challenge_field']) ? trim(stripslashes($_POST['recaptcha_challenge_field'])) : ''; $post_vars['recaptcha_response_field'] = isset($_POST['recaptcha_response_field']) ? trim(stripslashes($_POST['recaptcha_response_field'])) : ''; if (!c_ws_plugin__s2member_pro_stripe_responses::stripe_form_attr_validation_errors($post_vars['attr'])) { if (!($form_submission_validation_errors = c_ws_plugin__s2member_pro_stripe_responses::stripe_form_submission_validation_errors('cancellation', $post_vars))) { if (is_user_logged_in() && is_object($user = wp_get_current_user()) && ($user_id = $user->ID)) { if (($cur__subscr_cid = get_user_option('s2member_subscr_cid')) && ($cur__subscr_id = get_user_option('s2member_subscr_id'))) { if (is_object($stripe_subscription = c_ws_plugin__s2member_pro_stripe_utilities::get_customer_subscription($cur__subscr_cid, $cur__subscr_id))) { if (!preg_match('/^canceled$/i', $stripe_subscription->status) && !$stripe_subscription->cancel_at_period_end) { if (is_object(c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($cur__subscr_cid, $cur__subscr_id))) { if (is_array($ipn_signup_vars = c_ws_plugin__s2member_utils_users::get_user_ipn_signup_vars())) { $ipn['txn_type'] = 'subscr_cancel'; $ipn['subscr_cid'] = $ipn_signup_vars['subscr_cid']; $ipn['subscr_id'] = $ipn_signup_vars['subscr_id']; $ipn['custom'] = $ipn_signup_vars['custom']; $ipn['period1'] = $ipn_signup_vars['period1']; $ipn['period3'] = $ipn_signup_vars['period3']; $ipn['payer_email'] = $ipn_signup_vars['payer_email']; $ipn['first_name'] = $ipn_signup_vars['first_name']; $ipn['last_name'] = $ipn_signup_vars['last_name']; $ipn['option_name1'] = $ipn_signup_vars['option_name1']; $ipn['option_selection1'] = $ipn_signup_vars['option_selection1']; $ipn['option_name2'] = $ipn_signup_vars['option_name2']; $ipn['option_selection2'] = $ipn_signup_vars['option_selection2']; $ipn['item_name'] = $ipn_signup_vars['item_name']; $ipn['item_number'] = $ipn_signup_vars['item_number']; $ipn['s2member_paypal_proxy'] = 'stripe'; $ipn['s2member_paypal_proxy_use'] = 'pro-emails'; $ipn['s2member_paypal_proxy_verification'] = c_ws_plugin__s2member_paypal_utilities::paypal_proxy_key_gen(); c_ws_plugin__s2member_utils_urls::remote(home_url('/?s2member_paypal_notify=1'), $ipn, array('timeout' => 20)); } $global_response = array('response' => _x('<strong>Billing termination confirmed.</strong> Your account has been cancelled.', 's2member-front', 's2member')); if ($post_vars['attr']['success'] && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $post_vars['attr']['success'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } else { $global_response = array('response' => _x('API failure. Please contact Support for assistance.', 's2member-front', 's2member'), 'error' => TRUE); } } else { $global_response = array('response' => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', 's2member-front', 's2member')); if ($post_vars['attr']['success'] && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $post_vars['attr']['success'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } } else { $global_response = array('response' => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', 's2member-front', 's2member')); if ($post_vars['attr']['success'] && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $post_vars['attr']['success'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } } else { $global_response = array('response' => _x('<strong>Billing terminated.</strong> Your account has been cancelled.', 's2member-front', 's2member')); if ($post_vars['attr']['success'] && ($custom_success_url = str_ireplace(array('%%s_response%%', '%%response%%'), array(urlencode(c_ws_plugin__s2member_utils_encryption::encrypt($global_response['response'])), urlencode($global_response['response'])), $post_vars['attr']['success'])) && ($custom_success_url = trim(preg_replace('/%%(.+?)%%/i', '', $custom_success_url)))) { wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig($custom_success_url, 's2p-v')) . exit; } } if ($post_vars['attr']['unsub']) { c_ws_plugin__s2member_list_servers::process_list_server_removals_against_current_user(TRUE); } } else { $global_response = array('response' => _x('You\'re <strong>NOT</strong> logged in.', 's2member-front', 's2member'), 'error' => TRUE); } } else { // Input form field validation errors. $global_response = $form_submission_validation_errors; } } } }
/** * Handles Stripe Webhook/IPN event processing. * * @package s2Member\Stripe * @since 140617 * * @param string $customer_id Customer's ID in Stripe. * @param Stripe_Subscription $stripe_subscription Customer's subscription object instance. * * @return string Additional log entry if ending subscription; else an empty string. */ public static function _maybe_end_subscription_after_payment($customer_id, $stripe_subscription) { if (!$customer_id || !$stripe_subscription instanceof Stripe_Subscription) { return ''; } // Not possible. if (isset($stripe_subscription->plan->metadata->recurring) && !filter_var($stripe_subscription->plan->metadata->recurring, FILTER_VALIDATE_BOOLEAN) && strtolower($stripe_subscription->status) !== 'trialing') { c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($customer_id, $stripe_subscription->id); return 'Subscription `' . $stripe_subscription->id . '` has `plan->metadata->recurring=false`.' . ' Auto-cancelling subscription after current period ends.'; } else { if (isset($stripe_subscription->plan->metadata->recurring) && filter_var($stripe_subscription->plan->metadata->recurring, FILTER_VALIDATE_BOOLEAN) && isset($stripe_subscription->plan->metadata->recurring_times) && (int) $stripe_subscription->plan->metadata->recurring_times === 1 && strtolower($stripe_subscription->status) !== 'trialing') { c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($customer_id, $stripe_subscription->id); return 'Subscription `' . $stripe_subscription->id . '` has `plan->metadata->recurring=true` `plan->metadata->recurring_times=1`.' . ' Auto-cancelling subscription after current period ends. This was the last billing cycle.'; } else { if (isset($stripe_subscription->plan->metadata->recurring) && filter_var($stripe_subscription->plan->metadata->recurring, FILTER_VALIDATE_BOOLEAN) && isset($stripe_subscription->plan->metadata->recurring_times) && $stripe_subscription->plan->metadata->recurring_times > 0 && strtolower($stripe_subscription->plan->interval) === 'day' && strtolower($stripe_subscription->status) !== 'trialing' && ($rr_start_time = $stripe_subscription->trial_end ? $stripe_subscription->trial_end : $stripe_subscription->start) && ($rr_end_time = $rr_start_time + $stripe_subscription->plan->interval_count * $stripe_subscription->plan->metadata->recurring_times * 86400) && time() + 43200 >= $rr_end_time) { c_ws_plugin__s2member_pro_stripe_utilities::cancel_customer_subscription($customer_id, $stripe_subscription->id); return 'Subscription `' . $stripe_subscription->id . '` has `plan->metadata->recurring=true` `plan->metadata->recurring_times=' . $stripe_subscription->plan->metadata->recurring_times . '`.' . ' Auto-cancelling subscription after current period ends. This was the last billing cycle.'; } } } return ''; // Default behavior; i.e., do nothing. }