/**
  * Setup the reference link in the referrals table
  *
  * @access  public
  * @since   1.6
  */
 public function reference_link($reference = 0, $referral)
 {
     if (empty($referral->context) || $this->context != $referral->context) {
         return $reference;
     }
     $payment = SI_Payment::get_instance($reference);
     $invoice_id = $payment->get_invoice_id();
     $url = get_edit_post_link($invoice_id);
     $reference = get_the_title($invoice_id);
     return '<a href="' . esc_url($url) . '">' . $reference . '</a>';
 }
 function test_add_payment()
 {
     $payment_total = $this->invoice->get_balance();
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => SI_Paypal_EC::PAYMENT_METHOD, 'invoice' => $this->invoice->get_id(), 'amount' => $payment_total, 'data' => array('api_response' => array())), SI_Payment::STATUS_AUTHORIZED);
     if (!$payment_id) {
         return false;
     }
     $payment = SI_Payment::get_instance($payment_id);
     do_action('payment_authorized', $payment);
     // Complete and fire actions
     $payment->set_status(SI_Payment::STATUS_COMPLETE);
     do_action('payment_complete', $payment);
     $this->assertEquals($this->invoice->get_balance(), 0);
 }
 public static function create_admin_payment($invoice_id = 0, $amount = '0.00', $number = '', $date = '', $notes = '')
 {
     if (did_action('si_new_payment') > 0) {
         // make sure this
         return;
     }
     $invoice = SI_Invoice::get_instance($invoice_id);
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => self::get_payment_method(), 'invoice' => $invoice_id, 'amount' => $amount, 'transaction_id' => $number, 'data' => array('amount' => $amount, 'check_number' => $number, 'date' => strtotime($date), 'notes' => $notes)), SI_Payment::STATUS_COMPLETE);
     if (!$payment_id) {
         return false;
     }
     $payment = SI_Payment::get_instance($payment_id);
     if ($date != '') {
         $payment->set_post_date(date('Y-m-d H:i:s', strtotime($date)));
     }
     do_action('admin_payment', $payment_id, $invoice);
     do_action('payment_complete', $payment);
 }
 function build_test_payment($invoice_id, $total = 0, $date = false, $status = '')
 {
     $invoice = SI_Invoice::get_instance($invoice_id);
     // Randomize if no total is set.
     $payment_total = !$total ? rand(1, 300) : $total;
     $status = $status != '' ? $status : SI_Payment::STATUS_AUTHORIZED;
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => SI_Paypal_EC::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => $payment_total, 'data' => array('api_response' => array())), $status);
     $this->payment_ids[] = $payment_id;
     $new_payment = SI_Payment::get_instance($payment_id);
     do_action('payment_authorized', $new_payment);
     if (!$date) {
         $date = time();
     }
     if (!is_integer($date)) {
         $date = strtotime($date);
     }
     $new_payment->set_post_date(date('Y-m-d H:i:s', $date));
     $this->assertTrue(in_array($payment_id, $this->payment_ids));
     return $payment_id;
 }
