Payment_Process
[ class tree: Payment_Process ] [ index: Payment_Process ] [ all elements ]

Source for file Offline.php

Documentation is available at Offline.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Joe Stump <joe@joestump.net>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Offline.php,v 1.4 2004/03/22 20:35:58 ieure Exp $
  20.  
  21.  
  22. require_once('Validate/CreditCard.php');
  23.  
  24. /**
  25. * Payment_Process_offline
  26. *
  27. * An offline driver that allows you to do offline validation of credit card
  28. * via the Validate_CreditCard package. This package is intended for those
  29. * who wish to someday use a payment gateway, but at this time are not currently
  30. * using one.
  31. *
  32. @author Joe Stump <joe@joestump.net>
  33. @package Payment_Process
  34. */
  35.  
  36.   /**
  37.   * $_processed
  38.   *
  39.   * Set to true after the credit card has been processed
  40.   *
  41.   * @author Joe Stump <joe@joestump.net>
  42.   * @var bool $_processed 
  43.   */
  44.   var $_processed = false;
  45.  
  46.   /**
  47.   * $_response
  48.   *
  49.   * The response after the credit card has been processed
  50.   *
  51.   * @author Joe Stump <joe@joestump.net>
  52.   * @var bool $_response 
  53.   */
  54.   var $_response  = false;
  55.  
  56.   /**
  57.   * Payment_Process_offline
  58.   *
  59.   * Constructor - currently does nothing
  60.   *
  61.   * @author Joe Stump <joe@joestump.net>
  62.   * @return void 
  63.   */
  64.   function Payment_Process_offline()
  65.   {
  66.  
  67.   }
  68.  
  69.   /**
  70.   * process
  71.   *
  72.   * Processes the given credit card. Returns PEAR_Error when an error has
  73.   * occurred or it will return a valid Payment_Process_Result on success.
  74.   *
  75.   * @author Joe Stump <joe@joestump.net>
  76.   * @access public
  77.   * @return mixed 
  78.   */
  79.   function process(
  80.   
  81.     $card = array();
  82.     $card['number'$this->cardNumber;
  83.     $card['month']  $this->expMonth;
  84.     $card['year']   $this->expYear;
  85.  
  86.     $check = false;
  87.     switch($this->type)
  88.     {
  89.       case PROCESS_TYPE_VISA:
  90.         $card['type'= VALIDATE_CREDITCARD_TYPE_VS;
  91.         break;
  92.       case PROCESS_TYPE_MASTERCARD:
  93.         $card['type'= VALIDATE_CREDITCARD_TYPE_MC;
  94.         break;
  95.       case PROCESS_TYPE_AMEX:
  96.         $card['type'= VALIDATE_CREDITCARD_TYPE_AX;
  97.         break;
  98.       case PROCESS_TYPE_DISCOVER:
  99.         $card['type'= VALIDATE_CREDITCARD_TYPE_DS;
  100.         break;
  101.       case PROCESS_TYPE_CHECK:
  102.         return $check = true; // Nothing to process - it's a check
  103.     }
  104.   
  105.     if (!$check{
  106.       $this->_result    = Validate_CreditCard::card($card);
  107.       $this->_processed = true;
  108.     }
  109.   
  110.     if ($this->_result{
  111.       $code = PROCESS_RESULT_APPROVED;
  112.       $message 'Valid Credit Card';
  113.     else {
  114.       $code = PROCESS_RESULT_DECLINED;
  115.       
  116.       // Run extra checks to get a better error message
  117.       if(Validate_CreditCard::number($card['number'])) {
  118.         $message 'Card number is invalid';
  119.       elseif(Validate_CreditCard::expiryDate($card['month'],$card['year'])) {
  120.         $message 'Invalid expriation date';
  121.       elseif(Validate_CreditCard::expiryDate($card['number'],$card['type'])) {
  122.         $message 'Card number does not match specified type';
  123.       }
  124.     }
  125.  
  126.     if($code == PROCESS_RESULT_DECLINED{
  127.       return PEAR::raiseError($message,$code);
  128.     else {
  129.       return new Payment_Process_Result($message,$code);
  130.     }
  131.   }
  132.  
  133.   /**
  134.   * getStatus
  135.   *
  136.   * Return status or PEAR_Error when it has not been processed yet.
  137.   *
  138.   * @author Joe Stump <joe@joestump.net>
  139.   * @access public
  140.   */
  141.   function getStatus(
  142.   {
  143.     if(!$this->processed
  144.       return PEAR::raiseError('The transaction has not been processed yet.'PROCESS_ERROR_INCOMPLETE);
  145.     }
  146.  
  147.     return $this->_response;
  148.   }
  149. }
  150.  
  151. ?>

Documentation generated on Mon, 11 Mar 2019 13:51:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.