Beispiel #1
0
<?php

/**
*   Gateway implementation for PayPal.
*
*   @author     Lee Garner <*****@*****.**>
*   @copyright  Copyright (c) 2009-2016 Lee Garner <*****@*****.**>
*   @package    paypal
*   @version    0.5.7
*   @license    http://opensource.org/licenses/gpl-2.0.php 
*               GNU Public License v2 or later
*   @filesource
*/
/** Import base gateway class */
USES_paypal_gateway();
/**
*   Class for Paypal payment gateway
*   @since 0.5.0
*   @package paypal
*/
class paypal extends PaymentGw
{
    /** Business e-mail to be used for creating buttons
     *   @var string */
    private $receiver_email;
    /** PayPal-assigned certificate ID to be used for encrypted buttons
     *   @var string */
    private $cert_id;
    /**
     *   Constructor.
     *   Set gateway-specific items and call the parent constructor.
Beispiel #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;
 }
Beispiel #3
0
 case 'processorder':
     // Process the order, similar to what an IPN would normally do.
     // This is for internal, manual processes like C.O.D. or Prepayment orders
     $gw_name = isset($_POST['gateway']) ? $_POST['gateway'] : '';
     $status = USES_paypal_gateway($gw_name);
     if ($status) {
         $gw = new $gw_name();
         $output = $gw->handlePurchase($_POST);
         if (!empty($output)) {
             $content .= $output;
             $view = 'none';
             break;
         }
         $view = 'thanks';
         $ppGCart->Clear(false);
         if (USES_paypal_gateway($actionval)) {
             $gw = new $actionval();
             $tVars = $gw->thanksVars();
             if (!empty($tVars)) {
                 $T = new Template($_CONF['path'] . 'plugins/paypal/templates');
                 $T->set_file(array('msg' => 'thanks_for_order.thtml'));
                 $T->set_var(array('site_name' => $_CONF['site_name'], 'payment_date' => $tVars['payment_date'], 'currency' => $tVars['currency'], 'mc_gross' => $tVars['payment_amount'], 'gateway_url' => $tVars['gateway_url'], 'gateway_name' => $tVars['gateway_name']));
                 $message = $T->parse('output', 'msg');
             } else {
                 // Allow for no thanksVars function
                 $message = $LANG_PP['thanks_title'];
             }
         } else {
             // Allow for missing or unknown payment gateway name
             $message = $LANG_PP['thanks_title'];
         }
/**
 *  Display a single row from the IPN log.
 *
 *  @param  integer $id     Log Entry ID
 *  @param  string  $txn_id Transaction ID from Paypal
 *  @return string          HTML of the ipnlog row specified by $id
 */
function PAYPAL_ipnlogSingle($id, $txn_id)
{
    global $_TABLES, $_CONF, $LANG_PP;
    $sql = "SELECT * FROM {$_TABLES['paypal.ipnlog']} ";
    if ($id > 0) {
        $sql .= "WHERE id = {$id}";
    } else {
        $sql .= "WHERE txn_id = '{$txn_id}'";
    }
    $res = DB_query($sql);
    $A = DB_fetchArray($res, false);
    if (empty($A)) {
        return "Nothing Found";
    }
    // Allow all serialized data to be available to the template
    $ipn = @unserialize($A['ipn_data']);
    if (USES_paypal_gateway($A['gateway'])) {
        $gw = new $A['gateway']();
        $vals = $gw->ipnlogVars($ipn);
        // Create ipnlog template
        $T = new Template($_CONF['path'] . 'plugins/paypal/templates');
        $T->set_file(array('ipnlog' => 'ipnlog_detail.thtml'));
        // Display the specified ipnlog row
        $T->set_var(array('id' => $A['id'], 'ip_addr' => $A['ip_addr'], 'time' => $A['time'], 'txn_id' => $A['txn_id'], 'gateway' => $A['gateway']));
        if (!empty($vals)) {
            $T->set_block('ipnlog', 'DataBlock', 'Data');
            foreach ($vals as $key => $value) {
                $T->set_var(array('prompt' => isset($LANG_PP[$key]) ? $LANG_PP[$key] : $key, 'value' => htmlspecialchars($value, ENT_QUOTES, COM_getEncodingt())));
                $T->parse('Data', 'DataBlock', true);
            }
        }
    }
    /*if ($A['verified']) {
          $T->set_var('verified', 'true');
      } else {
          $T->set_var('verified', 'false');
      }*/
    if ($ipn) {
        $ipn_data = "<table><th class=\"admin-list-headerfield\">Name<th class=\"admin-list-headerfield\">Value\n";
        foreach ($ipn as $name => $value) {
            //$ipnlog->set_var($name, $value);
            $ipn_data .= "<tr><td>{$name}</td><td>{$value}</td></tr>\n";
        }
        $ipn_data .= "</table>\n";
    } else {
        $ipn_data = "Error decoding IPN transaction data";
    }
    $T->set_var('raw', $ipn_data);
    $display .= $T->parse('output', 'ipnlog');
    return $display;
}
Beispiel #5
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;
 }