Exemplo n.º 5
0
function si_doc_history_records($doc_id = 0, $filtered = true)
{
    if (!$doc_id) {
        $doc_id = get_the_ID();
    }
    $returned_history = array();
    switch (get_post_type($doc_id)) {
        case SI_Estimate::POST_TYPE:
            $estimate = SI_Estimate::get_instance($doc_id);
            $history = $estimate->get_history();
            break;
        case SI_Invoice::POST_TYPE:
            $invoice = SI_Invoice::get_instance($doc_id);
            $history = array_merge($invoice->get_history(), $invoice->get_payments());
            break;
        default:
            # code...
            break;
    }
    $history = apply_filters('si_doc_history_records_pre_sort', $history, $doc_id, $filtered);
    // Sort in ascending order
    asort($history, SORT_NUMERIC);
    foreach ($history as $item_id) {
        if (get_post_type($item_id) == SI_Record::POST_TYPE) {
            $record = SI_Record::get_instance($item_id);
            // If no type is set than just keep on moving.
            if ($record->get_type() == SI_Record::DEFAULT_TYPE) {
                continue;
            }
            // filter these types of records out.
            if ($filtered) {
                if (in_array($record->get_type(), array(SI_Controller::PRIVATE_NOTES_TYPE, SI_Estimates::VIEWED_STATUS_UPDATE, SI_Notifications::RECORD))) {
                    continue;
                }
            }
            $r_post = $record->get_post();
            switch ($record->get_type()) {
                case SI_Controller::PRIVATE_NOTES_TYPE:
                    $returned_history[$item_id]['type'] = __('Private Note', 'sprout-invoices');
                    break;
                case SI_Estimates::HISTORY_UPDATE:
                    $returned_history[$item_id]['type'] = __('Updated', 'sprout-invoices');
                    break;
                case SI_Estimates::VIEWED_STATUS_UPDATE:
                    $returned_history[$item_id]['type'] = __('Viewed', 'sprout-invoices');
                    break;
                case SI_Notifications::RECORD:
                    $returned_history[$item_id]['type'] = __('Notification', 'sprout-invoices');
                    break;
                case SI_Estimates::HISTORY_INVOICE_CREATED:
                    $returned_history[$item_id]['type'] = __('Invoice Created', 'sprout-invoices');
                    break;
                case SI_Estimate_Submissions::SUBMISSION_UPDATE:
                    $returned_history[$item_id]['type'] = __('Submitted', 'sprout-invoices');
                    break;
                case SI_Importer::RECORD:
                    $returned_history[$item_id]['type'] = __('Imported', 'sprout-invoices');
                    break;
                case SI_Estimates::HISTORY_STATUS_UPDATE:
                default:
                    $returned_history[$item_id]['type'] = __('Status Update', 'sprout-invoices');
                    break;
            }
            $returned_history[$item_id]['status_type'] = $record->get_type();
            $returned_history[$item_id]['post_date'] = $r_post->post_date;
            $returned_history[$item_id]['update_title'] = $r_post->post_title;
            $returned_history[$item_id]['content'] = $r_post->post_content;
        } elseif (get_post_type($item_id) == SI_Payment::POST_TYPE) {
            $payment = SI_Payment::get_instance($item_id);
            $p_post = $payment->get_post();
            $returned_history[$item_id]['type'] = __('Payment', 'sprout-invoices');
            $returned_history[$item_id]['status_type'] = 'payment';
            $returned_history[$item_id]['post_date'] = $p_post->post_date;
            $returned_history[$item_id]['update_title'] = $p_post->post_title;
            $returned_history[$item_id]['content'] = '';
            $returned_history[$item_id]['content'] .= '<span>' . $payment->get_payment_method() . '</span><br/>';
            $returned_history[$item_id]['content'] .= '<b>' . __('Payment Total', 'sprout-invoices') . ':</b> ' . sa_get_formatted_money($payment->get_amount(), $item_id);
        } else {
            if ($filtered) {
                $comment = get_comment($item_id);
                if (!is_wp_error($comment)) {
                    $returned_history[$item_id]['type'] = $comment->comment_author;
                    $returned_history[$item_id]['status_type'] = 'comment';
                    $returned_history[$item_id]['post_date'] = $comment->comment_date;
                    $returned_history[$item_id]['content'] = get_comment_text($comment->comment_ID);
                    $returned_history[$item_id]['comment_id'] = intval($comment->comment_ID);
                }
            }
        }
    }
    return $returned_history;
}
    function column_data($item)
    {
        $payment_id = $item->ID;
        $payment = SI_Payment::get_instance($payment_id);
        $method = $payment->get_payment_method();
        $data = $payment->get_data();
        $detail = '';
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                if (is_array($value)) {
                    $value = sprintf('<pre id="payment_detail_%s" style="width="500px"; white-space:pre-wrap; text-align: left; font: normal normal 11px/1.4 menlo, monaco, monospaced; padding: 5px;">%s</pre>', $payment_id, print_r($value, true));
                }
                if (is_string($value)) {
                    $detail .= '<dl>
						<dt><b>' . ucfirst(str_replace('_', ' ', $key)) . '</b></dt>
						<dd>' . $value . '</dd>
					</dl>';
                }
            }
        }
        //Build row actions
        $actions = array('detail' => sprintf('<a href="#TB_inline?width=900&height=600&inlineId=data_id_%s" class="thickbox button" title="' . __('Transaction Data', 'sprout-invoices') . '">' . __('Transaction Data', 'sprout-invoices') . '</a><div id="data_id_%s" style="display:none;">%s</div>', $payment_id, $payment_id, $detail));
        //Return the title contents
        return sprintf('%1$s %2$s', $method, $this->row_actions($actions));
    }
Exemplo n.º 7
0
 /**
  * Create the recurring payment profile.
  */
 private function add_customer_to_plan(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $invoice_id = $invoice->get_id();
     self::setup_stripe();
     try {
         $user = si_who_is_paying($invoice);
         $purchase_data = $this->purchase_data($checkout, $invoice);
         if (!$purchase_data) {
             return false;
         }
         $price = SI_Subscription_Payments::get_renew_price($invoice_id);
         $amount_in_cents = self::convert_money_to_cents(sprintf('%0.2f', $price));
         $balance = si_has_invoice_deposit($invoice_id) ? $invoice->get_deposit() : $invoice->get_balance();
         $subscribe = Stripe_Customer::create(array('card' => $purchase_data, 'plan' => $invoice_id . $amount_in_cents, 'email' => $user->user_email, 'account_balance' => self::convert_money_to_cents(sprintf('%0.2f', $balance - $price))));
         $subscribe = array('id' => $subscribe->id, 'subscription_id' => $subscribe->subscriptions->data[0]->id, 'amount' => $amount_in_cents, 'plan' => $invoice_id . $amount_in_cents, 'card' => $purchase_data, 'email' => $user->user_email);
         // Payment
         $payment_id = SI_Payment::new_payment(array('payment_method' => self::PAYMENT_METHOD, 'invoice' => $invoice_id, 'amount' => $price, 'data' => array('live' => self::MODE_LIVE === self::$api_mode, 'api_response' => $subscribe)), SI_Payment::STATUS_RECURRING);
         do_action('si_stripe_recurring_payment_profile_created', $payment_id);
         // Passed back to create the initial payment
         $response = $subscribe;
         $response['amount'] = $amount_in_cents;
         $response['plan'] = $invoice_id . $amount_in_cents;
         return $response;
     } catch (Exception $e) {
         self::set_error_messages($e->getMessage());
         return false;
     }
 }
Exemplo n.º 8
0
 public static function maybe_remove_deposit(SI_Payment $payment, SI_Checkouts $checkout)
 {
     $invoice_id = $payment->get_invoice_id();
     $invoice = SI_Invoice::get_instance($invoice_id);
     $payment_amount = $payment->get_amount();
     $invoice_deposit = $invoice->get_deposit();
     if ($payment_amount >= $invoice_deposit) {
         // Reset the deposit since the payment made covers it.
         $invoice->set_deposit('');
     }
 }
