コード例 #1
0
/**
 * Shows business information on front-end
 */
function wp_invoice_show_business_information() {
  $core = WPI_Core::getInstance();
  $business_info['name'] = $core->Settings->options['business_name'];
  $business_info['address'] = $core->Settings->options['business_address'];
  $business_info['phone'] = $core->Settings->options['business_phone'];
  ?>
  <div id="invoice_business_info" class="clearfix">
    <p class="invoice_page_subheading"><strong>Bill From:</strong></p>
    <p class="wp_invoice_bi wp_invoice_business_name"><?php echo $business_info['name']; ?></p>
    <p class="wp_invoice_bi wp_invoice_business_address"><?php echo $business_info['address']; ?></p>
    <p class="wp_invoice_bi wp_invoice_business_phone"><?php echo $business_info['phone']; ?></p>
  </div>
  <?php
}
コード例 #2
0
ファイル: wpi_chargify.php プロジェクト: JSpier/smacamp
 /**
  * This function checks for new chargify products and saves it to WPI settings
  */
 function check_chargify_products()
 {
     global $wpi_settings;
     $from_ajax = isset($_REQUEST['from_ajax']) && $_REQUEST['from_ajax'] ? true : false;
     try {
         /** Create the object */
         $wpi_chargify = new Chargify($wpi_settings['chargify']['domain'], $wpi_settings['chargify']['api_key']);
         /** Try to get the products */
         $products = $wpi_chargify->get_products();
         /** If we can't get products, something is wrong */
         if (!$products) {
             throw new Exception(__('Oops, something is wrong with the API. Did you remember to save the WPI settings first?', WPI));
         }
         /** We've got products, lets try to get the associated components */
         $components = array();
         foreach ((array) $products as $p) {
             $components[$p->product_family->id] = $wpi_chargify->get_components($p->product_family->id);
         }
         /** Now that we have our products, lets try to save the to the WPI settings predefined items list */
         if (!isset($wpi_settings['predefined_services']) || !is_array($wpi_settings['predefined_services'])) {
             $wpi_settings['predefined_services'] = array();
         }
         /** First, loop through, and remove all the ones which came from chargify */
         foreach ($wpi_settings['predefined_services'] as $key => $value) {
             if (isset($value['from_chargify'])) {
                 unset($wpi_settings['predefined_services'][$key]);
             }
         }
         /** Now, loop through the settings, and save our wpi options again */
         foreach ($products as $product) {
             $wpi_settings['predefined_services'][] = array('name' => wpi_chargify::get_product_title($product), 'description' => __('This is a subscription based product. ', WPI) . $product->description, 'quantity' => 1, 'price' => $product->price_in_cents / 100, 'tax' => false, 'from_chargify' => true);
         }
         /** Otherwise, lets save the products to the WPI settings, and then save */
         $wpi_settings['chargify']['products'] = json_encode($products);
         $wpi_settings['chargify']['components'] = json_encode($components);
         $wpi_settings['chargify']['products_last_updated'] = date('c');
         $wpi_settings['chargify']['enabled'] = true;
         /** Save the settings */
         $wpi_core = WPI_Core::getInstance();
         $wpi_core->Settings->SaveSettings($wpi_settings);
         if ($from_ajax) {
             die(__('Products updated. Please <a href="javascript:window.location.reload();">refresh</a>.', WPI));
         } else {
             return $products;
         }
     } catch (Exception $e) {
         /** We don't have anything now */
         $wpi_settings['chargify']['products'] = false;
         $wpi_settings['chargify']['components'] = false;
         $wpi_settings['chargify']['products_last_updated'] = date('c');
         $wpi_settings['chargify']['enabled'] = false;
         /** Save the settings */
         $wpi_core = WPI_Core::getInstance();
         $wpi_core->Settings->SaveSettings($wpi_settings);
         if ($from_ajax) {
             die($e->getMessage());
         } else {
             return false;
         }
     }
 }
コード例 #3
0
ファイル: wp-invoice.php プロジェクト: JSpier/smacamp
 /**
  * Singleton.
  * @since 3.0
  */
 static function getInstance()
 {
     return is_null(self::$instance) ? self::$instance = new WPI_Core() : self::$instance;
 }
