Example #1
0
 /**
  *   View the cart.
  *   This function shows the shopping cart, either with the quantity fields
  *   and option to update, or with the checkout buttons depending on the
  *   value of $checkout.
  *
  *   @uses   getCheckoutButtons()
  *   @param  boolean $checkout   True to indicate this is the final checkout
  *   @return string      HTML for the "view cart" form
  */
 public function View($checkout = false)
 {
     global $_CONF, $_PP_CONF, $_USER, $LANG_PP, $_TABLES, $_SYSTEM;
     USES_paypal_class_product();
     USES_paypal_class_currency();
     $currency = new ppCurrency();
     $T = new Template(PAYPAL_PI_PATH . '/templates');
     $tpltype = $_SYSTEM['framework'] == 'uikit' ? '.uikit' : '';
     $T->set_file('cart', $checkout ? "order{$tpltype}.thtml" : "viewcart{$tpltype}.thtml");
     if (!isset($this->m_cart) || empty($this->m_cart)) {
         return $LANG_PP['cart_empty'];
     }
     if ($checkout) {
         foreach ($_PP_CONF['workflows'] as $key => $value) {
             $T->set_var('have_' . $value, 'true');
             foreach ($this->_addr_fields as $fldname) {
                 $T->set_var($value . '_' . $fldname, $this->m_info[$value][$fldname]);
             }
         }
         $T->set_var('not_final', 'true');
     }
     $T->set_block('order', 'ItemRow', 'iRow');
     // Get the workflows so we show the relevant info.
     if (!isset($_PP_CONF['workflows']) || !is_array($_PP_CONF['workflows'])) {
         USES_paypal_class_workflow();
         ppWorkflow::Load();
     }
     $T->set_block('cart', 'ItemRow', 'iRow');
     $counter = 0;
     $subtotal = 0;
     $shipping = 0;
     foreach ($this->m_cart as $id => $item) {
         $counter++;
         $attr_desc = '';
         list($item_id, $attr_keys) = PAYPAL_explode_opts($item['item_id']);
         if (is_numeric($item_id)) {
             // a catalog item, get the "right" price
             $P = new Product($item_id);
             $item_price = $P->getPrice($attr_keys, $item['quantity']);
             if (!empty($attr_keys)) {
                 foreach ($attr_keys as $attr_key) {
                     if (!isset($P->options[$attr_key])) {
                         continue;
                     }
                     // invalid?
                     //$attr_price = (float)$P->options[$attr_key]['attr_price'];
                     $attr_name = $P->options[$attr_key]['attr_name'];
                     $attr_value = $P->options[$attr_key]['attr_value'];
                     $attr_desc .= "<br />&nbsp;&nbsp;-- {$attr_name}: {$attr_value}";
                     /*if ($attr_price != 0) {
                           $item_price += $attr_price;
                       }*/
                 }
             }
             $text_names = explode('|', $P->custom);
             if (!empty($text_names) && is_array($item['extras']['custom'])) {
                 foreach ($item['extras']['custom'] as $tid => $val) {
                     $attr_desc .= '<br />&nbsp;&nbsp;-- ' . htmlspecialchars($text_names[$tid]) . ': ' . htmlspecialchars($val);
                 }
             }
             $item['descrip'] .= $attr_desc;
             // Get shipping amount and weight
             if ($P->shipping_type == 2 && $P->shipping_amt > 0) {
                 // fixed shipping amount per item. Update actual cart
                 $this->m_cart[$id]['shipping'] = $P->shipping_amt * $item['quantity'];
                 $shipping += $this->m_cart[$id]['shipping'];
                 // for display
             } elseif ($P->shipping_type == 1 && $P->weight > 0) {
                 // using gateway profile, save the item's weight in the cart
                 $this->m_cart[$id]['weight'] = $P->weight * $item['quantity'];
             }
             $this->m_cart[$id]['taxable'] = $P->taxable ? 'Y' : 'N';
             $this->m_cart[$id]['type'] = $P->prod_type;
         } else {
             // A plugin item, it's not something we can look up
             $item_price = (double) $item['price'];
             if (isset($item['extras']['shipping'])) {
                 $shipping += (double) $item['extras']['shipping'];
                 $this->m_cart[$id]['shipping'] = $item['extras']['shipping'];
             }
         }
         $item_total = $item_price * $item['quantity'];
         $T->set_var(array('cart_item_id' => $id, 'pi_url' => PAYPAL_URL, 'cart_id' => $item['item_id'], 'pp_id' => $counter, 'item_id' => $item_id, 'item_descrip' => $item['descrip'], 'item_price' => COM_numberFormat($item_price, 2), 'item_quantity' => $item['quantity'], 'item_total' => COM_numberFormat($item_total, 2), 'item_link' => is_numeric($item_id) ? 'true' : ''));
         $T->parse('iRow', 'ItemRow', true);
         $subtotal += $item_total;
     }
     $custom_info = array('uid' => $_USER['uid'], 'transtype' => 'cart_upload', 'cart_id' => $this->cartID());
     $total = $subtotal + $shipping;
     // A little hack to show only the total if there are no other
     // charges
     //if ($total == $subtotal) $subtotal = 0;
     // Format the TOC link, if any
     if (!empty($_PP_CONF['tc_link'])) {
         $tc_link = str_replace('{site_url}', $_CONF['site_url'], $_PP_CONF['tc_link']);
     } else {
         $tc_link = '';
     }
     $T->set_var(array('paypal_url' => $_PP_CONF['paypal_url'], 'receiver_email' => $_PP_CONF['receiver_email'][0], 'custom' => serialize($custom_info), 'shipping' => $shipping > 0 ? $currency->Format($shipping) : '', 'subtotal' => $subtotal > 0 ? $currency->Format($subtotal) : '', 'total' => $currency->Format($total), 'order_instr' => htmlspecialchars($this->getInstructions()), 'tc_link' => $tc_link));
     // If this is the final checkout, then show the payment buttons
     if ($checkout) {
         $T->set_var(array('gateway_vars' => $this->getCheckoutButtons(), 'checkout' => 'true'));
     }
     $T->parse('output', 'cart');
     $form = $T->finish($T->get_var('output'));
     return $form;
 }
