/**
  * List invoices
  */
 public function listAction(Request $request)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     \Stripe::setApiKey($this->container->getParameter('avro_stripe.secret_key'));
     $invoices = \Stripe_Invoice::all(array('customer' => $user->getStripeCustomerId()))->data;
     $paginator = $this->container->get('knp_paginator')->paginate($invoices, $request->query->get('page', 1), 10);
     return $this->container->get('templating')->renderResponse('AvroStripeBundle:Invoice:list.html.twig', array('paginator' => $paginator));
 }
示例#2
0
 /**
  * @param array|null $params
  *
  * @returns array An array of the customer's Stripe_Invoices.
  */
 public function invoices($params = null)
 {
     if (!$params) {
         $params = array();
     }
     $params['customer'] = $this->id;
     $invoices = Stripe_Invoice::all($params, $this->_apiKey);
     return $invoices;
 }
 public function getInvoices(User $user)
 {
     $customer_id = $user->getProfile() ? $user->getProfile()->getCustomerId() : null;
     if ($customer_id) {
         $invoices = \Stripe_Invoice::all(array("customer" => $customer_id));
         if ($invoices && $invoices->data) {
             return $invoices->data;
         }
     }
     return null;
 }
示例#4
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;
    }
示例#5
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;
    }
示例#6
0
 public function stripe_getInvoices($user)
 {
     $customer = $this->returnFieldFromTable("company_stripetoken", "companies", "id='{$user}'");
     try {
         $data = Stripe_Invoice::all(array("customer" => $customer));
     } catch (exception $e) {
     }
     return $data;
 }
 public function testAll()
 {
     authorizeFromEnv();
     $invoices = Stripe_Invoice::all();
     $this->assertTrue(count($invoices) > 0);
 }
示例#8
0
 /**
  * Get all invoices
  * @param mixed $cus_attr
  * @param string $limit				Number of invoices to retrieve
  * @param string $ending_before		ID of the first element in the previous list
  * @param string $starting_after	ID of the last element in the previous list
  * @param mixed $date
  * @return boolean
  */
 public function getInvoices($cus_attr = null, $limit = 10, $ending_before = null, $starting_after = null, $date = null)
 {
     try {
         $params = array_filter(array('limit' => $limit, 'ending_before' => $ending_before, 'starting_after' => $starting_after, 'date' => $date));
         $customer = new StripeCustomer($cus_attr);
         $params['customer'] = $customer->getCustomerAccount()->id;
         return Stripe_Invoice::all(array_filter($params), $this->access_token);
     } catch (Exception $ex) {
         $this->log($ex);
         return false;
     }
 }
示例#9
0
<?php

require 'lib/Stripe.php';
$cus_id = $_POST['cus_id'];
$sub_id = $_POST['sub_id'];
$stripeKey = "sk_test_9b496fHXP5VKKsecxIzFxMld";
date_default_timezone_set('UTC');
Stripe::setApiKey($stripeKey);
//$invoiceID = 'in_16jRNHGoIOM2Af5cmztSyj57';
$invoiceID = Stripe_Invoice::all(array("customer" => $cus_id))->data[0]->id;
$invoice = Stripe_Invoice::retrieve($invoiceID);
$customer = Stripe_Customer::retrieve($cus_id);
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Invoice</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Customer Invoice">
    <meta name="author" content="5marks">

    <link rel="stylesheet" href="css/bootstrap-min.css">
    <style>
      .invoice-head td {
        padding: 0 8px;
      }
      .container {
      	padding-top:30px;
      }
      .invoice-body{
 /**
  * Gets all invoices for specified customer, up to max of 100 at a time
  *
  * @param $customer_id
  * @param int $num_invoices
  * @param int $offset
  * @return array|bool
  */
 public function get_all_customer($customer_id, $num_invoices = 100, $offset = 0)
 {
     try {
         $ch = Stripe_Invoice::all(array('customer' => $customer_id, 'count' => $num_invoices, 'offset' => $offset));
         return $ch;
     } catch (Exception $e) {
         $this->error = TRUE;
         $this->message = $e->getMessage();
         $this->code = $e->getCode();
         return FALSE;
     }
 }
 public function invoices($data)
 {
     global $WishListMemberInstance;
     global $current_user;
     if (empty($current_user->ID)) {
         return;
     }
     $cust_id = $this->wlm->Get_UserMeta($current_user->ID, 'stripe_cust_id');
     try {
         $stripeapikey = $this->wlm->GetOption('stripeapikey');
         $txns = $this->wlm->GetMembershipLevelsTxnIDs($current_user->ID);
         Stripe::setApiKey($stripeapikey);
         $inv = Stripe_Invoice::all(array('count' => 100, 'customer' => $cust_id));
         $invoices = array();
         if (!empty($inv['data'])) {
             $invoices = array_merge($invoices, $inv['data']);
         }
         //try to get manual charges
         //$manual_charges = Stripe_Charge::all(array("count" => 100, 'customer' => $cust_id));
         // $invoices = array_merge($invoices, $inv['data']);
         //var_dump($manual_charges);
         include $this->get_view_path('invoice_list');
         die;
     } catch (Exception $e) {
         echo __("<p>No invoices found for this user</p>", "wishlist-member");
         die;
     }
 }