예제 #1
0
파일: index.php 프로젝트: JohnToro/paypal
 case 'orderhist':
 case 'history':
     if (COM_isAnonUser()) {
         COM_404();
     }
     $content .= PAYPAL_orders();
     $menu_opt = $LANG_PP['purchase_history'];
     $page_title = $LANG_PP['purchase_history'];
     break;
 case 'billto':
 case 'shipto':
     if (COM_isAnonUser()) {
         COM_404();
     }
     USES_paypal_class_userinfo();
     $U = new ppUserInfo();
     $A = isset($_POST['address1']) ? $_POST : $ppGCart->getAddress($view);
     $content .= $U->AddressForm($view, $A);
     break;
 case 'order':
     if (COM_isAnonUser()) {
         COM_404();
     }
     USES_paypal_class_order();
     $order = new ppOrder($actionval);
     if ($order->canView()) {
         $content .= $order->View(true);
     } else {
         $content .= $LANG_PP['access_denied_msg'];
     }
     break;
예제 #2
0
 /**
  *   Set shipping address
  *
  *   @param  array   $A      Array of info, such as from $_POST
  */
 public function setShipping($A)
 {
     USES_paypal_class_userinfo();
     if (isset($A['useaddress'])) {
         // If set, read and use an existing address
         $_SESSION[PP_CART_VAR]['shipping'] = $A['useaddress'];
         $A = ppUserInfo::getAddress($A['useaddress']);
         $prefix = '';
     } else {
         // form vars have this prefix
         $prefix = 'shipto_';
     }
     if (!empty($A)) {
         $this->shipto_name = $A['name'];
         $this->shipto_company = $A['company'];
         $this->shipto_address1 = $A['address1'];
         $this->shipto_address2 = $A['address2'];
         $this->shipto_city = $A['city'];
         $this->shipto_state = $A['state'];
         $this->shipto_country = $A['country'];
         $this->shipto_zip = $A['zip'];
     }
 }