コード例 #4
0
ファイル: wpi_legacy.php プロジェクト: JSpier/smacamp
 /**
  * Run import process
  *
  * @global object $wpdb
  * @global array $wpi_settings
  */
 function do_import()
 {
     global $wpdb, $wpi_settings;
     /* Get plugin Singleton object */
     $core = WPI_Core::getInstance();
     /* Try to import General Plugin Settings from old version */
     $legacy_settings = self::get_legacy_settings();
     if (!empty($legacy_settings)) {
         $core->Settings->SaveSettings($legacy_settings);
         $core->Functions->log(__("Web Invoice setting options were successfully imported.", WPI));
     }
     /* Boolean variables which show 'legacy logs' data migration's status */
     $legacy_logs = false;
     $legacy_logs_import_error = false;
     /* Try to import Invoices from Web Invoice plugin */
     $legacy_invoices = self::get_legacy_invoices();
     if (is_array($legacy_invoices) && !empty($legacy_invoices)) {
         $errors = false;
         foreach ($legacy_invoices as $i) {
             $invoice_id = $core->Functions->save_invoice($i, array('type' => 'import'));
             if ($invoice_id) {
                 //* Try to get Logs of Invoices from the old version */
                 $logs = self::get_legacy_logs_by_id($invoice_id);
                 if (!empty($logs)) {
                     /* Imports logs to new table. */
                     if (self::import_logs($logs)) {
                         $legacy_logs = true;
                     } else {
                         $legacy_logs_import_error = true;
                     }
                 }
                 //* If invoice has 'paid' status we should add log of payment. */
                 if ($i['post_status'] == 'paid') {
                     $invoice = new WPI_Invoice();
                     $invoice->load_invoice("id={$invoice_id}");
                     if ($i['recurring']['active'] == 'on' && !empty($i['recurring']['cycles'])) {
                         $event_amount = $i['amount'] * $i['recurring']['cycles'];
                     } else {
                         $event_amount = $i['amount'];
                     }
                     $event_note = "Automatically created using Web Invoice log data";
                     $event_note = $core->Functions->currency_format(abs($event_amount), $invoice_id) . " paid in - {$event_note}";
                     $timestamp = time();
                     $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type=add_payment&time={$timestamp}");
                     $invoice->save_invoice();
                 }
             } else {
                 $errors = true;
             }
         }
         if ($errors == true) {
             $core->Functions->log(__("Invoices from Web Invoice plugin were migrated with errors.", WPI));
         } else {
             $core->Functions->log(__("Invoices from Web Invoice plugin were successfully migrated.", WPI));
         }
     }
     if ($legacy_logs == true) {
         if ($legacy_logs_import_error == false) {
             $core->Functions->log(__("Log data from Web Invoice plugin were successfully migrated.", WPI));
         } else {
             $core->Functions->log(__("Log data from Web Invoice plugin were migrated with errors.", WPI));
         }
     }
     //* Mark as imported */
     update_option('wpi_web_invoice_imported', 1);
 }
コード例 #5
0
 function show_business_info()
 {
     $core = WPI_Core::getInstance();
     return $core->Settings->options['globals']['show_business_address'] == 'false' ? FALSE : TRUE;
 }
コード例 #6
0
    /**
        Process special invoice-related event
    */
    function process_manual_event() {
      global $wpdb;
      
      $invoice_id   = $_REQUEST['invoice_id'];
      $event_type   = $_REQUEST['event_type'];
      $event_amount = $_REQUEST['event_amount'];
      $event_note   = $_REQUEST['event_note'];
      $event_date   = $_REQUEST['event_date'];
      $event_time   = $_REQUEST['event_time'];
      $event_tax    = $_REQUEST['event_tax'];
      $timestamp    = strtotime( $event_date.' '.$event_time );

      if(empty($event_note) || empty($event_amount) || !is_numeric($event_amount)) {
        die( json_encode( array('success' => 'false', 'message' => __('Please enter a note and numeric amount.', WPI)) ) );
      }
      
      if($event_type == 'add_payment' && !empty($event_amount)) {
        $event_amount = $event_amount;
        $event_note = WPI_Functions::currency_format(abs($event_amount), $invoice_id)." " . __('paid in', WPI) . " - $event_note";
      }

      if($event_type == 'add_charge' && !empty($event_amount)) {
        $name = $event_note;
        $event_note = "".WPI_Functions::currency_format($event_amount, $invoice_id)."  " . __('charge added', WPI) . " - $event_note";
        $core = WPI_Core::getInstance();
        $charge_item = $core->Functions->add_itemized_charge( $invoice_id, $name, $event_amount, $event_tax );
      }

      if($event_type == 'do_adjustment' && !empty($event_amount)) {
        $event_note = WPI_Functions::currency_format($event_amount, $invoice_id)."  " . __('adjusted', WPI) . " - $event_note";
      }

      $invoice = new WPI_Invoice();
      $invoice->load_invoice("id=$invoice_id");
      $insert_id = $invoice->add_entry("attribute=balance&note=$event_note&amount=$event_amount&type=$event_type&time=$timestamp");

      if($insert_id) {
        $response = array( 'success' => 'true', 'message' => sprintf(__('Event Added: %1s.', WPI), $event_note));
      } else {
        $response = array( 'success' => 'false',  'message' =>  sprintf(__('Could not save entry in invoice log. %1s', WPI), ''));
      }
      
      $invoice->save_invoice();

      if ( !empty( $charge_item ) && $event_type == 'add_charge' ) {
        $response['charge_item'] = $charge_item;
      }

      die( json_encode( $response ) );
    }