Example #2
0
 /**
  *   View the current order summary
  *
  *   @param  boolean $final      Indicates that this order is final.
  *   @param  string  $tpl        "print" for a printable template
  *   @return string      HTML for order view
  */
 public function View($final = false, $tpl = '')
 {
     global $_PP_CONF, $_USER, $LANG_PP, $LANG_ADMIN, $_TABLES, $_CONF, $_SYSTEM;
     USES_paypal_class_product();
     // canView should be handled by the caller
     if (!$this->canView()) {
         return '';
     }
     $T = new Template(PAYPAL_PI_PATH . '/templates');
     if ($tpl == 'print') {
         $tpltype = '.print';
     } else {
         $tpltype = $_SYSTEM['framework'] == 'uikit' ? '.uikit' : '';
     }
     $T->set_file('order', "order{$tpltype}.thtml");
     $isAdmin = SEC_hasRights('paypal.admin') ? true : false;
     foreach ($this->_addr_fields as $fldname) {
         $T->set_var($fldname, $this->{$fldname});
     }
     $T->set_block('order', 'ItemRow', 'iRow');
     // Get the workflows so we sho the relevant info.
     if (!isset($_PP_CONF['workflows']) || !is_array($_PP_CONF['workflows'])) {
         USES_paypal_class_workflow();
         ppWorkflow::Load();
     }
     foreach ($_PP_CONF['workflows'] as $key => $value) {
         $T->set_var('have_' . $value, 'true');
     }
     $this->no_shipping = 1;
     // no shipping unless physical item ordered
     $subtotal = 0;
     foreach ($this->items as $key => $item) {
         $P = new Product($item['product_id']);
         $item_options = '';
         $opt = json_decode($item['options_text'], true);
         if ($opt) {
             foreach ($opt as $opt_str) {
                 $item_options .= "&nbsp;&nbsp;--&nbsp;{$opt_str}<br />\n";
             }
         }
         $item_total = $item['price'] * $item['quantity'];
         $subtotal += $item_total;
         $T->set_var(array('item_id' => htmlspecialchars($item['product_id']), 'item_descrip' => htmlspecialchars($item['description']), 'item_price' => COM_numberFormat($item['price'], 2), 'item_quantity' => (int) $item['quantity'], 'item_total' => COM_numberFormat($item_total, 2), 'item_options' => $item_options, 'is_admin' => $isAdmin ? 'true' : '', 'is_file' => $P->file != '' ? 'true' : ''));
         $T->parse('iRow', 'ItemRow', true);
         if ($item['data']['prod_type'] == PP_PROD_PHYSICAL) {
             $this->no_shipping = 0;
         }
     }
     $dt = new Date($this->order_date, $_CONF['timezone']);
     $total = $subtotal + $this->shipping + $this->handling + $this->tax;
     $T->set_var(array('pi_url' => PAYPAL_URL, 'is_admin' => $isAdmin ? 'true' : '', 'pi_admin_url' => PAYPAL_ADMIN_URL, 'total' => sprintf('%6.2f', $total), 'not_final' => $final ? '' : 'true', 'order_date' => $dt->format($_PP_CONF['datetime_fmt'], true), 'order_date_tip' => $dt->format($_PP_CONF['datetime_fmt'], false), 'order_number' => $this->order_id, 'shipping' => COM_numberFormat($this->shipping, 2), 'handling' => COM_numberFormat($this->handling, 2), 'tax' => COM_numberFormat($this->tax, 2), 'subtotal' => COM_numberFormat($subtotal, 2), 'have_billto' => 'true', 'have_shipto' => 'true', 'order_instr' => htmlspecialchars($this->instructions), 'shop_name' => $_PP_CONF['shop_name'], 'shop_addr' => $_PP_CONF['shop_addr']));
     if ($isAdmin) {
         USES_paypal_class_orderstatus();
         $T->set_var(array('purch_name' => COM_getDisplayName($this->uid), 'purch_uid' => $this->uid, 'stat_update' => ppOrderStatus::Selection($this->order_id, 1, $this->status), 'status' => $this->status));
         $sql = "SELECT * FROM {$_TABLES['paypal.order_log']} WHERE order_id = '" . DB_escapeString($this->order_id) . "'";
         $res = DB_query($sql);
         $T->set_block('order', 'LogMessages', 'Log');
         while ($L = DB_fetchArray($res, false)) {
             $dt->setTimestamp(strtotime($L['ts']));
             $T->set_var(array('log_username' => $L['username'], 'log_msg' => $L['message'], 'log_ts' => $dt->format($_PP_CONF['datetime_fmt'], true), 'log_ts_tip' => $dt->format($_PP_CONF['datetime_fmt'], false)));
             $T->parse('Log', 'LogMessages', true);
         }
     }
     $status = $this->status;
     if ($this->pmt_method != '') {
         //if ($status & PP_STATUS_PAID) {
         if (USES_paypal_gateway($this->pmt_method)) {
             $gw = new $this->pmt_method();
             $pmt_method = $gw->Description();
         } else {
             $pmt_method = $this->pmt_method;
         }
         $T->set_var(array('pmt_method' => $pmt_method, 'pmt_txn_id' => $this->pmt_txn_id));
     }
     $T->parse('output', 'order');
     $form = $T->finish($T->get_var('output'));
     return $form;
 }
