Example #1
0
/**
*   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;
}
Example #2
0
 /**
  *   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;
 }
Example #3
0
     break;
 case 'editattr':
     USES_paypal_class_attribute();
     $attr_id = isset($_REQUEST['attr_id']) ? $_REQUEST['attr_id'] : '';
     $Attr = new Attribute($attr_id);
     $content .= $Attr->Edit();
     break;
 case 'other':
     $content .= '<a href="' . PAYPAL_ADMIN_URL . '/index.php?resetbuttons=x' . '">Reset All Buttons</a>' . "\n";
     break;
 case 'gwadmin':
     $content .= PAYPAL_adminList_Gateway();
     break;
 case 'gwedit':
     // Load all installed gateways, not just enabled ones
     PAYPAL_loadGateways(true);
     $gwid = isset($_GET['gw_id']) ? $_GET['gw_id'] : '';
     if (DB_count($_TABLES['paypal.gateways'], 'id', $gwid) > 0) {
         $gw = new $gwid();
         $content .= $gw->Configure();
     }
     break;
 case 'wfadmin':
     $content .= PAYPAL_adminlist_Workflow();
     $content .= PAYPAL_adminlist_OrderStatus();
     break;
 default:
     $view = 'productlist';
     $cat_id = isset($_GET['cat_id']) ? (int) $_GET['cat_id'] : 0;
     $content .= PAYPAL_adminlist_Product($cat_id);
     break;
Example #4
0
 /**
  *   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;
 }
Example #5
0
if (!defined('GVERSION')) {
    die('This file can not be used on its own.');
}
// Just for E_ALL. If "testing" isn't defined, define it.
if (!isset($_PP_CONF['sys_test_ipn'])) {
    $_PP_CONF['sys_test_ipn'] = false;
}
// Define failure reasons- maybe delete if not needed for all gateways
define('IPN_FAILURE_UNKNOWN', 0);
define('IPN_FAILURE_VERIFY', 1);
define('IPN_FAILURE_COMPLETED', 2);
define('IPN_FAILURE_UNIQUE', 3);
define('IPN_FAILURE_EMAIL', 4);
define('IPN_FAILURE_FUNDS', 5);
USES_paypal_class_product();
PAYPAL_loadGateways();
USES_paypal_class_order();
/**
*   Interface to deal with IPN transactions from a payment gateway.
*
*   @package paypal
*/
class BaseIPN
{
    /** Standard IPN data items required for all IPN types.
     *   @var array */
    var $pp_data = array();
    /** Holder for the complete IPN data array.  Used only for recording
     *   the raw data; no processing is done on this data by the base class.
     *   @var array */
    var $ipn_data = array();