예제 #3
0
 /**
  *   Create and populate an Order record for this purchase.
  *   Gets the billto and shipto addresses from the cart, if any.
  *   Items are saved in the purchases table by handlePurchase().
  *
  *   This function is called only by our own handlePurchase() function,
  *   but is made "protected" so a derived class can use it if necessary.
  *
  *   @return string  Order ID, to link to the purchases table
  */
 protected function CreateOrder()
 {
     global $_TABLES, $_PP_CONF;
     // See if an order already exists for this transaction.
     // If so, load it and update the status. If not, continue on
     // and create a new order
     $order_id = DB_getItem($_TABLES['paypal.orders'], 'order_id', "pmt_txn_id='" . DB_escapeString($this->pp_data['txn_id']) . "'");
     if (!empty($order_id)) {
         $this->Order = new ppOrder($order_id);
         if ($this->Order->order_id != '') {
             $this->Order->log_user = $this->gw->Description();
             $this->Order->UpdateStatus($this->pp_data['status']);
         }
         return 2;
     }
     $this->Order = new ppOrder();
     USES_paypal_class_cart();
     if (isset($this->pp_data['custom']['cart_id'])) {
         $cart = new ppCart($this->pp_data['custom']['cart_id']);
         if (!$_PP_CONF['sys_test_ipn'] && !$cart->hasItems()) {
             return 1;
             // shouldn't normally be empty except during testing
         }
     } else {
         $cart = NULL;
     }
     $uid = (int) $this->pp_data['custom']['uid'];
     $this->Order->uid = $uid;
     $this->Order->status = !empty($this->pp_data['status']) ? $this->pp_data['status'] : 'pending';
     if ($uid > 1) {
         USES_paypal_class_userinfo();
         $U = new ppUserInfo($uid);
     }
     // Get the billing and shipping addresses from the cart record,
     // if any.  There may not be a cart in the database if it was
     // removed by a previous IPN, e.g. this is the 'completed' message
     // and we already processed a 'pending' message
     if ($cart) {
         $BillTo = $cart->getAddress('billto');
     }
     if (empty($BillTo) && $uid > 1) {
         $BillTo = $U->getDefaultAddress('billto');
     }
     if (is_array($BillTo)) {
         $this->Order->setBilling($BillTo);
     }
     $ShipTo = $this->pp_data['shipto'];
     if (empty($ShipTo)) {
         if ($cart) {
             $ShipTo = $cart->getAddress('shipto');
         }
         if (empty($ShipTo) && $uid > 1) {
             $ShipTo = $U->getDefaultAddress('shipto');
         }
     }
     if (is_array($ShipTo)) {
         $this->Order->setShipping($ShipTo);
     }
     if (isset($this->pp_data['shipto']['phone'])) {
         $this->Order->phone = $this->pp_data['shipto']['phone'];
     }
     $this->Order->pmt_method = $this->gw_id;
     $this->Order->pmt_txn_id = $this->pp_data['txn_id'];
     $this->Order->tax = $this->pp_data['pmt_tax'];
     $this->Order->shipping = $this->pp_data['pmt_shipping'];
     $this->Order->handling = $this->pp_data['pmt_handling'];
     $this->Order->buyer_email = $this->pp_data['payer_email'];
     $this->Order->log_user = $this->gw->Description();
     $order_id = $this->Order->Save();
     $db_order_id = DB_escapeString($order_id);
     $this->Order->items = array();
     foreach ($this->items as $id => $item) {
         $options = DB_escapeString($item['options']);
         list($item_number, $options) = explode('|', $item['item_number']);
         //if (is_numeric($item['item_number'])) {
         if (is_numeric($item_number)) {
             // For Paypal catalog options, check for options and append
             // to the description.  Update quantity on hand if tracking
             // is enabled.  These actions don't apply to items from
             // other plugins.
             if (!empty($options)) {
                 // options is expected as CSV
                 $sql = "SELECT attr_value\n                            FROM {$_TABLES['paypal.prod_attr']}\n                            WHERE attr_id IN ({$options})";
                 $optres = DB_query($sql);
                 $opt_str = '';
                 while ($O = DB_fetchArray($optres, false)) {
                     $opt_str .= ', ' . $O['attr_value'];
                 }
                 $item['name'] .= $opt_str;
             }
             /*$sql = "UPDATE {$_TABLES['paypal.products']} SET
               onhand = GREATEST(0, onhand - " . 
                   (int)$item['quantity'] . ") 
               WHERE id = '" . (int)$item['item_number'] .
               "' AND track_onhand > 0";*/
             //COM_errorLog($sql);
             DB_query($sql, 1);
         }
         $sql = "INSERT INTO {$_TABLES['paypal.purchases']} SET \n                    order_id = '{$db_order_id}',\n                    product_id = '{$item['item_number']}',\n                    description = '" . DB_escapeString($item['name']) . "',\n                    quantity = '{$item['quantity']}', \n                    user_id = '{$this->pp_data['custom']['uid']}', \n                    txn_type = '{$this->pp_data['custom']['transtype']}',\n                    txn_id = '{$this->pp_data['txn_id']}', \n                    purchase_date = '{$this->sql_date}', \n                    status = 'pending',\n                    token = '" . md5(time()) . "',\n                    price = " . (double) $item['price'] . ",\n                    options = '{$options}'";
         // add an expiration date if appropriate
         if (is_numeric($item['expiration']) && $item['expiration'] > 0) {
             $sql .= ", expiration = DATE_ADD('{$_PP_CONF['now']}', INTERVAL {$item['expiration']} DAY)";
         }
         PAYPAL_debug($sql);
         DB_query($sql);
     }
     // foreach item
     // Reload the order to get the items
     $this->Order->Load();
     // If this was a user's cart, then clear that also
     if (isset($this->pp_data['custom']['cart_id']) && !empty($this->pp_data['custom']['cart_id'])) {
         if (!$_PP_CONF['sys_test_ipn']) {
             DB_delete($_TABLES['paypal.cart'], 'cart_id', $this->pp_data['custom']['cart_id']);
             PAYPAL_debug('Cart ' . $this->pp_data['custom']['cart_id'] . ' deleted');
         }
     } else {
         PAYPAL_debug('no cart to delete');
     }
     return 0;
 }