コード例 #1
0
/**
 * Emails user after payment is done
 * 
 * @param array $invoice
 * @author korotkov@ud
 * 
 * @todo Refactor message text to be loaded from editable templates from settings.
 */
function wp_invoice_send_email_receipt($invoice) {
  global $wpi_settings;

  $post_id = wpi_invoice_id_to_post_id($invoice['invoice_id']);

  $name = stripslashes($wpi_settings['business_name']);
  $from = stripslashes($wpi_settings['email_address']);

  $permalink = get_invoice_permalink($invoice['invoice_id']);

  $headers = "From: {$name} <{$from}>\r\n";

  $message = sprintf(
    __("Dear %1s,\n%2s has received your payment for the invoice.\n\nYou can overview invoice status and payment history by clicking this link:\n%3s\n\nThank you very much for your patronage.\n\nBest regards,\n%4s (%5s)", WPI),
    wpi_get_user_display_name($invoice),
    $wpi_settings['business_name'],
    $permalink,
    $name,
    $from
  );

  $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');

  if (wp_mail($invoice['user_data']['user_email'], $subject, $message, $headers)) {
    WPI_Functions::log_event($post_id, 'invoice', 'emailed', '', __('Receipt eMailed', WPI));
  }

  return $message;
}
コード例 #2
0
 /**
  * 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&note={$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();
     }
 }
コード例 #3
0
ファイル: class_wpi_paypal.php プロジェクト: JSpier/smacamp
 /**
  * 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&note={$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&note={$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&note={$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&note={$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&note={$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 ' ';
     }
 }
コード例 #4
0
  /**
   * This function sends our our notifications from the admin screen
   * @since 3.0
   */
  function send_notification(){
    //** Setup, and send our e-mail */
    $headers = "From: ".get_bloginfo()." <".get_bloginfo('admin_email').">\r\n";
    $message = html_entity_decode($_REQUEST['body'], ENT_QUOTES, 'UTF-8');
    $subject = html_entity_decode($_REQUEST['subject'], ENT_QUOTES, 'UTF-8');
    $to = $_REQUEST['to'];

    //** Validate for empty fields data */
    if(empty($to) || empty($subject) || empty($message)) {
      die(json_encode(array("status" => 500, "msg" => __("The fields should not be empty. Please, check the fields data and try to send notification again.", WPI))));
    }

    if (wp_mail($to, $subject, $message, $headers)) {
      $pretty_time = date(get_option('time_format') . " " . get_option('date_format'));
      $text = __("Notification Sent", WPI).(isset($_REQUEST['template']) && !empty($_REQUEST['template']) ? " (".$_REQUEST['template'].")" : "")." ".__('to', WPI)." {$to} ".__('at', WPI)." {$pretty_time}.";
      WPI_Functions::log_event(wpi_invoice_id_to_post_id($_REQUEST['invoice_id']), 'invoice', 'notification', '', $text, time());
      die(json_encode(array("status" => 200, "msg" => __("Successfully sent the invoice notification!", WPI))));
    }
    die(json_encode(array("status" => 500, "msg" => __("Unable to send the e-mail. Please, try again later.", WPI))));
  }
コード例 #5
0
ファイル: wpi_invoice.php プロジェクト: JSpier/smacamp
 /**
  * This is a cruicial function.
  * In addition to basic events it also tracks amounts paid, reimburshed, etc
  *
  * Structure:
  * - timestamp
  * - event_type
  * - amount_paid (sum of these is used to calculate if money is still owed)
  * - basic_event
  * - event_note
  */
 function add_entry($args = '')
 {
     global $wpdb;
     if (!empty($this->data['ID'])) {
         $ID = $this->data['ID'];
     } else {
         if (!empty($this->data['invoice_id'])) {
             $ID = $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'invoice_id' AND meta_value = '{$this->data['invoice_id']}'");
         }
     }
     if (empty($ID)) {
         return false;
     }
     extract(wp_parse_args($args, array('type' => 'update', 'attribute' => 'invoice', 'amount' => '', 'note' => '', 'time' => time())), EXTR_SKIP);
     return WPI_Functions::log_event($ID, $attribute, $type, $amount, $note, $time);
 }