Exemplo n.º 9
0
 public static function create_payment($payment = array())
 {
     if (!isset($payment['Invoice ID'])) {
         do_action('si_error', 'No Invoice ID given within payment import', $payment);
         return;
     }
     // Find the associated invoice
     $invoices = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(self::CSV_ID => $payment['Invoice ID']));
     // Can't assign a payment without an invoice
     if (empty($invoices)) {
         do_action('si_error', 'No invoice found for this payment', $payment['Payment ID']);
         return;
     }
     $invoice = SI_Invoice::get_instance($invoices[0]);
     if (!is_a($invoice, 'SI_Invoice')) {
         return;
     }
     $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['Payment Method']) ? $payment['Payment Method'] : self::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => round($payment['Amount'], 2), 'transaction_id' => isset($payment['Payment ID']) ? $payment['Payment ID'] : '', 'data' => array('api_response' => $payment)));
     $new_payment = SI_Payment::get_instance($payment_id);
     $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment['Date'])));
     return $new_payment;
 }
Exemplo n.º 10
0
 /**
  * If an invoice was deleted also delete the payments associated
  * @param  integer $post_id
  * @return null
  */
 public static function maybe_delete_payment($post_id = 0)
 {
     if (get_post_type($post_id) == SI_Invoice::POST_TYPE) {
         $payment_ids = SI_Payment::get_payments(array('invoices' => $post_id));
         foreach ($payment_ids as $payment_id) {
             wp_delete_post($payment_id);
         }
     }
 }
Exemplo n.º 11
0
 public static function total_payment_data_by_date_segment($segment = 'weeks', $span = 6)
 {
     // Return cache if present.
     $cache = self::get_cache(__FUNCTION__ . $segment . $span);
     if ($cache) {
         return $cache;
     }
     // FUTURE charts should be dynamic based on selected segment.
     $weeks = self::walk_back_x_span($span, $segment);
     $year = date('Y', strtotime($span . ' weeks ago'));
     // Build data array, without a explicit build segments without posts will not show.
     $data = array();
     foreach ($weeks as $week_num) {
         $data[$week_num] = array('payments' => 0, 'totals' => 0, 'status_pending' => 0, 'status_authorized' => 0, 'status_complete' => 0, 'status_partial' => 0, 'status_void' => 0);
     }
     $args = array('post_type' => SI_Payment::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'date', 'fields' => 'ids', 'date_query' => array(array('after' => date('Y-m-d', strtotime($year . 'W' . array_shift($weeks))), 'inclusive' => true)));
     $payments = new WP_Query($args);
     foreach ($payments->posts as $payment_id) {
         $payment = SI_Payment::get_instance($payment_id);
         $week = get_the_time('W', $payment_id);
         $data[$week]['payments'] += 1;
         $data[$week]['totals'] += $payment->get_amount();
         switch (get_post_status($payment_id)) {
             case SI_Payment::STATUS_PENDING:
                 $data[$week]['status_pending'] += 1;
                 break;
             case SI_Payment::STATUS_AUTHORIZED:
                 $data[$week]['status_authorized'] += 1;
                 break;
             case SI_Payment::STATUS_COMPLETE:
                 $data[$week]['status_complete'] += 1;
                 break;
             case SI_Payment::STATUS_PARTIAL:
                 $data[$week]['status_partial'] += 1;
                 break;
             case SI_Payment::STATUS_VOID:
                 $data[$week]['status_void'] += 1;
                 break;
             default:
                 break;
         }
     }
     return self::set_cache(__FUNCTION__ . $segment . $span, $data, self::CACHE_TIMEOUT);
 }
 private function create_recurring_payment_nvp_data(SI_Checkouts $checkout, SI_Invoice $invoice, SI_Payment $payment)
 {
     $invoice_id = $invoice->get_id();
     $payment_data = $payment->get_data();
     $term = SI_Subscription_Payments::get_term($invoice_id);
     // day, week, month, or year
     $duration = (int) SI_Subscription_Payments::get_duration($invoice_id);
     $price = SI_Subscription_Payments::get_renew_price($invoice_id);
     $terms = array('day' => 'Day', 'week' => 'Week', 'month' => 'Month', 'year' => 'Year');
     if (!isset($terms[$term])) {
         $term = 'day';
     }
     // The first payment was just now, so
     // the subscription starts based on the term
     $starts = strtotime(date('Y-m-d') . ' +' . $duration . ' ' . $term);
     $user = si_who_is_paying($invoice);
     // User email or none
     $user_email = $user ? $user->user_email : '';
     $nvp = array('USER' => self::$api_username, 'PWD' => self::$api_password, 'SIGNATURE' => self::$api_signature, 'VERSION' => self::$version, 'METHOD' => 'CreateRecurringPaymentsProfile', 'PROFILESTARTDATE' => date('Y-m-d', $starts) . 'T00:00:00Z', 'PROFILEREFERENCE' => $payment->get_id(), 'DESC' => $this->recurring_desc($invoice), 'MAXFAILEDPAYMENTS' => 2, 'AUTOBILLOUTAMT' => 'AddToNextBilling', 'BILLINGPERIOD' => $terms[$term], 'BILLINGFREQUENCY' => $duration, 'TOTALBILLINGCYCLES' => 0, 'AMT' => si_get_number_format($price), 'CURRENCYCODE' => self::get_currency_code($invoice_id), 'EMAIL' => $user_email, 'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => 'Digital', 'L_PAYMENTREQUEST_0_NAME0' => $invoice->get_title(), 'L_PAYMENTREQUEST_0_AMT0' => si_get_number_format($price), 'L_PAYMENTREQUEST_0_NUMBER0' => $invoice_id, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'CREDITCARDTYPE' => self::get_card_type($this->cc_cache['cc_number']), 'ACCT' => $this->cc_cache['cc_number'], 'EXPDATE' => self::expiration_date($this->cc_cache['cc_expiration_month'], $this->cc_cache['cc_expiration_year']), 'CVV2' => $this->cc_cache['cc_cvv'], 'FIRSTNAME' => $checkout->cache['billing']['first_name'], 'LASTNAME' => $checkout->cache['billing']['last_name'], 'STREET' => $checkout->cache['billing']['street'], 'CITY' => $checkout->cache['billing']['city'], 'STATE' => $checkout->cache['billing']['zone'], 'COUNTRYCODE' => self::country_code($checkout->cache['billing']['country']), 'ZIP' => $checkout->cache['billing']['postal_code']);
     return $nvp;
 }
Exemplo n.º 13
0
 public static function create_invoice_payment($payment = array(), SI_Invoice $invoice)
 {
     $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::WPINVOICE_ID => $payment['ID']));
     // Don't create a duplicate if this was already imported.
     if (!empty($possible_dups)) {
         do_action('si_error', 'Invoice imported already', $payment['ID']);
         return;
     }
     $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['action']) ? self::PAYMENT_METHOD . ' :: ' . $payment['action'] : self::PAYMENT_METHOD, 'invoice' => $invoice->get_id(), 'amount' => $payment['value'], 'transaction_id' => isset($payment['ID']) ? $payment['object_id'] . '::' . $payment['ID'] : '', 'data' => array('api_response' => $payment)));
     $new_payment = SI_Payment::get_instance($payment_id);
     $new_payment->set_post_date(date('Y-m-d H:i:s', $payment['time']));
     return $new_payment;
 }
