/** * Send an email to the buyer * * @param string $status Order status (pending, paid, etc.) * @param string $msg Optional message to include with email */ public function Notify($status = '', $gw_msg = '') { global $_CONF, $_PP_CONF, $_TABLES; // Check if we're supposed to send a notification if ($this->uid != 1 && $_PP_CONF['purch_email_user'] || $this->uid == 1 && $_PP_CONF['purch_email_anon']) { PAYPAL_debug("Sending email to " . $this->uid); // setup templates $message = new Template(PAYPAL_PI_PATH . '/templates'); $message->set_file(array('subject' => 'purchase_email_subject.txt', 'msg_admin' => 'purchase_email_admin.txt', 'msg_user' => 'purchase_email_user.txt', 'msg_body' => 'purchase_email_body.txt')); // Add all the items to the message $total = (double) 0; // Track total purchase value $files = array(); // Array of filenames, for attachments $num_format = "%5.2f"; $item_total = 0; $have_physical = 0; // Assume no physical items. $dl_links = ''; // Start with empty download links USES_paypal_class_product(); foreach ($this->items as $id => $item) { if (!PAYPAL_is_plugin_item($item['product_id'])) { $P = new Product($item['product_id']); if ($P->prod_type & PP_PROD_PHYSICAL == PP_PROD_PHYSICAL) { $have_physical = 1; } // Add the file to the filename array, if any. Download // links are only included if the order status is 'paid' $file = $P->file; if (!empty($file) && $this->status == 'paid') { $files[] = $file; $dl_url = PAYPAL_URL . '/download.php?'; // There should always be a token, but fall back to the // product ID if there isn't if (!empty($item['token'])) { $dl_url .= 'token=' . urlencode($item['token']); } else { $dl_url .= 'id=' . $item['item_number']; } $dl_links .= "<a href=\"{$dl_url}\">{$dl_url}</a><br />"; } } $ext = (double) $item['quantity'] * (double) $item['price']; $item_total += $ext; $item_descr = isset($item['description']) ? $item['description'] : $item['descrip']; //$message->set_block('message', 'ItemList', 'List'); $opts = json_decode($item['options_text'], true); if ($opts) { foreach ($opts as $opt_text) { $options_text .= " -- {$opt_text}<br />"; } } $message->set_block('msg_body', 'ItemList', 'List'); $message->set_var(array('qty' => $item['quantity'], 'price' => sprintf($num_format, $item['price']), 'ext' => sprintf($num_format, $ext), 'name' => $item_descr, 'options_text' => $options_text)); //PAYPAL_debug("Qty: {$item['quantity']} : Amount: {$item['price']} : Name: {$item['name']}", 'debug_ipn'); $message->parse('List', 'ItemList', true); } // Determine if files will be attached to this message based on // global config and whether there are actually any files to // attach. Affects the 'files' flag in the email template and // which email function is used. if ((is_numeric($this->uid) && $this->uid != 1 && $_PP_CONF['purch_email_user_attach'] || (!is_numeric($this->uid) || $this->uid == 1) && $_PP_CONF['purch_email_anon_attach']) && count($files) > 0) { $do_send_attachments = true; } else { $do_send_attachments = false; } $total_amount = $item_total + $this->tax + $this->shipping + $this->handling; $user_name = COM_getDisplayName($this->uid); if ($this->billto_name == '') { $this->billto_name = $user_name; } $message->set_var(array('payment_gross' => sprintf($num_format, $total_amount), 'payment_items' => sprintf($num_format, $item_total), 'tax' => sprintf($num_format, $this->tax), 'shipping' => sprintf($num_format, $this->shipping), 'handling' => sprintf($num_format, $this->handling), 'payment_date' => $_PP_CONF['now']->toMySQL(true), 'payer_email' => $this->buyer_email, 'payer_name' => $this->billto_name, 'site_name' => $_CONF['site_name'], 'txn_id' => $this->pmt_txn_id, 'pi_url' => PAYPAL_URL, 'pi_admin_url' => PAYPAL_ADMIN_URL, 'dl_links' => $dl_links, 'files' => $do_send_attachments ? 'true' : '', 'buyer_uid' => $this->uid, 'user_name' => $user_name, 'gateway_name' => $this->pmt_method, 'pending' => $this->status == 'pending' ? 'true' : '', 'gw_msg' => $gw_msg, 'status' => $this->status, 'order_instr' => $this->instructions)); // parse templates for subject/text $subject = trim($message->parse('output', 'subject')); $message->set_var('purchase_details', $message->parse('detail', 'msg_body')); $user_text = $message->parse('user_out', 'msg_user'); $admin_text = $message->parse('admin_out', 'msg_admin'); if ($this->buyer_email != '') { // if specified to mail attachment, do so, otherwise skip // attachment if ($do_send_attachments) { // Make sure plugin functions are available USES_paypal_functions(); PAYPAL_mailAttachment($this->buyer_email, $subject, $user_text, $_CONF['site_email'], true, 0, '', '', $files); } else { // Otherwise send a standard notification COM_emailNotification(array('to' => array($this->buyer_email), 'from' => $_CONF['site_mail'], 'htmlmessage' => $user_text, 'subject' => $subject)); } } // Send a notification to the administrator, new purchases only if ($status == '') { if ($_PP_CONF['purch_email_admin'] == 2 || $have_physical && $_PP_CONF['purch_email_admin'] == 1) { PAYPAL_debug('Sending email to Admin'); $email_addr = empty($_PP_CONF['admin_email_addr']) ? $_CONF['site_mail'] : $_PP_CONF['admin_email_addr']; COM_emailNotification(array('to' => array($email_addr), 'from' => $_CONF['noreply_mail'], 'htmlmessage' => $admin_text, 'subject' => $subject)); } } } }
/** * Send the customer an email notification. * This function is also responsible for sending purchased files as * attachments. * * @deprecated * @see Order::Notify() */ protected function sendNotification() { global $_CONF, $_PP_CONF; // Check if we're supposed to send a notification if ($this->pp_data['custom']['uid'] != 1 && $_PP_CONF['purch_email_user'] || $this->pp_data['custom']['uid'] == 1 && $_PP_CONF['purch_email_anon']) { PAYPAL_debug("Sending email to " . $this->pp_data['custom']['uid']); // setup templates $message = new Template(PAYPAL_PI_PATH . '/templates'); $message->set_file(array('subject' => 'purchase_email_subject.txt', 'msg_admin' => 'purchase_email_admin.txt', 'msg_user' => 'purchase_email_user.txt', 'msg_body' => 'purchase_email_body.txt')); // Add all the items to the message $total = (double) 0; // Track total purchase value $files = array(); // Array of filenames, for attachments $num_format = "%5.2f"; $item_total = 0; $have_physical = 0; // Assume no physical items. $dl_links = ''; // Start with empty download links foreach ($this->items as $id => $item) { if ($item['prod_type'] & PP_PROD_PHYSICAL == PP_PROD_PHYSICAL) { $have_physical = 1; } $ext = (double) $item['quantity'] * (double) $item['price']; $item_total += $ext; $item_descr = $item['name']; $message->set_block('msg_body', 'ItemList', 'List'); $message->set_var(array('qty' => $item['quantity'], 'price' => sprintf($num_format, $item['price']), 'ext' => sprintf($num_format, $ext), 'name' => $item_descr)); PAYPAL_debug("Qty: {$item['quantity']} : Amount: {$item['price']} : Name: {$item['name']}", 'debug_ipn'); $message->parse('List', 'ItemList', true); // Add the file to the filename array, if any if (!empty($item['file']) && $this->pp_data['status'] == 'paid') { $files[] = $item['file']; $dl_url = PAYPAL_URL . '/download.php?'; // There should always be a token, but fall back to the // product ID if there isn't if (!empty($item['token'])) { $dl_url .= 'token=' . urlencode($item['token']); } else { $dl_url .= 'id=' . $item['item_number']; } $dl_links .= "<p /><a href=\"{$dl_url}\">{$dl_url}</a>"; } } if (!empty($files)) { $message->set_var('files', 'true'); } $gw_msg = sprintf($LANG_PP['pmt_made_via'], $this->pp_data['gw_name'], $this->pp_data['pmt_date']); $message->set_var(array('payment_gross' => sprintf('%6.2f', $this->pp_data['pmt_gross']), 'payment_items' => sprintf('%6.2f', $item_total), 'tax' => sprintf('%6.2f', $this->pp_data['pmt_tax']), 'shipping' => sprintf('%6.2f', $this->pp_data['pmt_shipping']), 'handling' => sprintf('%6.2f', $this->pp_data['pmt_handling']), 'payment_date' => $this->pp_data['pmt_date'], 'payer_email' => $this->pp_data['payer_email'], 'payer_name' => $this->pp_data['payer_name'], 'site_url' => $_CONF['site_url'], 'site_name' => $_CONF['site_name'], 'txn_id' => $this->pp_data['txn_id'], 'pi_url' => PAYPAL_URL, 'pi_admin_url' => PAYPAL_ADMIN_URL, 'dl_links' => $dl_links, 'buyer_uid' => $this->pp_data['custom']['uid'], 'user_name' => COM_getDisplayName($this->pp_data['custom']['uid']), 'gateway_name' => isset($this->pp_data['gw_name']) ? $this->pp_data['gw_name'] : 'PayPal', 'pending' => $this->pp_data['status'] == 'pending' ? 'true' : '', 'gw_msg' => $gw_msg)); // parse templates for subject/text $subject = trim($message->parse('output', 'subject')); $message->set_var('purchase_details', $message->parse('detail', 'msg_body')); $user_text = $message->parse('user_out', 'msg_user'); $admin_text = $message->parse('admin_out', 'msg_admin'); // if specified to mail attachment, do so, otherwise skip attachment if ((is_numeric($this->pp_data['custom']['uid']) && $this->pp_data['custom']['uid'] != 1 && $_PP_CONF['purch_email_user_attach'] || (!is_numeric($this->pp_data['custom']['uid']) || $this->pp_data['custom']['uid'] == 1) && $_PP_CONF['purch_email_anon_attach']) && count($files) > 0) { // Make sure plugin functions are available USES_paypal_functions(); PAYPAL_mailAttachment($this->pp_data['payer_email'], $subject, $user_text, $_CONF['site_email'], true, 0, '', '', $files); } else { COM_mail($this->pp_data['payer_email'], $subject, $user_text, $_CONF['site_email'], true); } // Send a notification to the administrator if ($_PP_CONF['purch_email_admin'] == 2 || $have_physical && $_PP_CONF['purch_email_admin'] == 1) { PAYPAL_debug('Sending email to Admin'); $email_addr = empty($_PP_CONF['admin_email_addr']) ? $_CONF['site_mail'] : $_PP_CONF['admin_email_addr']; COM_mail($email_addr, $subject, $admin_text, '', true); } } }