Ejemplo n.º 1
1
 /**
  * @param array $process_data
  * @param $blog_id
  * @param $domain
  *
  * @return bool
  */
 public static function process_checkout_form($process_data = array(), $blog_id, $domain)
 {
     global $psts, $current_user, $current_site;
     $site_name = $current_site->site_name;
     $img_base = $psts->plugin_url . 'images/';
     $session_keys = array('new_blog_details', 'upgraded_blog_details', 'COUPON_CODE', 'activation_key');
     foreach ($session_keys as $key) {
         $process_data[$key] = isset($process_data[$key]) ? $process_data[$key] : ProSites_Helper_Session::session($key);
     }
     if (!empty($domain)) {
         $site_name = !empty($_POST['blogname']) ? $_POST['blogname'] : !empty($_POST['signup_email']) ? $_POST['signup_email'] : '';
     }
     //Process Checkout
     if (isset($_POST['cc_stripe_checkout']) && 1 == (int) $_POST['cc_stripe_checkout']) {
         //check for level, if empty don't go ahead and return
         if (empty($_POST['level']) || empty($_POST['period'])) {
             $psts->errors->add('general', __('Please choose your desired level and payment plan.', 'psts'));
             return false;
         } else {
             if (!isset($_POST['stripeToken']) && empty($_POST['wp_password'])) {
                 $psts->errors->add('general', __('There was an error processing your Credit Card with Stripe. Please try again.', 'psts'));
             }
         }
         // TAX Object
         $tax_object = ProSites_Helper_Session::session('tax_object');
         if (empty($tax_object) || empty($tax_object->evidence)) {
             $tax_object = ProSites_Helper_Tax::get_tax_object();
             ProSites_Helper_Session::session('tax_object', $tax_object);
         }
         $evidence_string = ProSites_Helper_Tax::get_evidence_string($tax_object);
         $error = '';
         $success = '';
         $plan = self::get_plan_id($_POST['level'], $_POST['period']);
         $customer_id = '';
         $current_plan_level = 0;
         $activation_key = isset($_POST['activation']) ? $_POST['activation'] : '';
         $email = !empty($_POST['user_email']) ? $_POST['user_email'] : (!empty($_POST['signup_email']) ? $_POST['signup_email'] : (!empty($_POST['blog_email']) ? $_POST['blog_email'] : ''));
         $blog_id = !empty($blog_id) ? $blog_id : isset($_REQUEST['bid']) ? (int) $_REQUEST['bid'] : 0;
         //If there is a blog id, fetch existing customer details (Upgrade)
         if (!empty($blog_id)) {
             $customer_id = self::get_customer_data($blog_id)->customer_id;
             $email = isset($current_user->user_email) ? $current_user->user_email : get_blog_option($blog_id, 'admin_email');
             //Get current plan for the user
             if ($current_plan = self::get_current_plan($blog_id)) {
                 list($current_plan_level, $current_plan_period) = explode('_', $current_plan);
             }
         } else {
             //New Signup
             if (empty($email) && isset($process_data['new_blog_details']) && isset($process_data['new_blog_details']['user_email'])) {
                 $email = $process_data['new_blog_details']['user_email'];
             }
             $customer_id = self::get_customer_data(false, false, $email)->customer_id;
         }
         if (!self::plan_exists($plan)) {
             $psts->errors->add('general', sprintf(__('Stripe plan %1$s does not exist.', 'psts'), $plan));
             return;
         }
         //Create s Stripe profile for the customer with all the available details,
         //If customer already exists, retrieve customer from stripe
         try {
             if (!$customer_id) {
                 try {
                     $customer_args = array('email' => $email, 'description' => sprintf(__('%s user', 'psts'), $site_name), 'card' => $_POST['stripeToken'], 'metadata' => array('domain' => $domain));
                     $user = get_user_by('email', $email);
                     if ($user) {
                         $blog_string = '';
                         $customer_args['metadata']['user'] = $user->user_login;
                         $customer_args['description'] = sprintf(__('%s user - %s ', 'psts'), $site_name, $user->first_name . ' ' . $user->last_name);
                         $user_blogs = get_blogs_of_user($user->ID);
                         foreach ($user_blogs as $user_blog) {
                             $blog_string .= $user_blog->blogname . ', ';
                         }
                         $customer_args['metadata']['blogs'] = $blog_string;
                     }
                     if (!$domain) {
                         unset($customer_args['metadata']['domain']);
                     }
                     $c = Stripe_Customer::create($customer_args);
                 } catch (Exception $e) {
                     $psts->errors->add('general', __('The Stripe customer could not be created. Please try again.', 'psts'));
                     return;
                 }
                 //Update the stripe customer id, this is temporary, will be overridden by subscription or charge id
                 self::set_customer_data($blog_id, $c->id, 'ak_' . $activation_key);
                 $customer_id = $c->id;
                 $new = true;
             } else {
                 // Get a customer if they exist
                 try {
                     $c = Stripe_Customer::retrieve($customer_id);
                 } catch (Exception $e) {
                     $psts->errors->add('general', __('The Stripe customer could not be retrieved. Please try again.', 'psts'));
                     return;
                 }
                 $c->description = sprintf(__('%s user', 'psts'), $site_name);
                 $c->email = $email;
                 $user = get_user_by('email', $email);
                 if ($user) {
                     $blog_string = '';
                     $c->metadata->user = $user->user_login;
                     $c->description = sprintf(__('%s user - %s ', 'psts'), $site_name, $user->first_name . ' ' . $user->last_name);
                     $user_blogs = get_blogs_of_user($user->ID);
                     foreach ($user_blogs as $user_blog) {
                         $blog_string .= $user_blog->blogname . ', ';
                     }
                     $c->metadata->blogs = $blog_string;
                 }
                 $c->save();
                 $new = false;
                 //validate wp password (if applicable)
                 if (!empty($_POST['wp_password']) && !wp_check_password($_POST['wp_password'], $current_user->data->user_pass, $current_user->ID)) {
                     $psts->errors->add('general', __('The password you entered is incorrect.', 'psts'));
                     return;
                 }
             }
             //prepare vars
             $currency = self::currency();
             $amount_off = false;
             $paymentAmount = $initAmount = $psts->get_level_setting($_POST['level'], 'price_' . $_POST['period']);
             $trial_days = $psts->get_setting('trial_days', 0);
             $cp_code = false;
             $setup_fee = (double) $psts->get_setting('setup_fee', 0);
             $has_coupon = isset($process_data['COUPON_CODE']) && ProSites_Helper_Coupons::check_coupon($process_data['COUPON_CODE'], $blog_id, $_POST['level'], $_POST['period'], $domain) ? true : false;
             $has_setup_fee = $psts->has_setup_fee($blog_id, $_POST['level']);
             $recurring = $psts->get_setting('recurring_subscriptions', 1);
             if ($has_setup_fee) {
                 $initAmount = $setup_fee + $paymentAmount;
             }
             if ($has_coupon || $has_setup_fee) {
                 $lifetime = 'once';
                 if ($has_coupon) {
                     //apply coupon
                     $adjusted_values = ProSites_Helper_Coupons::get_adjusted_level_amounts($process_data['COUPON_CODE']);
                     $coupon_obj = ProSites_Helper_Coupons::get_coupon($process_data['COUPON_CODE']);
                     $lifetime = isset($coupon_obj['lifetime']) && 'indefinite' == $coupon_obj['lifetime'] ? 'forever' : 'once';
                     //	$coupon_value = $psts->coupon_value( $process_data['COUPON_CODE'], $paymentAmount );
                     $coupon_value = $adjusted_values[$_POST['level']]['price_' . $_POST['period']];
                     // $amount_off   = $paymentAmount - $coupon_value['new_total'];
                     $amount_off = $paymentAmount - $coupon_value;
                     $initAmount -= $amount_off;
                     $initAmount = 0 > $initAmount ? 0 : $initAmount;
                     // avoid negative
                     $cpn = false;
                     //Create a stripe coupon if it doesn't exists already
                     try {
                         $cpn = Stripe_Coupon::create(array('amount_off' => $amount_off * 100, 'duration' => $lifetime, 'currency' => $currency, 'max_redemptions' => 1));
                     } catch (Exception $e) {
                         $psts->errors->add('general', __('Temporary Stripe coupon could not be generated correctly. Please try again.', 'psts'));
                         return;
                     }
                     $cp_code = $cpn->id;
                 }
                 //Check if it's a recurring subscription
                 if ($recurring) {
                     $recurringAmmount = 'forever' == $lifetime && $has_coupon ? $coupon_value : $paymentAmount;
                     if ($_POST['period'] == 1) {
                         $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for the first month, then %2$s each month', 'psts'), $psts->format_currency($currency, $initAmount), $psts->format_currency($currency, $recurringAmmount));
                     } else {
                         $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for the first %2$s month period, then %3$s every %4$s months', 'psts'), $psts->format_currency($currency, $initAmount), $_POST['period'], $psts->format_currency($currency, $recurringAmmount), $_POST['period']);
                     }
                 } else {
                     if (!empty($blog_id)) {
                         $initAmount = $psts->calc_upgrade_cost($blog_id, $_POST['level'], $_POST['period'], $initAmount);
                     }
                     if ($_POST['period'] == 1) {
                         $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for 1 month', 'psts'), $psts->format_currency($currency, $initAmount));
                     } else {
                         $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for %2$s months', 'psts'), $psts->format_currency($currency, $initAmount), $_POST['period']);
                     }
                 }
             } elseif ($recurring) {
                 if ($_POST['period'] == 1) {
                     $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s %2$s each month', 'psts'), $psts->format_currency($currency, $paymentAmount), $currency);
                 } else {
                     $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s %2$s every %3$s months', 'psts'), $psts->format_currency($currency, $paymentAmount), $currency, $_POST['period']);
                 }
             } else {
                 //New Signups
                 if (!empty($blog_id)) {
                     $paymentAmount = $psts->calc_upgrade_cost($blog_id, $_POST['level'], $_POST['period'], $paymentAmount);
                 }
                 if ($_POST['period'] == 1) {
                     $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for 1 month', 'psts'), $psts->format_currency($currency, $paymentAmount));
                 } else {
                     $desc = $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name') . ': ' . sprintf(__('%1$s for %2$s months', 'psts'), $psts->format_currency($currency, $paymentAmount), $_POST['period']);
                 }
             }
             // Override the Stripe description
             $desc = apply_filters('psts_stripe_checkout_desc', $desc, $_POST['period'], $_POST['level'], $paymentAmount, $initAmount, $blog_id, $domain);
             // Time to process invoices with Stripe
             if ($recurring) {
                 // Recurring subscription
                 // Assign plan to customer
                 $args = array("plan" => $plan, "prorate" => true);
                 // Apply tax?
                 if ($tax_object->apply_tax) {
                     $args['tax_percent'] = $tax_object->tax_rate * 100;
                 }
                 // If there is a coupon, add its reference
                 if ($cp_code) {
                     $args["coupon"] = $cp_code;
                 }
                 // If this is a trial before the subscription starts
                 if ($psts->is_trial_allowed($blog_id)) {
                     if (isset($process_data['new_blog_details']) || !$psts->is_existing($blog_id)) {
                         //customer is new - add trial days
                         $args['trial_end'] = strtotime('+ ' . $trial_days . ' days');
                     } elseif (is_pro_trial($blog_id) && $psts->get_expire($blog_id) > time()) {
                         //customer's trial is still valid - carry over existing expiration date
                         $args['trial_end'] = $psts->get_expire($blog_id);
                     }
                 }
                 // Meta data for `pay before blog` creation
                 $args['metadata'] = array('domain' => !empty($domain) ? $domain : '', 'period' => $_POST['period'], 'level' => $_POST['level']);
                 if ($tax_object->apply_tax) {
                     $args['metadata']['tax_evidence'] = $evidence_string;
                 }
                 if (!$domain) {
                     unset($args['metadata']['domain']);
                 }
                 // new blog
                 if (isset($_POST['activation'])) {
                     $args['metadata']['activation'] = $_POST['activation'];
                 }
                 // Create Stripe Invoice for the setup fee
                 if ($has_setup_fee) {
                     try {
                         $customer_args = array('customer' => $customer_id, 'amount' => $setup_fee * 100, 'currency' => $currency, 'description' => __('One-time setup fee', 'psts'), 'metadata' => array('domain' => !empty($domain) ? $domain : '', 'period' => $_POST['period'], 'level' => $_POST['level'], 'setup_fee' => 'yes'));
                         if ($tax_object->apply_tax) {
                             $customer_args['metadata']['tax_evidence'] = $evidence_string;
                         }
                         if (!$domain) {
                             unset($customer_args['metadata']['domain']);
                         }
                         // new blog
                         if (isset($_POST['activation'])) {
                             $customer_args['metadata']['activation'] = $_POST['activation'];
                         }
                         Stripe_InvoiceItem::create($customer_args);
                     } catch (Exception $e) {
                         wp_mail(get_blog_option($blog_id, 'admin_email'), __('Error charging setup fee. Attention required!', 'psts'), sprintf(__('An error occurred while charging a setup fee of %1$s to Stripe customer %2$s. You will need to manually process this amount.', 'psts'), $psts->format_currency($currency, $setup_fee), $customer_id));
                     }
                 }
                 // Create/update subscription
                 try {
                     $result = false;
                     $sub = false;
                     // Brand new blog...
                     if (empty($blog_id)) {
                         $result = $c->subscriptions->create($args);
                     } else {
                         $customer_data = self::get_customer_data($blog_id);
                         try {
                             $sub = $c->subscriptions->retrieve($customer_data->subscription_id);
                             $sub_id = $sub->id;
                             $prev_plan = $sub->plan->id;
                             $sub->plan = isset($args['plan']) ? $args['plan'] : $sub->plan;
                             $changed_plan = $sub->plan;
                             $sub->prorate = isset($args['prorate']) ? $args['prorate'] : $sub->prorate;
                             if (isset($args['coupon'])) {
                                 $sub->coupon = $args['coupon'];
                             }
                             if (isset($args['trial_end'])) {
                                 $sub->trial_end = $args['trial_end'];
                             }
                             $sub->metadata->period = $args['metadata']['period'];
                             $sub->metadata->level = $args['metadata']['level'];
                             if (isset($args['metadata']['activation'])) {
                                 $sub->metadata->activation = $args['metadata']['activation'];
                             } else {
                                 $activation_key = ProSites_Helper_ProSite::get_activation_key($blog_id);
                                 if (!empty($activation_key)) {
                                     $sub->metadata->activation = $activation_key;
                                 }
                             }
                             $sub->metadata->blog_id = $blog_id;
                             if (isset($args['metadata']['domain'])) {
                                 $sub->metadata->domain = $args['metadata']['domain'];
                             }
                             // Apply tax?
                             if ($tax_object->apply_tax) {
                                 $sub->tax_percent = $tax_object->tax_rate * 100;
                                 $sub->metadata->tax_evidence = $evidence_string;
                             }
                             $sub->save();
                             // As per Stripe API, to charge immediately, apply an invoice now
                             if ($prev_plan != $changed_plan) {
                                 $customer_args = array('customer' => $customer_id, 'subscription' => $sub_id, 'metadata' => array('plan_change' => 'yes'));
                                 $invoice = Stripe_Invoice::create($customer_args);
                                 $invoice = $invoice->pay();
                                 $plan_parts = explode('_', $changed_plan);
                                 $new_period = array_pop($plan_parts);
                                 $new_level = array_pop($plan_parts);
                                 $plan_parts = explode('_', $prev_plan);
                                 $prev_period = array_pop($plan_parts);
                                 $prev_level = array_pop($plan_parts);
                                 $updated = array('render' => true, 'blog_id' => $blog_id, 'level' => $new_level, 'period' => $new_period, 'prev_level' => $prev_level, 'prev_period' => $prev_period);
                                 ProSites_Helper_Session::session('plan_updated', $updated);
                             }
                         } catch (Exception $e) {
                             // Fall through...
                         }
                         // Additional blog
                         if (empty($sub)) {
                             $args['metadata']['blog_id'] = $blog_id;
                             if (!isset($args['metadata']['activation'])) {
                                 $activation_key = ProSites_Helper_ProSite::get_activation_key($blog_id);
                                 if (!empty($activation_key)) {
                                     $args['metadata']['activation'] = $activation_key;
                                 }
                             }
                             $result = $c->subscriptions->create($args);
                         }
                         // This one is now deprecated
                         // $result = $c->updateSubscription( $args );
                     }
                     // Capture success as soon as we can!
                     if (!empty($result)) {
                         $sub_id = $result->id;
                         $plan = $result->plan;
                         $plan_parts = explode('_', $plan->id);
                         $period = array_pop($plan_parts);
                         $level = array_pop($plan_parts);
                         $trial = isset($plan->status) && 'trialing' == $plan->status ? true : false;
                         $expire = $trial ? $plan->trial_end : $result->current_period_end;
                         $result = ProSites_Helper_Registration::activate_blog($activation_key, $trial, $period, $level, $expire);
                         $blog_id = $result['blog_id'];
                         if (isset($process_data['new_blog_details'])) {
                             ProSites_Helper_Session::session(array('new_blog_details', 'blog_id'), $blog_id);
                             ProSites_Helper_Session::session(array('new_blog_details', 'payment_success'), true);
                         } else {
                             ProSites_Helper_Session::session('upgrade_blog_details', array());
                             ProSites_Helper_Session::session(array('upgrade_blog_details', 'blog_id'), $blog_id);
                             ProSites_Helper_Session::session(array('upgrade_blog_details', 'level'), $level);
                             ProSites_Helper_Session::session(array('upgrade_blog_details', 'period'), $period);
                             ProSites_Helper_Session::session(array('upgrade_blog_details', 'payment_success'), true);
                         }
                         self::set_customer_data($blog_id, $customer_id, $sub_id);
                     }
                     if ($current_plan = self::get_current_plan($blog_id)) {
                         list($current_plan_level, $current_plan_period) = explode('_', $current_plan);
                     }
                     //Extend the Blog Subscription
                     $old_expire = $psts->get_expire($blog_id);
                     $new_expire = $old_expire && $old_expire > time() ? $old_expire : false;
                     $psts->extend($blog_id, $_POST['period'], self::get_slug(), $_POST['level'], $initAmount, $new_expire, false);
                     //$psts->email_notification( $blog_id, 'receipt' );
                     if (isset($current_plan_level)) {
                         if ($current_plan_level > $_POST['level']) {
                             $psts->record_stat($blog_id, 'upgrade');
                         } else {
                             $psts->record_stat($blog_id, 'modify');
                         }
                     } else {
                         $psts->record_stat($blog_id, 'signup');
                     }
                     // Update the sub with the new blog id (old subscriptions will update later).
                     if (!empty($blog_id)) {
                         $sub = $c->subscriptions->retrieve($sub_id);
                         $sub->metadata->blog_id = $blog_id;
                         $sub->save();
                     }
                 } catch (Exception $e) {
                     $body = $e->getJsonBody();
                     $error = $body['error'];
                     $psts->errors->add('general', $error['message']);
                     return;
                 }
             } else {
                 // Not a subscription, this is a one of payment, charged for 1 term
                 try {
                     if (!empty($blog_id)) {
                         $initAmount = $psts->calc_upgrade_cost($blog_id, $_POST['level'], $_POST['period'], $initAmount);
                         //If activation key is empty
                         $activation_key = !empty($activation_key) ? $activation_key : ProSites_Helper_ProSite::get_activation_key($blog_id);
                     }
                     if ($tax_object->apply_tax) {
                         $amount = $initAmount + $initAmount * $tax_object->tax_rate;
                         $desc += sprintf(__('(includes tax of %s%% [%s])', 'psts'), $tax_object->tax_rate * 100, $tax_object->country);
                     } else {
                         $amount = $initAmount;
                     }
                     $customer_args = array('customer' => $customer_id, 'amount' => $amount * 100, 'currency' => $currency, 'description' => $desc, 'metadata' => array('domain' => !empty($domain) ? $domain : '', 'period' => $_POST['period'], 'level' => $_POST['level']));
                     if ($tax_object->apply_tax) {
                         $customer_args['metadata']['tax_evidence'] = $evidence_string;
                     }
                     if (!$domain) {
                         unset($customer_args['metadata']['domain']);
                     }
                     // new blog
                     if (isset($_POST['activation'])) {
                         $customer_args['metadata']['activation'] = $_POST['activation'];
                     }
                     /**
                      * 1 off charge of not trialing, but if trialing, just send a zero-dollar invoice
                      */
                     if (empty($trial_days) || 0 == $customer_args['amount']) {
                         $result = Stripe_Charge::create($customer_args);
                     } else {
                         $result = Stripe_InvoiceItem::create($customer_args);
                     }
                     // Capture success as soon as we can!
                     if ($result) {
                         $period = (int) $_POST['period'];
                         $level = (int) $_POST['level'];
                         $signup_details = ProSites_Helper_Registration::activate_blog($activation_key, false, $period, $level);
                         $blog_id = $signup_details['blog_id'];
                         if (isset($process_data['new_blog_details'])) {
                             ProSites_Helper_Session::session(array('new_blog_details', 'blog_id'), $blog_id);
                             ProSites_Helper_Session::session(array('new_blog_details', 'payment_success'), true);
                         }
                         self::set_customer_data($blog_id, $customer_id, $result->id);
                     }
                     if ($current_plan = self::get_current_plan($blog_id)) {
                         list($current_plan_level, $current_plan_period) = explode('_', $current_plan);
                     }
                     $old_expire = $psts->get_expire($blog_id);
                     $new_expire = $old_expire && $old_expire > time() ? $old_expire : false;
                     $psts->extend($blog_id, $_POST['period'], self::get_slug(), $_POST['level'], $initAmount, $new_expire, false);
                     //$psts->email_notification( $blog_id, 'receipt' );
                     if (isset($current_plan_level)) {
                         if ($current_plan_level > $_POST['level']) {
                             $psts->record_stat($blog_id, 'upgrade');
                         } else {
                             $psts->record_stat($blog_id, 'modify');
                         }
                     } else {
                         $psts->record_stat($blog_id, 'signup');
                     }
                 } catch (Stripe_CardError $e) {
                     $body = $e->getJsonBody();
                     $err = $body['error'];
                     $psts->errors->add('general', $e['message']);
                 } catch (Exception $e) {
                     $psts->errors->add('general', __('An unknown error occurred while processing your payment. Please try again.', 'psts'));
                 }
             }
             //delete the temporary coupon code
             if ($cp_code) {
                 try {
                     $cpn = Stripe_Coupon::retrieve($cp_code);
                     $cpn->delete();
                 } catch (Exception $e) {
                     wp_mail(get_blog_option($blog_id, 'admin_email'), __('Error deleting temporary Stripe coupon code. Attention required!.', 'psts'), sprintf(__('An error occurred when attempting to delete temporary Stripe coupon code %1$s. You will need to manually delete this coupon via your Stripe account.', 'psts'), $cp_code));
                 }
                 $psts->use_coupon($process_data['COUPON_CODE'], $blog_id, $domain);
             }
             if ($new || $psts->is_blog_canceled($blog_id)) {
                 // Added for affiliate system link
                 if ($recurring) {
                     $psts->log_action($blog_id, sprintf(__('User creating new subscription via CC: Subscription created (%1$s) - Customer ID: %2$s', 'psts'), $desc, $customer_id), $domain);
                 } else {
                     $psts->log_action($blog_id, sprintf(__('User completed new payment via CC: Site created/extended (%1$s) - Customer ID: %2$s', 'psts'), $desc, $customer_id), $domain);
                 }
                 do_action('supporter_payment_processed', $blog_id, $paymentAmount, $_POST['period'], $_POST['level']);
             } else {
                 $psts->log_action($blog_id, sprintf(__('User modifying subscription via CC: Plan changed to (%1$s) - %2$s', 'psts'), $desc, $customer_id), $domain);
             }
             //display GA ecommerce in footer
             $psts->create_ga_ecommerce($blog_id, $_POST['period'], $initAmount, $_POST['level'], $site_name, $domain);
             if (!empty($blog_id)) {
                 update_blog_option($blog_id, 'psts_stripe_canceled', 0);
                 /* 	some times there is a lag receiving webhooks from Stripe. we want to be able to check for that
                 				and display an appropriate message to the customer (e.g. there are changes pending to your account) */
                 update_blog_option($blog_id, 'psts_stripe_waiting', 1);
             } else {
                 if (isset($process_data['activation_key'])) {
                     //Update signup meta
                     $key = $process_data['activation_key'];
                     $signup_meta = '';
                     $signup_meta = $psts->get_signup_meta($key);
                     $signup_meta['psts_stripe_canceled'] = 0;
                     $signup_meta['psts_stripe_waiting'] = 1;
                     $psts->update_signup_meta($signup_meta, $key);
                 }
             }
             update_blog_option($blog_id, 'psts_stripe_waiting', 1);
             if (empty(self::$complete_message)) {
                 // Message is redundant now, but still used as a flag.
                 self::$complete_message = __('Your payment was successfully recorded! You should be receiving an email receipt shortly.', 'psts');
             }
         } catch (Exception $e) {
             $psts->errors->add('general', $e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 public static function is_last_gateway_used($blog_id, $gateway_key)
 {
     $last_gateway = ProSites_Helper_ProSite::last_gateway($blog_id);
     if (!empty($last_gateway) && $last_gateway == $gateway_key) {
         return true;
     } else {
         return false;
     }
 }
 private static function update_evidence($blog_id, $transaction_id, $evidence)
 {
     $blog_meta = ProSites_Helper_ProSite::get_prosite_meta($blog_id);
     if (empty($blog_meta)) {
         $blog_meta = array();
     }
     if (empty($blog_meta['evidence'])) {
         $blog_meta['evidence'] = array();
     }
     $blog_meta['evidence'][$transaction_id] = $evidence;
     ProSites_Helper_ProSite::update_prosite_meta($blog_id, $blog_meta);
 }
Ejemplo n.º 4
0
	/**
	 * Sets meta for a ProSite
	 *
	 * @param array $meta
	 * @param int $blog_id
	 *
	 * @return bool
	 */
	public static function update_prosite_meta( $blog_id = 0, $meta = array() ) {
		return ProSites_Helper_ProSite::update_prosite_meta( $blog_id, $meta );
	}
Ejemplo n.º 5
0
 public static function get_site($blog_id)
 {
     global $wpdb;
     self::$last_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %d", $blog_id));
     return self::$last_site;
 }
Ejemplo n.º 6
0
 public static function render_current_plan_information($render_data = array(), $blog_id, $domain, $gateways, $gateway_order)
 {
     global $psts, $wpdb, $current_site, $current_prosite_blog;
     if (empty($gateway_order)) {
         return '';
     }
     $content = '';
     $info_retrieved = array();
     if (empty($blog_id) && isset($_GET['bid'])) {
         $blog_id = (int) $_GET['bid'];
     }
     $blog_id = empty($blog_id) && !empty($current_prosite_blog) ? $current_prosite_blog : $blog_id;
     if (empty($blog_id)) {
         return '';
     }
     // Is this a trial, if not, get the normal gateway data?
     $sql = $wpdb->prepare("SELECT `gateway` FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %s", $blog_id);
     $result = $wpdb->get_row($sql);
     if (!empty($result) && 'Trial' == $result->gateway) {
         $info_retrieved = ProSites_Gateway_Trial::get_existing_user_information($blog_id, $domain);
     } else {
         foreach ($gateway_order as $key) {
             // @todo: replace the called method with hooks with different names in the gateways (filter is from ProSites_Helper_ProSite::get_blog_info() )
             if (!empty($key) && empty($info_retrieved) && method_exists($gateways[$key]['class'], 'get_existing_user_information')) {
                 $info_retrieved = call_user_func($gateways[$key]['class'] . '::get_existing_user_information', $blog_id, $domain);
             }
         }
     }
     $generic_info = ProSites_Helper_ProSite::get_blog_info($blog_id);
     $info_retrieved = array_merge($generic_info, $info_retrieved);
     // Notifications
     $content .= self::get_notifications_only($info_retrieved);
     // Output level information
     if (!empty($info_retrieved) && empty($info_retrieved['complete_message'])) {
         // Manual payments
         if (!empty($info_retrieved['last_payment_gateway']) && 'manual' == strtolower($info_retrieved['last_payment_gateway'])) {
             $content .= '<div id="psts-general-error" class="psts-warning psts-manual-payment-notify">' . __('Your site is currently using manual payments and will not automatically renew. Please upgrade your site or contact us with your renewal request.', 'psts') . '</div>';
         }
         $content .= '<ul class="psts-info-list">';
         //level
         if (!empty($info_retrieved['level'])) {
             $content .= '<li class="psts-level">' . esc_html__('Level:', 'psts') . ' <strong>' . $info_retrieved['level'] . '</strong></li>';
         }
         //payment method
         if (!empty($info_retrieved['card_type'])) {
             $content .= '<li class="psts-payment-method">' . sprintf(__('Payment method: <strong>%1$s card</strong> ending in <strong>%2$s</strong>. Expires <strong>%3$s/%4$s</strong>', 'psts'), $info_retrieved['card_type'], $info_retrieved['card_reminder'], $info_retrieved['card_expire_month'], $info_retrieved['card_expire_year']) . '</li>';
         }
         //last payment
         if (!empty($info_retrieved['last_payment_date'])) {
             $content .= '<li class="psts-last-payment">' . esc_html__('Last payment date:', 'psts') . ' <strong>' . date_i18n(get_option('date_format'), $info_retrieved['last_payment_date']) . '</strong></li>';
         }
         //next payment
         if (!empty($info_retrieved['next_payment_date'])) {
             $content .= '<li class="psts-next-payment">' . esc_html__('Next payment date:', 'psts') . ' <strong>' . date_i18n(get_option('date_format'), $info_retrieved['next_payment_date']) . '</strong></li>';
         }
         //period
         if (!empty($info_retrieved['period']) && !empty($info_retrieved['recurring'])) {
             $content .= '<li class="psts-period">' . esc_html__('Renewal Period:', 'psts') . sprintf(__(' Every <strong>%d</strong> month(s)', 'psts'), $info_retrieved['period']) . '</li>';
         }
         // Is recurring?
         if (empty($info_retrieved['recurring'])) {
             $content .= '<li class="psts-expiry">' . esc_html__('Plan expires on:', 'psts') . ' <strong>' . $info_retrieved['expires'] . '</strong></li>';
         } else {
             if (!empty($info_retrieved['recurring']) && empty($info_retrieved['next_payment_date'])) {
                 $content .= '<li class="psts-expiry">' . esc_html__('Renewal due on:', 'psts') . ' <strong>' . $info_retrieved['expires'] . '</strong></li>';
             }
         }
         $content .= '</ul>';
         // Cancel link?
         if (empty($info_retrieved['cancellation_message'])) {
             if (!empty($info_retrieved['cancel_link'])) {
                 $content .= '<div class="psts-cancel-link">' . $info_retrieved['cancel_link'] . $info_retrieved['cancel_info'] . '</div>';
             } else {
                 if (!empty($info_retrieved['cancel_info_link'])) {
                     $content .= '<div class="psts-cancel-link">' . $info_retrieved['cancel_info_link'] . $info_retrieved['cancel_info'] . '</div>';
                 }
             }
             // Receipt form
             if (!empty($info_retrieved['receipt_form'])) {
                 $content .= '<div class="psts-receipt-link">' . $info_retrieved['receipt_form'] . '</div>';
             }
         }
         // Signup for another blog?
         $allow_multi = $psts->get_setting('multiple_signup');
         $registeration = get_site_option('registration');
         $allow_multi = 'all' == $registeration || 'blog' == $registeration ? $allow_multi : false;
         if ($allow_multi) {
             $content .= '<div class="psts-signup-another"><a href="' . esc_url($psts->checkout_url() . '?action=new_blog') . '">' . esc_html__('Sign up for another site.', 'psts') . '</a>' . '</div>';
         }
         $content .= apply_filters('prosites_myaccount_details', '', $blog_id);
     }
     return '<div id="psts_existing_info"><h2>' . esc_html__('Your current plan', 'psts') . '</h2>' . $content . '</div>';
 }