/**
 * 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);
}
Exemple #2
0
/**
 * 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'));
    }
}