Example #1
0
 /**
  *   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 .= "&nbsp;&nbsp;--&nbsp;{$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));
             }
         }
     }
 }
Example #2
0
 /**
  *   Processes the purchase, for purchases made without an IPN message.
  *
  *   @param  array   $vals   Submitted values, e.g. $_POST
  */
 public function handlePurchase($vals = array())
 {
     global $_TABLES, $_CONF, $_PP_CONF;
     USES_paypal_functions();
     USES_paypal_class_cart();
     USES_paypal_class_order();
     USES_paypal_class_product();
     if (!empty($vals['cart_id'])) {
         $cart = new ppCart($vals['cart_id']);
         if (!$cart->hasItems()) {
             return;
         }
         // shouldn't be empty
         $items = $cart->Cart();
     } else {
         $cart = new ppCart();
     }
     // Create an order record to get the order ID
     $Order = $this->CreateOrder($vals, $cart);
     $db_order_id = DB_escapeString($Order->order_id);
     $prod_types = 0;
     // For each item purchased, record purchase in purchase table
     foreach ($items as $id => $item) {
         //COM_errorLog("Processing item: $id");
         list($item_number, $item_opts) = PAYPAL_explode_opts($id, true);
         // If the item number is numeric, assume it's an
         // inventory item.  Otherwise, it should be a plugin-supplied
         // item with the item number like pi_name:item_number:options
         if (PAYPAL_is_plugin_item($item_number)) {
             PAYPAL_debug("handlePurchase for Plugin item " . $item_number);
             // Initialize item info array to be used later
             $A = array();
             // Split the item number into component parts.  It could
             // be just a single string, depending on the plugin's needs.
             $pi_info = explode(':', $item['item_number']);
             PAYPAL_debug('Paymentgw::handlePurchase() pi_info: ' . print_r($pi_info, true));
             $status = LGLIB_invokeService($pi_info[0], 'productinfo', array($item_number, $item_opts), $product_info, $svc_msg);
             if ($status != PLG_RET_OK) {
                 $product_info = array();
             }
             if (!empty($product_info)) {
                 $items[$id]['name'] = $product_info['name'];
             }
             PAYPAL_debug("Paymentgw::handlePurchase() Got name " . $items[$id]['name']);
             $vars = array('item' => $item, 'ipn_data' => array());
             $status = LGLIB_invokeService($pi_info[0], 'handlePurchase', $vars, $A, $svc_msg);
             if ($status != PLG_RET_OK) {
                 $A = array();
             }
             // Mark what type of product this is
             $prod_types |= PP_PROD_VIRTUAL;
         } else {
             PAYPAL_debug("Paypal item " . $item_number);
             $P = new Product($item_number);
             $A = array('name' => $P->name, 'short_description' => $P->short_description, 'expiration' => $P->expiration, 'prod_type' => $P->prod_type, 'file' => $P->file, 'price' => $item['price']);
             if (!empty($item_opts)) {
                 $opts = explode(',', $itemopts);
                 $opt_str = $P->getOptionDesc($opts);
                 if (!empty($opt_str)) {
                     $A['short_description'] .= " ({$opt_str})";
                 }
                 $item_number .= '|' . $item_opts;
             }
             // Mark what type of product this is
             $prod_types |= $P->prod_type;
         }
         // An invalid item number, or nothing returned for a plugin
         if (empty($A)) {
             //$this->Error("Item {$item['item_number']} not found");
             continue;
         }
         // If it's a downloadable item, then get the full path to the file.
         // TODO: pp_data isn't available here, should be from $vals?
         if (!empty($A['file'])) {
             $this->items[$id]['file'] = $_PP_CONF['download_path'] . $A['file'];
             $token_base = $this->pp_data['txn_id'] . time() . rand(0, 99);
             $token = md5($token_base);
             $this->items[$id]['token'] = $token;
         } else {
             $token = '';
         }
         $items[$id]['prod_type'] = $A['prod_type'];
         // If a custom name was supplied by the gateway's IPN processor,
         // then use that.  Otherwise, plug in the name from inventory or
         // the plugin, for the notification email.
         if (empty($item['name'])) {
             $items[$id]['name'] = $A['short_description'];
         }
         // Add the purchase to the paypal purchase table
         $uid = isset($vals['uid']) ? (int) $vals['uid'] : $_USER['uid'];
         $sql = "INSERT INTO {$_TABLES['paypal.purchases']} SET \n                        order_id = '{$db_order_id}',\n                        product_id = '{$item_number}',\n                        description = '{$items[$id]['name']}',\n                        quantity = '{$item['quantity']}', \n                        user_id = '{$uid}', \n                        txn_type = '{$this->gw_id}',\n                        txn_id = '', \n                        purchase_date = '{$_PP_CONF['now']->toMySQL()}', \n                        status = 'complete',\n                        token = '{$token}',\n                        price = " . (double) $item['price'] . ",\n                        options = '" . DB_escapeString($item_opts) . "'";
         // add an expiration date if appropriate
         if (is_numeric($A['expiration']) && $A['expiration'] > 0) {
             $sql .= ", expiration = DATE_ADD('{$_PP_CONF['now']->toMySQL()}', INTERVAL {$A['expiration']} DAY)";
         }
         //echo $sql;die;
         PAYPAL_debug($sql);
         DB_query($sql);
     }
     // foreach item
     // If this was a user's cart, then clear that also
     if (isset($vals['cart_id']) && !empty($vals['cart_id'])) {
         DB_delete($_TABLES['paypal.cart'], 'cart_id', $vals['cart_id']);
     }
 }
Example #3
0
*   @version    0.5.0
*   @license    http://opensource.org/licenses/gpl-2.0.php 
*               GNU Public License v2 or later
*   @filesource
*/
/** Require core glFusion code */
require_once '../lib-common.php';
// If plugin is installed but not enabled, display an error and exit gracefully
if (!in_array('paypal', $_PLUGINS)) {
    COM_404();
    exit;
}
/* Ensure sufficient privs to read this page */
paypal_access_check();
// Import plugin-specific functions
USES_paypal_functions();
// Create a global shopping cart for our use.  This allows the cart to be
// manipulated in an action and then displayed in a view, without necessarily
// having to revisit the database or create a new cart.
USES_paypal_class_cart();
$ppGCart = new ppCart();
COM_setArgNames(array('id'));
if (isset($_GET['id'])) {
    $id = COM_sanitizeID($_GET['id']);
} else {
    $id = COM_applyFilter(COM_getArgument('id'));
}
$display = PAYPAL_siteHeader();
$T = new Template(PAYPAL_PI_PATH . '/templates');
$T->set_file('title', 'paypal_title.thtml');
$T->set_var('title', $LANG_PP['main_title']);
Example #4
0
 /**
  *   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);
         }
     }
 }