Example #3
0
        $gw_id = $_POST['gw_id'];
        $gw = new $gw_id();
        $status = $gw->SaveConfig($_POST);
        $view = 'gwadmin';
        break;
    case 'gwmove':
        PAYPAL_loadGateways();
        // just need the PaymentGw class
        PaymentGw::moveRow($_GET['id'], $actionval);
        $view = 'gwadmin';
        break;
    case 'wfmove':
        switch ($_GET['type']) {
            case 'workflow':
                USES_paypal_class_workflow();
                ppWorkflow::moveRow($_GET['id'], $actionval);
                break;
            case 'orderstatus':
                USES_paypal_class_orderstatus();
                ppOrderStatus::moveRow($_GET['id'], $actionval);
                break;
        }
        $view = 'wfadmin';
        break;
    default:
        $view = $action;
        break;
}
//PAYPAL_debug('Admin view: ' . $action);
switch ($view) {
    case 'history':
Example #4
0
         echo '<?xml version="1.0" encoding="ISO-8859-1"?>
 <info>' . "\n";
         echo "<newval>{$newval}</newval>\n";
         echo "<id>{$_REQUEST['id']}</id>\n";
         echo "<type>{$_REQUEST['type']}</type>\n";
         echo "<component>{$_REQUEST['component']}</component>\n";
         echo "<imgurl>{$img_url}</imgurl>\n";
         echo "<baseurl>" . PAYPAL_ADMIN_URL . "</baseurl>\n";
         echo "</info>\n";
         break;
     case 'workflow':
         USES_paypal_class_workflow();
         $field = $_GET['type'];
         switch ($field) {
             case 'enabled':
                 $newval = ppWorkflow::Toggle($_REQUEST['id'], $field, $_REQUEST['oldval']);
                 break;
             default:
                 exit;
         }
         $img_url = PAYPAL_URL . '/images/';
         $img_url .= $newval == 1 ? 'on.png' : 'off.png';
         header('Content-Type: text/xml');
         header("Cache-Control: no-cache, must-revalidate");
         //A date in the past
         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
         echo '<?xml version="1.0" encoding="ISO-8859-1"?>
 <info>' . "\n";
         echo "<newval>{$newval}</newval>\n";
         echo "<id>{$_REQUEST['id']}</id>\n";
         echo "<type>{$_REQUEST['type']}</type>\n";
Example #5
0
         break;
     }
     $U = new ppUserInfo();
     if ($U->uid > 1) {
         $addr_id = $U->SaveAddress($_POST, $addr_type);
         if ($addr_id[0] < 0) {
             if (!empty($addr_id[1])) {
                 $content .= PAYPAL_errorMessage($addr_id[1], 'alert', $LANG_PP['missing_fields']);
             }
             $view = $addr_type;
             break;
         } else {
             $_POST['useaddress'] = $addr_id[0];
         }
     }
     $view = ppWorkflow::getNextView($addr_type);
     $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;
