Development

Changeset 25735

You must first sign up to be able to contribute.

Changeset 25735

Show
Ignore:
Timestamp:
12/21/09 17:35:47 (3 years ago)
Author:
marijn
Message:

[sfPaymentPlugin] Reorganized transaction classes and interfaces and updated the implementations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPaymentPlugin/branches/1.2-marijn/lib/sfSellable.php

    r25580 r25735  
    2626    function getAmount (); 
    2727 
     28    /** 
     29     * Get the description for the transaction. 
     30     * 
     31     * @return  string  The description for the transaction. 
     32     */ 
     33    function getDescription (); 
     34 
    2835  } 
  • plugins/sfPaymentPlugin/branches/1.2-marijn/lib/transaction/sfTransaction.php

    r25619 r25735  
    22 
    33  /** 
    4    * General transaction implementation
     4   * Base class for sfTransactionInterface implementations
    55   *  
    66   * @package   sfPaymentPlugin 
     
    202202      if ($this->_amount !== (int) $arg_amount) 
    203203      { 
    204         throw new sfTransactionException(sprintf('Amount returned by gateway %d doesn\'t match requested amount %d.', $arg_amount, $this->_amount)); 
     204        throw new sfTransactionException(sprintf('Amount returned by gateway "%d" doesn\'t match requested amount "%d".', $arg_amount, $this->_amount)); 
    205205      } 
    206206    } 
     
    217217      if ($this->_currency !== $arg_currency) 
    218218      { 
    219         throw new sfTransactionException(sprintf('Currency returned by gateway %s doesn\'t match requested currency %s.', $arg_currency, $this->_currency)); 
    220       } 
     219        throw new sfTransactionException(sprintf('Currency returned by gateway "%s" doesn\'t match requested currency "%s".', $arg_currency, $this->_currency)); 
     220      } 
     221    } 
     222 
     223    /** 
     224     * Cast the object to an XML notation. 
     225     * 
     226     * @return  DomDocument 
     227     */ 
     228    public function toXmlElement () 
     229    { 
     230      return sprintf("<transaction%s>\n  <!-- test -->\n</transaction>" 
     231                    ,$this->_getTransactionNodeAttributes() ?: ''); 
     232    } 
     233 
     234    /** 
     235     * Create an object from an XML node. 
     236     * 
     237     * @param   string  $arg_xmlElement The XML representation. 
     238     * 
     239     * @return  void 
     240     */ 
     241    public function fromXmlElement (SimpleXMLElement $arg_xmlElement) 
     242    { 
     243      $attributes = $arg_xmlElement->attributes; 
     244 
     245      foreach ($attributes as $key => $value) 
     246      { 
     247        if (NULL !== $value) 
     248        { 
     249          $method = 'set' . ucfirst($key); 
     250 
     251          $this->$method($value); 
     252        } 
     253      } 
     254    } 
     255 
     256    /** 
     257     * Get the XML attributes for the transaction node. 
     258     * 
     259     * @return  string 
     260     */ 
     261    private function _getTransactionNodeAttributes () 
     262    { 
     263      $fields     = array('transactionId', 'status'); 
     264      $attributes = array(); 
     265 
     266      foreach ($fields as $fieldName) 
     267      { 
     268        $method = 'get' . ucfirst($fieldName); 
     269        $value  = $this->$method(); 
     270 
     271        if (NULL !== $value) 
     272        { 
     273          $attributes[] = $fieldName . '="' . $value . '"'; 
     274        } 
     275      } 
     276 
     277      return implode(' ', $attributes); 
    221278    } 
    222279 
  • plugins/sfPaymentPlugin/branches/1.2-marijn/lib/transaction/sfTransactionInterface.php

    r25619 r25735  
    99   * @version   $Revision$ changed by $Author$ 
    1010   */ 
    11   interface sfTransactionInterface 
     11  interface sfTransactionInterface extends sfSellable 
    1212  { 
    1313 
     
    6363 
    6464    /** 
    65      * Get the amount for the transaction. 
    66      * 
    67      * @return  integer The amount for the transaction in cents. 
    68      */ 
    69     function getAmount (); 
    70  
    71     /** 
    7265     * Set the amount for the transaction. 
    7366     * 
     
    9588 
    9689    /** 
    97      * Get the currency for the transaction. 
    98      * 
    99      * @return  string  The currency for the transaction. 
    100      */ 
    101     function getCurrency (); 
    102  
    103     /** 
    10490     * Set the currency for the transaction. 
    10591     * 
     
    10995     */ 
    11096    function setCurrency ($arg_currency); 
    111  
    112     /** 
    113      * Get the description for the transaction. 
    114      * 
    115      * @return  string  The description for the transaction. 
    116      */ 
    117     function getDescription (); 
    11897 
    11998    /** 
     
    144123    function checkCurrency ($arg_currency); 
    145124 
     125    /** 
     126     * Cast the object to an XML notation. 
     127     * 
     128     * @return  DomDocument 
     129     */ 
     130    function toXml (); 
     131 
     132    /** 
     133     * Create an object from an XML data source. 
     134     * 
     135     * @param   string  $arg_xml  The XML representation. 
     136     * 
     137     * @return  void 
     138     */ 
     139    function fromXml ($arg_xml); 
     140 
    146141  }