コード例 #1
0
ファイル: services.inc.php プロジェクト: NewRoute/paypal
/**
*   Create the payment buttons for an external item.
*   Creates the requested buy_now button type and, if requested,
*   an add_cart button.
*
*   All gateways that have the 'external' service enabled as well as the
*   requested button type will provide a button.
*
*   $args['btn_type'] can be empty or not set, to create only an Add to Cart
*   button.  $args['add_cart'] must still be set in this case.  If neither
*   button type is requested, an empty array is returned.
*
*   Provided $args should include at least:
*       'item_number', 'item_name', 'price', 'quantity', and 'item_type'
*   $args['btn_type'] should reflect the type of immediate-purchase button
*   desired.  $args['add_cart'] simply needs to be set to get an add-to-cart
*   button.
*
*   @uses   PaymentGw::ExternalButton()
*   @param  array   $args       Array of item information
*   @param  array   &$output    Pointer to output array
*   @param  array   &$svc_msg   Unused
*   @return integer             Status code
*/
function service_genButton_paypal($args, &$output, &$svc_msg)
{
    global $_CONF, $_PP_CONF;
    $btn_type = isset($args['btn_type']) ? $args['btn_type'] : '';
    $output = array();
    // Create the immediate purchase button, if requested.  As soon as a
    // gateway supplies the requested button type, break from the loop.
    if (!empty($btn_type)) {
        PAYPAL_loadGateways();
        // load all gateways
        if (!empty($_PP_CONF['gateways'])) {
            // Should be at least one
            // Get the first gateway that supports the button type
            foreach ($_PP_CONF['gateways'] as $gw_info) {
                if (PaymentGw::Supports($btn_type, $gw_info) && PaymentGw::Supports('external', $gw_info) && class_exists($gw_info['id'])) {
                    $gw = new $gw_info['id']();
                    $output[] = $gw->ExternalButton($args, $btn_type);
                }
            }
        }
    }
    // Now create an add-to-cart button, if requested.
    if (isset($args['add_cart']) && $_PP_CONF['ena_cart'] == 1) {
        if (!isset($args['item_type'])) {
            $args['item_type'] = PP_PROD_VIRTUAL;
        }
        $T = new Template(PAYPAL_PI_PATH . '/templates');
        $T->set_file('cart', 'buttons/btn_add_cart.thtml');
        $T->set_var(array('item_name' => $args['item_name'], 'item_number' => $args['item_number'], 'short_description' => $args['short_description'], 'amount' => $args['amount'], 'pi_url' => PAYPAL_URL, 'item_type' => $args['item_type'], 'have_tax' => isset($args['tax']) ? 'true' : '', 'tax' => isset($args['tax']) ? $args['tax'] : 0, 'quantity' => isset($args['quantity']) ? $args['quantity'] : '', '_ret_url' => isset($args['_ret_url']) ? $args['_ret_url'] : ''));
        $output['add_cart'] = $T->parse('', 'cart');
    }
    return PLG_RET_OK;
}
コード例 #2
0
ファイル: cart.class.php プロジェクト: JohnToro/paypal
 /**
  *   Get the payment gateway checkout buttons.
  *
  *   @uses   PaymentGw::CheckoutButton()
  *   @return string      HTML for checkout buttons
  */
 public function getCheckoutButtons()
 {
     global $_PP_CONF;
     $gateway_vars = '';
     if ($_PP_CONF['anon_buy'] || !COM_isAnonUser()) {
         PAYPAL_loadGateways();
         foreach ($_PP_CONF['gateways'] as $gw_info) {
             if (!PaymentGw::Supports('checkout', $gw_info)) {
                 continue;
             }
             $gw_name = $gw_info['id'];
             $gateway = new $gw_name();
             $gateway_vars .= '<div class="paypalCheckoutButton">' . $gateway->CheckoutButton($this) . '</div>';
         }
     } else {
         $L = new Template(PAYPAL_PI_PATH . '/templates/buttons');
         $L->set_file('login', 'btn_login_req.thtml');
         $L->parse('login_btn', 'login');
         $gateway_vars = $L->finish($L->get_var('login_btn'));
     }
     return $gateway_vars;
 }
コード例 #3
0
ファイル: paypal.class.php プロジェクト: JohnToro/paypal
 /**
  *   Prepare to save the configuraiton.
  *   This copies the new config values into our local variables, then
  *   calls the parent function to save to the database.
  *
  *   @param  array   $A      Array of name=>value pairs (e.g. $_POST)
  */
 function SaveConfig($A)
 {
     if (!is_array($A)) {
         return false;
     }
     foreach ($this->config as $name => $value) {
         switch ($name) {
             case 'encrypt':
                 // Check if the "encrypt" value has changed.  If so, clear the
                 // button cache
                 $encrypt = isset($A['encrypt']) ? 1 : 0;
                 if ($encrypt != $this->config['encrypt']) {
                     $this->ClearButtonCache();
                 }
                 $this->config['encrypt'] = $encrypt;
                 break;
             case 'test_mode':
                 $this->config[$name] = isset($A[$name]) ? 1 : 0;
                 break;
             default:
                 $this->config[$name] = $A[$name];
                 break;
         }
     }
     return parent::SaveConfig($A);
 }
