/
ezredirectgateway.php
179 lines (157 loc) · 5.55 KB
/
ezredirectgateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
//
// Definition of eZRedirectGateway class
//
// Created on: <11-Jun-2004 14:18:58 dl>
//
// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
// SOFTWARE NAME: eZ publish
// SOFTWARE RELEASE: 3.8.x
// COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//
/*! \file ezredirectgateway.php
*/
/*!
\class eZRedirectGateway ezredirectgateway.php
\brief The class eZRedirectGateway is a
base class for payment gateways which
support payment through redirection to
the payment site and payment notifications
throught callbacks(postbacks).
*/
define( "EZ_REDIRECT_GATEWAY_OBJECT_NOT_CREATED", 1 );
define( "EZ_REDIRECT_GATEWAY_OBJECT_CREATED" , 2 );
include_once( 'kernel/shop/classes/ezpaymentgateway.php' );
class eZRedirectGateway extends eZPaymentGateway
{
/*!
Constructor.
*/
function eZRedirectGateway()
{
//__DEBUG__
$this->logger = eZPaymentLogger::CreateForAdd( "var/log/eZRedirectGateway.log" );
$this->logger->writeTimedString( 'eZRedirectGateway::eZRedirectGateway()' );
//___end____
}
function execute( &$process, &$event )
{
//__DEBUG__
$this->logger->writeTimedString("execute");
//___end____
$processParameters =& $process->attribute( 'parameter_list' );
$processID = $process->attribute( 'id' );
switch ( $process->attribute( 'event_state' ) )
{
case EZ_REDIRECT_GATEWAY_OBJECT_CREATED:
{
//__DEBUG__
$this->logger->writeTimedString("case EZ_REDIRECT_GATEWAY_OBJECT_CREATED");
//___end____
$thePayment = eZPaymentObject::fetchByProcessID( $processID );
if ( is_object( $thePayment ) && $thePayment->approved() )
{
//__DEBUG__
$this->logger->writeTimedString("Payment accepted.");
//___end____
return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
}
//__DEBUG__
else
{
$this->logger->writeTimedString("Error. Payment rejected: unable to fetch 'eZPaymentObject' or payment status 'not approved'");
}
//___end____
return EZ_WORKFLOW_TYPE_STATUS_REJECTED;
}break;
case EZ_REDIRECT_GATEWAY_OBJECT_NOT_CREATED:
//__DEBUG__
$this->logger->writeTimedString("case EZ_REDIRECT_GATEWAY_OBJECT_NOT_CREATED");
//___end____
default:
{
$orderID = $processParameters['order_id'];
$paymentObject =& $this->createPaymentObject( $processID, $orderID );
if( is_object( $paymentObject ) )
{
$paymentObject->store();
$process->setAttribute( 'event_state', EZ_REDIRECT_GATEWAY_OBJECT_CREATED );
$process->RedirectUrl = $this->createRedirectionUrl( $process );
}
else
{
//__DEBUG__
$this->logger->writeTimedString("Unable to create 'eZPaymentObject'. Payment rejected.");
//___end____
return EZ_WORKFLOW_TYPE_STATUS_REJECTED;
}
}break;
};
//__DEBUG__
$this->logger->writeTimedString("return EZ_WORKFLOW_TYPE_STATUS_REDIRECT_REPEAT");
//___end____
return EZ_WORKFLOW_TYPE_STATUS_REDIRECT_REPEAT;
}
function needCleanup()
{
return true;
}
/*!
Removes temporary eZPaymentObject from database.
*/
function cleanup( &$process, &$event )
{
//__DEBUG__
$this->logger->writeTimedString("cleanup");
//___end____
$paymentObj = eZPaymentObject::fetchByProcessID( $process->attribute( 'id' ) );
if ( is_object( $paymentObj ) )
{
$paymentObj->remove();
}
}
/*!
Creates instance of subclass of eZPaymentObject which stores
information about payment processing(orderID, workflowID, ...).
Must be overridden in subclass.
*/
function &createPaymentObject( &$processID, &$orderID )
{
//__DEBUG__
$this->logger->writeTimedString("createPaymentObject. You have to override this");
//___end____
$theObject = null;
return $theObject;
}
/*!
Creates redirection url to payment site.
Must be overridden in subclass.
*/
function &createRedirectionUrl( &$process )
{
//__DEBUG__
$this->logger->writeTimedString("createRedirectionUrl. You have to override this");
//___end____
$theObject = null;
return $theObject;
}
}
?>