Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

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

    r42 r136  
    11<?php
    22/**
    3  * The PayPal:: class provides functions for creating PayPal buttons and for
     3 * PayPal.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
     6 * The PayPal class provides functions for creating PayPal buttons and for
    47 * receiving PayPal's Instant Payment Notification (IPN) service.
    58 *
     
    7477    function setButtonDefaults($type, $options)
    7578    {
     79        $app =& App::getInstance();
     80
    7681        if (!is_array($options) || empty($options)) {
    77             App::logMsg(sprintf('Invalid options: %s', getDump($options)), LOG_WARNING, __FILE__, __LINE__);
     82            $app->logMsg(sprintf('Invalid options: %s', getDump($options)), LOG_WARNING, __FILE__, __LINE__);
    7883            return false;
    7984        }
     
    8287            $this->_default_button_options['_global'] = array_merge($this->_default_button_options['_global'], $options);
    8388        } else if (!isset($this->_default_button_options[$type])) {
    84             App::logMsg(sprintf('Invalid button type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
     89            $app->logMsg(sprintf('Invalid button type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
    8590            return false;
    8691        }
     
    104109    function newButton($type, $name, $options=null)
    105110    {
     111        $app =& App::getInstance();
     112
    106113        if (!isset($this->_default_button_options[$type])) {
    107             App::logMsg(sprintf('Invalid button type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
     114            $app->logMsg(sprintf('Invalid button type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
    108115            return false;
    109116        }
    110117
    111118        if (!is_array($options) || empty($options)) {
    112             App::logMsg(sprintf('Invalid options: %s', getDump($options)), LOG_WARNING, __FILE__, __LINE__);
     119            $app->logMsg(sprintf('Invalid options: %s', getDump($options)), LOG_WARNING, __FILE__, __LINE__);
    113120            return false;
    114121        }
    115122
    116123        if (isset($this->_buttons[$name])) {
    117             App::logMsg(sprintf('Overwriting existing button name: %s', getDump($this->_buttons[$name])), LOG_DEBUG, __FILE__, __LINE__);
     124            $app->logMsg(sprintf('Overwriting existing button name: %s', getDump($this->_buttons[$name])), LOG_DEBUG, __FILE__, __LINE__);
    118125        }
    119126
     
    137144    function getLink($name)
    138145    {
     146        $app =& App::getInstance();
     147
    139148        if (!isset($this->_buttons[$name])) {
    140             App::logMsg(sprintf('Button does not exist: %s', $name), LOG_WARNING, __FILE__, __LINE__);
     149            $app->logMsg(sprintf('Button does not exist: %s', $name), LOG_WARNING, __FILE__, __LINE__);
    141150            return false;
    142151        }
     
    207216    function setParam($params)
    208217    {
     218        $app =& App::getInstance();
     219
    209220        if (isset($params) && is_array($params)) {
    210221            // Merge new parameters with old overriding only those passed.
    211222            $this->_params = array_merge($this->_params, $params);
    212223        } else {
    213             App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     224            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
    214225        }
    215226    }
     
    224235    function getParam($param)
    225236    {
     237        $app =& App::getInstance();
     238   
    226239        if (isset($this->_params[$param])) {
    227240            return $this->_params[$param];
    228241        } else {
    229             App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     242            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    230243            return null;
    231244        }
     
    259272    function processIPN()
    260273    {
     274        $app =& App::getInstance();
     275
    261276        if (getPost('test_ipn') == '1' || $this->getParam('test_mode')) {
    262             App::logMsg(sprintf('Processing PayPal IPN in test mode: %s', getDump(getFormData())), LOG_DEBUG, __FILE__, __LINE__);
     277            $app->logMsg(sprintf('Processing PayPal IPN in test mode: %s', getDump(getFormData())), LOG_DEBUG, __FILE__, __LINE__);
    263278            $url = parse_url('https://www.sandbox.paypal.com/cgi-bin/webscr');
    264279        } else {
    265             App::logMsg(sprintf('Processing PayPal IPN: %s', getDump(getFormData())), LOG_DEBUG, __FILE__, __LINE__);
     280            $app->logMsg(sprintf('Processing PayPal IPN: %s', getDump(getFormData())), LOG_DEBUG, __FILE__, __LINE__);
    266281            $url = parse_url($this->getParam('paypal_url'));
    267282        }
     
    287302
    288303        if (!$fp) {
    289             App::logMsg(sprintf('Connection to PayPal URL %s failed with error: %s (%s)', $ssl . $url['host'], $errstr, $errnum), LOG_WARNING, __FILE__, __LINE__);
     304            $app->logMsg(sprintf('Connection to PayPal URL %s failed with error: %s (%s)', $ssl . $url['host'], $errstr, $errnum), LOG_WARNING, __FILE__, __LINE__);
    290305            return false;
    291306        } else {
     
    304319            fclose($fp);
    305320
    306             App::logMsg(sprintf('IPN response received: %s', $this->_ipn_response), LOG_NOTICE, __FILE__, __LINE__);
     321            $app->logMsg(sprintf('IPN response received: %s', $this->_ipn_response), LOG_NOTICE, __FILE__, __LINE__);
    307322            return true;
    308323        }
     
    318333    function verifiedIPN()
    319334    {
     335        $app =& App::getInstance();
     336
    320337        if (!isset($this->_ipn_response)) {
    321             App::logMsg(sprintf('Cannot verify IPN, response not received.', null), LOG_WARNING, __FILE__, __LINE__);
     338            $app->logMsg(sprintf('Cannot verify IPN, response not received.', null), LOG_WARNING, __FILE__, __LINE__);
    322339            return false;
    323340        }
    324341
    325342        if (empty($this->_ipn_response)) {
    326             App::logMsg(sprintf('Cannot verify IPN, response empty.', null), LOG_WARNING, __FILE__, __LINE__);
     343            $app->logMsg(sprintf('Cannot verify IPN, response empty.', null), LOG_WARNING, __FILE__, __LINE__);
    327344            return false;
    328345        }
    329346
    330347        if (preg_match('/VERIFIED/', $this->_ipn_response)) {
    331             App::logMsg(sprintf('IPN verified!', null), LOG_DEBUG, __FILE__, __LINE__);
     348            $app->logMsg(sprintf('IPN verified!', null), LOG_DEBUG, __FILE__, __LINE__);
    332349            return true;
    333350        } else if (preg_match('/INVALID/', $this->_ipn_response)) {
    334             App::logMsg(sprintf('IPN invalid.', null), LOG_DEBUG, __FILE__, __LINE__);
    335             return false;
    336         } else {
    337             App::logMsg(sprintf('IPN unknown.', null), LOG_WARNING, __FILE__, __LINE__);
     351            $app->logMsg(sprintf('IPN invalid.', null), LOG_DEBUG, __FILE__, __LINE__);
     352            return false;
     353        } else {
     354            $app->logMsg(sprintf('IPN unknown.', null), LOG_WARNING, __FILE__, __LINE__);
    338355            return false;
    339356        }
Note: See TracChangeset for help on using the changeset viewer.