Exemplo n.º 14
0
 public static function create_invoice_payment(Harvest_Payment $payment, SI_Invoice $invoice)
 {
     $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::HARVEST_ID => $payment->id));
     // Don't create a duplicate if this was already imported.
     if (!empty($possible_dups)) {
         do_action('si_error', 'Invoice imported already', $payment->id);
         return;
     }
     $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment->recorded_by) ? $payment->recorded_by : self::PAYMENT_METHOD, 'invoice' => $invoice->get_ID(), 'amount' => $payment->amount, 'transaction_id' => isset($payment->pay_pal_transaction_id) ? $payment->pay_pal_transaction_id : '', 'data' => array('api_response' => array('amount' => $payment->amount, 'authorization' => $payment->authorization, 'created_at' => $payment->created_at, 'id' => $payment->id, 'invoice_id' => $payment->invoice_id, 'paid_at' => $payment->paid_at, 'paypal_transaction_id' => $payment->pay_pal_transaction_id, 'payment_gateway_id' => $payment->payment_gateway_id, 'recorded_by' => $payment->recorded_by, 'recorded_by_email' => $payment->recorded_by_email, 'updated_at' => $payment->updated_at))));
     $new_payment = SI_Payment::get_instance($payment_id);
     $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment->created_at)));
     return $new_payment;
 }
 public static function invoice_has_subscription_payments($bool, SI_Invoice $invoice, SI_Payment $payment)
 {
     // Set the payment token on the invoice.
     $data = $payment->get_data();
     if (isset($data['payment_token'])) {
         self::set_token($invoice->get_id(), $data['payment_token']);
         // has subscription options
         return self::has_subscription_payment($invoice->get_id());
     }
     return $bool;
 }
Exemplo n.º 16
0
		<a href="javascript:;" onclick="Uversa.SureInvoice.Calendar.show('timestamp')"><img width="16" height="16" border="0" src="images/dynCalendar.gif"/></a>&nbsp;
	</TD>
</TR>
<TR>
	<TD CLASS="form_field_header_cell">Company:</TD>
	<TD CLASS="form_field_cell"><?php 
echo SI_Company::getName($payment->company_id);
?>
</TD>
</TR>
<TR>
	<TD CLASS="form_field_header_cell">Payment Type:</TD>
	<TD CLASS="form_field_cell">
		<SELECT NAME="type" CLASS="input_text">
			<?php 
echo SI_Payment::getTypeSelectTags($payment->type);
?>
		</SELECT>
	</TD>
</TR>
<TR>
	<TD CLASS="form_field_header_cell">Amount:</TD>
	<TD CLASS="form_field_cell"><INPUT NAME="amount" ID="amount" CLASS="input_text" SIZE="10" TYPE="text" VALUE="<?php 
echo $payment->amount;
?>
"></TD>
</TR>
<TR>
	<TD CLASS="form_field_header_cell">Auth Code:</TD>
	<TD CLASS="form_field_cell"><INPUT NAME="auth_code" CLASS="input_text" SIZE="10" TYPE="text" VALUE="<?php 
echo $payment->auth_code;
Exemplo n.º 17
0
	function get($id = NULL){
		global $db_conn;

		if(!isset($id)){
			$id = $this->id;
		}

		if(!isset($id)){
			$this->error = "SI_Payment::get() : Payment id not set\n";
			return FALSE;
		}

		$Payment = SI_Payment::retrieveSet("WHERE id = $id", TRUE);
		if($Payment === FALSE){
			return FALSE;
		}

		if(isset($Payment[0])){
			$this->updateFromAssocArray($Payment[0]);
			$this->stripSlashes();
			if($this->_populateInvoices() === FALSE)
				return FALSE;
		}else{
			$this->error = "SI_Payment::get() : No data retrieved from query\n";
			return FALSE;
		}
		return TRUE;
	}
Exemplo n.º 18
0
/**
 * Load the SI application
 * (function called at the bottom of this page)
 *
 * @package Sprout_Invoices
 * @return void
 */
