/**
  * Add action when the payment page is complete and before the review page. 
  * @param  SI_Checkouts $checkout 
  * @return                  
  */
 public function processed_payment_page(SI_Checkouts $checkout)
 {
     if ($checkout->is_page_complete(SI_Checkouts::PAYMENT_PAGE)) {
         // Make sure to send offsite when it's okay to do so.
         do_action('si_send_offsite_for_payment', $checkout);
     }
 }
 /**
  * Process the review page
  *
  * @param SI_Checkouts $checkout
  * @return void
  */
 public function process_review_page(SI_Checkouts $checkout)
 {
     $checkout->mark_page_complete(self::REVIEW_PAGE);
 }
 /**
  * Remove the payments page from the list of completed checkout pages
  *
  * @param SI_Checkouts $checkout
  * @return void
  */
 protected function invalidate_checkout(SI_Checkouts $checkout)
 {
     $checkout->mark_page_incomplete(SI_Checkouts::PAYMENT_PAGE);
 }
Example #4
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');
}
 public function confirmation_pane(SI_Checkouts $checkout)
 {
     self::load_view('templates/checkout/credit-card/confirmation', array('checkout' => $checkout, 'payment_id' => $checkout->get_payment_id()), true);
 }
 public function post_checkout_redirect(SI_Checkouts $checkout, SI_Payment $payment)
 {
     if (!is_a($checkout->get_processor(), __CLASS__)) {
         return;
     }
     wp_redirect($checkout->checkout_confirmation_url(self::PAYMENT_SLUG));
     exit;
 }
 /**
  * Build the NVP data array for submitting the current checkout to PayPal as an Authorization request
  *
  * @param SI_Checkouts $checkout
  * @return array
  */
 private function set_nvp_data(SI_Checkouts $checkout)
 {
     $invoice = $checkout->get_invoice();
     $client = $invoice->get_client();
     $user = si_who_is_paying($invoice);
     // User email or none
     $user_email = $user ? $user->user_email : '';
     $nvpData = array();
     $nvpData['USER'] = self::$api_username;
     $nvpData['PWD'] = self::$api_password;
     $nvpData['SIGNATURE'] = self::$api_signature;
     $nvpData['VERSION'] = self::$version;
     $nvpData['CANCELURL'] = self::$cancel_url;
     $nvpData['RETURNURL'] = $checkout->checkout_complete_url($this->get_slug());
     $nvpData['METHOD'] = 'SetExpressCheckout';
     $nvpData['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization';
     $nvpData['EMAIL'] = $user_email;
     $nvpData['LANDINGPAGE'] = 'Billing';
     $nvpData['SOLUTIONTYPE'] = 'Sole';
     $payment_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance();
     $nvpData['PAYMENTREQUEST_0_AMT'] = si_get_number_format($payment_amount);
     $nvpData['PAYMENTREQUEST_0_CURRENCYCODE'] = self::get_currency_code($invoice->get_id());
     $item_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance() - ($invoice->get_tax_total() + $invoice->get_tax2_total());
     $nvpData['PAYMENTREQUEST_0_ITEMAMT'] = si_get_number_format($item_amount);
     // $nvpData['PAYMENTREQUEST_0_SHIPPINGAMT'] = si_get_number_format( $invoice->get_shipping_total() ); // FUTURE
     $tax_amount = si_has_invoice_deposit($invoice->get_id()) ? 0 : $invoice->get_tax_total() + $invoice->get_tax2_total();
     $nvpData['PAYMENTREQUEST_0_TAXAMT'] = si_get_number_format($tax_amount);
     $nvpData['BUTTONSOURCE'] = self::PLUGIN_NAME;
     $nvpData += self::payment_request_line_items($invoice);
     // Recurring billing agreement
     if (si_is_invoice_recurring($invoice)) {
         $nvpData['L_BILLINGTYPE0'] = 'RecurringPayments';
         $nvpData['L_BILLINGAGREEMENTDESCRIPTION0'] = $this->recurring_desc($invoice);
     }
     $nvpData = apply_filters('si_paypal_ec_set_nvp_data', $nvpData);
     do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC SetCheckout Data', $nvpData);
     return apply_filters('si_set_nvp_data', $nvpData, $checkout, $i);
 }
 /**
  * Charge via Stripe API using a token or the full credit card data.
  *
  * @param SI_Checkouts $checkout
  * @param SI_Invoice $purchase
  * @return array
  */
 private function charge_stripe(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $invoice = $checkout->get_invoice();
     $client = $invoice->get_client();
     $user_id = si_whos_user_id_is_paying($invoice);
     self::setup_stripe();
     try {
         // Create the payment data for the customer
         $purchase_data = $this->purchase_data($checkout, $invoice);
         if (!$purchase_data) {
             return false;
         }
         // Create the customer
         $customer_id = $this->get_customer($user_id, $purchase_data);
         if (!$customer_id) {
             self::set_error_messages('ERROR: No customer id was created.');
             return false;
         }
         $payment_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance();
         // Charge the card!
         $charge = Stripe_Charge::create(array('amount' => self::convert_money_to_cents(sprintf('%0.2f', $payment_amount)), 'currency' => self::get_currency_code($invoice->get_id()), 'customer' => $customer_id, 'description' => get_the_title($invoice->get_id())));
         $response = array('id' => $charge->id, 'amount' => $charge->amount, 'customer' => $charge->customer, 'card' => $charge->card->id);
         // Return something for the response
         return $response;
     } catch (Exception $e) {
         self::set_error_messages($e->getMessage());
         return false;
     }
 }