forked from Pragmawork/org.civicrm.payment.ogone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ogone.php
215 lines (191 loc) · 6.52 KB
/
Ogone.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
require_once 'CRM/Core/Payment.php';
require_once 'OgoneUtils.php';
class org_civicrm_payment_ogone extends CRM_Core_Payment {
/**
* We only need one instance of this object. So we use the singleton
* pattern and cache the instance in this variable
*
* @var object
* @static
*/
static private $_singleton = null;
/**
* mode of operation: live or test
*
* @var object
* @static
*/
static protected $_mode = null;
/**
* Constructor
*
* @param string $mode the mode of operation: live or test
*
* @return void
*/
function __construct( $mode, &$paymentProcessor ) {
$this->_mode = $mode;
$this->_paymentProcessor = $paymentProcessor;
$this->_processorName = ts('Ogone');
}
/**
* singleton function used to manage this object
*
* @param string $mode the mode of operation: live or test
*
* @return object
* @static
*
*/
static function &singleton( $mode, &$paymentProcessor ) {
$processorName = $paymentProcessor['name'];
if (self::$_singleton[$processorName] === null ) {
self::$_singleton[$processorName] = new org_civicrm_payment_ogone($mode, $paymentProcessor);
}
return self::$_singleton[$processorName];
}
/**
* This function checks to see if we have the right config values
*
* @return string the error message if any
* @public
*/
function checkConfig( ) {
$config = CRM_Core_Config::singleton();
$error = array();
if (empty($this->_paymentProcessor['user_name'])) {
$error[] = ts('The "PSPID" is not set in the Administer CiviCRM Payment Processor.');
}
if (!empty($error)) {
return implode('<p>', $error);
} else {
return NULL;
}
}
function doDirectPayment(&$params) {
CRM_Core_Error::fatal(ts('This function is not implemented'));
}
/**
* Sets appropriate parameters for checking out to Ogone
*
* @param array $params name value pair of contribution datat
*
* @return void
* @access public
*
*/
function doTransferCheckout($params, $component) {
$config = CRM_Core_Config::singleton();
CRM_Core_Error::debug_var('doTransferCheckOut - params', $params);
CRM_Core_Error::debug_var('doTransferCheckOut - component', $component);
if ($component != 'contribute' && $component != 'event') {
CRM_Core_Error::fatal(ts('Component is invalid'));
}
// Start building our parameters
// - Algemene parameters
// PSPID
// orderID
// amount
// currency
// language
// CN
// EMAIL
// ownerZIP
// owneraddress
// ownercty
// ownertown
// ownertelno
// - Controle voor betaling
// SHASign
// - Feedback na betaling
// accepturl
// declineurl
// exceptionurl
// cancelurl
//
// In order to calculate SHA1 hash:
// * parameters sorted in alphabetical order,
// * parameter names in uppercase
// * name=value pairs separated with SHA passphrase (defined in Ogone > Technical info settings)
//
$OgoneParams['PSPID'] = $this->_paymentProcessor['user_name'];
//TODO: from Ogone tech spec
// Although our system can accept up to 30 characters, the norm for most acquirers is 10 or 12.
// The exact accepted length and data validation format depend on the acquirer/bank.
// If the orderID does not comply to the ref2 rules set by the acquirer, we’ll send our PAYID as ref2 to the acquirer instead.
// Avoid using spaces or special characters in the orderID.
//
// We need to encode following values in orderID to allow further processing in OgoneIPN.php
// getContext() in OgoneIPN.php
// contributionId
// eventID
// newOrderNotify() in OgoneIPN.php
// contactID
// contributionId
// eventID
// participantID
// membershipID
// invoiceID - SKIP THIS AND MODIFY newOrderNotify() to ignore this.
// invoiceID is too long and causes Ogone orderid to exceed its maximum value of 30 chars.
//
$orderID = array(
CRM_Utils_Array::value('contactID', $params),
CRM_Utils_Array::value('contributionID', $params),
CRM_Utils_Array::value('contributionTypeID', $params),
CRM_Utils_Array::value('eventID', $params),
CRM_Utils_Array::value('participantID', $params),
CRM_Utils_Array::value('membershipID', $params)
);
$OgoneParams['orderID'] = implode('-', $orderID);
$OgoneParams['amount'] = sprintf("%d", (float)$params['amount'] * 100);
$OgoneParams['currency'] = 'EUR';
if (isset($params['preferred_language'])) {
$OgoneParams['language'] = $params['preferred_language'];
} else {
$OgoneParams['language'] = 'nl_NL';
}
if (isset($params['first_name']) || isset($params['last_name'])) {
$OgoneParams['CN'] = $params['first_name'] . ' ' . $params['last_name'];
}
if (isset($params['email'])) {
$OgoneParams['EMAIL'] = $params['email'];
}
if (isset($params['postal_code-1'])) {
$OgoneParams['ownerZIP'] = $params['postal_code-1'];
}
if (isset($params['street_address-1'])) {
$OgoneParams['owneraddress'] = $params['street_address-1'];
}
if (isset($params['country-1'])) {
$OgoneParams['ownercty'] = $params['country-1'];
}
if (isset($params['city-1'])) {
$OgoneParams['ownertown'] = $params['city-1'];
}
if (isset($params['phone-1'])) {
$OgoneParams['ownertelno'] = $params['phone'];
}
$notifyURL = $config->userFrameworkResourceURL . "extern/OgoneNotify.php";
$notifyURL .= "?qfKey=" . $params['qfKey'];
$OgoneParams['accepturl'] = $notifyURL;
$OgoneParams['declineurl'] = $notifyURL;
$OgoneParams['exceptionurl'] = $notifyURL;
$OgoneParams['cancelurl'] = $notifyURL;
$shaSign = calculateSHA1($OgoneParams, $this->_paymentProcessor['password']);
$OgoneParams['SHASign'] = $shaSign;
//CRM_Core_Error::debug_var('doTransferCheckout - OgoneParams', $OgoneParams);
// Allow further manipulation of the arguments via custom hooks ..
CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $OgoneParams);
// Build our query string;
$query_string = '';
foreach ($OgoneParams as $name => $value) {
$query_string .= $name . '=' . urlencode($value) . '&';
}
// Remove extra &
$query_string = rtrim($query_string, '&');
// Redirect the user to the payment url.
CRM_Utils_System::redirect($this->_paymentProcessor['url_site'] . '?' . $query_string);
exit();
}
}