function sprout_invoices_load()
{
    if (class_exists('Sprout_Invoices')) {
        error_log('** Sprout_Invoices Already Loaded **');
        return;
        // already loaded, or a name collision
    }
    do_action('sprout_invoices_preload');
    //////////
    // Load //
    //////////
    // Master class
    require_once SI_PATH . '/Sprout_Invoices.class.php';
    // base classes
    require_once SI_PATH . '/models/_Model.php';
    require_once SI_PATH . '/controllers/_Controller.php';
    do_action('si_require_base_classes');
    // models
    require_once SI_PATH . '/models/Client.php';
    require_once SI_PATH . '/models/Estimate.php';
    require_once SI_PATH . '/models/Invoice.php';
    require_once SI_PATH . '/models/Notification.php';
    require_once SI_PATH . '/models/Payment.php';
    require_once SI_PATH . '/models/Record.php';
    // Premium models
    require_once SI_PATH . '/models/Project.php';
    // i18n
    require_once SI_PATH . '/controllers/i18n/Countries_States.php';
    require_once SI_PATH . '/controllers/i18n/Locales.php';
    do_action('si_require_model_classes');
    /////////////////
    // Controllers //
    /////////////////
    // settings
    require_once SI_PATH . '/controllers/admin/Settings.php';
    if (!class_exists('SA_Settings_API')) {
        require_once SI_PATH . '/controllers/admin/Settings_API.php';
    }
    require_once SI_PATH . '/controllers/admin/Capabilities.php';
    require_once SI_PATH . '/controllers/admin/Help.php';
    // json api
    require_once SI_PATH . '/controllers/api/JSON_API.php';
    // checkouts
    require_once SI_PATH . '/controllers/checkout/Checkouts.php';
    // clients
    require_once SI_PATH . '/controllers/clients/Clients.php';
    // developer logs
    require_once SI_PATH . '/controllers/developer/Logs.php';
    // Estimates
    require_once SI_PATH . '/controllers/estimates/Estimate_Submission.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/estimates/Estimate_Submission_Premium.php')) {
        require_once SI_PATH . '/controllers/estimates/Estimate_Submission_Premium.php';
    }
    require_once SI_PATH . '/controllers/estimates/Estimates.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Admin.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Edit.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Records.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Template.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/estimates/Estimates_Premium.php')) {
        require_once SI_PATH . '/controllers/estimates/Estimates_Premium.php';
    }
    // invoices
    require_once SI_PATH . '/controllers/invoices/Invoices.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Admin.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Edit.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Records.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Template.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Deposit.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/invoices/Invoices_Premium.php')) {
        require_once SI_PATH . '/controllers/invoices/Invoices_Premium.php';
    }
    // Line Items
    require_once SI_PATH . '/controllers/line-items/Line_Items.php';
    // notifications
    require_once SI_PATH . '/controllers/notifications/Notifications_Control.php';
    require_once SI_PATH . '/controllers/notifications/Notifications.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/notifications/Notifications_Premium.php')) {
        require_once SI_PATH . '/controllers/notifications/Notifications_Premium.php';
    }
    require_once SI_PATH . '/controllers/notifications/Notifications_Admin_Table.php';
    // payment processing
    require_once SI_PATH . '/controllers/payment-processing/Payment_Processors.php';
    require_once SI_PATH . '/controllers/payment-processing/Credit_Card_Processors.php';
    require_once SI_PATH . '/controllers/payment-processing/Offsite_Processors.php';
    // payment processors
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_EC.php')) {
        require_once SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_EC.php';
    }
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_Pro.php')) {
        require_once SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_Pro.php';
    }
    require_once SI_PATH . '/controllers/payment-processing/processors/SI_Checks.php';
    require_once SI_PATH . '/controllers/payment-processing/processors/SI_Admin_Payment.php';
    do_action('si_payment_processors_loaded');
    // payments
    require_once SI_PATH . '/controllers/payments/Payments.php';
    require_once SI_PATH . '/controllers/payments/Payments_Admin_Table.php';
    // Projects
    require_once SI_PATH . '/controllers/projects/Projects.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/projects/Projects_Premium.php')) {
        require_once SI_PATH . '/controllers/projects/Projects_Premium.php';
    }
    // internal records
    require_once SI_PATH . '/controllers/records/Internal_Records.php';
    require_once SI_PATH . '/controllers/records/Records_Admin_Table.php';
    // reporting
    require_once SI_PATH . '/controllers/reporting/Dashboard.php';
    require_once SI_PATH . '/controllers/reporting/Reporting.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/reporting/Reporting_Premium.php')) {
        require_once SI_PATH . '/controllers/reporting/Reporting_Premium.php';
    }
    require_once SI_PATH . '/controllers/templating/Templating.php';
    require_once SI_PATH . '/controllers/templating/Customizer.php';
    // updates
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/updates/Updates.php')) {
        require_once SI_PATH . '/controllers/updates/Updates.php';
    }
    if (file_exists(SI_PATH . '/controllers/updates/Free_License.php')) {
        require_once SI_PATH . '/controllers/updates/Free_License.php';
    }
    // importers
    require_once SI_PATH . '/importers/Importer.php';
    require_once SI_PATH . '/importers/Freshbooks.php';
    require_once SI_PATH . '/importers/Harvest.php';
    require_once SI_PATH . '/importers/WP-Invoice.php';
    require_once SI_PATH . '/importers/CSV.php';
    do_action('si_importers_loaded');
    // Fix others problems
    require_once SI_PATH . '/controllers/compat/Compatibility.php';
    // all done
    do_action('si_require_controller_classes');
    // Template tags
    require_once SI_PATH . '/template-tags/estimates.php';
    require_once SI_PATH . '/template-tags/clients.php';
    require_once SI_PATH . '/template-tags/forms.php';
    require_once SI_PATH . '/template-tags/invoices.php';
    require_once SI_PATH . '/template-tags/line-items.php';
    require_once SI_PATH . '/template-tags/projects.php';
    require_once SI_PATH . '/template-tags/ui.php';
    require_once SI_PATH . '/template-tags/utility.php';
    require_once SI_PATH . '/template-tags/docs.php';
    // l18n
    require_once SI_PATH . '/languages/SI_l10n.php';
    require_once SI_PATH . '/languages/SI_Strings.php';
    // i18n & l10n
    SI_l10n::init();
    SI_Strings::load_additional_strings();
    SI_Locales::init();
    SI_Countries_States::init();
    ///////////////////
    // init() models //
    ///////////////////
    do_action('si_models_init');
    SI_Post_Type::init();
    // _Model
    SI_Record::init();
    SI_Notification::init();
    SI_Invoice::init();
    SI_Estimate::init();
    SI_Client::init();
    SI_Payment::init();
    SI_Project::init();
    /////////////////////////
    // init() controllers //
    /////////////////////////
    do_action('si_controllers_init');
    SI_Controller::init();
    SA_Settings_API::init();
    SI_Templating_API::init();
    SI_Customizer::init();
    SI_Admin_Capabilities::init();
    // updates
    if (!SI_FREE_TEST && class_exists('SI_Updates')) {
        SI_Updates::init();
    }
    if (class_exists('SI_Free_License')) {
        SI_Free_License::init();
    }
    // api
    SI_JSON_API::init();
    // reports
    SI_Dashboard::init();
    SI_Reporting::init();
    if (!SI_FREE_TEST && class_exists('SI_Reporting_Premium')) {
        SI_Reporting_Premium::init();
    }
    // records and logs
    SI_Internal_Records::init();
    SI_Dev_Logs::init();
    // settings
    SI_Admin_Settings::init();
    // payments and processing
    SI_Payment_Processors::init();
    SI_Payments::init();
    // notifications
    SI_Notifications::init();
    // Hooks come before parent class.
    if (!SI_FREE_TEST && class_exists('SI_Notifications_Premium')) {
        SI_Notifications_Premium::init();
    }
    SI_Notifications_Control::init();
    // clients
    SI_Clients::init();
    // estimates
    SI_Estimates::init();
    if (!SI_FREE_TEST && class_exists('SI_Estimates_Premium')) {
        SI_Estimates_Premium::init();
    }
    if (!SI_FREE_TEST && class_exists('SI_Estimates_Submission_Premium')) {
        SI_Estimates_Submission_Premium::init();
    }
    SI_Estimate_Submissions::init();
    SI_Estimates_Admin::init();
    SI_Estimates_Edit::init();
    SI_Estimates_Template::init();
    SI_Estimates_Records::init();
    // checkouts
    SI_Checkouts::init();
    // invoices
    SI_Invoices::init();
    SI_Invoices_Admin::init();
    SI_Invoices_Edit::init();
    SI_Invoices_Template::init();
    SI_Invoices_Records::init();
    SI_Invoices_Deposit::init();
    if (!SI_FREE_TEST && class_exists('SI_Invoices_Premium')) {
        SI_Invoices_Premium::init();
    }
    // Line items
    SI_Line_Items::init();
    // projects
    SI_Projects::init();
    if (!SI_FREE_TEST && class_exists('SI_Projects_Premium')) {
        SI_Projects_Premium::init();
    }
    // importer
    SI_Importer::init();
    // help
    SI_Help::init();
    // Compat
    SI_Compatibility::init();
    // addons
    require_once SI_PATH . '/add-ons/Addons.php';
    require_once SI_PATH . '/add-ons/updates/edd_plugin_updater.class.php';
    SA_Addons::init();
    do_action('sprout_invoices_loaded');
}
Exemplo n.º 19
0
 public function get_payments_total($pending = true)
 {
     if (isset($this->payments_total)) {
         return $this->payments_total;
     }
     $payment_ids = self::get_payments();
     $payment_total = 0;
     foreach ($payment_ids as $payment_id) {
         $payment = SI_Payment::get_instance($payment_id);
         if (!$pending && $payment->get_status() == SI_Payment::STATUS_PENDING) {
             continue;
         }
         if (!in_array($payment->get_status(), array(SI_Payment::STATUS_VOID, SI_Payment::STATUS_RECURRING, SI_Payment::STATUS_CANCELLED))) {
             $payment_total += $payment->get_amount();
         }
     }
     $this->payment_total = $payment_total;
     return $payment_total;
 }
