public function testUpcoming()
 {
     authorizeFromEnv();
     $c = Stripe_Customer::create(array('card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015)));
     $invoice = Stripe_Invoice::upcoming(array('customer' => $c->id));
     $this->assertEqual($invoice->customer, $c->id);
     $this->assertEqual($invoice->attempted, false);
 }
示例#2
0
 public function stripe_getUpcoming($cid)
 {
     if (!$cid) {
         $cid = $this->company->id;
     }
     $customer = $this->returnFieldFromTable("company_stripetoken", "companies", "id='{$cid}'");
     return Stripe_Invoice::upcoming(array("customer" => $customer));
 }
示例#3
0
 public function testUpcoming()
 {
     authorizeFromEnv();
     $customer = self::createTestCustomer();
     Stripe_InvoiceItem::create(array('customer' => $customer->id, 'amount' => 0, 'currency' => 'usd'));
     $invoice = Stripe_Invoice::upcoming(array('customer' => $customer->id));
     $this->assertEqual($invoice->customer, $customer->id);
     $this->assertEqual($invoice->attempted, false);
 }
示例#4
0
 public function testItemsAccessWithParameter()
 {
     self::authorizeFromEnv();
     $customer = self::createTestCustomer();
     Stripe_InvoiceItem::create(array('customer' => $customer->id, 'amount' => 100, 'currency' => 'usd'));
     $invoice = Stripe_Invoice::upcoming(array('customer' => $customer->id));
     $lines = $invoice->lines->all(array('limit' => 10));
     $this->assertEqual(count($lines->data), 1);
     $this->assertEqual($lines->data[0]->amount, 100);
 }
示例#5
0
    /**
     * 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 &raquo;', 'psts' ) . '</a></p>';
            //			} else {
            $args['visit_site_message'] = '<p><a href="' . get_admin_url($blog_id, '', 'http') . '">' . __('Go to your site &raquo;', '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;
    }
示例#6
0
    function checkout_screen($content, $blog_id)
    {
        global $psts, $wpdb, $current_site, $current_user;
        if (!$blog_id) {
            return $content;
        }
        //cancel subscription
        if (isset($_GET['action']) && $_GET['action'] == 'cancel' && wp_verify_nonce($_GET['_wpnonce'], 'psts-cancel')) {
            $error = '';
            try {
                $customer_id = $this->get_customer_id($blog_id);
                $cu = Stripe_Customer::retrieve($customer_id);
                $cu->cancelSubscription();
            } catch (Exception $e) {
                $error = $e->getMessage();
            }
            if ($error != '') {
                $content .= '<div id="message" class="error fade"><p>' . __('There was a problem canceling your subscription, please contact us for help: ', 'psts') . $error . '</p></div>';
            } else {
                //record stat
                $psts->record_stat($blog_id, 'cancel');
                $psts->email_notification($blog_id, 'canceled');
                update_blog_option($blog_id, 'psts_stripe_canceled', 1);
                $end_date = date_i18n(get_option('date_format'), $psts->get_expire($blog_id));
                $psts->log_action($blog_id, sprintf(__('Subscription successfully cancelled by %1$s. They should continue to have access until %2$s', 'psts'), $current_user->display_name, $end_date));
                $content .= '<div id="message" class="updated fade"><p>' . sprintf(__('Your %1$s subscription has been canceled. You should continue to have access until %2$s.', 'psts'), $current_site->site_name . ' ' . $psts->get_setting('rebrand'), $end_date) . '</p></div>';
            }
        }
        $cancel_status = get_blog_option($blog_id, 'psts_stripe_canceled');
        $cancel_content = '';
        $img_base = $psts->plugin_url . 'images/';
        $pp_active = false;
        //hide top part of content if its a pro blog
        if (is_pro_site($blog_id) || $psts->errors->get_error_message('coupon')) {
            $content = '';
        }
        if ($errmsg = $psts->errors->get_error_message('general')) {
            $content = '<div id="psts-general-error" class="psts-error">' . $errmsg . '</div>';
            //hide top part of content if theres an error
        }
        //if transaction was successful display a complete message and skip the rest
        if ($this->complete_message) {
            $content = '<div id="psts-complete-msg">' . $this->complete_message . '</div>';
            $content .= '<p>' . $psts->get_setting('stripe_thankyou') . '</p>';
            $content .= '<p><a href="' . get_admin_url($blog_id, '', 'http') . '">' . __('Visit your newly upgraded site &raquo;', 'psts') . '</a></p>';
            return $content;
        }
        if ($customer_id = $this->get_customer_id($blog_id)) {
            try {
                $customer_object = Stripe_Customer::retrieve($customer_id);
            } catch (Exception $e) {
                $error = $e->getMessage();
            }
            $content .= '<div id="psts_existing_info">';
            $end_date = date_i18n(get_option('date_format'), $psts->get_expire($blog_id));
            $level = $psts->get_level_setting($psts->get_level($blog_id), 'name');
            try {
                $invoice_object = Stripe_Invoice::upcoming(array("customer" => $customer_id));
            } catch (Exception $e) {
                $cancel_status = 1;
            }
            try {
                $existing_invoice_object = Stripe_Invoice::all(array("customer" => $customer_id, "count" => 1));
            } catch (Exception $e) {
                $error = $e->getMessage();
            }
            if ($cancel_status == 1) {
                $content .= '<h3>' . __('Your subscription has been canceled', 'psts') . '</h3>';
                $content .= '<p>' . sprintf(__('This site should continue to have %1$s features until %2$s.', 'psts'), $psts->get_setting('rebrand'), $end_date) . '</p>';
            }
            if ($cancel_status == 0) {
                $content .= '<ul>';
                if (is_pro_site($blog_id)) {
                    $content .= '<li>' . __('Level:', 'psts') . ' <strong>' . $level . '</strong></li>';
                }
                if (isset($customer_object->active_card)) {
                    $content .= '<li>' . __('Payment Method: <strong>' . $customer_object->active_card->type . ' Card</strong> ending in <strong>' . $customer_object->active_card->last4 . '</strong>. Expires <strong>' . $customer_object->active_card->exp_month . '/' . $customer_object->active_card->exp_year . '</strong>', 'psts') . '</li>';
                }
                if (isset($exitsing_invoice_object->data[0])) {
                    $content .= '<li>' . __('Last Payment Date:', 'psts') . ' <strong>' . date_i18n(get_option('date_format'), $existing_invoice_object->data[0]->date) . '</strong></li>';
                }
                if (isset($invoice_object->next_payment_attempt)) {
                    $content .= '<li>' . __('Next Payment Date:', 'psts') . ' <strong>' . date_i18n(get_option('date_format'), $invoice_object->next_payment_attempt) . '</strong></li>';
                }
                $content .= "</ul>";
                $cancel_content .= '<h3>' . __('Cancel Your Subscription', 'psts') . '</h3>';
                $pp_active = false;
                if (is_pro_site($blog_id)) {
                    $cancel_content .= '<p>' . 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_content .= '<p><a id="stripe_cancel" href="' . wp_nonce_url($psts->checkout_url($blog_id) . '&action=cancel', 'psts-cancel') . '" title="' . __('Cancel Your Subscription', 'psts') . '"><img src="' . $img_base . 'cancel_subscribe_gen.gif" /></a></p>';
                    $pp_active = true;
                }
                //print receipt send form
                $content .= $psts->receipt_form($blog_id);
                if (!defined('PSTS_CANCEL_LAST')) {
                    $content .= $cancel_content;
                }
                $content .= "<br>";
                $content .= '</div>';
            }
        }
        if (!$cancel_status && is_pro_site($blog_id) && !is_pro_trial($blog_id)) {
            $content .= '<h2>' . __('Change Your Plan or Payment Details', 'psts') . '</h2>
        <p>' . __('You can modify or upgrade your plan or just change your payment method or information below. Your new subscription will automatically go into effect when your next payment is due.', 'psts') . '</p>';
        } else {
            if (!is_pro_site($blog_id) || is_pro_trial($blog_id)) {
                $content .= '<p>' . __('Please choose your desired plan then click the checkout button below.', 'psts') . '</p>';
            }
        }
        $content .= '<form action="' . $psts->checkout_url($blog_id) . '" method="post" autocomplete="off"  id="payment-form">';
        //print the checkout grid
        $content .= $psts->checkout_grid($blog_id);
        $content .= '<div id="psts-stripe-checkout">
			<h2>' . __('Checkout With a Credit Card:', 'psts') . '</h2>';
        $content .= '<div id="psts-processcard-error"></div>';
        $content .= '
				<table id="psts-cc-table">
				<tbody>
				<!-- Credit Card Type -->
				<tr>
				<td class="pypl_label" align="right">' . __('Cardholder Name:', 'psts') . '&nbsp;</td><td>';
        if ($errmsg = $psts->errors->get_error_message('name')) {
            $content .= '<div class="psts-error">' . $errmsg . '</div>';
        }
        $content .= '<input id="cc_name" type="text" class="cctext card-first-name" value="" size="25" /> </td>
				</tr>
					<tr>
					<td class="pypl_label" align="right">' . __('Card Number:', 'psts') . '&nbsp;</td>
					<td>';
        if ($errmsg = $psts->errors->get_error_message('number')) {
            $content .= '<div class="psts-error">' . $errmsg . '</div>';
        }
        $content .= '<input id="cc_number" type="text" class="cctext card-number" value="" size="23" /><br /><img src="' . $img_base . 'stripe-cards.png" />
					</td>
					</tr>

					<tr>
					<td class="pypl_label" align="right">' . __('Expiration Date:', 'psts') . '&nbsp;</td>
					<td valign="middle">';
        if ($errmsg = $psts->errors->get_error_message('expiration')) {
            $content .= '<div class="psts-error">' . $errmsg . '</div>';
        }
        $content .= '<select id="cc_month" class="card-expiry-month">' . $this->month_dropdown() . '</select>&nbsp;/&nbsp;<select id="cc_year" class="card-expiry-year">' . $this->year_dropdown() . '</select>
					</td>
					</tr>

					<!-- Card Security Code -->
					<tr>
						<td class="pypl_label" align="right"><nobr>' . __('Card Security Code:', 'psts') . '</nobr>&nbsp;</td>
						<td valign="middle">';
        if ($errmsg = $psts->errors->get_error_message('cvv2')) {
            $content .= '<div class="psts-error">' . $errmsg . '</div>';
        }
        $content .= '<label><input id="cc_cvv2" size="5" maxlength="4" type="password" class="cctext card-cvc" title="' . __('Please enter a valid card security code. This is the 3 digits on the signature panel, or 4 digits on the front of Amex cards.', 'psts') . '" />
						<img src="' . $img_base . 'buy-cvv.gif" height="27" width="42" title="' . __('Please enter a valid card security code. This is the 3 digits on the signature panel, or 4 digits on the front of Amex cards.', 'psts') . '" /></label>
						</td>
					</tr>
				

				</table>
				</tbody></table>
				<input type="hidden" name="cc_checkout" value="1" />
			<p>
				<input type="submit" id="cc_checkout" name="stripe_checkout_button" value="' . __('Subscribe', 'psts') . ' &raquo;" class="submit-button"/>
				<span id="stripe_processing" style="display: none;float: right;"><img src="' . $img_base . 'loading.gif" /> ' . __('Processing...', 'psts') . '</span>
			</p>
			</div>';
        $content .= '</form>';
        if (defined('PSTS_CANCEL_LAST')) {
            $content .= $cancel_content;
        }
        return $content;
    }
示例#7
0
 /**
  * Get an upcoming invoice
  * @param mixed $cus_attr
  * @param string $subscription_id
  * @return Stripe_Invoice|false
  */
 public function getUpcomingInvoice($cus_attr = null, $subscription_id = '')
 {
     try {
         $customer = new StripeCustomer($cus_attr);
         $data = array('customer' => $customer->getCustomerAccount()->id, 'subscription' => $subscription_id);
         return Stripe_Invoice::upcoming(array_filter($data), $this->access_token);
     } catch (Exception $ex) {
         $this->log($ex);
         return false;
     }
 }
 /**
  * Get Next Invoice
  *
  * Get user next invoice details details
  */
 public function postGetUpcomingInvoice()
 {
     if ($this->_isValidRequest()) {
         // Include Stripe Library
         $this->_include_stripe_lib();
         $customer_id = $this->_get_stripe_customer_id();
         try {
             // Get customer's upcoming invoice
             $invoice = Stripe_Invoice::upcoming(array("customer" => $customer_id));
         } catch (Exception $e) {
             $this->_invalidRequest($e->getMessage());
         }
         if (!empty($invoice->lines)) {
             $invoice = json_decode($invoice);
             $lines_data = !empty($invoice->lines->data) ? $invoice->lines->data : NULL;
             $lines = NULL;
             if ($lines_data) {
                 foreach ($lines_data as $line) {
                     $lines[] = array('description' => $this->_get_stripe_invoice_line_description($line), 'amount' => $this->_format_stripe_amount($line->amount));
                 }
             }
             $invoiceObj = new StdClass();
             $invoiceObj->duration = date('M d, Y', $invoice->period_start) . ' to ' . date('M d, Y', $invoice->period_end);
             $invoiceObj->summary = array('subtotal' => $this->_format_stripe_amount($invoice->subtotal), 'total' => $this->_format_stripe_amount($invoice->total), 'amount_due' => $this->_format_stripe_amount($invoice->amount_due) . ' USD');
             $invoiceObj->lines = $lines;
             return Response::json($invoiceObj);
         }
     }
 }
 /**
  * Gets upcoming invoice for customer
  * @param $customer_id
  * @return array|bool
  */
 public function get_upcoming_customer($customer_id)
 {
     try {
         $ch = Stripe_Invoice::upcoming(array('customer' => $customer_id));
         return $ch;
     } catch (Exception $e) {
         $this->error = TRUE;
         $this->message = $e->getMessage();
         $this->code = $e->getCode();
         return FALSE;
     }
 }