Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpaymentgatewaytype.php
Go to the documentation of this file.
1 <?php
19 class eZPaymentGatewayType extends eZWorkflowEventType
20 {
21 const WORKFLOW_TYPE_STRING = 'ezpaymentgateway';
22 const GATEWAY_NOT_SELECTED = 0;
23 const GATEWAY_SELECTED = 1;
24
25 public function __construct()
26 {
27 $this->logger = eZPaymentLogger::CreateForAdd( "var/log/eZPaymentGatewayType.log" );
28
29 parent::__construct( eZPaymentGatewayType::WORKFLOW_TYPE_STRING, ezpI18n::tr( 'kernel/workflow/event', "Payment Gateway" ) );
30 $this->loadAndRegisterGateways();
31 }
32
40 function execute( $process, $event )
41 {
42 $this->logger->writeTimedString( 'execute' );
43
44 if( $process->attribute( 'event_state' ) == eZPaymentGatewayType::GATEWAY_NOT_SELECTED )
45 {
46 $this->logger->writeTimedString( 'execute: eZPaymentGatewayType::GATEWAY_NOT_SELECTED' );
47
48 $process->setAttribute( 'event_state', eZPaymentGatewayType::GATEWAY_SELECTED );
49 if ( !$this->selectGateway( $event ) )
50 {
51 $process->Template = array();
52 $process->Template['templateName'] = 'design:workflow/selectgateway.tpl';
53 $process->Template['templateVars'] = array ( 'event' => $event );
54
55 return eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT;
56 }
57 }
58
59 $theGateway = $this->getCurrentGateway( $event );
60 if( $theGateway != null )
61 {
62 return $theGateway->execute( $process, $event );
63 }
64
65 $this->logger->writeTimedString( 'execute: something wrong' );
66 return eZWorkflowType::STATUS_REJECTED;
67 }
68
78 function attributeDecoder( $event, $attr )
79 {
80 switch ( $attr )
81 {
82 case 'selected_gateways_types':
83 {
84 return explode( ',', $event->attribute( 'data_text1' ) );
85 }
86 break;
87
88 case 'selected_gateways':
89 {
90 $selectedGatewaysTypes = explode( ',', $event->attribute( 'data_text1' ) );
91 return $this->getGateways( $selectedGatewaysTypes );
92 }break;
93
94 case 'current_gateway':
95 {
96 return $event->attribute( 'data_text2' );
97 }
98 break;
99 }
100 return null;
101 }
102
103 function typeFunctionalAttributes( )
104 {
105 return array( 'selected_gateways_types', 'selected_gateways', 'current_gateway' );
106 }
107
108 function attributes()
109 {
110 return array_merge( array( 'available_gateways' ),
111 eZWorkflowEventType::attributes() );
112 }
113
114 function hasAttribute( $attr )
115 {
116 return in_array( $attr, $this->attributes() );
117 }
118
119 function attribute( $attr )
120 {
121 switch( $attr )
122 {
123 case 'available_gateways':
124 {
125 return $this->getGateways( array( -1 ) );
126 }break;
127 }
128 return eZWorkflowEventType::attribute( $attr );
129 }
130
136 function loadAndRegisterGateways()
137 {
138 eZPaymentGatewayType::loadAndRegisterBuiltInGateways();
139 eZPaymentGatewayType::loadAndRegisterExtensionGateways();
140 }
141
145 function loadAndRegisterBuiltInGateways()
146 {
147 $gatewaysINI = eZINI::instance( 'paymentgateways.ini' );
148 $gatewaysTypes = $gatewaysINI->variable( 'GatewaysSettings', 'AvailableGateways' );
149 $gatewaysDir = false;
150
151 // GatewaysDirectories was spelt as GatewaysDerictories, which is
152 // confusing for people writing ini files - it's a typo.
153 if ( $gatewaysINI->hasVariable( 'GatewaysSettings', 'GatewaysDerictories' ) )
154 $gatewaysDir = $gatewaysINI->variable( 'GatewaysSettings', 'GatewaysDerictories' );
155 else
156 $gatewaysDir = $gatewaysINI->variable( 'GatewaysSettings', 'GatewaysDirectories' );
157
158 if ( is_array( $gatewaysDir ) && is_array( $gatewaysTypes ) )
159 {
160 foreach( $gatewaysDir as $dir )
161 {
162 foreach( $gatewaysTypes as $gateway )
163 {
164 $gatewayPath = "$dir/$gateway/classes/" . $gateway . 'gateway.php';
165 if( file_exists( $gatewayPath ) )
166 {
167 include_once( $gatewayPath );
168 }
169 }
170 }
171 }
172 }
173
177 function loadAndRegisterExtensionGateways()
178 {
179 $gatewaysINI = eZINI::instance( 'paymentgateways.ini' );
180 $siteINI = eZINI::instance( 'site.ini' );
181 $extensionDirectory = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' );
182 $activeExtensions = eZExtension::activeExtensions();
183
184 foreach ( $activeExtensions as $extension )
185 {
186 $gatewayPath = "$extensionDirectory/$extension/classes/" . $extension . 'gateway.php';
187 if ( file_exists( $gatewayPath ) )
188 {
189 include_once( $gatewayPath );
190 }
191 }
192 }
193
198 function registerGateway( $gateway, $class_name, $description )
199 {
200 $gateways =& $GLOBALS["eZPaymentGateways"];
201 if ( !is_array( $gateways ) )
202 {
203 $gateways = array();
204 }
205
206 if ( isset( $gateways[$gateway] ) )
207 {
208 eZDebug::writeError( "Gateway already registered: $gateway", __METHOD__ );
209 }
210 else
211 {
212 $gateways[$gateway] = array( "class_name" => $class_name, "description" => $description );
213 }
214 }
215
221 function getGateways( $gatewaysTypes )
222 {
223 $gateways = array();
224 $availableGateways = $GLOBALS[ 'eZPaymentGateways' ];
225 if ( !is_array( $availableGateways ) ){
226 return $gateways;
227 }
228
229 if ( in_array( '-1', $gatewaysTypes ) )
230 {
231 $gatewaysTypes = array_keys( $availableGateways );
232 }
233
234 foreach ( $gatewaysTypes as $key )
235 {
236 $gateway = $availableGateways[$key];
237
238 $gateway['Name'] = $gateway['description'];
239 $gateway['value'] = $key;
240 $gateways[] = $gateway;
241 }
242
243 return $gateways;
244 }
245
250 function createGateway( $inGatewayType )
251 {
252 $gateway_difinition = $GLOBALS[ 'eZPaymentGateways' ][ $inGatewayType ];
253
254 $this->logger->writeTimedString( $gateway_difinition, "createGateway. gateway_difinition" );
255
256 if( $gateway_difinition )
257 {
258 $class_name = $gateway_difinition[ 'class_name' ];
259 return new $class_name();
260 }
261
262 return null;
263 }
264
269 function getCurrentGateway( $event )
270 {
271 $theGateway = null;
272 $gatewayType = $this->getCurrentGatewayType( $event );
273
274 if( $gatewayType != null )
275 {
276 $theGateway = $this->createGateway( $gatewayType );
277 }
278
279 return $theGateway;
280 }
281
286 function getCurrentGatewayType( $event )
287 {
288 $gateway = null;
289 $http = eZHTTPTool::instance();
290
291 if ( $http->hasPostVariable( 'SelectButton' ) && $http->hasPostVariable( 'SelectedGateway' ) )
292 {
293 $gateway = $http->postVariable( 'SelectedGateway' );
294 $event->setAttribute( 'data_text2', $gateway );
295 $event->store();
296 }
297 else if ( $http->hasPostVariable( 'CancelButton' ) )
298 {
299 $gateway = null;
300 }
301 else
302 {
303 $gateway = $event->attribute( 'current_gateway' );
304 }
305
306 return $gateway;
307 }
308
315 function selectGateway( $event )
316 {
317 $selectedGatewaysTypes = explode( ',', $event->attribute( 'data_text1' ) );
318
319 if ( count( $selectedGatewaysTypes ) == 1 && $selectedGatewaysTypes[0] != -1 )
320 {
321 $event->setAttribute( 'data_text2', $selectedGatewaysTypes[0] );
322 $event->store();
323
324 $this->logger->writeTimedString( $selectedGatewaysTypes[0], 'selectGateway' );
325 return true;
326 }
327
328 $this->logger->writeTimedString( 'selectGateways. multiple gateways, let user choose.' );
329 return false;
330 }
331
332 function needCleanup()
333 {
334 return true;
335 }
336
341 function cleanup( $process, $event )
342 {
343 $theGateway = $this->getCurrentGateway( $event );
344 if( $theGateway != null and $theGateway->needCleanup() )
345 {
346 $theGateway->cleanup( $process, $event );
347 }
348 }
349
350 function initializeEvent( $event )
351 {
352 }
353
359 function fetchHTTPInput( $http, $base, $event )
360 {
361 $gatewaysVar = $base . "_event_ezpaymentgateway_gateways_" . $event->attribute( "id" );
362 if ( $http->hasPostVariable( $gatewaysVar ) )
363 {
364 $gatewaysArray = $http->postVariable( $gatewaysVar );
365 if ( in_array( '-1', $gatewaysArray ) )
366 {
367 $gatewaysArray = array( -1 );
368 }
369
370 $gatewaysString = implode( ',', $gatewaysArray );
371 $event->setAttribute( "data_text1", $gatewaysString );
372 }
373 }
374
375 public $logger;
376 }
377
378 eZWorkflowEventType::registerEventType( eZPaymentGatewayType::WORKFLOW_TYPE_STRING, 'ezpaymentgatewaytype' );
379 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\activeExtensions
static activeExtensions( $extensionType=false, eZINI|null $siteINI=null)
Definition: ezextension.php:60
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZPaymentGatewayType
Interface for different types of payment gateways.
Definition: ezpaymentgatewaytype.php:20
eZPaymentGatewayType\attributeDecoder
attributeDecoder( $event, $attr)
Definition: ezpaymentgatewaytype.php:78
eZPaymentGatewayType\WORKFLOW_TYPE_STRING
const WORKFLOW_TYPE_STRING
Definition: ezpaymentgatewaytype.php:21
eZPaymentGatewayType\GATEWAY_NOT_SELECTED
const GATEWAY_NOT_SELECTED
Definition: ezpaymentgatewaytype.php:22
eZPaymentGatewayType\GATEWAY_SELECTED
const GATEWAY_SELECTED
Definition: ezpaymentgatewaytype.php:23
eZPaymentGatewayType\attribute
attribute( $attr)
Definition: ezpaymentgatewaytype.php:119
eZPaymentGatewayType\createGateway
createGateway( $inGatewayType)
Definition: ezpaymentgatewaytype.php:250
eZPaymentGatewayType\hasAttribute
hasAttribute( $attr)
Definition: ezpaymentgatewaytype.php:114
eZPaymentGatewayType\getGateways
getGateways( $gatewaysTypes)
Definition: ezpaymentgatewaytype.php:221
eZPaymentGatewayType\attributes
attributes()
Definition: ezpaymentgatewaytype.php:108
eZPaymentGatewayType\$logger
$logger
Definition: ezpaymentgatewaytype.php:375
eZPaymentGatewayType\getCurrentGateway
getCurrentGateway( $event)
Definition: ezpaymentgatewaytype.php:269
eZPaymentGatewayType\needCleanup
needCleanup()
Definition: ezpaymentgatewaytype.php:332
eZPaymentGatewayType\fetchHTTPInput
fetchHTTPInput( $http, $base, $event)
Definition: ezpaymentgatewaytype.php:359
eZPaymentGatewayType\loadAndRegisterExtensionGateways
loadAndRegisterExtensionGateways()
Definition: ezpaymentgatewaytype.php:177
eZPaymentGatewayType\loadAndRegisterBuiltInGateways
loadAndRegisterBuiltInGateways()
Definition: ezpaymentgatewaytype.php:145
eZPaymentGatewayType\registerGateway
registerGateway( $gateway, $class_name, $description)
Definition: ezpaymentgatewaytype.php:198
eZPaymentGatewayType\loadAndRegisterGateways
loadAndRegisterGateways()
Definition: ezpaymentgatewaytype.php:136
eZPaymentGatewayType\execute
execute( $process, $event)
Definition: ezpaymentgatewaytype.php:40
eZPaymentGatewayType\__construct
__construct()
Definition: ezpaymentgatewaytype.php:25
eZPaymentGatewayType\cleanup
cleanup( $process, $event)
Definition: ezpaymentgatewaytype.php:341
eZPaymentGatewayType\typeFunctionalAttributes
typeFunctionalAttributes()
Definition: ezpaymentgatewaytype.php:103
eZPaymentGatewayType\selectGateway
selectGateway( $event)
Definition: ezpaymentgatewaytype.php:315
eZPaymentGatewayType\getCurrentGatewayType
getCurrentGatewayType( $event)
Definition: ezpaymentgatewaytype.php:286
eZPaymentGatewayType\initializeEvent
initializeEvent( $event)
Definition: ezpaymentgatewaytype.php:350
eZPaymentLogger\CreateForAdd
static CreateForAdd($fileName)
Definition: ezpaymentlogger.php:27
eZWorkflowEventType
Definition: ezworkfloweventtype.php:18
eZWorkflowEventType\registerEventType
static registerEventType( $typeString, $class_name)
Definition: ezworkfloweventtype.php:40
eZWorkflowType\attribute
attribute( $attr)
Definition: ezworkflowtype.php:237
eZWorkflowType\STATUS_FETCH_TEMPLATE_REPEAT
const STATUS_FETCH_TEMPLATE_REPEAT
Definition: ezworkflowtype.php:28
eZWorkflowType\attributes
attributes()
Definition: ezworkflowtype.php:225
eZWorkflowType\STATUS_REJECTED
const STATUS_REJECTED
Definition: ezworkflowtype.php:22
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.