/** * Populate an array with existing user information * * Array will be rendered by ProSites_View_Front_Gateway * * @param $blog_id * @param $domain * @param bool $get_all * * @return array|bool */ public static function get_existing_user_information($blog_id, $domain, $get_all = true) { global $psts; $args = array(); $img_base = $psts->plugin_url . 'images/'; $trialing = ProSites_Helper_Registration::is_trial($blog_id); if ($trialing) { $args['trial'] = '<div id="psts-general-error" class="psts-warning">' . __('You are still within your trial period. Once your trial finishes your account will be automatically charged.', 'psts') . '</div>'; } // Pending information /** * @todo: Hook psts_blog_info_pending (Front/Gateway.php) */ if (!empty($blog_id) && 1 == get_blog_option($blog_id, 'psts_stripe_waiting')) { $args['pending'] = '<div id="psts-general-error" class="psts-warning">' . __('There are pending changes to your account. This message will disappear once these pending changes are completed.', 'psts') . '</div>'; } // Successful payment if (self::$complete_message) { // @todo: Hook psts_blog_info_complete_message $args['complete_message'] = '<div id="psts-complete-msg">' . self::$complete_message . '</div>'; // @todo: Hook psts_blog_info_thanks_message $args['thanks_message'] = '<p>' . $psts->get_setting('stripe_thankyou') . '</p>'; //If Checking out on signup, there wouldn't be a blogid probably // if ( ! empty ( $domain ) ) { // //Hardcoded, TODO: Search for alternative // $admin_url = is_ssl() ? trailingslashit( "https://$domain" ) . 'wp-admin/' : trailingslashit( "http://$domain" ) . 'wp-admin/'; // $args['visit_site_message'] = '<p><a href="' . $admin_url . '">' . __( 'Visit your newly upgraded site »', 'psts' ) . '</a></p>'; // } else { $args['visit_site_message'] = '<p><a href="' . get_admin_url($blog_id, '', 'http') . '">' . __('Go to your site »', 'psts') . '</a></p>'; // } self::$complete_message = false; } // Cancellation message if (self::$cancel_message) { $args['cancel'] = true; $args['cancellation_message'] = self::$cancel_message; self::$cancel_message = false; } // Existing customer information --- only if $get_all is true (default) $customer_id = self::get_customer_data($blog_id)->customer_id; if (!empty($customer_id) && $get_all) { try { $customer_object = Stripe_Customer::retrieve($customer_id); } catch (Exception $e) { $error = $e->getMessage(); } // Move to render info class $end_date = date_i18n(get_option('date_format'), $psts->get_expire($blog_id)); $level = $psts->get_level_setting($psts->get_level($blog_id), 'name'); $is_recurring = $psts->is_blog_recurring($blog_id); $args['recurring'] = $is_recurring; // If invoice cant be created, its not looking good. Cancel. try { $invoice_object = Stripe_Invoice::upcoming(array("customer" => $customer_id)); } catch (Exception $e) { if ($is_recurring) { $args['cancel'] = true; $args['cancellation_message'] = '<div class="psts-cancel-notification"> <p class="label"><strong>' . __('Your subscription has been canceled', 'psts') . '</strong></p> <p>' . sprintf(__('This site should continue to have %1$s features until %2$s.', 'psts'), $level, $end_date) . '</p>'; } } $args['level'] = $level; $args['expires'] = $end_date; // All good, keep populating the array. if (!isset($args['cancel'])) { // Get the last valid card if (isset($customer_object->cards->data[0]) && isset($customer_object->default_card)) { foreach ($customer_object->cards->data as $tmpcard) { if ($tmpcard->id == $customer_object->default_card) { $card = $tmpcard; break; } } } elseif (isset($customer_object->active_card)) { //for API pre 2013-07-25 $card = $customer_object->active_card; } $args['card_type'] = $card->brand; $args['card_reminder'] = $card->last4; $args['card_digit_location'] = 'end'; $args['card_expire_month'] = $card->exp_month; $args['card_expire_year'] = $card->exp_year; // Get the period $plan_parts = explode('_', $customer_object->subscriptions->data[0]->plan->id); $period = array_pop($plan_parts); $args['period'] = $period; // Get last payment date try { $existing_invoice_object = Stripe_Invoice::all(array("customer" => $customer_id, "count" => 1)); } catch (Exception $e) { $error = $e->getMessage(); } if (isset($existing_invoice_object->data[0]) && $customer_object->subscriptions->data[0]->status != 'trialing') { $args['last_payment_date'] = $existing_invoice_object->data[0]->date; } // Get next payment date if (isset($invoice_object->next_payment_attempt)) { $args['next_payment_date'] = $invoice_object->next_payment_attempt; } // Cancellation link if ($is_recurring) { if (is_pro_site($blog_id)) { $args['cancel_info'] = '<p class="prosites-cancel-description">' . sprintf(__('If you choose to cancel your subscription this site should continue to have %1$s features until %2$s.', 'psts'), $level, $end_date) . '</p>'; $cancel_label = __('Cancel Your Subscription', 'psts'); // CSS class of <a> is important to handle confirmations $args['cancel_link'] = '<p class="prosites-cancel-link"><a class="cancel-prosites-plan button" href="' . wp_nonce_url($psts->checkout_url($blog_id) . '&action=cancel', 'psts-cancel') . '" title="' . esc_attr($cancel_label) . '">' . esc_html($cancel_label) . '</a></p>'; } } // Receipt form $args['receipt_form'] = $psts->receipt_form($blog_id); } // Show all is true $args['all_fields'] = true; } return empty($args) ? array() : $args; }