Exemplo n.º 20
0
// Add a progress bar to show table record collection.
echo '<tr class="odd" id="progress_row"><td valign="top" colspan="8" class="dataTables_empty"><div id="rows_progress" style="width:100%;border:1px solid #ccc;"></div> <div id="table_progress">' . __('Preparing rows...', 'sprout-invoices') . '</div></td></tr>';
$records = new WP_Query($args);
$i = 0;
while ($records->have_posts()) {
    $records->the_post();
    // Calculate the percentage
    $i++;
    $percent = intval($i / $records->found_posts * 100) . "%";
    // Javascript for updating the progress bar and information
    echo '<script language="javascript" id="progress_js">
						document.getElementById("rows_progress").innerHTML="<div style=\\"width:' . $percent . ';background-color:#ddd;\\">&nbsp;</div>";
						document.getElementById("table_progress").innerHTML="' . sprintf(__('%o records(s) of %o added.', 'sprout-invoices'), $i, $records->found_posts) . '";
						document.getElementById("progress_js").remove();
						</script>';
    $payment = SI_Payment::get_instance(get_the_ID());
    $invoice_id = $payment->get_invoice_id();
    if ($payment->get_status() == SI_Payment::STATUS_VOID) {
        $table_voided_payment_total += $payment->get_amount();
        $payment_total = 0;
        $payment_void_total = $payment->get_amount();
    } else {
        $table_payment_total += $payment->get_amount();
        $payment_total = $payment->get_amount();
        $payment_void_total = 0;
    }
    $payment_link = sprintf('<a class="payments_link" title="%s" href="%s&s=%s">#%s</a>', __('Payment', 'sprout-invoices'), get_admin_url('', '/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments'), get_the_ID(), get_the_ID());
    $payments_link = sprintf('<a class="payments_link" title="%s" href="%s&s=%s">%s</a>', __('Invoice Payments', 'sprout-invoices'), get_admin_url('', '/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments'), $invoice_id, sa_get_formatted_money(si_get_invoice_payments_total($invoice_id)));
    $invoice_name = $invoice_id ? sprintf('<a href="%s">%s</a>', get_edit_post_link($invoice_id), get_the_title($invoice_id)) : __('N/A', 'sprout-invoices');
    $client_name = si_get_invoice_client_id($invoice_id) ? sprintf('<a href="%s">%s</a>', get_edit_post_link(si_get_invoice_client_id($invoice_id)), get_the_title(si_get_invoice_client_id($invoice_id))) : __('N/A', 'sprout-invoices');
    ?>
Exemplo n.º 21
0
 /**
  * Process a payment
  *
  * @param SI_Checkouts $checkout
  * @param SI_Invoice $invoice
  * @return SI_Payment|bool false if the payment failed, otherwise a Payment object
  */
 public function process_payment(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $amount = isset($_POST['sa_checks_amount']) ? $_POST['sa_checks_amount'] : false;
     $number = isset($_POST['sa_checks_check_number']) ? $_POST['sa_checks_check_number'] : false;
     $date = isset($_POST['sa_checks_mailed']) ? $_POST['sa_checks_mailed'] : false;
     $notes = isset($_POST['sa_checks_notes']) ? $_POST['sa_checks_notes'] : '';
     if (!isset($_POST['sa_checks_nonce']) || !wp_verify_nonce($_POST['sa_checks_nonce'], self::NONCE)) {
         return false;
     }
     if (!$amount) {
         return false;
     }
     // create new payment
     $payment_id = SI_Payment::new_payment(array('payment_method' => self::get_payment_method(), 'invoice' => $invoice->get_id(), 'amount' => $amount, 'transaction_id' => $number, 'data' => array('amount' => $amount, 'check_number' => $number, 'date' => strtotime($date), 'notes' => $notes)), SI_Payment::STATUS_PENDING);
     if (!$payment_id) {
         return false;
     }
     $payment = SI_Payment::get_instance($payment_id);
     if ($date != '') {
         $payment->set_post_date(date('Y-m-d H:i:s', strtotime($date)));
     }
     do_action('payment_pending', $payment);
     return $payment;
 }
 public static function payment($data = array())
 {
     if (!isset($data['id'])) {
         $data['id'] = $_GET['id'];
     }
     $payment = SI_Payment::get_instance($data['id']);
     if (!is_a($payment, 'SI_Payment')) {
         return;
     }
     return self::payment_data($payment);
 }
 /**
  * Mark payment complete
  *
  * @return
  */
 public static function manually_mark_complete()
 {
     if (!isset($_REQUEST['complete_payment_nonce'])) {
         self::ajax_fail('Forget something?');
     }
     $nonce = $_REQUEST['complete_payment_nonce'];
     if (!wp_verify_nonce($nonce, self::AJAX_NONCE)) {
         self::ajax_fail('Not going to fall for it!');
     }
     if (!current_user_can('manage_sprout_invoices_payments')) {
         return;
     }
     $payment_id = $_REQUEST['payment_id'];
     $payment = SI_Payment::get_instance($payment_id);
     $status = $payment->get_status();
     if (!is_a($payment, 'SI_Payment')) {
         self::ajax_fail('Payment ID Error.');
     }
     $payment->set_status(SI_Payment::STATUS_COMPLETE);
     if ($payment->get_status() != $status) {
         header('Content-type: application/json');
         echo wp_json_encode(array('response' => si__('Payment status updated.')));
         exit;
     } else {
         self::ajax_fail('Failed payment capture.');
     }
 }
Exemplo n.º 24
0
				$error_msg .= "Error getting transaction for invoice!";
				debug_message($ct->getLastError());	
			}else{
				$ct->company_id = $invoice->company_id;
				if($ct->update() === FALSE){
					$error_msg .= "Error moving company transaction with new price";
					debug_message($ct->getLastError());	
				}else{
					goBack();
				}
			}	
		}	
	}
}	

