|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZPaymentObject class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZPaymentObject ezpaymentobject.php 00013 \brief This is a base class for objects, which 00014 uses in redirectional payment gateways. 00015 They stores in database information about payment processing. 00016 These objects are temporary and will be destroyed after 00017 payment approvement. 00018 00019 */ 00020 00021 class eZPaymentObject extends eZPersistentObject 00022 { 00023 const STATUS_NOT_APPROVED = 0; 00024 const STATUS_APPROVED = 1; 00025 00026 /*! 00027 Constructor. 00028 */ 00029 function eZPaymentObject( $row ) 00030 { 00031 $this->eZPersistentObject( $row ); 00032 } 00033 00034 /*! 00035 \static 00036 Creates new object. 00037 */ 00038 static function createNew( $workflowprocessID, $orderID, $paymentType ) 00039 { 00040 return new eZPaymentObject( array( 'workflowprocess_id' => $workflowprocessID, 00041 'order_id' => $orderID, 00042 'payment_string' => $paymentType ) ); 00043 } 00044 00045 /*! 00046 Approves payment. 00047 */ 00048 function approve() 00049 { 00050 $this->setAttribute( 'status', self::STATUS_APPROVED ); 00051 $this->store(); 00052 } 00053 00054 function approved() 00055 { 00056 return ( $this->attribute( 'status' ) == self::STATUS_APPROVED ); 00057 } 00058 00059 static function definition() 00060 { 00061 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 00062 'datatype' => 'integer', 00063 'default' => 0, 00064 'required' => true ), 00065 'workflowprocess_id' => array( 'name' => 'WorkflowProcessID', 00066 'datatype'=> 'integer', 00067 'default' => 0, 00068 'required'=> true, 00069 'foreign_class' => 'eZWorkflowProcess', 00070 'foreign_attribute' => 'id', 00071 'multiplicity' => '1..*' ), 00072 'order_id' => array( 'name' => 'OrderID', 00073 'datatype'=> 'integer', 00074 'default' => 0, 00075 'required'=> false, 00076 'foreign_class' => 'eZOrder', 00077 'foreign_attribute' => 'id', 00078 'multiplicity' => '1..*' ), 00079 'payment_string' => array( 'name' => 'PaymentString', 00080 'datatype'=> 'string', 00081 'default' => 'Payment', 00082 'required'=> false ), 00083 'status' => array( 'name' => 'Status', 00084 'datatype'=> 'integer', 00085 'default' => 0, 00086 'required'=> true ) ), 00087 'keys' => array( 'id' ), 00088 'increment_key' => 'id', 00089 'class_name' => 'eZPaymentObject', 00090 'name' => 'ezpaymentobject' ); 00091 } 00092 00093 /*! 00094 \static 00095 Returns eZPaymentObject by 'id'. 00096 */ 00097 static function fetchByID( $transactionID ) 00098 { 00099 return eZPersistentObject::fetchObject( eZPaymentObject::definition(), 00100 null, 00101 array( 'id' => $transactionID ) ); 00102 } 00103 00104 /*! 00105 \static 00106 Returns eZPaymentObject by 'id' of eZOrder. 00107 */ 00108 static function fetchByOrderID( $orderID ) 00109 { 00110 return eZPersistentObject::fetchObject( eZPaymentObject::definition(), 00111 null, 00112 array( 'order_id' => $orderID ) ); 00113 } 00114 00115 /*! 00116 \static 00117 Returns eZPaymentObject by 'id' of eZWorkflowProcess. 00118 */ 00119 static function fetchByProcessID( $workflowprocessID ) 00120 { 00121 return eZPersistentObject::fetchObject( eZPaymentObject::definition(), 00122 null, 00123 array( 'workflowprocess_id' => $workflowprocessID ) ); 00124 } 00125 00126 /*! 00127 \static 00128 Continues workflow after approvement. 00129 */ 00130 static function continueWorkflow( $workflowProcessID ) 00131 { 00132 $operationResult = null; 00133 $theProcess = eZWorkflowProcess::fetch( $workflowProcessID ); 00134 if ( $theProcess != null ) 00135 { 00136 //restore memento and run it 00137 $bodyMemento = eZOperationMemento::fetchChild( $theProcess->attribute( 'memento_key' ) ); 00138 if ( $bodyMemento === null ) 00139 { 00140 eZDebug::writeError( $bodyMemento, "Empty body memento in workflow.php" ); 00141 return $operationResult; 00142 } 00143 $bodyMementoData = $bodyMemento->data(); 00144 $mainMemento = $bodyMemento->attribute( 'main_memento' ); 00145 if ( !$mainMemento ) 00146 { 00147 return $operationResult; 00148 } 00149 00150 $mementoData = $bodyMemento->data(); 00151 $mainMementoData = $mainMemento->data(); 00152 $mementoData['main_memento'] = $mainMemento; 00153 $mementoData['skip_trigger'] = false; 00154 $mementoData['memento_key'] = $theProcess->attribute( 'memento_key' ); 00155 $bodyMemento->remove(); 00156 00157 $operationParameters = array(); 00158 if ( isset( $mementoData['parameters'] ) ) 00159 $operationParameters = $mementoData['parameters']; 00160 00161 $operationResult = eZOperationHandler::execute( $mementoData['module_name'], 00162 $mementoData['operation_name'], 00163 $operationParameters, 00164 $mementoData ); 00165 } 00166 00167 return $operationResult; 00168 } 00169 } 00170 ?>