コード例 #6
0
 /**
  * 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&note={$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&note={$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&note={$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;
             }
         }
     }
 }
コード例 #7
0
ファイル: wpi_ajax.php プロジェクト: JSpier/smacamp
 /**
  * This function sends our our notifications from the admin screen
  */
 static function send_notification()
 {
     global $wpi_settings;
     //** Start buffering to avoid appearing any errors in response */
     ob_start();
     //** Setup, and send our e-mail */
     $headers = "From: " . get_bloginfo() . " <" . get_bloginfo('admin_email') . ">\r\n";
     $message = html_entity_decode($_REQUEST['body'], ENT_QUOTES, 'UTF-8');
     $subject = html_entity_decode($_REQUEST['subject'], ENT_QUOTES, 'UTF-8');
     $to = $_REQUEST['to'];
     //** Validate for empty fields data */
     if (empty($to) || empty($subject) || empty($message)) {
         ob_end_clean();
         die(json_encode(array("status" => 500, "msg" => __("The fields should not be empty. Please, check the fields data and try to send notification again.", WPI))));
     }
     //** 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'));
     }
     if (wp_mail($to, $subject, $message, $headers)) {
         $pretty_time = date(get_option('time_format') . " " . get_option('date_format'));
         $text = __("Notification Sent", WPI) . (isset($_REQUEST['template']) && !empty($_REQUEST['template']) ? " (" . $_REQUEST['template'] . ")" : "") . " " . __('to', WPI) . " {$to} " . __('at', WPI) . " {$pretty_time}.";
         WPI_Functions::log_event(wpi_invoice_id_to_post_id($_REQUEST['invoice_id']), 'invoice', 'notification', '', $text, time());
         ob_end_clean();
         die(json_encode(array("status" => 200, "msg" => __("Successfully sent the invoice notification!", WPI))));
     }
     ob_end_clean();
     die(json_encode(array("status" => 500, "msg" => __("Unable to send the e-mail. Please, try again later.", WPI))));
 }
コード例 #8
0
ファイル: wpi_functions.php プロジェクト: JSpier/smacamp
/**
 * Emails user after payment is done
 *
 * @param array $invoice
 *
 * @author korotkov@ud
 * @refactoring odokienko@UD
 */
function wp_invoice_send_email_receipt($invoice, $notification_data)
{
    global $wpi_settings;
    $subject = sprintf(__("Invoice #%s has been paid", WPI), $notification_data['invoice_id']);
    $headers = array("From: {$notification_data['business_name']} <{$notification_data['from']}>\r\n", "Content-Type: text/html");
    $message = sprintf(__("Dear %1s,<br>%2s has received your payment for the invoice.<br><br>You can overview invoice status and payment history by clicking this link:<br>%3s<br><br>Thank you very much for your patronage.<br><br>Best regards,<br>%4s (%5s)", WPI), $notification_data['user_name'], $notification_data['business_name'], $notification_data['permalink'], $notification_data['business_name'], $notification_data['from']);
    /**
     * @todo add condition witch will be look at this option odokienko@UD
     */
    if (function_exists('wp_crm_send_notification') && !empty($wpi_settings['use_wp_crm_to_send_notifications']) && $wpi_settings['use_wp_crm_to_send_notifications'] == 'true') {
        wp_crm_send_notification('wpi_send_thank_you_email', $notification_data);
        //** Add message to user activity stream */
        wp_crm_add_to_user_log($notification_data['user_id'], sprintf(__("WP-Invoice: Message with subject '%1s' was sent", WPI), $subject), false, array('attribute' => 'wpi_notification'));
    } else {
        $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
        $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
        if (wp_mail("{$notification_data['user_name']} <{$notification_data['user_email']}>", $subject, $message, implode("\r\n", (array) $headers) . "\r\n")) {
            WPI_Functions::log_event($notification_data['invoice_id'], 'invoice', 'emailed', '', __('Receipt eMailed', WPI));
        }
    }
    return $message;
}