/** * Sends notification to invoice creator * * @global array $wpi_settings * @param array $invoice * @author korotkov@UD * * @todo Refactor message text to be loaded from editable templates from settings. */ function wp_invoice_send_creator_notification($invoice) { global $wpi_settings; $creator = get_userdata( $invoice['post_author'] ); $to = stripslashes( $creator->user_email ); $site = stripslashes($wpi_settings['business_name']); $permalink = get_invoice_permalink($invoice['invoice_id']); $total = $invoice['subtotal']-$invoice['total_discount']+$invoice['total_tax']; $display_name = wpi_get_user_display_name($invoice); $message = sprintf( __("%1s has paid invoice #%2s.\n\n%3s\nTotal payments: %4s %5s of %6s %7s.\n\nYou can overview invoice status and payment history by clicking this link:\n%8s\n\nUser information:\n\nID: %9s\nName: %10s\nEmail: %11s\n\n--------------------\n%12s", WPI), $display_name, $invoice['invoice_id'], $invoice['post_title'], $invoice['default_currency_code'], $invoice['total_payments'], $invoice['default_currency_code'], $total, $permalink, $invoice['user_data']['ID'], $display_name, $invoice['user_data']['user_email'], $site ); $subject = sprintf(__("Invoice #%s has been paid", WPI), $invoice['invoice_id']); $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8'); $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8'); wp_mail($to, $subject, $message); }
function invoice_pdf_link() { global $invoice; echo get_invoice_permalink($invoice['invoice_id']) . "&format=pdf"; }
/** * 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; } } }
<div id="titlediv"> <div id="titlewrap"> <?php echo WPI_UI::input("id=title&name=wpi_invoice[subject]&value=".(!empty( $this_invoice->data['post_title'] )?$this_invoice->data['post_title']:'')."&special autocomplete='off'")?> <?php echo WPI_UI::input("id=title&name=wpi_invoice[post_status]&value=".(!empty( $this_invoice->data['post_status'] )?$this_invoice->data['post_status']:'')."&type=hidden")?> </div> <div class="inside"> <div id="edit-slug-box" class="wpi-edit-slug-box" title="<?php _e('Click to view full link',WPI); ?>"><strong><?php _e('Invoice Link',WPI); ?>:</strong> <span id="sample-permalink"><?php echo get_invoice_permalink( !empty($this_invoice->data['invoice_id'])?$this_invoice->data['invoice_id']:'' ); ?></span> </div> </div> </div> <?php // Fixed Metaboxes // Always included but hidden until button is pressed message_meta_box( !empty( $this_invoice->data )?$this_invoice->data:null );
} <?php } ?> }); });*/ </script> <form action="https://www.paypal.com/us/cgi-bin/webscr" id="wpi_paypal_payment_form" class="wpi_payment_form" method="post" class="clearfix"> <input type="hidden" name="currency_code" value="<?php echo $invoice['meta']['default_currency_code']; ?>"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<?php echo $invoice['billing']['paypal']['settings']['paypal_address']['value']; ?>"> <input type="hidden" name="return" value="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"> <input type="hidden" name="notify_url" value="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cancel_return" value="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>&return_info=cancel"> <input type="hidden" name="amount" value="<?php echo $invoice['amount']; ?>"> <input type="hidden" name="cbt" value="Go back to Merchant"> <input type="hidden" name="item_name" value="<?php echo $invoice['subject']; ?>"> <input type="hidden" name="invoice" id="invoice_id" value="<?php echo $invoice['invoice_id']; ?>"> <fieldset id="credit_card_information"> <ol> <li> <label for="first_name"><?php _e('First Name', WPI); ?></label> <input name="first_name" value="<?php echo $invoice['user_data'][first_name];?>" /> </li> <li> <label for="last_name"><?php _e('Last Name', WPI); ?></label> <input name="last_name" value="<?php echo $invoice[user_data][last_name];?>" /> </li>
/** * Save invoice from Ajax */ function save_invoice() { $invoice_id = WPI_Functions::save_invoice($_REQUEST['wpi_invoice']); if ($invoice_id) { echo sprintf(__("Saved. <a target='_blank' href='%s'>View Invoice</a>", WPI), get_invoice_permalink($invoice_id)).". ".__('Invoice id #', WPI)."<span id='new_invoice_id'>$invoice_id</span>."; } else { echo __("There was a problem with saving the invoice. Reference the log for troubleshooting.", WPI); } die(); }
/** * 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 }
<input type="hidden" name="currency_code" value="<?php echo $invoice['default_currency_code']; ?> "> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="<?php echo $this->get_business($invoice); ?> "> <input type="hidden" name="return" value="<?php echo get_invoice_permalink($invoice['invoice_id']); ?> "> <input type="hidden" name="cancel_return" value="<?php echo get_invoice_permalink($invoice['invoice_id']); ?> "> <input type="hidden" name="cbt" value="Go back to Merchant"> <input type="hidden" name="item_name" value="<?php echo $invoice['post_title']; ?> "> <input type="hidden" name="invoice" id="invoice_id" value="<?php echo $invoice['invoice_id']; ?> "> <input type="hidden" name="bn" value="UsabilityDynamics_SP" /> <?php if ($this->do_send_notify_url($invoice)) {
/** * @param $post * @return string */ public function column_id($post) { $post = $this->get_invoice_object($post); $regular_id = false; $invoice_id = $post->invoice_id; if (!empty($post->custom_id)) { $invoice_id = $post->custom_id; $regular_id = $post->invoice_id; } return '<a href="' . get_invoice_permalink($post->invoice_id) . '" target="_blank">' . apply_filters("wpi_attribute_invoice_id", $invoice_id, $post) . ($regular_id ? ' (' . $regular_id . ') ' : '') . '</a>'; }
function postbox_publish($this_invoice) { global $wpi_settings; $invoice_id = $this_invoice['invoice_id']; $status_names = apply_filters('wpi_invoice_statuses', $wpi_settings['invoice_statuses']); if (!empty($this_invoice['status'])) { $status_label = ( $status_names[$this_invoice['status']] ? $status_names[$this_invoice['status']] : $this_invoice['status']); } ?> <div id="submitpost" class="submitbox"> <div id="minor-publishing"> <ul class="wpi_publish_seetings"> <li class="wpi_hide_until_saved"><a target="_blank" class="wpi_new_win wpi_update_with_invoice_url" href="<?php echo get_invoice_permalink(!empty($this_invoice['invoice_id']) ? $this_invoice['invoice_id'] : '' ); ?>"><?php _e('View Online', WPI); ?></a></li> <?php do_action('wpi_publish_options', $this_invoice); ?> <li class="wpi_hide_until_saved"><span onclick="wpi_show_paycharge_box();" class="wpi_link" id="wpi_button_show_paycharge_box"><?php _e('Enter Payment', WPI); ?></span></li> <li class="wpi_hide_until_saved"><span onclick='wpi_show_notification_box();' class="wpi_link" id="wpi_button_show_notification"><?php _e('Send Notification', WPI); ?></span></li> <?php if ($wpi_settings['allow_deposits'] == 'true') { ?> <li class="wpi_not_for_recurring wpi_hide_deposit_option wpi_not_for_quote"> <?php $app_title = __("Allow Partial Payment", WPI); ?> <?php echo WPI_UI::checkbox("name=wpi_invoice[deposit]&value=true&label={$app_title}", ((!empty($this_invoice['deposit_amount']) && (int) $this_invoice['deposit_amount'] > 0) ? true : false)) ?></li> <li class="wpi_deposit_settings"> <table class="wpi_deposit_settings"> <tr> <th><?php _e("Minimum Payment", WPI); ?></th> <td><?php echo WPI_UI::input("id=wpi_meta_deposit_amount&name=wpi_invoice[deposit_amount]&value=" . (!empty($this_invoice['deposit_amount']) ? $this_invoice['deposit_amount'] : 0)); ?></td> </tr> </table> </li> <?php } ?> <?php if ($wpi_settings['show_recurring_billing'] == 'true') { ?> <li class="wpi_turn_off_recurring wpi_not_for_quote"><?php echo WPI_UI::checkbox("name=wpi_invoice[recurring][active]&value=true&label=Recurring Bill", (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['active'] : false)) ?></li> <li class="wpi_recurring_bill_settings <?php if (!empty($this_invoice['recurring']) && $this_invoice['recurring']['active'] != 'on') { ?>hidden<?php } ?>"> <table class="wpi_recurring_bill_settings"> <tr> <th><?php _e("Bill Every", WPI) ?></th> <td> <?php echo WPI_UI::input("name=wpi_invoice[recurring][length]&value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['length'] : '') . "&class=wpi_small wpi_bill_every_length"); ?> <?php echo WPI_UI::select("name=wpi_invoice[recurring][unit]&values=" . serialize(apply_filters('wpi_schedule_units', array("months" => __("Month(s)", WPI), "days" => __("Day(s)", WPI)))) . "¤t_value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['unit'] : '')); ?> </td> </tr> <tr> <th><?php _e("Billing Cycles", WPI) ?></th> <td><?php echo WPI_UI::input("id=wpi_meta_recuring_cycles&name=wpi_invoice[recurring][cycles]&value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['cycles'] : '') . "&class=wpi_small"); ?></td> </tr> <tr> <th>Send Invoice</th> <td> <script type="text/javascript">var recurring_send_invoice_automatically = '<?php echo!empty($this_invoice['recurring']['send_invoice_automatically']) ? $this_invoice['recurring']['send_invoice_automatically'] : 'on'; ?>';</script> <?php echo WPI_UI::checkbox("name=wpi_invoice[recurring][send_invoice_automatically]&value=true&label=".__('Automatically.', WPI), !empty($this_invoice['recurring']['send_invoice_automatically']) ? $this_invoice['recurring']['send_invoice_automatically'] : 'on'); ?> </td> </tr> <tr class="wpi_recurring_start_date" style="display:<?php echo!empty($this_invoice['recurring']) && $this_invoice['recurring']['send_invoice_automatically'] == 'on' ? 'none;' : ''; ?>"> <th>Date:</th> <td> <div> <?php echo WPI_UI::select("id=r_start_date_mm&name=wpi_invoice[recurring][start_date][month]&values=months¤t_value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['start_date']['month'] : '')); ?> <?php echo WPI_UI::input("id=r_start_date_jj&name=wpi_invoice[recurring][start_date][day]&value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['start_date']['day'] : '') . "&special=size='2' maxlength='2' autocomplete='off'") ?> <?php echo WPI_UI::input("id=r_start_date_aa&name=wpi_invoice[recurring][start_date][year]&value=" . (!empty($this_invoice['recurring']) ? $this_invoice['recurring']['start_date']['year'] : '') . "&special=size='2' maxlength='4' autocomplete='off'") ?><br /> <span onclick="wp_invoice_add_time('r_start_date', 7);" class="wp_invoice_click_me"><?php _e('In One Week', WPI); ?></span> | <span onclick="wp_invoice_add_time('r_start_date', 30);" class="wp_invoice_click_me"><?php _e('In 30 Days', WPI); ?></span> | <span onclick="wp_invoice_add_time('r_start_date', 'clear');" class="wp_invoice_click_me"><?php _e('Clear', WPI); ?></span> </div> </td> </tr> </table> </li> <?php } ?> </ul> <table class="form-table"> <thead> <th colspan="2"> <span id="wpi_button_show_advanced" class="wpi_link"><?php _e('Toggle Advanced', WPI); ?></span> </th> </thead> <tbody> <tr class="column-publish-due-date wpi_not_for_recurring wpi_not_for_quote"> <th>Due Date</th> <td> <div class="timestampdiv" style="display:block;"> <?php echo WPI_UI::select("id=due_date_mm&name=wpi_invoice[due_date_month]&values=months¤t_value=" . (!empty($this_invoice['due_date_month']) ? $this_invoice['due_date_month'] : '')); ?> <?php echo WPI_UI::input("id=due_date_jj&name=wpi_invoice[due_date_day]&value=" . (!empty($this_invoice['due_date_day']) ? $this_invoice['due_date_day'] : '') . "&special=size='2' maxlength='2' autocomplete='off'") ?> <?php echo WPI_UI::input("id=due_date_aa&name=wpi_invoice[due_date_year]&value=" . (!empty($this_invoice['due_date_year']) ? $this_invoice['due_date_year'] : '') . "&special=size='2' maxlength='4' autocomplete='off'") ?><br /> <span onclick="wp_invoice_add_time('due_date', 7);" class="wp_invoice_click_me"><?php _e('In One Week', WPI); ?></span> | <span onclick="wp_invoice_add_time('due_date', 30);" class="wp_invoice_click_me"><?php _e('In 30 Days', WPI); ?></span> | <span onclick="wp_invoice_add_time('due_date','clear');" class="wp_invoice_click_me"><?php _e('Clear', WPI); ?></span> </div> </td> </tr> <tr class="invoice_main column-publish-invoice_id"> <th><?php _e('Invoice ID', WPI); ?> </th> <td> <?php $custom_invoice_id = !empty($this_invoice['custom_id']) ? $this_invoice['custom_id'] : ''; if (empty($custom_invoice_id) && $wpi_settings['increment_invoice_id'] == 'true') { $highest_custom_id = WPI_Functions::get_highest_custom_id(); $custom_invoice_id = ($highest_custom_id ? ($highest_custom_id + 1) : $this_invoice['invoice_id']); echo WPI_UI::input("name=wpi_invoice[meta][custom_id]&value=$custom_invoice_id"); } else { ?> <input style="width: 80px;" class="input_field wp_invoice_custom_invoice_id<?php echo empty($this_invoice['custom_id'])?" wp_invoice_hidden":""; ?>" name="wpi_invoice[meta][custom_id]" value="<?php echo !empty($this_invoice['custom_id']) ? $this_invoice['custom_id'] : ''; ?>"> <span class="wp_invoice_custom_invoice_id"> <?php echo $this_invoice['invoice_id']; ?> </span> <a onClick="jQuery('.wp_invoice_custom_invoice_id').toggle(); return false;" class="wp_invoice_click_me <?php echo empty($this_invoice['custom_id'])?" wp_invoice_hidden":""; ?>" href="#"><?php _e('Custom Invoice ID', WPI); ?></a> <?php } ?> </td> </tr> <tr class="invoice_main column-publish-global_tax"> <th><?php _e('Global Tax', WPI); ?></th> <td> <?php echo WPI_UI::input("id=wp_invoice_tax&name=wpi_invoice[meta][tax]&value=" . (!empty($this_invoice['tax']) ? $this_invoice['tax'] : '')) ?> </td> </tr> <tr class="invoice_main column-publish-global_tax"> <th><?php _e('Tax Method', WPI); ?></th> <td> <?php $tax_method = !empty($this_invoice['tax_method']) ? $this_invoice['tax_method'] : (isset($wpi_settings['tax_method']) ? $wpi_settings['tax_method'] : ''); ?> <?php echo WPI_UI::select("id=wpi_tax_method&name=wpi_invoice[tax_method]&values=" . serialize(array('before_discount' => __('Before Discount', WPI), 'after_discount' => __('After Discount', WPI))) . "¤t_value={$tax_method}"); ?> </td> </tr> </tbody> </table> </div> <div id="major-publishing-actions" class="clearfix"> <div id="delete-action" class="wpi_hide_until_saved"> <a href="<?php echo admin_url($wpi_settings['links']['overview_page']) . "&action=trash&post=" . (!empty($this_invoice['ID']) ? $this_invoice['ID'] : '') . "&_wpnonce=" . wp_create_nonce('wpi-status-change-' . (!empty($this_invoice['ID']) ? $this_invoice['ID'] : '')); ?>" class="submitdelete deletion"><?php _e('Trash Invoice', WPI); ?></a> </div> <div id="publishing-action"> <input type="submit" class="alignright button-primary" value="<?php esc_attr(_e('Save', WPI)); ?>" id="wpi_save_invoice"> </div> </div> </div> <?php }
/** * 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; } } } }
?> </div> <div class="inside"> <div id="edit-slug-box" class="wpi-edit-slug-box" title="<?php _e('Click to view full link', WPI); ?> "><strong><?php _e('Invoice Link', WPI); ?> :</strong> <span id="sample-permalink"><?php echo get_invoice_permalink(!empty($this_invoice->data['invoice_id']) ? $this_invoice->data['invoice_id'] : ''); ?> </span> </div> </div> </div> <?php // Fixed Metaboxes // Always included but hidden until button is pressed message_meta_box(!empty($this_invoice->data) ? $this_invoice->data : null); if (!empty($new_user)) { postbox_user_new($this_invoice->data);
/** @see WP_Widget::widget */ function widget($args, $instance) { extract($args); global $current_user; if (!$current_user->ID) return; $title = apply_filters('widget_title', $instance['title']); $message = $instance['message']; $button_text = !empty($instance['button_text']) ? $instance['button_text'] : __('Submit'); ?> <?php echo $before_widget; ?> <?php if ($title) echo $before_title . $title . $after_title; ?> <div class="wpi_widget_invoice_history"> <!-- <?php //$invoice_array = WPI_Functions::get_user_quotes("user_id={$current_user->ID}"); if (!empty($invoice_array) && is_array($invoice_array)) { ?> <b class="wpi_sidebar_title">Quotes</b> <ul class="wpi_invoice_history_list wpi_quotes_list"> <?php foreach ($invoice_array as $invoice) { if ($invoice['reporting']['status'] == 'balance_due') { ?> <li><a href="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"><?php echo $invoice['subject']; ?></a></li> <?php } } ?> </ul> <?php } ?> --> <?php //$invoice_array = WPI_Functions::get_user_invoices("user_id={$current_user->ID}&status=balance_due"); /* if(is_array($invoice_array)) { ?> <b class="wpi_sidebar_title">Due Invoice(s)</b> <ul class="wpi_invoice_history_list wpi_due_invoices"> <?php foreach($invoice_array as $invoice) { if($invoice['reporting']['status'] == 'balance_due') { ?> <li><a href="<?php echo get_invoice_permalink($invoice['invoice_id']); ?>"><?php echo $invoice['subject']; ?></a></li> <?php } } ?> </ul> <?php } */ ?> <?php $invoice_array = WPI_Functions::get_user_invoices("user_email={$current_user->user_email}&status=active"); if (!empty($invoice_array) && is_array($invoice_array)) { ?> <b class="wpi_sidebar_title"><?php _e("Active Invoice(s)"); ?></b> <ul class="wpi_invoice_history_list wpi_active_invoices"> <?php foreach ($invoice_array as $invoice) { ?> <li><a href="<?php echo get_invoice_permalink($invoice->data['invoice_id']); ?>"><?php echo $invoice->data['post_title']; ?></a></li> <?php } ?> </ul> <?php } ?> <?php $invoice_array = WPI_Functions::get_user_invoices("user_email={$current_user->user_email}&status=paid"); if (!empty($invoice_array) && is_array($invoice_array)) { ?> <b class="wpi_sidebar_title"><?php _e("Paid Invoice(s)"); ?></b> <ul class="wpi_invoice_history_list wpi_active_invoices"> <?php foreach ($invoice_array as $invoice) { ?> <li><a href="<?php echo get_invoice_permalink($invoice->data['invoice_id']); ?>"><?php echo $invoice->data['post_title']; ?></a></li> <?php } ?> </ul> <?php } ?> </div> <?php echo $after_widget; ?> <?php }
/** * Generate HTML for a single row on the users.php admin panel. * */ function single_row( $object ) { global $wpi_settings, $post; $object = (array) $object; $post = new WPI_Invoice(); $post->load_invoice("id={$object['ID']}"); $post = (object)$post->data; $post_owner = ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); $edit_link = admin_url("admin.php?page=wpi_page_manage_invoice&wpi[existing_invoice][invoice_id]={$post->ID}"); $title = _draft_or_post_title($post->ID); $post_type_object = get_post_type_object( $post->post_type ); $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID ); $result = "<tr id='object-{$object['ID']}' class='wpi_parent_element'>"; list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column => $column_display_name ) { $class = "class=\"$column column-$column\""; $style = ''; if ( in_array( $column, $hidden ) ) { $style = ' style="display:none;"'; } $attributes = "$class$style"; $result .= "<td {$attributes}>"; $r = ""; switch($column) { case 'cb': if ( $can_edit_post ) { $r .= '<input type="checkbox" name="post[]" value="'. get_the_ID() . '"/>'; } else { $r .= ' '; } break; case 'post_title': $attributes = 'class="post-title page-title column-title"' . $style; if ( $can_edit_post && $post->post_status != 'trash' && $post->post_status != 'archived' ) { $r .= '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”', WPI ), $title ) ) . '">' . $title . '</a>'; } else { $r .= $title; } $r .= (isset( $parent_name ) ? ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ) : ''); $actions = array(); if ( $can_edit_post && 'trash' != $post->post_status && 'archived' != $post->post_status ) { $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', WPI ) ) . '">' . __( 'Edit', WPI ) . '</a>'; } if ( 'archived' == $post->post_status ) { $actions['unarchive'] = '<a href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=unarchive', $post->ID ) ), 'unarchive-' . $post->post_type . '_' . $post->ID ) . '" title="' . esc_attr( __( 'Un-Archive this item', WPI ) ) . '">' . __( 'Un-Archive', WPI ) . '</a>'; } else if ( 'trash' != $post->post_status && 'pending' != $post->post_status ) { $actions['archive'] = '<a href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=archive', $post->ID ) ), 'archive-' . $post->post_type . '_' . $post->ID ) . '" title="' . esc_attr( __( 'Archive this item', WPI ) ) . '">' . __( 'Archive', WPI ) . '</a>'; } if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) { if ( 'trash' == $post->post_status ) { $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', WPI ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore', WPI ) . "</a>"; } elseif ( EMPTY_TRASH_DAYS && 'pending' != $post->post_status ) { $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', WPI ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash', WPI ) . "</a>"; } if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) { $actions['delete'] = "<a class='submitdelete permanently' title='" . esc_attr( __( 'Delete this item permanently', WPI ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently', WPI ) . "</a>"; } } if ( 'trash' != $post->post_status && 'archived' != $post->post_status ) { $actions['view'] = '<a target="_blank" href="' . get_invoice_permalink( $post->invoice_id ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', WPI ), $title ) ) . '" rel="permalink">' . __( 'View', WPI ) . '</a>'; } $actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post ); $r .= $this->row_actions( $actions ); break; case 'post_modified': if ( !empty( $post->post_status ) ) { if ( $post->post_status == 'paid' ) { $r .= get_post_status_object($post->post_status)->label.' '.human_time_diff(strtotime($post->post_modified), (time() + get_option('gmt_offset')*60*60)).' ago'; } else { $r .= human_time_diff(strtotime($post->post_modified), (time() + get_option('gmt_offset')*60*60)).' ago'; } } else { $r .= date(get_option('date_format'), strtotime($post->post_date)); } break; case 'invoice_id': $invoice_id = $post->{$column}; /* If custom_id exists we use it as invoice_id */ if(!empty($post->custom_id)) { $invoice_id = $post->custom_id; } $r .= '<a href="' . get_invoice_permalink($post->{$column}) . '" target="_blank">'.apply_filters("wpi_attribute_{$column}", $invoice_id ,$post).'</a>'; break; case 'post_status': $r .= get_post_status_object($post->post_status)->label; break; case 'user_email': //** Get User Edit Link */ if(class_exists('WP_CRM_Core')) { $edit_user_url = admin_url("admin.php?page=wp_crm_add_new&user_id={$post->user_data['ID']}"); } else { $edit_user_url = admin_url("user-edit.php?user_id={$post->user_data['ID']}"); } $r .= '<ul>'; $r .= '<li><a href="'.$edit_user_url.'">' . $post->user_data['display_name'] . '</a></li>'; $r .= '<li>' . $post->user_data['user_email'] . '</li>'; $r .= '</ul>'; break; case 'type': $r .= $wpi_settings['types'][$post->type]['label']; break; case 'total': if ( !empty( $post->subtotal ) ) { if ( $post->type != 'single_payment' ) { $r .= (!empty($wpi_settings['currency']['symbol'][$post->default_currency_code])?$wpi_settings['currency']['symbol'][$post->default_currency_code]:'$') . wp_invoice_currency_format( !empty( $post->total_payments )?$post->total_payments:0 ) ." <span style='color:#aaaaaa;'>" . __('of', WPI) ." ". (!empty($wpi_settings['currency']['symbol'][$post->default_currency_code])?$wpi_settings['currency']['symbol'][$post->default_currency_code]:'$') . wp_invoice_currency_format($post->subtotal-(!empty($post->total_discount)?$post->total_discount:0)+(!empty($post->total_tax)?$post->total_tax:0)) ."</span>"; } else { $r .= (!empty($wpi_settings['currency']['symbol'][$post->default_currency_code])?$wpi_settings['currency']['symbol'][$post->default_currency_code]:'$') . wp_invoice_currency_format( !empty( $post->total_payments )?$post->total_payments:0 ); } } else { $r .= (!empty($wpi_settings['currency']['symbol'][$post->default_currency_code])?$wpi_settings['currency']['symbol'][$post->default_currency_code]:'$') . wp_invoice_currency_format(0); } break; default: $r .= apply_filters("wpi_attribute_{$column}", $post->{$column}, $post); break; } //** Need to insert some sort of space in there to avoid DataTable error that occures when "null" is returned */ $ajax_cells[] = $r; $result .= $r; $result .= "</td>"; } $result .= '</tr>'; if($this->_args['ajax']) { return $ajax_cells; } return $result; }
/** * 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 $wpdb, $invoice_id, $wpi_user_id, $wpi_settings, $wpi_invoice_object, $post; //** 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 ($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(mysql_escape_string($_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"); $wpi_invoice_object->data; 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; } // 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'); //** 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('jquery', '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')); if ( $wpi_settings['where_to_display'] == 'replace_tag' ) { add_shortcode('wp-invoice', array('WPI_UI', 'the_content_shortcode')); } } 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'])) { header("location:" . get_invoice_permalink($_POST['wp_invoice_lookup_input'])); //exit; } }
/** * Sends required notifications * * @global array $wpi_settings * * @param array $invoice * * @author korotkov@UD * @refactoring odokienko@UD */ function send_notification($invoice) { global $wpi_settings; if (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true' || !empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true' || !empty($wpi_settings['send_invoice_creator_email']) && $wpi_settings['send_invoice_creator_email'] == 'true') { $paid_invoice = new WPI_Invoice(); $paid_invoice->load_invoice("id={$invoice['invoice_id']}"); $invoice = $paid_invoice->data; $notification_data['invoice_id'] = !empty($invoice['custom_id']) ? $invoice['custom_id'] : $invoice['invoice_id']; $notification_data['invoice_title'] = $invoice['post_title']; $notification_data['from'] = stripslashes(get_option('admin_email')); $notification_data['permalink'] = get_invoice_permalink($invoice['invoice_id']); $notification_data['business_name'] = $wpi_settings['business_name']; $notification_data['site'] = stripslashes($wpi_settings['business_name']); $notification_data['user_email'] = $invoice['user_data']['user_email']; $notification_data['user_name'] = wpi_get_user_display_name($invoice); $notification_data['user_id'] = $invoice['user_data']['ID']; $admin = get_user_by('email', get_option('admin_email')); $notification_data['admin_email'] = stripslashes($admin->user_email); $notification_data['admin_id'] = $admin->ID; $notification_data['admin_name'] = stripslashes($admin->display_name); $creator = get_userdata($invoice['post_author']); $notification_data['creator_email'] = stripslashes($creator->user_email); $notification_data['creator_name'] = stripslashes($creator->display_name); $notification_data['creator_id'] = $creator->ID; $notification_data['total'] = $invoice['subtotal'] - $invoice['total_discount'] + $invoice['total_tax']; $notification_data['default_currency_code'] = $invoice['default_currency_code']; $notification_data['total_payments'] = $invoice['total_payments']; //** If we are going to change our Mail From */ if (!empty($wpi_settings['change_mail_from']) && $wpi_settings['change_mail_from'] == 'true') { add_filter('wp_mail_from', array('WPI_Functions', 'notification_mail_from')); add_filter('wp_mail_from_name', array('WPI_Functions', 'notification_mail_from_name')); } /** Email client */ if (!empty($wpi_settings['send_thank_you_email']) && $wpi_settings['send_thank_you_email'] == 'true') { wp_invoice_send_email_receipt($invoice, $notification_data); } /** Email site admin */ if (!empty($wpi_settings['cc_thank_you_email']) && $wpi_settings['cc_thank_you_email'] == 'true') { wp_invoice_send_me_notification($invoice, $notification_data); } /** Email invoice creator */ if (!empty($wpi_settings['send_invoice_creator_email']) && $wpi_settings['send_invoice_creator_email'] == 'true') { wp_invoice_send_creator_notification($invoice, $notification_data); } remove_filter('wp_mail_from', array('WPI_Functions', 'notification_mail_from')); remove_filter('wp_mail_from_name', array('WPI_Functions', 'notification_mail_from_name')); } }