/** Invoice lookup function If return is passed as true, function is returned. */ function wp_invoice_lookup($args = '') { global $wpi_settings; $defaults = array ( 'message' => __('Enter Invoice ID', WPI), 'button' => __('Lookup', WPI), 'return' => false ); extract(wp_parse_args($args, $defaults), EXTR_SKIP); ob_start(); if(WPI_Functions::wpi_use_custom_template('invoice_lookup.php')) include($wpi_settings['frontend_template_path'] . 'invoice_lookup.php'); else include($wpi_settings['default_template_path'] . 'invoice_lookup.php'); $result .= ob_get_contents(); ob_end_clean(); if($return) return $result; echo $result; }
function get_user_worth($user_id, $args = "") { global $wpdb; $defaults = array('format_number' => 'true'); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); $user_email = $wpdb->get_var("SELECT user_email FROM {$wpdb->users} WHERE ID = {$user_id}"); if ($have_sales = $wpdb->get_var("\n SELECT SUM(value)\n FROM {$wpdb->prefix}wpi_object_log as log\n LEFT JOIN {$wpdb->postmeta} as invoice_meta\n ON log.object_ID = invoice_meta.post_id\n WHERE action = 'add_payment'\n AND meta_value = '{$user_email}'\n AND meta_key = 'user_email'\n ")) { if (class_exists('WPI_Functions')) { if ($args['format_number'] == 'true') { return WPI_Functions::currency_format($have_sales); } else { return $have_sales; } } else { return $have_sales; } } //echo $wpdb->last_query; return false; }
/** * CRM user_meta updating on payment done * * @global type $invoice * @param type $data * @return type */ function user_meta_updated( $data ) { global $invoice; // CRM data updating if ( !class_exists('WP_CRM_Core') ) return; $crm_attributes = WPI_Functions::get_wpi_crm_attributes(); if ( empty( $crm_attributes ) ) return; $wp_users_id = $invoice['user_data']['ID']; foreach ( $data as $key => $value ) { if ( key_exists( $key, $crm_attributes ) ) { update_user_meta($wp_users_id, $key, $value); } } }
/** * */ static function server_callback() { global $wpdb; //** Get request body */ $body = @file_get_contents('php://input'); $event_object = json_decode($body); switch ($event_object->type) { //** Used only for subscriptions since single payments processed without Webhook */ case 'charge.succeeded': $post_id = $wpdb->get_col("SELECT post_id\r\n FROM {$wpdb->postmeta}\r\n WHERE meta_key = '_stripe_customer_id'\r\n AND meta_value = '{$event_object->data->object->customer}'"); $invoice_object = new WPI_Invoice(); $invoice_object->load_invoice("id=" . $post_id[0]); if (empty($invoice_object->data['ID'])) { die("Can't load invoice"); } if (!class_exists('Stripe')) { require_once WPI_Path . '/third-party/stripe/lib/Stripe.php'; } $pk = trim($invoice_object->data['billing']['wpi_stripe']['settings'][$invoice_object->data['billing']['wpi_stripe']['settings']['mode']['value'] . '_secret_key']['value']); Stripe::setApiKey($pk); $event = Stripe_Event::retrieve($event_object->id); if ($event->data->object->paid == 1) { $event_amount = (double) ($event->data->object->amount / 100); $event_note = WPI_Functions::currency_format(abs($event_amount), $invoice_object->data['invoice_id']) . ' ' . __('Stripe Subscription Payment', WPI); $event_type = 'add_payment'; $invoice_object->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); $invoice_object->save_invoice(); } break; case 'customer.subscription.deleted': $post_id = $wpdb->get_col("SELECT post_id\r\n FROM {$wpdb->postmeta}\r\n WHERE meta_key = '_stripe_customer_id'\r\n AND meta_value = '{$event_object->data->object->customer}'"); $invoice_object = new WPI_Invoice(); $invoice_object->load_invoice("id=" . $post_id[0]); if (empty($invoice_object->data['ID'])) { die("Can't load invoice"); } if (!class_exists('Stripe')) { require_once WPI_Path . '/third-party/stripe/lib/Stripe.php'; } $pk = trim($invoice_object->data['billing']['wpi_stripe']['settings'][$invoice_object->data['billing']['wpi_stripe']['settings']['mode']['value'] . '_secret_key']['value']); Stripe::setApiKey($pk); $event = Stripe_Event::retrieve($event_object->id); if ($event->data->object->status == 'canceled') { $invoice_object->add_entry("attribute=invoice¬e=" . __('Stripe Subscription has been canceled', WPI) . "&type=update"); $invoice_object->save_invoice(); wp_invoice_mark_as_paid($invoice_object->data['invoice_id']); } break; default: break; } }
<input type="hidden" name="cc_data[currency_code]" id="currency_code" value="<?php echo $invoice['default_currency_code']; ?> " /> <div id="credit_card_information"> <?php do_action('wpi_payment_fields_' . $this->type, $invoice); ?> <ul id="wp_invoice_process_wait"> <li> <div class="wpi-control-group"> <div class="controls"> <button type="submit" id="cc_pay_button" class="hide_after_success submit_button"><?php echo sprintf(__('Process Payment of %s', WPI), !empty($wpi_settings['currency']['symbol'][$invoice['default_currency_code']]) ? $wpi_settings['currency']['symbol'][$invoice['default_currency_code']] : "\$"); ?> <span id="pay_button_value"><?php echo WPI_Functions::money_format($invoice['net']); ?> </span></button> </div> <img style="display: none;" class="loader-img" src="<?php echo WPI_URL; ?> /core/css/images/processing-ajax.gif" alt="" /> </div> </li> </ul> <br class="cb" /> </div>
/** * Saves passed settings * * @global array $wpi_settings * @param array $new_settings */ function SaveSettings($new_settings) { global $wpi_settings; //** Set 'first_time_setup_ran' as 'true' to avoid loading First Time Setup Page in future */ $new_settings['first_time_setup_ran'] = 'true'; $this->options = WPI_Functions::array_merge_recursive_distinct($this->options, $new_settings); //** Copy template files from plugin folder to active theme/template */ if(isset($new_settings['install_use_custom_templates']) && isset($new_settings['use_custom_templates']) && $new_settings['install_use_custom_templates'] == 'yes' && $new_settings['use_custom_templates'] == 'yes') { WPI_Functions::install_templates(); } //** Process Special Settings */ //** Default predefined services */ $this->options['predefined_services'][0]['name'] = __("Web Design Services", WPI); $this->options['predefined_services'][0]['quantity'] = 1; $this->options['predefined_services'][0]['price'] = 30; $this->options['predefined_services'][1]['name'] = __("Web Development Services", WPI); $this->options['predefined_services'][1]['quantity'] = 1; $this->options['predefined_services'][1]['price'] = 30; $this->options['predefined_services'] = ( isset($new_settings['predefined_services']) ? $new_settings['predefined_services'] : $this->options['predefined_services'] ); //** E-Mail Templates */ if(isset($new_settings['notification'])) { $this->options['notification'] = $new_settings['notification']; } //** Process Special Settings */ //** fix checkboxes */ foreach($this->options['billing'] as $key => $value) { if(!isset($new_settings['billing'][$key]['allow'])) unset($this->options['billing'][$key]['allow']); } $checkbox_array = array('increment_invoice_id', 'send_thank_you_email', 'cc_thank_you_email', 'force_https', 'show_recurring_billing', 'send_invoice_creator_email'); foreach($checkbox_array as $checkbox_name) { if(!isset($new_settings[$checkbox_name])) unset($this->options[$checkbox_name]); } $this->CommitUpdates(); //** Update global variable */ $wpi_settings = WPI_Functions::array_merge_recursive_distinct($wpi_settings, $this->options); //** Fix Predefined Services */ $wpi_settings['predefined_services'] = $this->options['predefined_services']; //** Fix E-Mail Templates */ $wpi_settings['notification'] = $this->options['notification']; wpi_gateway_base::sync_billing_objects(); }
/** * Header action * * @global array $wpi_settings */ static function frontend_header() { global $wpi_settings, $wpi_invoice_object; $invoice_items = array(); //** It is for adding SKU (unique) field to items list */ if (!empty($wpi_invoice_object->data['itemized_list'])) { foreach ((array) $wpi_invoice_object->data['itemized_list'] as $key => $value) { $invoice_items[$key] = $value; $invoice_items[$key]['id'] = str_replace('-', '_', sanitize_title($invoice_items[$key]['name'])); } } $order = array("\\r\\n", "\\n", "\\r", "\\t"); $replace = array("\\\\r\\\\n", "\\\\n", "\\\\r", "\\\\t"); $encode_invoice_items = str_replace($order, $replace, json_encode($invoice_items)); ?> <script type="text/javascript"> var site_url = '<?php echo WPI_Functions::current_page(); ?> '; jQuery( document ).ready( function () { <?php if (!empty($wpi_settings['ga_event_tracking']) && $wpi_settings['ga_event_tracking']['enabled'] == 'true') { ?> wpi = wpi || {}; wpi.invoice_title = '<?php echo addslashes($wpi_invoice_object->data['post_title']); ?> '; wpi.invoice_amount = <?php echo $wpi_invoice_object->data['net']; ?> ; wpi.invoice_id = '<?php echo !empty($wpi_invoice_object->data['custom_id']) ? $wpi_invoice_object->data['custom_id'] : $wpi_invoice_object->data['ID']; ?> '; wpi.tax = '<?php echo !empty($wpi_invoice_object->data['tax']) ? $wpi_invoice_object->data['tax'] : ''; ?> '; wpi.business_name = '<?php echo $wpi_settings['business_name']; ?> '; wpi.user_data = {city: '<?php echo !empty($wpi_settings['user_data']['city']) ? $wpi_settings['user_data']['city'] : ''; ?> ', state: '<?php echo !empty($wpi_settings['user_data']['state']) ? $wpi_settings['user_data']['state'] : ''; ?> ', country: '<?php echo !empty($wpi_settings['user_data']['country']) ? $wpi_settings['user_data']['country'] : ''; ?> '} wpi.invoice_items = jQuery.parseJSON( '<?php echo $encode_invoice_items; ?> ' ); if ( typeof window._gaq != 'undefined' ) wpi.ga.tracking.init( <?php echo !empty($wpi_settings['ga_event_tracking']['events']['invoices']) ? json_encode($wpi_settings['ga_event_tracking']['events']['invoices']) : '{}'; ?> ); <?php } ?> } ); </script> <meta name="robots" content="noindex, nofollow"/> <?php }
/** * Handler for Silent Post Url */ static function server_callback() { $arb = false; $fields = array(); foreach ($_REQUEST as $name => $value) { $fields[$name] = $value; if ($name == 'x_subscription_id') { $arb = true; } } // Handle recurring billing payments if ($arb == true && $fields['x_response_code'] == 1) { $paynum = $fields['x_subscription_paynum']; $subscription_id = $fields['x_subscription_id']; $amount = $fields['x_amount']; $invoice_id = wpi_post_id_to_invoice_id(wpi_subscription_id_to_post_id($subscription_id)); $invoice_obj = new WPI_Invoice(); $invoice_obj->load_invoice("id={$invoice_id}"); // Add payment amount $event_note = WPI_Functions::currency_format(abs($amount), $invoice_id) . ". ARB payment {$paynum} of {$invoice_obj->data['recurring']['wpi_authorize']['cycles']}"; $event_amount = $amount; $event_type = 'add_payment'; $invoice_obj->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); // Complete subscription if last payment done if ($invoice_obj->data['recurring']['wpi_authorize']['cycles'] <= $paynum) { WPI_Functions::log_event(wpi_invoice_id_to_post_id($invoice_id), 'invoice', 'update', '', __('Subscription completely paid', WPI)); wp_invoice_mark_as_paid($invoice_id); } $invoice_obj->save_invoice(); } }
/** * Handler for 2Checkout Callback * @author Craig Christenson * Full callback URL: http://domain/wp-admin/admin-ajax.php?action=wpi_gateway_server_callback&type=wpi_twocheckout */ static function server_callback() { if (empty($_REQUEST)) { die(__('Direct access not allowed', WPI)); } $invoice = new WPI_Invoice(); $invoice->load_invoice("id={$_REQUEST['merchant_order_id']}"); /** Verify callback request */ if (self::_ipn_verified($invoice)) { if ($_REQUEST['key']) { $event_note = sprintf(__('%s paid via 2Checkout', WPI), WPI_Functions::currency_format(abs($_REQUEST['total']), $_REQUEST['merchant_order_id'])); $event_amount = (double) $_REQUEST['total']; $event_type = 'add_payment'; /** Log balance changes */ $invoice->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); /** Log payer email */ $payer_email = sprintf(__("2Checkout buyer email: %s", WPI), $_REQUEST['email']); $invoice->add_entry("attribute=invoice¬e={$payer_email}&type=update"); $invoice->save_invoice(); /** ... and mark invoice as paid */ wp_invoice_mark_as_paid($_REQUEST['invoice_id'], $check = true); send_notification($invoice->data); echo '<script type="text/javascript">window.location="' . get_invoice_permalink($invoice->data['ID']) . '";</script>'; /** Handle INS messages */ } elseif ($_POST['md5_hash']) { switch ($_POST['message_type']) { case 'FRAUD_STATUS_CHANGED': if ($_POST['fraud_status'] == 'pass') { WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Passed 2Checkout fraud review.', WPI)); } elseif (condition) { WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Failed 2Checkout fraud review.', WPI)); wp_invoice_mark_as_pending($_POST['vendor_order_id']); } break; case 'RECURRING_STOPPED': WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring billing stopped.', WPI)); break; case 'RECURRING_INSTALLMENT_FAILED': WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring installment failed.', WPI)); break; case 'RECURRING_INSTALLMENT_SUCCESS': $event_note = sprintf(__('%1s paid for subscription %2s', WPI), WPI_Functions::currency_format(abs($_POST['item_rec_list_amount_1']), $_POST['vendor_order_id']), $_POST['sale_id']); $event_amount = (double) $_POST['item_rec_list_amount_1']; $event_type = 'add_payment'; $invoice->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); $invoice->save_invoice(); send_notification($invoice->data); break; case 'RECURRING_COMPLETE': WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring installments completed.', WPI)); wp_invoice_mark_as_paid($_POST['invoice'], $check = false); break; case 'RECURRING_RESTARTED': WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring sale restarted.', WPI)); break; default: break; } } } }
function status_meta_box($this_invoice) { $hidden = ''; if (!empty($_REQUEST['wpi']['new_invoice'])) { $hidden = ' hidden '; } ?> <div id="postbox_status_and_history" class="postbox <?php echo $hidden; ?>"> <h3 class="hndle"><?php _e("Invoice Status and History", WPI) ?></h3> <div class="inside" style="margin:0;padding:0;"> <div id="submitbox" class="submitbox" style="overflow: auto; max-height: 150px;"> <table id="wpi_enter_payments" class="form-table hidden" > <tr> <th><?php _e("Event Type", WPI) ?></th> <td> <?php echo WPI_UI::select("name=event_type&values=" . serialize(array('add_payment' => __('Receive Payment', WPI), 'add_charge' => __('Add Charge', WPI), 'do_adjustment' => __('Administrative Adjustment', WPI)))); ?> <span class="wpi_recurring_options"><?php _e('Note: Recurring bills cannot have administrative adjustments or additional charges, only received payments.', WPI); ?></span> </td> </tr> <tr> <th><?php _e("Event Amount", WPI) ?></th> <td> <?php echo WPI_UI::input("type=text&name=wpi_event_amount&class=wpi_money&special=autocomplete='off'"); ?> <span id="event_tax_holder" class="hidden"> <b style="padding:5px;"><?php _e("Charge Tax", WPI) ?></b><?php echo WPI_UI::input("type=text&name=wpi_event_tax&class=wpi_money&special=autocomplete='off'"); ?>% </span> </td> </tr> <tr> <th><?php _e("Event Date & Time", WPI) ?></th> <td> <?php echo WPI_UI::input("type=text&name=wpi_event_date&class=wpi_date"); ?> <?php echo WPI_UI::input("type=text&name=wpi_event_time&class=wpi_time"); ?> </td> </tr> <tr> <th><?php _e("Event Note", WPI) ?></th> <td><?php echo WPI_UI::input("name=wpi_event_note"); ?> </td> </tr> <tr> <th> </th> <td> <?php wp_nonce_field('wpi_process_manual_event_nonce', 'wpi_process_manual_event_nonce'); ?> <input type="button" class="button" value="<?php esc_attr(_e('Process Charge / Payment', WPI)); ?>" id="wpi_process_manual_event" /> <input type="button" class="button" value="<?php esc_attr(_e('Cancel', WPI)); ?>" onclick="wpi_show_paycharge_box();" /> <span class="wpi_ajax_response"></span> </td> </tr> </table> <div style="padding: 5px;"> <table class="form-table" id="wpi_invoice_status_table"> <?php if (!empty($this_invoice['log']) && is_array($this_invoice['log'])) { if (!empty($this_invoice['ID'])) { WPI_Functions::get_status($this_invoice['ID']); } } ?> </table> </div> </div> <div class="footer_functions"> <span class="wpi_clickable" onclick="jQuery('.wpi_event_update').toggle();"><?php _e('Toggle History Detail', WPI); ?></span> </div> </div> </div> <?php do_action('wpi_add_comments_box'); ?> <?php } ?>
<form method="post" name="online_payment_form" id="online_payment_form-<?php print $this->type; ?>" class="wpi_checkout online_payment_form <?php print $this->type; ?> clearfix"> <input type="hidden" id="wpi_action" name="wpi_action" value="wpi_gateway_process_payment" /> <input type="hidden" id="wpi_form_type" name="type" value="<?php print $this->type; ?>" /> <input type="hidden" id="wpi_form_invoice_id" name="invoice_id" value="<?php print $invoice['invoice_id']; ?>" /> <input type="hidden" name="wp_invoice[hash]" value="<?php echo wp_create_nonce($invoice['invoice_id'] .'hash');; ?>" /> <input type="hidden" id="payment_amount" name="cc_data[amount]" value="<?php echo $invoice['net']; ?>" /> <input type="hidden" name="cc_data[user_id]" value="<?php echo $invoice['user_data']['user_email']; ?>" /> <input type="hidden" name="cc_data[invoice_id]" value="<?php echo $invoice['invoice_id']; ?>" /> <input type="hidden" name="cc_data[currency_code]" id="currency_code" value="<?php echo $invoice['default_currency_code']; ?>" /> <div id="credit_card_information"> <?php do_action('wpi_payment_fields_authorize', $invoice); ?> <ul id="wp_invoice_process_wait"> <li> <label for="submit"><span></span> </label> <button type="submit" id="cc_pay_button" class="hide_after_success submit_button"><?php echo sprintf(__('Process Payment of %s', WPI), (!empty($wpi_settings['currency']['symbol'][$invoice['default_currency_code']]) ? $wpi_settings['currency']['symbol'][$invoice['default_currency_code']] : "$")); ?><span id="pay_button_value"><?php echo WPI_Functions::money_format($invoice['net']); ?></span></button> <img style="display: none;" class="loader-img" src="<?php echo WPI_URL; ?>/core/css/images/processing-ajax.gif" alt="" /> </li> </ul> <br class="cb" /> </div>
/** * Plugins tab * * @param type $wpi_settings */ static function plugins($wpi_settings) { $parseUrl = parse_url(trim(get_bloginfo('url'))); $this_domain = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2))); ?> <script type="text/javascript"> jQuery(document).ready(function() { //** Check plugin updates */ jQuery("#wpi_ajax_check_plugin_updates").click(function() { jQuery('.plugin_status').remove(); jQuery.post(ajaxurl, { action: 'wpi_ajax_check_plugin_updates' }, function(data) { message = "<div class='plugin_status updated fade'><p>" + data + "</p></div>"; jQuery(message).insertAfter("h2"); }); }); }); </script> <table class="form-table wpi_premium_feature_intro"> <tbody> <tr> <th><?php _e('Check for Updates', WPI); ?> </th> <td> <?php _e('Check for any premium feature updates from the Usability Dynamics Update server:', WPI); ?> <input type="button" id="wpi_ajax_check_plugin_updates" value="<?php esc_attr(_e('Check Updates', WPI)); ?> "> </td> </tr> <tr> <th><?php _e('Your Domain', WPI); ?> </th> <td> <?php _e('When purchasing the premium features you will need to specify your domain to add the license correctly. This is your domain:', WPI); echo ' <b>' . $this_domain . '</b>'; ?> <div id="wpi_plugins_ajax_response" class="hidden"></div> </td> </tr> <!--<tr> <th><?php _e('WP-Invoice API Key', WPI); ?> for <?php echo $this_domain; ?> </th> <td> <?php echo WPI_UI::input("type=text&name=wpi_api_key&group=wpi_settings&value=" . (isset($wpi_settings['wpi_api_key']) ? $wpi_settings['wpi_api_key'] : '')); ?> <div class="description"> <?php _e('Some subscription based premium features require an API key that is specific to this domain and WP-Invoice. You can get this from your account on <a href="#" target="_blank">UsabilityDynamics.com</a>.', WPI); ?> </div> </td> </tr>--> </tbody> </table> <table id="wpi_premium_feature_table" cellpadding="0" cellspacing="0"> <tr> <?php if (!empty($wpi_settings['available_features'])) { foreach ($wpi_settings['available_features'] as $plugin_slug => $plugin_data) { ?> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?> ][title]" value="<?php echo esc_attr(stripslashes($plugin_data['title'])); ?> " /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?> ][tagline]" value="<?php echo esc_attr(stripslashes($plugin_data['tagline'])); ?> " /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?> ][image]" value="<?php echo esc_attr(stripslashes($plugin_data['image'])); ?> " /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?> ][description]" value="<?php echo esc_attr(stripslashes($plugin_data['description'])); ?> " /> <?php $installed = WPI_Functions::check_premium($plugin_slug); ?> <?php $active = @$wpi_settings['installed_features'][$plugin_slug]['disabled'] != 'false' ? true : false; ?> <?php if ($installed) { ?> <?php /* Do this to preserve settings after page save. */ ?> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?> ][disabled]" value="<?php echo esc_attr(stripslashes($wpi_settings['installed_features'][$plugin_slug]['disabled'])); ?> " /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?> ][name]" value="<?php echo esc_attr(stripslashes($wpi_settings['installed_features'][$plugin_slug]['name'])); ?> " /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?> ][version]" value="<?php echo esc_attr(stripslashes($wpi_settings['installed_features'][$plugin_slug]['version'])); ?> " /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?> ][description]" value="<?php echo esc_attr(stripslashes($wpi_settings['installed_features'][$plugin_slug]['description'])); ?> " /> <?php } ?> <tr class="wpi_premium_feature_block"> <td valign="top" class="wpi_premium_feature_image"> <?php if (!empty($plugin_data['image'])) { ?> <a target="_blank" href="https://usabilitydynamics.com/products/wp-invoice/"><img src="<?php echo $plugin_data['image']; ?> " /></a> <?php } ?> </td> <td valign="top"> <div class="wpi_box"> <div class="wpi_box_header"> <strong><?php echo $plugin_data['title']; ?> </strong> <p><?php echo $plugin_data['tagline']; ?> <a target="_blank" href="https://usabilitydynamics.com/products/wp-invoice/premium-features/"><?php _e('[purchase feature]', WPI); ?> </a></p> </div> <div class="wpi_box_content"> <p><?php echo stripslashes($plugin_data['description']); ?> </p> </div> <div class="wpi_box_footer clearfix"> <?php if ($installed) { ?> <div class="alignleft"> <?php if ($wpi_settings['installed_features'][$plugin_slug]['needs_higher_wpi_version'] == 'true') { printf(__('This feature is disabled because it requires WP-Invoice %1$s or higher.'), $wpi_settings['installed_features'][$plugin_slug]['minimum_wpi_version']); } else { echo WPI_UI::checkbox("value=true&name=wpi_settings[installed_features][{$plugin_slug}][disabled]&label=" . __('Disable premium feature.', WPI), $wpi_settings['installed_features'][$plugin_slug]['disabled']); ?> </div> <div class="alignright"><?php _e('Feature installed, using version', WPI); ?> <?php echo $wpi_settings['installed_features'][$plugin_slug]['version']; ?> .</div> <?php } } else { $pr_link = 'https://usabilitydynamics.com/products/wp-invoice/premium/'; echo sprintf(__('Please visit <a href="%s">UsabilityDynamics.com</a> to purchase this feature.', WPI), $pr_link); } ?> </div> </div> </td> </tr> <?php } } else { ?> <tr> <td class="wpi_features_not_found"><?php _e('There are no available premium features. Try clicking Check Updates button above.', WPI); ?> </td><td></td> </tr> <?php } ?> </table> <?php }
/** * This function prints out our invoice data for debugging purposes */ static function debug_get_invoice() { if (!isset($_REQUEST['invoice_id'])) { die(__("Please enter an invoice id.", WPI)); } $this_invoice = new WPI_Invoice(); $this_invoice->load_invoice("id=" . $_REQUEST['invoice_id']); echo WPI_Functions::pretty_print_r($this_invoice->data); die; }
/** * Invoice lookup function * If return is passed as true, function is returned. * * @global type $wpi_settings * * @param type $args * * @return type */ function wp_invoice_lookup($args = '') { global $wpi_settings, $current_user; $result = ''; $defaults = array('message' => __('Enter Invoice ID', WPI), 'button' => __('Lookup', WPI), 'return' => true); extract(wp_parse_args($args, $defaults), EXTR_SKIP); if (!$current_user->ID) { return; } ob_start(); if (WPI_Functions::wpi_use_custom_template('invoice_lookup.php')) { include $wpi_settings['frontend_template_path'] . 'invoice_lookup.php'; } else { include $wpi_settings['default_template_path'] . 'invoice_lookup.php'; } $result .= ob_get_clean(); if ($return) { return $result; } echo $result; }
/** * Actions metabox used for primary filtering purposes * * * @uses CRM_User_List_Table class * @since 0.01 * */ function filter($wp_list_table) { global $wpi_settings; ?> <div class="misc-pub-section"> <?php $wp_list_table->search_box( 'Search', 'post' ); ?> <?php $filters = WPI_Functions::get_search_filters(); ?> <?php $users = wpi_invoice_users_dropdown('wpi_object', '', true); ?> <?php /* echo "<pre>"; print_r($filters); echo "</pre>"; return;*/ ?> <?php /** * Filter by Type */ if ( !empty( $filters['type'] ) && is_array( $filters['type'] ) ) : ?> <ul class="wpi_overview_filters type"> <li class="wpi_filter_section_title">Type<a class="wpi_filter_show">Show</a></li> <li class="all wpi_checkbox_filter"> <ul> <?php foreach ( $filters['type'] as $item ) : ?> <li class="type"> <input type="radio" id="wpi_filter_type_<?php echo 'type_'. $item['key']; ?>" value="<?php echo ($item['key'] != 'all' ? $item['key'] : ''); ?>" name="wpi_search[type]" <?php echo ($item['key'] == 'all' ? 'checked="checked"' : ''); ?> /> <label for="wpi_filter_type_<?php echo 'type_'. $item['key']; ?>"><?php echo $item['label']; ?> <span class="count">(<?php echo $item['amount']; ?>)</span></label> </li> <?php endforeach; ?> </ul> </li> </ul> <?php endif; ?> <?php /** * Filter by Status */ if ( !empty( $filters['status'] ) && is_array( $filters['status'] ) ) : ?> <ul class="wpi_overview_filters status"> <li class="wpi_filter_section_title"><?php _e('Status', WPI) ?><a class="wpi_filter_show"><?php _e('Hide', WPI) ?></a></li> <li class="all wpi_checkbox_filter" style="display:block;"> <ul> <?php foreach ( $filters['status'] as $item ) : ?> <li class="status"> <input type="checkbox" <?php echo $item['key']=='active'?'checked="checked"':'' ?> id="wpi_filter_type_<?php echo 'status_'. $item['key']; ?>" value="<?php echo ($item['key'] != 'all' ? $item['key'] : ''); ?>" name="wpi_search[status][]"> <label for="wpi_filter_type_<?php echo 'status_'. $item['key']; ?>"><?php echo $item['label']; ?> <span class="count">(<?php echo $item['amount']; ?>)</span></label> </li> <?php endforeach; ?> </ul> </li> </ul> <?php endif; ?> <?php if ( !empty( $users ) && is_array( $users ) ) : ?> <ul class="wpi_overview_filters users"> <li class="wpi_filter_section_title"><?php _e('Recipient', WPI) ?><a class="wpi_filter_show"><?php _e('Show', WPI) ?></a></li> <li class="all wpi_checkbox_filter"> <?php wpi_invoice_users_dropdown('wpi_object', 'wpi_search[recipient]'); ?> </li> </ul> <?php endif; ?> <?php /* Filter by Date */ ?> <?php $months_dropdown = $wp_list_table->months_dropdown('wpi_object', 'wpi_search[m]', true); ?> <?php if (!empty($months_dropdown)) : ?> <ul class="wpi_overview_filters month"> <li class="wpi_filter_section_title"><?php _e('Date', WPI) ?><a class="wpi_filter_show"><?php _e('Show', WPI) ?></a></li> <li class="all wpi_checkbox_filter"> <?php echo $months_dropdown; ?> </li> </ul> <?php endif; ?> <?php do_action('wpi_invoice_list_filter'); ?> </div> <div class="major-publishing-actions"> <?php do_action( 'wpi_other_actions' ); ?> <div class="publishing-action"> <?php submit_button( __('Filter Results', WPI), 'button', false, false, array('id' => 'search-submit') ); ?> </div> <br class='clear' /> </div> <?php do_action( 'wpi_after_actions' ); ?> <?php }
/** * Draw widget. * * @see WP_Widget::widget * @global type $current_user * * @param type $args * @param type $instance * * @return type */ function widget($args, $instance) { extract($args); global $current_user, $wpi_settings; if (!$current_user->ID) { return; } $title = apply_filters('widget_title', !empty($instance['title']) ? $instance['title'] : ''); $allow_types = !empty($instance['allow_types']) ? $instance['allow_types'] : array('invoice', 'recurring'); $allow_statuses = !empty($instance['allow_statuses']) ? $instance['allow_statuses'] : array('active', 'paid'); if (!is_array($allow_types)) { $allow_types = explode(',', $allow_types); } if (!is_array($allow_statuses)) { $allow_statuses = explode(',', $allow_statuses); } echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <div class="wpi_widget_invoice_history"> <?php foreach ($allow_types as $_type) { $invoice_array = WPI_Functions::get_user_invoices(array('user_email' => $current_user->user_email, 'status' => $allow_statuses, 'type' => $_type)); $invoices_found = false; if (!empty($invoice_array) && is_array($invoice_array)) { $invoices_found = true; ?> <b class="wpi_sidebar_title"><?php echo $wpi_settings['types'][$_type]['label']; ?> </b> <ul class="wpi_invoice_history_list wpi_active_invoices"> <?php foreach ($invoice_array as $invoice) { ?> <li class="<?php echo $_type; ?> <?php echo $invoice->data['post_status']; ?> "> <a href="<?php echo get_invoice_permalink($invoice->data['invoice_id']); ?> "><?php echo $invoice->data['post_title']; ?> </a> (<?php echo $invoice->data['post_status']; ?> ) </li> <?php } ?> </ul> <?php } } ?> </div> <?php echo $after_widget; ?> <?php }
/** * Get search results based on query. * * @todo Needs to be updated to handle the AJAX requests. * */ function prepare_items($wpi_search = false) { if(!isset($this->all_items)) { $this->all_items = WPI_Functions::query( $wpi_search ); } //** Do pagination */ if(!empty($this->all_items) && $this->_args['per_page'] != -1) { $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']); $total_chunks = count($this->item_pages); //** figure out what page chunk we are on based on iDisplayStart $this_chunk = ($this->_args['iDisplayStart'] / $this->_args['per_page']); //** Get page items */ $this->items = $this->item_pages[$this_chunk]; } else { $this->items = $this->all_items; } }
/** * Figures out when next payment is due. Mostly for recurring cycles. * * @global type $wpi_settings * @param type $args * @return type */ function payment_due($args = '') { $defaults = array('invoice_id' => false); extract(wp_parse_args($args, $defaults), EXTR_SKIP); //** Figure out if this is a recurring bill */ return WPI_Functions::days_since($this->data['meta'][due_date]); }
/** * * @since 3.0 * */ static function legacy_version_exist() { global $wpdb, $wpi_settings; $version = get_option('wp_invoice_version'); if (!empty($version) && (int) $version < 3 && (int) $version != 0) { WPI_Functions::log(sprintf(__("Old WP-Invoice version %s was found.", WPI), $version)); return true; } return false; }
/** * Validation is already passed, this is the wp_head filter * It needs a lot of work * * @TODO: Does it need at all? Old functionality? Should be revised. Maxim Peshkov. */ function frontend_header() { global $wpi_settings; ?> <script type="text/javascript"> var site_url = '<?php echo WPI_Functions::current_page(); ?>'; <?php /* var ajax_image = '<?php echo $frontend_path; ?>/core/images/processing-ajax.gif'; */ ?> </script> <meta name="robots" content="noindex, nofollow" /> <?php }
function plugins($wpi_settings) { $parseUrl = parse_url(trim(get_bloginfo('url'))); $this_domain = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2))); ?> <table id="wpi_premium_feature_table" cellpadding="0" cellspacing="0"> <thead> <tr> <td colspan="2" class="wpi_premium_feature_intro"> <span class="header"><?php _e('WP-Invoice Premium Features',WPI) ?></span> <p><?php _e('When purchasing the premium features you will need to specify your domain to add the license correctly. This is your domain:',WPI); echo ' <b>'. $this_domain .'</b>'; ?></p> <p id="wpi_plugins_ajax_response" class="hidden"></p> </td> </tr> </thead> <?php if(!empty($wpi_settings['available_features'])) : foreach($wpi_settings['available_features'] as $plugin_slug => $plugin_data): ?> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?>][title]" value="<?php echo $plugin_data['title']; ?>" /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?>][tagline]" value="<?php echo $plugin_data['tagline']; ?>" /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?>][image]" value="<?php echo $plugin_data['image']; ?>" /> <input type="hidden" name="wpi_settings[available_features][<?php echo $plugin_slug; ?>][description]" value="<?php echo $plugin_data['description']; ?>" /> <?php $installed = WPI_Functions::check_premium($plugin_slug); ?> <?php $active = (@$wpi_settings['installed_features'][$plugin_slug]['disabled'] != 'false' ? true : false); ?> <?php if($installed): ?> <?php /* Do this to preserve settings after page save. */ ?> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?>][disabled]" value="<?php echo $wpi_settings['installed_features'][$plugin_slug]['disabled']; ?>" /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?>][name]" value="<?php echo $wpi_settings['installed_features'][$plugin_slug]['name']; ?>" /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?>][version]" value="<?php echo $wpi_settings['installed_features'][$plugin_slug]['version']; ?>" /> <input type="hidden" name="wpi_settings[installed_features][<?php echo $plugin_slug; ?>][description]" value="<?php echo $wpi_settings['installed_features'][$plugin_slug]['description']; ?>" /> <?php endif; ?> <tr class="wpi_premium_feature_block"> <td valign="top" class="wpi_premium_feature_image"> <?php if(!empty($plugin_data['image'])) { ?> <a href="http://usabilitydynamics.com/products/wp-invoice/"><img src="<?php echo $plugin_data['image']; ?>" /></a> <?php } ?> </td> <td valign="top"> <div class="wpi_box"> <div class="wpi_box_header"> <strong><?php echo $plugin_data['title']; ?></strong> <p><?php echo $plugin_data['tagline']; ?> <a href="https://usabilitydynamics.com/products/wp-invoice/premium/?wp_checkout_payment_domain=<?php echo $this_domain; ?>"><?php _e('[purchase feature]', WPI) ?></a> </p> </div> <div class="wpi_box_content"> <p><?php echo $plugin_data['description']; ?></p> </div> <div class="wpi_box_footer clearfix"> <?php if($installed) { ?> <div class="alignleft"> <?php if($wpi_settings['installed_features'][$plugin_slug]['needs_higher_wpi_version'] == 'true') { printf(__('This feature is disabled because it requires WP-Invoice %1$s or higher.'), $wpi_settings['installed_features'][$plugin_slug]['minimum_wpi_version']); } else { echo WPI_UI::checkbox("value=true&name=wpi_settings[installed_features][$plugin_slug][disabled]&label=" . __('Disable premium feature.',WPI), $wpi_settings['installed_features'][$plugin_slug]['disabled']); ?> </div> <div class="alignright"><?php _e('Feature installed, using version',WPI) ?> <?php echo $wpi_settings['installed_features'][$plugin_slug]['version']; ?>.</div> <?php } } else { $pr_link = 'https://usabilitydynamics.com/products/wp-invoice/premium/'; echo sprintf(__('Please visit <a href="%s">UsabilityDynamics.com</a> to purchase this feature.',WPI),$pr_link); } ?> </div> </div> </td> </tr> <?php endforeach; else: ?> <tr> <td class="wpi_features_not_found"><?php _e('There are no available premium features.', WPI); ?></td><td></td> </tr> <?php endif; ?> </table> <?php }
_e('Whether to exclude Products from front end search results.', WPI); ?> </div> </li> <li> <?php echo WPI_UI::checkbox("name=wpi_settings[products][post_type][hierarchical]&value=true&label=" . __('Hierarchical Products', WPI), WPI_Functions::is_true(!empty($wpi_settings['products']['post_type']['hierarchical']) ? $wpi_settings['products']['post_type']['hierarchical'] : self::$defaults['post_type']['hierarchical'])); ?> <div class="description"><?php _e('Whether Products are hierarchical.', WPI); ?> </div> </li> <li> <?php echo WPI_UI::checkbox("name=wpi_settings[products][post_type][has_archive]&value=true&label=" . __('Products have archives', WPI), WPI_Functions::is_true(!empty($wpi_settings['products']['post_type']['has_archive']) ? $wpi_settings['products']['post_type']['has_archive'] : self::$defaults['post_type']['has_archive'])); ?> <div class="description"><?php _e('Enables Products archives.', WPI); ?> </div> </li> <li> <?php _e('Products Menu Position', WPI); ?> <br /> <?php echo WPI_UI::input("type=text&name=menu_position&group=wpi_settings[products][post_type]&value=" . (!empty($wpi_settings['products']['post_type']['menu_position']) ? $wpi_settings['products']['post_type']['menu_position'] : self::$defaults['post_type']['menu_position'])); ?> <div class="description"><?php
/** * Handler for PayPal IPN queries * @author korotkov@ud * Full callback URL: http://domain/wp-admin/admin-ajax.php?action=wpi_gateway_server_callback&type=wpi_paypal */ static function server_callback() { if (empty($_POST)) { die(__('Direct access not allowed', WPI)); } $invoice = new WPI_Invoice(); $invoice->load_invoice("id={$_POST['invoice']}"); /** Verify callback request */ if (self::_ipn_verified($invoice)) { switch ($_POST['txn_type']) { /** New PayPal Subscription */ case 'subscr_signup': /** PayPal Subscription created */ WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription created', WPI)); wp_invoice_mark_as_pending($_POST['invoice']); do_action('wpi_paypal_subscr_signup_ipn', $_POST); break; case 'subscr_cancel': /** PayPal Subscription cancelled */ WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription cancelled', WPI)); do_action('wpi_paypal_subscr_cancel_ipn', $_POST); break; case 'subscr_failed': /** PayPal Subscription failed */ WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription payment failed', WPI)); do_action('wpi_paypal_subscr_failed_ipn', $_POST); break; case 'subscr_payment': /** Payment of Subscription */ switch ($_POST['payment_status']) { case 'Completed': /** Add payment amount */ $event_note = sprintf(__('%1s paid for subscription %2s', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice']), $_POST['subscr_id']); $event_amount = (double) $_POST['mc_gross']; $event_type = 'add_payment'; /** Log balance changes */ $invoice->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); $invoice->save_invoice(); send_notification($invoice->data); break; default: break; } do_action('wpi_paypal_subscr_payment_ipn', $_POST); break; case 'subscr_eot': /** PayPal Subscription end of term */ WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription term is finished', WPI)); wp_invoice_mark_as_paid($_POST['invoice'], $check = false); do_action('wpi_paypal_subscr_eot_ipn', $_POST); break; case 'subscr_modify': /** PayPal Subscription modified */ WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription modified', WPI)); do_action('wpi_paypal_subscr_modify_ipn', $_POST); break; case 'web_accept': /** PayPal simple button */ switch ($_POST['payment_status']) { case 'Pending': /** Mark invoice as Pending */ wp_invoice_mark_as_pending($_POST['invoice']); do_action('wpi_paypal_pending_ipn', $_POST); break; case 'Completed': /** Add payment amount */ $event_note = sprintf(__('%s paid via PayPal', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice'])); $event_amount = (double) $_POST['mc_gross']; $event_type = 'add_payment'; /** Log balance changes */ $invoice->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); /** Log payer email */ $payer_email = sprintf(__("PayPal Payer email: %s", WPI), $_POST['payer_email']); $invoice->add_entry("attribute=invoice¬e={$payer_email}&type=update"); $invoice->save_invoice(); /** ... and mark invoice as paid */ wp_invoice_mark_as_paid($_POST['invoice'], $check = true); send_notification($invoice->data); do_action('wpi_paypal_complete_ipn', $_POST); break; default: break; } break; case 'cart': /** PayPal Cart. Used for SPC */ switch ($_POST['payment_status']) { case 'Pending': /** Mark invoice as Pending */ wp_invoice_mark_as_pending($_POST['invoice']); do_action('wpi_paypal_pending_ipn', $_POST); break; case 'Completed': /** Add payment amount */ $event_note = sprintf(__('%s paid via PayPal', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice'])); $event_amount = (double) $_POST['mc_gross']; $event_type = 'add_payment'; /** Log balance changes */ $invoice->add_entry("attribute=balance¬e={$event_note}&amount={$event_amount}&type={$event_type}"); /** Log payer email */ $payer_email = sprintf(__("PayPal Payer email: %s", WPI), $_POST['payer_email']); $invoice->add_entry("attribute=invoice¬e={$payer_email}&type=update"); $invoice->save_invoice(); /** ... and mark invoice as paid */ wp_invoice_mark_as_paid($_POST['invoice'], $check = true); send_notification($invoice->data); do_action('wpi_paypal_complete_ipn', $_POST); break; default: break; } break; default: break; } echo ' '; } }
/** * Saves passed settings * * @global array $wpi_settings * * @param array $new_settings */ function SaveSettings($new_settings) { global $wpi_settings; //** Set 'first_time_setup_ran' as 'true' to avoid loading First Time Setup Page in future */ $new_settings['first_time_setup_ran'] = 'true'; $this->options = WPI_Functions::array_merge_recursive_distinct($this->options, $new_settings); //** just fo now we use the merged options array and overwrite two brances with new values. It is the custom solution to be able detete currency. odokienko@UD */ if (isset($new_settings['currency']) && $new_settings['currency']) { $this->options['currency']['symbol'] = $new_settings['currency']['symbol']; $this->options['currency']['types'] = $new_settings['currency']['types']; } //** Process Special Settings */ //** Default predefined services */ $this->options['predefined_services'][0]['name'] = __("Web Design Services", WPI); $this->options['predefined_services'][0]['quantity'] = 1; $this->options['predefined_services'][0]['price'] = 30; $this->options['predefined_services'][1]['name'] = __("Web Development Services", WPI); $this->options['predefined_services'][1]['quantity'] = 1; $this->options['predefined_services'][1]['price'] = 30; $this->options['predefined_services'] = isset($new_settings['predefined_services']) ? $new_settings['predefined_services'] : $this->options['predefined_services']; //** E-Mail Templates */ if (isset($new_settings['notification'])) { $this->options['notification'] = $new_settings['notification']; } //** fix checkboxes */ foreach ($this->options['billing'] as $key => $value) { if (!isset($new_settings['billing'][$key]['allow'])) { unset($this->options['billing'][$key]['allow']); } } $checkbox_array = array('increment_invoice_id', 'send_thank_you_email', 'cc_thank_you_email', 'force_https', 'show_recurring_billing', 'send_invoice_creator_email'); foreach ($checkbox_array as $checkbox_name) { if (!isset($new_settings[$checkbox_name])) { unset($this->options[$checkbox_name]); } } $this->CommitUpdates(); //** Update global variable */ $wpi_settings = WPI_Functions::array_merge_recursive_distinct($wpi_settings, $this->options); //** Fix Predefined Services */ $wpi_settings['predefined_services'] = $this->options['predefined_services']; //** Fix E-Mail Templates */ $wpi_settings['notification'] = $this->options['notification']; wpi_gateway_base::sync_billing_objects(); }
/** * Handles validation when somebody is attempting to view an invoice. * If validation is passsed, we add the necessary * filters to display the invoice header and page content; * Global $invoice_id variable set by WPI_Functions::validate_page_hash(); */ function template_redirect() { global $invoice_id, $wpi_settings, $wpi_invoice_object, $post, $current_user; //** Alwys load styles without checking if given page has an invoice */ wp_enqueue_style('wpi-theme-specific'); wp_enqueue_style('wpi-default-style'); //** Determine if the current page is invoice's page */ if (empty($post->ID) || $wpi_settings['web_invoice_page'] != $post->ID) { return; } //** If invoice_id is passed, run validate_page_hash to make sure this is the right page and invoice_id exists */ if (isset($_GET['invoice_id'])) { if (WPI_Functions::validate_page_hash(esc_sql($_GET['invoice_id']))) { //** load global invoice object */ $post_id = wpi_invoice_id_to_post_id($invoice_id); $wpi_invoice_object = new WPI_Invoice(); $wpi_invoice_object->load_invoice("id={$post_id}"); add_filter('viewable_invoice_types', array($this, 'viewable_types')); //** Determine if current invoice object is "viewable" */ if (!in_array($wpi_invoice_object->data['post_status'], apply_filters('viewable_invoice_types', array('active')))) { return; } if (isset($wpi_settings['logged_in_only']) && $wpi_settings['logged_in_only'] == 'true') { if (!current_user_can(WPI_UI::get_capability_by_level($wpi_settings['user_level'])) && !WPI_Functions::user_is_invoice_recipient($wpi_invoice_object)) { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } //** Load front end scripts */ wp_enqueue_script('jquery.validate'); wp_enqueue_script('wpi-gateways'); wp_enqueue_script('jquery.maskedinput'); wp_enqueue_script('wpi-frontend-scripts'); if (!empty($wpi_settings['ga_event_tracking']) && $wpi_settings['ga_event_tracking']['enabled'] == 'true') { wp_enqueue_script('wpi-ga-tracking', WPI_URL . "/core/js/wpi.ga.tracking.js", array('jquery')); } //** Apply Filters to the invoice description */ add_action('wpi_description', 'wpautop'); add_action('wpi_description', 'wptexturize'); add_action('wpi_description', 'shortcode_unautop'); add_action('wpi_description', 'convert_chars'); add_action('wpi_description', 'capital_P_dangit'); //** Declare the variable that will hold our AJAX url for JavaScript purposes */ wp_localize_script('wpi-gateways', 'wpi_ajax', array('url' => admin_url('admin-ajax.php'))); add_action('wp_head', array('WPI_UI', 'frontend_header')); if ($wpi_settings['replace_page_title_with_subject'] == 'true' || $wpi_settings['hide_page_title'] == 'true') { add_action('wp_title', array('WPI_UI', 'wp_title'), 0, 3); } if ($wpi_settings['replace_page_heading_with_subject'] == 'true' || $wpi_settings['hide_page_title'] == 'true') { add_action('the_title', array('WPI_UI', 'the_title'), 0, 2); } add_action('the_content', array('WPI_UI', 'the_content'), 20); } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } //** Fixed WordPress filters if page is being opened in HTTPS mode */ if (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on") { if (function_exists('force_ssl')) { add_filter('option_siteurl', 'force_ssl'); add_filter('option_home', 'force_ssl'); add_filter('option_url', 'force_ssl'); add_filter('option_wpurl', 'force_ssl'); add_filter('option_stylesheet_url', 'force_ssl'); add_filter('option_template_url', 'force_ssl'); add_filter('script_loader_src', 'force_ssl'); } } //** Lookup functionality */ if (isset($_POST['wp_invoice_lookup_input'])) { if (!empty($current_user->ID)) { $id = get_invoice_id($_POST['wp_invoice_lookup_input']); if (empty($id)) { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } $invoice = get_invoice($id); if (current_user_can('level_10') || $current_user->data->user_email == $invoice['user_email']) { header("location:" . get_invoice_permalink($_POST['wp_invoice_lookup_input'])); die; } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } }
<li class="hide_after_success"> <label class="inputLabel" for="cc_data[card_num]"><?php _e('Credit Card Number', WPI); ?></label> <input name="cc_data[card_num]" autocomplete="off" onkeyup="cc_card_pick();" id="cc_data[card_num]" class="credit_card_number input_field" type="text" size="22" maxlength="22" /> </li> <li class="hide_after_success nocard" id="cardimage" style="background: url(<?php echo $wpi_settings['frontend_path']; ?>/core/images/card_array.png) no-repeat;"> </li> <li class="hide_after_success"> <label class="inputLabel" for="exp_month"><?php _e('Expiration Date', WPI); ?></label> <?php _e('Month', WPI); ?> <?php echo WPI_UI::select("name=cc_data[exp_year]&values=months"); ?> <?php _e('Year', WPI); ?> <?php echo WPI_UI::select("name=cc_data[exp_year]&values=years"); ?> </li> <li class="hide_after_success"> <label class="inputLabel" for="card_code"><?php _e('Security Code', WPI); ?></label> <input id="card_code" autocomplete="off" name="cc_data[card_code]" class="input_field" style="width: 70px;" type="text" size="4" maxlength="4" /> </li> <li id="wp_invoice_process_wait"> <label for="submit"><span></span> </label> <button type="submit" id="cc_pay_button" class="hide_after_success submit_button"><?php echo sprintf(__('Process Payment of %s', WPI), $invoice['meta']['currency_symbol'] . WPI_Functions::money_format($invoice['amount'])); ?></button> </li> <br class="cb" /> </ol> </fieldset> </form> <div id="wp_cc_response"></div>
/** * Checks for, and downloads, any premium features from TCT servers * * @uses $wpdb * @since 3.0 * */ function check_for_premium_features($return = false) { global $wpi_settings; $blogname = get_bloginfo('url'); $blogname = urlencode(str_replace(array('http://', 'https://'), '', $blogname)); $system = 'wpi'; $wpi_version = WP_INVOICE_VERSION_NUM; $api_key = WPI_Functions::get_api_key(array('force_check' => true, 'return' => true)); if(empty($api_key) || strlen($api_key) != 40) { if($return) { if(empty($api_key)) { $api_key = __("The API key could not be generated.", WPI); } return sprintf(__('An error occured during premium feature check: <b>%s</b>.',WPI), $api_key); } else { return; } } $check_url = "http://updates.usabilitydynamics.com/?system={$system}&site={$blogname}&system_version={$wpi_version}&api_key={$api_key}"; $response = @wp_remote_get($check_url); if (!$response) { return; } // Check for errors if (is_object($response) && !empty($response->errors)) { foreach ($response->errors as $update_errrors) { $error_string .= implode(",", $update_errrors); WPI_Functions::log("Feature Update Error: " . $error_string); } if ($return) { return sprintf(__('An error occured during premium feature check: <b> %s </b>.', WPI), $error_string); } return; } //** Quit if failure */ if ($response['response']['code'] != '200') { return; } $response = @json_decode($response['body']); if (is_object($response->available_features)) { $response->available_features = WPI_Functions::objectToArray($response->available_features); //** Update the database */ $wpi_settings = get_option('wpi_options'); $wpi_settings['available_features'] = WPI_Functions::objectToArray($response->available_features); update_option('wpi_options', $wpi_settings); } // available_features if ($response->features == 'eligible' && $wpi_settings['disable_automatic_feature_update'] != 'true') { // Try to create directory if it doesn't exist if (!is_dir(WPI_Premium)) { @mkdir(WPI_Premium, 0755); } // If didn't work, we quit if (!is_dir(WPI_Premium)) { continue; } // Save code if (is_object($response->code)) { foreach ($response->code as $code) { $filename = $code->filename; $php_code = $code->code; $version = $code->version; //** Check version */ $default_headers = array( 'Name' => __('Feature Name', WPI), 'Version' => __('Version', WPI), 'Description' => __('Description', WPI) ); $current_file = @get_file_data(WPI_Premium . "/" . $filename, $default_headers, 'plugin'); if (@version_compare($current_file[Version], $version) == '-1') { $this_file = WPI_Premium . "/" . $filename; $fh = @fopen($this_file, 'w'); if ($fh) { fwrite($fh, $php_code); fclose($fh); if ($current_file[Version]) { //UD_F::log(sprintf(__('WP-Invoice Premium Feature: %s updated to version %s from %s.', WPI), $code->name, $version, $current_file[Version])); } else { //UD_F::log(sprintf(__('WP-Invoice Premium Feature: %s updated to version %s.', WPI), $code->name, $version)); } $updated_features[] = $code->name; } } else { } } } } // Update settings //WPI_Functions::settings_action(true); if ($return && $wpi_settings['disable_automatic_feature_update'] == 'true') { return __('Update ran successfully but no features were downloaded because the setting is disabled. Enable in the "Developer" tab.', WPI); } elseif ($return) { return __('Update ran successfully.', WPI); } }
function revalidate() { WPI_Functions::total_revalidate(); }
wp_redirect(add_query_arg('paged', $total_pages)); exit; } $title = $post_type_object->labels->name; ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php _e('Sales Log', WPI); ?> </h2> <?php WPI_Functions::print_messages(); ?> <?php $wp_list_table->views(); ?> <form id="posts-filter" action="" method="get"> <?php $wp_list_table->search_box($post_type_object->labels->search_items, 'post'); ?> <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?> " /> <input type="hidden" name="post_type" class="post_type_page" value="<?php
/** * Create new invoice * * @param array $args * * @return WPI_Invoice * @see WPI_Invoice * @uses Internal API of plugin */ function create_invoice($args = array()) { global $wpi_settings; //** Default arguments */ $defaults = array('custom_id' => false, 'subject' => false, 'description' => false, 'type' => false, 'user_data' => array('user_email' => false, 'first_name' => false, 'last_name' => false, 'phonenumber' => false, 'streetaddress' => false, 'city' => false, 'state' => false, 'zip' => false, 'country' => false), 'deposit' => false, 'due_date' => array('year' => false, 'month' => false, 'day' => false), 'currency' => false, 'tax' => false, 'tax_method' => false, 'recurring' => array('unit' => false, 'length' => false, 'cycles' => false, 'send_invoice_automatically' => false, 'start_date' => array('month' => false, 'day' => false, 'year' => false)), 'status' => false, 'discount' => array('name' => false, 'type' => false, 'amount' => false), 'items' => array(), 'charges' => array()); //** Parse arguments */ extract($args = wp_parse_args($args, $defaults)); //** If empty subject - return error */ if (!$subject) { return new WP_Error('wp.invoice', __('Method requires "subject" argument to be passed.', WPI), $args); } //** If empty user_email - return error */ if (!$user_data['user_email']) { return new WP_Error('wp.invoice', __('Method requires "user_email" in "user_data" argument to be passed.', WPI), $args); } if (!filter_var($user_data['user_email'], FILTER_VALIDATE_EMAIL)) { return new WP_Error('wp.invoice', __('User Email is malformed.', WPI), $args); } //** Items/Charges check */ if (empty($items) && empty($charges)) { return new WP_Error('wp.invoice', __('Method requires "items" or "charges" argument to be passed.', WPI), $args); } //** If type is registered */ if (!array_key_exists($type, $wpi_settings['types'])) { return new WP_Error('wp.invoice', __('Unknown invoice type.', WPI), $args); } //** If recurring */ if ($type == 'recurring') { $recurring = array_filter($recurring); if (empty($recurring['unit']) || empty($recurring['cycles'])) { return new WP_Error('wp.invoice', __('Method requires correct "recurring" argument if "type" is recurring.', WPI), $args); } if (!empty($deposit)) { return new WP_Error('wp.invoice', __('Cannot use "deposit" with "recurring" type.', WPI), $args); } } //** If quote */ if ($type == 'quote') { if (!empty($deposit)) { return new WP_Error('wp.invoice', __('Cannot use "deposit" with "quote" type.', WPI), $args); } } //** Check status */ if (!$status) { return new WP_Error('wp.invoice', __('Method requires "status" argument to be passed.', WPI), $args); } if (!array_key_exists($status, $wpi_settings['invoice_statuses'])) { return new WP_Error('wp.invoice', __('Unknown invoice status.', WPI), $args); } //** New Invoice object */ $invoice = new WPI_Invoice(); //** Load invoice by ID */ $invoice->create_new_invoice($args); //** Set type */ $invoice->set(array('type' => $type)); //** If quote */ if ($type == 'quote') { $invoice->set(array('status' => $type)); $invoice->set(array('is_quote' => 'true')); } //** Recurring */ if ($type == 'recurring') { $invoice->create_schedule($recurring); } //** Try loading user by email */ $invoice->load_user(array('email' => $user_data['user_email'])); //** If new user - add data to his object */ if (empty($invoice->data['user_data'])) { $invoice->data['user_data'] = $user_data; } //** Create/Update user if need */ WPI_Functions::update_user($user_data); //** Try loading user by email again */ $invoice->load_user(array('email' => $user_data['user_email'])); //** Partial payments */ if ($deposit) { $invoice->set(array('deposit_amount' => $deposit)); } else { $invoice->set(array('deposit_amount' => 0)); } //** Due date */ $invoice->set(array('due_date_year' => $due_date['year'])); $invoice->set(array('due_date_month' => $due_date['month'])); $invoice->set(array('due_date_day' => $due_date['day'])); //** Currency */ $invoice->set(array('default_currency_code' => $currency)); //** Tax */ $invoice->set(array('tax' => $tax)); //** Status */ $invoice->set(array('post_status' => $status)); //** Discount */ $discount = array_filter($discount); if (!empty($discount)) { if (empty($discount['name'])) { return new WP_Error('wp.invoice', __('Discount name is required.', WPI), $args); } if (empty($discount['type'])) { return new WP_Error('wp.invoice', __('Discount type is required. ("amount" or "percent").', WPI), $args); } if (empty($discount['amount'])) { return new WP_Error('wp.invoice', __('Discount amount is required.', WPI), $args); } $invoice->add_discount($discount); } //** Items */ foreach ($items as $item) { //** Do not allow to save melformed items */ if (empty($item['name']) || empty($item['quantity']) || empty($item['price'])) { return new WP_Error('wp.invoice', __('One or more "items" have malformed structure. Cannot create Invoice.', WPI), $args); } //** Global tax has higher priority */ if (!empty($tax)) { $item['tax_rate'] = $tax; } //** Check types */ if (!is_numeric($item['quantity'])) { return new WP_Error('wp.invoice', __('One or more "items" have wrong "quantity" value. Cannot create Invoice.', WPI), $args); } if (!is_numeric($item['price'])) { return new WP_Error('wp.invoice', __('One or more "items" have wrong "price" value. Cannot create Invoice.', WPI), $args); } if (!empty($item['tax_rate'])) { if (!is_numeric($item['tax_rate'])) { return new WP_Error('wp.invoice', __('One or more "items" have wrong "tax_rate" value. Cannot create Invoice.', WPI), $args); } } //** If passed validation - save item */ $invoice->line_item($item); } //** Charges */ foreach ($charges as $charge) { //** Do not allow to save melformed items */ if (empty($charge['name']) || empty($charge['amount'])) { return new WP_Error('wp.invoice', __('One or more "charges" have malformed structure. Cannot create Invoice.', WPI), $args); } //** Global tax has higher priority */ if (!empty($tax)) { $charge['tax'] = $tax; } //** Check types */ if (!is_numeric($charge['amount'])) { return new WP_Error('wp.invoice', __('One or more "charges" have wrong "amount" value. Cannot create Invoice.', WPI), $args); } if (!empty($charge['tax'])) { if (!is_numeric($charge['tax'])) { return new WP_Error('wp.invoice', __('One or more "charges" have wrong "tax" value. Cannot create Invoice.', WPI), $args); } } //** If passed validation - save item */ $invoice->line_charge($charge); } //** Set tax method */ if (!empty($tax_method)) { if ($tax_method != 'before_discount' && $tax_method != 'after_discount') { return new WP_Error('wp.invoice', __('Unknown "tax_method".', WPI), $args); } } $invoice->set(array('tax_method' => $tax_method)); //** Save */ $invoice->save_invoice(); //** Return saved object */ return $invoice; }