Example #6
0
 /**
  *   View the current order summary
  *
  *   @param  boolean $final      Indicates that this order is final.
  *   @return string      HTML for order view
  */
 public function View($final = false)
 {
     global $_PP_CONF, $_USER, $LANG_PP, $LANG_ADMIN, $_TABLES;
     $T = new Template(PAYPAL_PI_PATH . '/templates');
     $T->set_file(array('order' => 'order.thtml'));
     $isAdmin = SEC_hasRights('paypal.admin') ? true : false;
     foreach ($this->_addr_fields as $fldname) {
         $T->set_var($fldname, $this->{$fldname});
     }
     $T->set_block('order', 'ItemRow', 'iRow');
     // Get the workflows so we sho the relevant info.
     if (!isset($_PP_CONF['workflows']) || !is_array($_PP_CONF['workflows'])) {
         USES_paypal_class_workflow();
         ppWorkflow::Load();
     }
     foreach ($_PP_CONF['workflows'] as $key => $value) {
         $T->set_var('have_' . $value, 'true');
     }
     $this->no_shipping = 1;
     // no shipping unless physical item ordered
     $subtotal = 0;
     foreach ($this->items as $key => $item) {
         $item_total = $item['price'] * $item['quantity'];
         $subtotal += $item_total;
         $T->set_var(array('item_id' => $item['product_id'], 'item_descrip' => $item['description'], 'item_price' => COM_numberFormat($item['price'], 2), 'item_quantity' => (int) $item['quantity'], 'item_total' => COM_numberFormat($item_total, 2)));
         $T->parse('iRow', 'ItemRow', true);
         if ($item['data']['prod_type'] == PP_PROD_PHYSICAL) {
             $this->no_shipping = 0;
         }
     }
     $total = $subtotal + $this->shipping + $this->handling + $this->tax;
     $T->set_var(array('pi_url' => PAYPAL_URL, 'is_admin' => $isAdmin ? 'true' : '', 'pi_admin_url' => PAYPAL_ADMIN_URL, 'total' => sprintf('%6.2f', $total), 'not_final' => $final ? '' : 'true', 'order_date' => $this->order_date, 'order_number' => $this->order_id, 'shipping' => COM_numberFormat($this->shipping, 2), 'handling' => COM_numberFormat($this->handling, 2), 'tax' => COM_numberFormat($this->tax, 2), 'subtotal' => COM_numberFormat($subtotal, 2), 'have_billto' => 'true', 'have_shipto' => 'true'));
     if ($isAdmin) {
         USES_paypal_class_orderstatus();
         $T->set_var(array('purch_name' => COM_getDisplayName($this->uid), 'purch_uid' => $this->uid, 'stat_update' => ppOrderStatus::Selection($this->order_id, 1, $this->status)));
         $sql = "SELECT * FROM {$_TABLES['paypal.order_log']} WHERE order_id = '" . DB_escapeString($this->order_id) . "'";
         $res = DB_query($sql, 1);
         $T->set_block('order', 'LogMessages', 'Log');
         while ($L = DB_fetchArray($res, false)) {
             $T->set_var(array('log_username' => $L['username'], 'log_msg' => $L['message'], 'log_ts' => $L['ts']));
             $T->parse('Log', 'LogMessages', true);
         }
     }
     $status = $this->status;
     if ($this->pmt_method != '') {
         //if ($status & PP_STATUS_PAID) {
         if (USES_paypal_gateway($this->pmt_method)) {
             $gw = new $this->pmt_method();
             $pmt_method = $gw->Description();
         } else {
             $pmt_method = $this->pmt_method;
         }
         $T->set_var(array('pmt_method' => $pmt_method, 'pmt_txn_id' => $this->pmt_txn_id));
     }
     $T->parse('output', 'order');
     $form = $T->finish($T->get_var('output'));
     return $form;
 }