コード例 #1
0
ファイル: order.class.php プロジェクト: JohnToro/paypal
 /**
  *   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));
             }
         }
     }
 }
コード例 #2
0
ファイル: index.php プロジェクト: JohnToro/paypal
     $ppGCart->setAddress($_POST, $addr_type);
     break;
 case 'addcartitem':
 case 'addcartitem_x':
     // using the image submit button, such as Paypal's
     USES_paypal_class_cart();
     $view = 'productlist';
     if (isset($_POST['_unique']) && $_POST['_unique'] && $ppGCart->Contains($_POST['item_number']) !== false) {
         break;
     }
     $qty = isset($_POST['quantity']) ? (double) $_POST['quantity'] : 1;
     $ppGCart->addItem($_POST['item_number'], $_POST['item_name'], $_POST['item_descr'], $qty, $_POST['amount'], $_POST['options'], $_POST['extras']);
     if (isset($_POST['_ret_url'])) {
         COM_refresh($_POST['_ret_url']);
         exit;
     } elseif (PAYPAL_is_plugin_item(${$_POST}['item_number'])) {
         COM_refresh(PAYPAL_URL);
         exit;
     } else {
         COM_refresh(PAYPAL_URL . '/detail.php?id=' . $_POST['item_number']);
         exit;
     }
     break;
 case 'delcartitem':
     $ppGCart->Remove($_GET['id']);
     /*if (isset($_SESSION[PP_CART_VAR]['order_id']) &&
           !empty($_SESSION[PP_CART_VAR]['order_id'])) {
           //USES_paypal_class_order();
           //ppOrder::delCartItem($_GET['id'], $_SESSION[PP_CART_VAR]['order_id']);
           $ppGCart->Remove($_GET['id']);
       }*/
コード例 #3
0
ファイル: paymentgw.class.php プロジェクト: JohnToro/paypal
 /**
  *   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']);
     }
 }
コード例 #4
0
ファイル: BaseIPN.class.php プロジェクト: NewRoute/paypal
 /**
  *   Process a refund.
  *   If a purchase is completely refunded, then call the plugins to
  *   handle the refund.  Otherwise, do nothing; partial refunds need to
  *   be handled manually.
  *
  *   @todo: handle partial refunds
  */
 protected function handleRefund()
 {
     global $_TABLES, $_CONF, $_PP_CONF, $LANG_PP;
     // Try to get original order information.  Use the "parent transaction"
     // or invoice number, if available from the IPN message
     if (isset($this->pp_data['invoice'])) {
         $order_id = $this->pp_data['invoice'];
     } else {
         $order_id = DB_getItem($_TABLES['paypal.orders'], 'order_id', "pmt_txn_id = '" . DB_escapeString($this->pp_data['parent_txn_id']) . "'");
     }
     $Order = new ppOrder($order_id);
     if ($Order->order_id == '') {
         return false;
     }
     // Figure out if the entire order was refunded
     $refund_amt = abs((double) $this->pp_data['pmt_gross']);
     $item_total = 0;
     foreach ($Order->items as $key => $data) {
         $item_total += $data['quantity'] * $data['price'];
     }
     $item_total += $Order->miscCharges();
     if ($item_total == $refund_amt) {
         // Completely refunded, let the items handle any refund
         // actions.  None for catalog items (since there's no inventory,
         // but plugin items may need to do something.
         foreach ($Order->items as $key => $data) {
             if (PAYPAL_is_plugin_item($data['product_id'])) {
                 // Split the item number into component parts.  It could
                 // be just a single string, depending on the plugin's needs.
                 if (strstr($data['product_id'], ':')) {
                     $pi_info = split(':', $data['product_id']);
                 } else {
                     $pi_info = array($data['product_id']);
                 }
                 $vars = array('item' => $pi_info, 'ipn_data' => $this->pp_data);
                 $status = LGLIB_invokeService($pi_info[0], 'handleRefund', $vars, $output, $svc_msg);
                 // Don't care about the status, really.  May not even be
                 // a plugin function to handle refunds
             }
         }
         // Update the order status to Refunded
         $Order->UpdateStatus($LANG_PP['orderstatus']['refunded']);
     }
 }