$payment = new SI_Payment();
$payments = $payment->getForInvoice($invoice->id);
if($payments === FALSE){
	$error_msg .= "Error retreiving payment information!\n";
	debug_message($payment->getLastError());
}

$_REQUEST['detail'] = strtolower(substr($_REQUEST['detail'],0,1)) == "y" ? TRUE : FALSE;
$url = $_SERVER['PHP_SELF'].'?id='.$_REQUEST['id'].'&';

$title = "Edit Invoice";

require('header.php') ?>
<form name="invoice_edit" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
 public static function payment_data(SI_Payment $payment)
 {
     $payment_data = array('title' => $payment->get_title(), 'id' => $payment->get_id(), 'status' => $payment->get_status(), 'payment_method' => $payment->get_payment_method(), 'amount' => $payment->get_amount(), 'invoice_id' => $payment->get_invoice_id(), 'data' => $payment->get_data());
     $invoice = SI_Invoice::get_instance($payment->get_invoice_id());
     if (is_a($invoice, 'SI_Invoice')) {
         $payment_data['invoice_data'] = self::invoice_data($invoice);
     }
     return $payment_data;
 }
            ?>
								<?php 
            if ($inv_payments = $invoice->get_payments()) {
                ?>

									<div class="si_payment_history">

										<strong><?php 
                _e('Payment History', 'sprout-invoices');
                ?>
</strong>
										<?php 
                foreach ($inv_payments as $payment_id) {
                    ?>
											<?php 
                    $payment = SI_Payment::get_instance($payment_id);
                    $method = strpos(strtolower($payment->get_payment_method()), 'credit') !== false ? __('Credit Card', 'sprout-invoices') : $payment->get_payment_method();
                    ?>
													<small><?php 
                    printf(__('<b>%s:</b> %s', 'sprout-invoices'), $method, sa_get_formatted_money($payment->get_amount(), $invoice_id));
                    ?>
</small>
										<?php 
                }
                ?>

									</div>

								<?php 
            }
            ?>