コード例 #4
0
ファイル: amazon.class.php プロジェクト: NewRoute/paypal
 /**
  *   Prepare to save the configuraiton.
  *   This copies the new config values into our local variables, then
  *   calls the parent function to save to the database.
  *
  *   @uses   PaymentGw::SaveConfig()
  *   @param  array   $A      Array of name=>value pairs (e.g. $_POST)
  *   @return boolean         Results of parent SaveConfig function
  */
 public function SaveConfig($A)
 {
     if (!is_array($A)) {
         return false;
     }
     foreach ($this->config as $name => $value) {
         switch ($name) {
             case 'test_mode':
                 $this->config[$name] = isset($A[$name]) ? 1 : 0;
                 break;
             default:
                 $this->config[$name] = $A[$name];
                 break;
         }
     }
     return parent::SaveConfig($A);
 }
コード例 #5
0
ファイル: product.class.php プロジェクト: JohnToro/paypal
 /**
  *   Gets the purchase links appropriate for the product.
  *   May be Paypal buttons, login-required link, or download button.
  *
  *   @return array   Array of buttons as name=>html.
  */
 public function PurchaseLinks()
 {
     global $_CONF, $_USER, $_PP_CONF, $_TABLES;
     $buttons = array();
     // Indicate that an "add to cart" button should be returned along with
     // the "buy now" button.  If the product has already been purchased
     // and is available for immediate download, this will be turned off.
     $add_cart = $_PP_CONF['ena_cart'] == 1 ? true : false;
     // Get the free download button, if this is a downloadable product
     // already purchased and not expired
     $exptime = DB_getItem($_TABLES['paypal.purchases'], 'MAX(UNIX_TIMESTAMP(expiration))', "user_id = {$_USER['uid']} AND product_id = '" . DB_escapeString($this->id) . "'");
     if ($this->prod_type == PP_PROD_DOWNLOAD && ($this->price == 0 || $_USER['uid'] > 1 && $exptime > time())) {
         // Free, or unexpired downloads for non-anymous
         $T = new Template(PAYPAL_PI_PATH . '/templates');
         $T->set_file('download', 'buttons/btn_download.thtml');
         $T->set_var('pi_url', PAYPAL_URL);
         $T->set_var('id', $this->id);
         $buttons['download'] = $T->parse('', 'download');
         $add_cart = false;
     } elseif ($this->track_onhand == 1 && $this->onhand < 1 && $this->oversell == 1) {
         // Do nothing but show the download link (see above).
         // Make sure the add_cart button isn't shown, either.
         $add_cart = false;
     } elseif ($_USER['uid'] == 1 && !$_PP_CONF['anon_buy'] && !$this->hasAttributes() && $this->price > 0) {
         // Requires login before purchasing
         $T = new Template(PAYPAL_PI_PATH . '/templates');
         $T->set_file('login_req', 'buttons/btn_login_req.thtml');
         $buttons['login'] = $T->parse('', 'login_req');
     } else {
         // Normal buttons for everyone else
         if ($this->canBuyNow() && $this->btn_type != '') {
             // Gateway buy-now buttons only used if no options
             PAYPAL_loadGateways();
             foreach ($_PP_CONF['gateways'] as $gw_info) {
                 if (!PaymentGw::Supports($this->btn_type, $gw_info)) {
                     continue;
                 }
                 $gw_name = $gw_info['id'];
                 $gw = new $gw_name();
                 $buttons[$gw->Name()] = $gw->ProductButton($this);
             }
         }
     }
     // All users and products get an add-to-cart button, if price > 0
     // and cart is enabled, and product is not a donation. Donations
     // can't be mixed with products, so don't allow adding to the cart.
     if ($add_cart && $this->btn_type != 'donation' && ($this->price > 0 || !$this->canBuyNow())) {
         if ($this->hasAttributes()) {
             $tpl_add_cart = 'btn_add_cart_attrib.thtml';
         } else {
             $tpl_add_cart = 'btn_add_cart.thtml';
         }
         // test one template
         $tpl_add_cart = 'btn_add_cart_attrib.thtml';
         $T = new Template(PAYPAL_PI_PATH . '/templates');
         $T->set_file('cart', 'buttons/' . $tpl_add_cart);
         $T->set_var(array('item_name' => htmlspecialchars($this->name), 'item_number' => $this->id, 'short_description' => htmlspecialchars($this->short_description), 'amount' => $this->getPrice(), 'pi_url' => PAYPAL_URL, 'form_url' => $this->hasAttributes() ? '' : 'true', 'tpl_ver' => $_PP_CONF['product_tpl_ver']));
         $buttons['add_cart'] = $T->parse('', 'cart');
     }
     return $buttons;
 }
コード例 #6
0
ファイル: index.php プロジェクト: NewRoute/paypal
     $gw = new $gw_id();
     $status = $gw->Remove();
     $view = 'gwadmin';
     break;
 case 'gwsave':
     // Save a payment gateway configuration
     PAYPAL_loadGateways(true);
     $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;
コード例 #7
0
ファイル: ajax.php プロジェクト: NewRoute/paypal
         echo "<component>{$_REQUEST['component']}</component>\n";
         echo "<imgurl>{$img_url}</imgurl>\n";
         echo "<baseurl>" . PAYPAL_ADMIN_URL . "</baseurl>\n";
         echo "</info>\n";
         break;
     case 'gateway':
         USES_paypal_gateway();
         switch ($_GET['type']) {
             case 'enabled':
                 $newval = PaymentGw::toggleEnabled($_REQUEST['oldval'], $_REQUEST['id']);
                 break;
             case 'buy_now':
                 $newval = PaymentGw::toggleBuyNow($_REQUEST['oldval'], $_REQUEST['id']);
                 break;
             case 'donation':
                 $newval = PaymentGw::toggleDonation($_REQUEST['oldval'], $_REQUEST['id']);
                 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";