Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/PayPal.inc.php

    r41 r42  
    11<?php
    22/**
    3  * The PayPal:: class provides functions for creating PayPal buttons and for 
     3 * The PayPal:: class provides functions for creating PayPal buttons and for
    44 * receiving PayPal's Instant Payment Notification (IPN) service.
    55 *
     
    88 */
    99class PayPal {
    10    
     10
    1111    // General object parameters.
    1212    var $_params = array(
     
    1414        'test_mode' => false,
    1515    );
    16    
    17     // Options used for specific buttons and links. 
     16
     17    // Options used for specific buttons and links.
    1818    var $_default_button_options = array();
    19    
     19
    2020    // Array of buttons created by newButton().
    2121    var $_buttons = array();
    22    
     22
    2323    // Store the response from the last IPN.
    2424    var $_ipn_response;
    25    
     25
    2626    /**
    2727     * Constructor.
     
    3838            $url = 'www.paypal.com';
    3939        }
    40        
     40
    4141        $this->_default_button_options = array(
    4242            '_global' => array(
     
    5959        );
    6060    }
    61    
    62     /**
    63      * Updates the _default_button_options array with options used for 
     61
     62    /**
     63     * Updates the _default_button_options array with options used for
    6464     * specific buttons, or all buttons if $type is null.
    6565     *
    6666     * @access  public
    6767     *
    68      * @param   mixed   $type       The type of button to set defaults. If null, 
     68     * @param   mixed   $type       The type of button to set defaults. If null,
    6969     *                              sets the global button types.
    7070     * @param   array   $options    Options to set for button.
     
    7878            return false;
    7979        }
    80        
     80
    8181        if (is_null($type) || '_global' == $type) {
    8282            $this->_default_button_options['_global'] = array_merge($this->_default_button_options['_global'], $options);
     
    8585            return false;
    8686        }
    87        
     87
    8888        $this->_default_button_options[$type] = array_merge($this->_default_button_options[$type], $options);
    8989        return true;
    9090    }
    91    
     91
    9292    /**
    9393     * Creates a new element in the _buttons array. Uses _default_button_options
     
    108108            return false;
    109109        }
    110        
     110
    111111        if (!is_array($options) || empty($options)) {
    112112            App::logMsg(sprintf('Invalid options: %s', getDump($options)), LOG_WARNING, __FILE__, __LINE__);
    113113            return false;
    114114        }
    115        
     115
    116116        if (isset($this->_buttons[$name])) {
    117117            App::logMsg(sprintf('Overwriting existing button name: %s', getDump($this->_buttons[$name])), LOG_DEBUG, __FILE__, __LINE__);
    118118        }
    119        
     119
    120120        $this->_buttons[$name] = array(
    121121            'type' => $type,
     
    141141            return false;
    142142        }
    143        
     143
    144144        $query_string = '';
    145145        $delim = '';
     
    156156        $search = array('/%2F/');
    157157        $replace = array('/');
    158        
     158
    159159        return $this->_buttons[$name]['options']['link_url'] . preg_replace($search, $replace, $query_string);
    160160    }
     
    183183        ?>
    184184        <form action="<?php echo $this->_buttons[$name]['options']['button_url']; ?>" method="post">
    185         <?php 
     185        <?php
    186186        if (is_array($this->_buttons[$name]['options']) && !empty($this->_buttons[$name]['options'])) {
    187187            foreach ($this->_buttons[$name]['options'] as $key=>$val) {
     
    192192                }
    193193            }
    194         } 
     194        }
    195195        ?>
    196196        <input type="image" src="<?php echo $this->_buttons[$name]['options']['submit_img']; ?>" border="0" name="submit" alt="<?php echo $this->_buttons[$name]['options']['submit_text']; ?>" />
     
    241241    function incomingIPNRequest()
    242242    {
    243         if ($_SERVER['REQUEST_METHOD'] == 'POST' 
     243        if ($_SERVER['REQUEST_METHOD'] == 'POST'
    244244        && $_SERVER['CONTENT_TYPE'] == 'application/x-www-form-urlencoded'
    245245        && !empty($_POST)) {
     
    258258     */
    259259    function processIPN()
    260     {       
     260    {
    261261        if (getPost('test_ipn') == '1' || $this->getParam('test_mode')) {
    262262            App::logMsg(sprintf('Processing PayPal IPN in test mode: %s', getDump(getFormData())), LOG_DEBUG, __FILE__, __LINE__);
     
    266266            $url = parse_url($this->getParam('paypal_url'));
    267267        }
    268        
     268
    269269        // Read POST request and add 'cmd'.
    270270        $received_data = getPost();
     
    273273            $return_data .= '&' . $post_key . '=' . urlencode($post_val);
    274274        }
    275        
     275
    276276        // Set the port number based on the scheme.
    277         if ($url['scheme'] == "https") { 
     277        if ($url['scheme'] == "https") {
    278278            $url['port'] = 443;
    279279            $ssl = 'ssl://';
     
    282282            $ssl = '';
    283283        }
    284            
     284
    285285        // Open connection to PayPal server.
    286         $fp = fsockopen($ssl . $url['host'], $url['port'], $errnum, $errstr, 30); 
     286        $fp = fsockopen($ssl . $url['host'], $url['port'], $errnum, $errstr, 30);
    287287
    288288        if (!$fp) {
     
    290290            return false;
    291291        } else {
    292             fputs($fp, "POST {$url['path']} HTTP/1.1\r\n"); 
    293             fputs($fp, "Host: {$url['host']}\r\n"); 
    294             fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
    295             fputs($fp, "Content-length: " . strlen($return_data) . "\r\n"); 
    296             fputs($fp, "Connection: close\r\n\r\n"); 
    297             fputs($fp, $return_data . "\r\n\r\n"); 
    298                            
     292            fputs($fp, "POST {$url['path']} HTTP/1.1\r\n");
     293            fputs($fp, "Host: {$url['host']}\r\n");
     294            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
     295            fputs($fp, "Content-length: " . strlen($return_data) . "\r\n");
     296            fputs($fp, "Connection: close\r\n\r\n");
     297            fputs($fp, $return_data . "\r\n\r\n");
     298
    299299            // Loop through the response lines from the server.
    300300            $this->_ipn_response = '';
     
    303303            }
    304304            fclose($fp);
    305            
     305
    306306            App::logMsg(sprintf('IPN response received: %s', $this->_ipn_response), LOG_NOTICE, __FILE__, __LINE__);
    307307            return true;
    308308        }
    309309    }
    310    
     310
    311311    /**
    312312     * Checks the response received from PayPal's IPN upon calling processIPN().
     
    322322            return false;
    323323        }
    324        
     324
    325325        if (empty($this->_ipn_response)) {
    326326            App::logMsg(sprintf('Cannot verify IPN, response empty.', null), LOG_WARNING, __FILE__, __LINE__);
    327327            return false;
    328328        }
    329        
     329
    330330        if (preg_match('/VERIFIED/', $this->_ipn_response)) {
    331331            App::logMsg(sprintf('IPN verified!', null), LOG_DEBUG, __FILE__, __LINE__);
     
    339339        }
    340340    }
    341    
    342    
     341
     342
    343343} // End of class.
    344344
Note: See TracChangeset for help on using the changeset viewer.