コード例 #7
0
ファイル: wpi_ajax.php プロジェクト: JSpier/smacamp
 /**
  * Process special invoice-related event
  */
 static function process_manual_event()
 {
     $invoice_id = $_REQUEST['invoice_id'];
     $event_type = $_REQUEST['event_type'];
     $event_amount = $_REQUEST['event_amount'];
     $event_note = $_REQUEST['event_note'];
     $event_date = $_REQUEST['event_date'];
     $event_time = $_REQUEST['event_time'];
     $event_tax = $_REQUEST['event_tax'];
     $timestamp = strtotime($event_date . ' ' . $event_time) - get_option('gmt_offset') * 60 * 60;
     if (empty($event_note) || empty($event_amount) || !is_numeric($event_amount)) {
         die(json_encode(array('success' => 'false', 'message' => __('Please enter a note and numeric amount.', WPI))));
     }
     switch ($event_type) {
         case WPI_EVENT_TYPE_ADD_PAYMENT:
             if (!empty($event_amount)) {
                 $event_note = WPI_Functions::currency_format(abs($event_amount), $invoice_id) . " " . __('paid in', WPI) . " - {$event_note}";
             }
             break;
         case WPI_EVENT_TYPE_ADD_CHARGE:
             if (!empty($event_amount)) {
                 $name = $event_note;
                 $event_note = WPI_Functions::currency_format($event_amount, $invoice_id) . " " . (!empty($event_tax) ? '&#43;' . $event_tax . '%' : '') . "  " . __('charge added', WPI) . " - {$event_note}";
                 $core = WPI_Core::getInstance();
                 $charge_item = $core->Functions->add_itemized_charge($invoice_id, $name, $event_amount, $event_tax);
             }
             break;
         case WPI_EVENT_TYPE_ADD_ADJUSTMENT:
             if (!empty($event_amount)) {
                 $event_note = WPI_Functions::currency_format($event_amount, $invoice_id) . "  " . __('adjusted', WPI) . " - {$event_note}";
             }
             break;
         case WPI_EVENT_TYPE_ADD_REFUND:
             if (!empty($event_amount)) {
                 $event_amount = abs((double) $event_amount);
                 $event_note = WPI_Functions::currency_format($event_amount, $invoice_id) . "  " . __('refunded', WPI) . " - {$event_note}";
             }
             break;
         default:
             break;
     }
     $invoice = new WPI_Invoice();
     $invoice->load_invoice("id={$invoice_id}");
     $insert_id = $invoice->add_entry(array('attribute' => 'balance', 'note' => $event_note, 'amount' => $event_amount, 'type' => $event_type, 'time' => $timestamp));
     if ($insert_id) {
         $response = array('success' => 'true', 'message' => sprintf(__('Event Added: %1s.', WPI), $event_note));
     } else {
         $response = array('success' => 'false', 'message' => sprintf(__('Could not save entry in invoice log. %1s', WPI), ''));
     }
     $invoice->save_invoice();
     if (!empty($charge_item) && $event_type == 'add_charge') {
         $response['charge_item'] = $charge_item;
     }
     die(json_encode($response));
 }
コード例 #8
0
 /**
  * Singleton.
  *
  * @since 3.0
  *
  */
 static function getInstance() {
   if (is_null(self::$instance)) {
     self::$instance = new WPI_Core();
   }
   return self::$instance;
 }