Exemplo n.º 27
0
 public static function create_payment($payment)
 {
     $possible_dups = SI_Post_Type::find_by_meta(SI_Payment::POST_TYPE, array(self::FRESHBOOKS_ID => $payment['payment_id']));
     // Don't create a duplicate if this was already imported.
     if (!empty($possible_dups)) {
         do_action('si_error', 'Invoice imported already', $payment['payment_id']);
         return;
     }
     // Find the associated invoice
     $invoices = SI_Post_Type::find_by_meta(SI_Invoice::POST_TYPE, array(self::FRESHBOOKS_ID => $payment['invoice_id']));
     $invoice = SI_Invoice::get_instance($invoices[0]);
     $invoice_id = is_a($invoice, 'SI_Invoice') ? $invoice->get_id() : 0;
     // Can't assign a payment without an invoice
     if (!$invoice_id) {
         do_action('si_error', 'No invoice found for this payment', $payment['payment_id']);
         return;
     }
     $payment_id = SI_Payment::new_payment(array('payment_method' => isset($payment['type']) && !is_array($payment['type']) ? $payment['type'] : self::PAYMENT_METHOD, 'invoice' => $invoice_id, 'amount' => round($payment['amount'], 2), 'transaction_id' => isset($payment['payment_id']) ? $payment['payment_id'] : '', 'data' => array('api_response' => $payment)));
     $new_payment = SI_Payment::get_instance($payment_id);
     $new_payment->set_post_date(date('Y-m-d H:i:s', strtotime($payment['date'])));
     return $new_payment;
 }
Exemplo n.º 28
0
		fatal_error("Error getting company export data!\n".$company->getLastError());
	}
}elseif(strtolower($_REQUEST['mode']) == 'item_code'){
	$code = new SI_ItemCode();
	$output = $code->exportQB();
	if($output === FALSE){
		fatal_error("Error getting item code export data!\n".$code->getLastError());
	}
}elseif(strtolower($_REQUEST['mode']) == 'account'){
	$account = new SI_Account();
	$output = $account->exportQB();
	if($output === FALSE){
		fatal_error("Error getting account export data!\n".$account->getLastError());
	}
}elseif(strtolower($_REQUEST['mode']) == 'payment'){
	$payment = new SI_Payment();
	$output = $payment->exportQB();
	if($output === FALSE){
		fatal_error("Error getting payment export data!\n".$payment->getLastError());
	}
}elseif(strtolower($_REQUEST['mode']) == 'invoice'){
	$invoice = new SI_Invoice();
	$output = $invoice->exportQB();
	if($output === FALSE){
		fatal_error("Error getting invoice export data!\n".$invoice->getLastError());
	}
}else{
	fatal_error("Unknown export mode!");
}

ob_end_clean();
Exemplo n.º 29
0
	$company_id = $_REQUEST['company_id'];
}else{
	$company_id = $loggedin_user->company_id;
}

$company = new SI_Company();
if($company->get($company_id) === FALSE){
	fatal_error("Could not get company for id $company_id");	
}

$invoice = new SI_Invoice();
if($invoice->get($_REQUEST['invoice_id']) === FALSE){
	fatal_error("Could not get invoice {$_REQUEST['invoice_id']}\n");	
}

$payment = new SI_Payment();
$payment->company_id = $company_id;
$title = "Add Payment";

if($_POST['save']){
	$payment->amount = preg_replace('/[^0-9\.]/','', $_POST['amount']);
	if($payment->amount > $invoice->getTotal()){
		fatal_error("Amount can not be more than amount due on the invoice!\n");	
	}
	$payment->timestamp = time();
	$payment->type = 'CC';
	
	// Process the card
	$cc_processor = SI_CCProcessor::getInstance();
	$params = array(
		'id' => $company_id,
Exemplo n.º 30
0
 /**
  * Send the admin a notification when a payment is received.
  * @param  SI_Payment $payment
  * @param  array      $args
  * @return
  */
 public static function admin_payment_notification(SI_Payment $payment, $args = array())
 {
     $payment_method = $payment->get_payment_method();
     // A notification shouldn't be sent to the admin when s/he created it
     if ($payment_method == SI_Admin_Payment::PAYMENT_METHOD) {
         return;
     }
     $invoice_id = $payment->get_invoice_id();
     $invoice = SI_Invoice::get_instance($invoice_id);
     if (!is_a($invoice, 'SI_Invoice')) {
         do_action('si_error', 'Admin Payment Notification Not Sent to Client; No Invoice Found: ' . $invoice_id, $payment->get_id());
         return;
     }
     $client = $invoice->get_client();
     // Admin email
     $data = array('payment' => $payment, 'invoice' => $invoice, 'client' => $client);
     $admin_to = self::admin_email($data);
     self::send_notification('payment_notification', $data, $admin_to);
 }