1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* osCommerce Online Merchant |
4
|
|
|
* |
5
|
|
|
* @copyright (c) 2016 osCommerce; https://www.oscommerce.com |
6
|
|
|
* @license MIT; https://www.oscommerce.com/license/mit.txt |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use OSC\OM\HTML; |
10
|
|
|
use OSC\OM\Mail; |
11
|
|
|
use OSC\OM\OSCOM; |
12
|
|
|
use OSC\OM\Registry; |
13
|
|
|
|
14
|
|
|
class sage_pay_form { |
15
|
|
|
var $code, $title, $description, $enabled; |
16
|
|
|
|
17
|
|
|
function __construct() { |
18
|
|
|
global $order; |
19
|
|
|
|
20
|
|
|
$this->signature = 'sage_pay|sage_pay_form|2.0|2.3'; |
|
|
|
|
21
|
|
|
$this->api_version = '3.00'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
$this->code = 'sage_pay_form'; |
24
|
|
|
$this->title = OSCOM::getDef('module_payment_sage_pay_form_text_title'); |
25
|
|
|
$this->public_title = OSCOM::getDef('module_payment_sage_pay_form_text_public_title'); |
|
|
|
|
26
|
|
|
$this->description = OSCOM::getDef('module_payment_sage_pay_form_text_description'); |
27
|
|
|
$this->sort_order = defined('MODULE_PAYMENT_SAGE_PAY_FORM_SORT_ORDER') ? MODULE_PAYMENT_SAGE_PAY_FORM_SORT_ORDER : 0; |
|
|
|
|
28
|
|
|
$this->enabled = defined('MODULE_PAYMENT_SAGE_PAY_FORM_STATUS') && (MODULE_PAYMENT_SAGE_PAY_FORM_STATUS == 'True') ? true : false; |
29
|
|
|
$this->order_status = defined('MODULE_PAYMENT_SAGE_PAY_FORM_ORDER_STATUS_ID') && ((int)MODULE_PAYMENT_SAGE_PAY_FORM_ORDER_STATUS_ID > 0) ? (int)MODULE_PAYMENT_SAGE_PAY_FORM_ORDER_STATUS_ID : 0; |
|
|
|
|
30
|
|
|
|
31
|
|
|
if ( defined('MODULE_PAYMENT_SAGE_PAY_FORM_STATUS') ) { |
32
|
|
|
if ( MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_SERVER == 'Test' ) { |
33
|
|
|
$this->title .= ' [Test]'; |
34
|
|
|
$this->public_title .= ' (' . $this->code . '; Test)'; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ( !function_exists('mcrypt_encrypt') ) { |
39
|
|
|
$this->description = '<div class="secWarning">' . OSCOM::getDef('module_payment_sage_pay_form_error_admin_mcrypt') . '</div>' . $this->description; |
40
|
|
|
|
41
|
|
|
$this->enabled = false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ( $this->enabled === true ) { |
45
|
|
|
if ( !tep_not_null(MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_LOGIN_NAME) || !tep_not_null(MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD) ) { |
46
|
|
|
$this->description = '<div class="secWarning">' . OSCOM::getDef('module_payment_sage_pay_form_error_admin_configuration') . '</div>' . $this->description; |
47
|
|
|
|
48
|
|
|
$this->enabled = false; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ( $this->enabled === true ) { |
53
|
|
|
if ( isset($order) && is_object($order) ) { |
54
|
|
|
$this->update_status(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ( $this->enabled === true ) { |
59
|
|
|
if ( MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_SERVER == 'Live' ) { |
60
|
|
|
$this->form_action_url = 'https://live.sagepay.com/gateway/service/vspform-register.vsp'; |
|
|
|
|
61
|
|
|
} else { |
62
|
|
|
$this->form_action_url = 'https://test.sagepay.com/gateway/service/vspform-register.vsp'; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
function update_status() { |
|
|
|
|
68
|
|
|
global $order; |
69
|
|
|
|
70
|
|
|
$OSCOM_Db = Registry::get('Db'); |
71
|
|
|
|
72
|
|
|
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SAGE_PAY_FORM_ZONE > 0) ) { |
|
|
|
|
73
|
|
|
$check_flag = false; |
74
|
|
|
$Qcheck = $OSCOM_Db->get('zones_to_geo_zones', 'zone_id', ['geo_zone_id' => MODULE_PAYMENT_SAGE_PAY_FORM_ZONE, 'zone_country_id' => $order->billing['country']['id']], 'zone_id'); |
75
|
|
|
while ($Qcheck->fetch()) { |
76
|
|
|
if ($Qcheck->valueInt('zone_id') < 1) { |
77
|
|
|
$check_flag = true; |
78
|
|
|
break; |
79
|
|
|
} elseif ($Qcheck->valueInt('zone_id') == $order->billing['zone_id']) { |
80
|
|
|
$check_flag = true; |
81
|
|
|
break; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($check_flag == false) { |
|
|
|
|
86
|
|
|
$this->enabled = false; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function javascript_validation() { |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function selection() { |
96
|
|
|
return array('id' => $this->code, |
97
|
|
|
'module' => $this->public_title); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function pre_confirmation_check() { |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function confirmation() { |
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function process_button() { |
109
|
|
|
global $order; |
110
|
|
|
|
111
|
|
|
$process_button_string = ''; |
112
|
|
|
|
113
|
|
|
$params = array('VPSProtocol' => $this->api_version, |
114
|
|
|
'Vendor' => substr(MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_LOGIN_NAME, 0, 15)); |
115
|
|
|
|
116
|
|
View Code Duplication |
if ( MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_METHOD == 'Payment' ) { |
|
|
|
|
117
|
|
|
$params['TxType'] = 'PAYMENT'; |
118
|
|
|
} elseif ( MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_METHOD == 'Deferred' ) { |
119
|
|
|
$params['TxType'] = 'DEFERRED'; |
120
|
|
|
} else { |
121
|
|
|
$params['TxType'] = 'AUTHENTICATE'; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$crypt = array('ReferrerID' => 'C74D7B82-E9EB-4FBD-93DB-76F0F551C802', |
125
|
|
|
'VendorTxCode' => substr(date('YmdHis') . '-' . $_SESSION['customer_id'] . '-' . $_SESSION['cartID'], 0, 40), |
126
|
|
|
'Amount' => $this->format_raw($order->info['total']), |
127
|
|
|
'Currency' => $_SESSION['currency'], |
128
|
|
|
'Description' => substr(STORE_NAME, 0, 100), |
129
|
|
|
'SuccessURL' => OSCOM::link('checkout_process.php'), |
130
|
|
|
'FailureURL' => OSCOM::link('checkout_payment.php', 'payment_error=' . $this->code), |
131
|
|
|
'CustomerName' => substr($order->billing['firstname'] . ' ' . $order->billing['lastname'], 0, 100), |
132
|
|
|
'CustomerEMail' => substr($order->customer['email_address'], 0, 255), |
133
|
|
|
'BillingSurname' => substr($order->billing['lastname'], 0, 20), |
134
|
|
|
'BillingFirstnames' => substr($order->billing['firstname'], 0, 20), |
135
|
|
|
'BillingAddress1' => substr($order->billing['street_address'], 0, 100), |
136
|
|
|
'BillingCity' => substr($order->billing['city'], 0, 40), |
137
|
|
|
'BillingPostCode' => substr($order->billing['postcode'], 0, 10), |
138
|
|
|
'BillingCountry' => $order->billing['country']['iso_code_2']); |
139
|
|
|
|
140
|
|
View Code Duplication |
if ($crypt['BillingCountry'] == 'US') { |
|
|
|
|
141
|
|
|
$crypt['BillingState'] = tep_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], ''); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$crypt['BillingPhone'] = substr($order->customer['telephone'], 0, 20); |
145
|
|
|
$crypt['DeliverySurname'] = substr($order->delivery['lastname'], 0, 20); |
146
|
|
|
$crypt['DeliveryFirstnames'] = substr($order->delivery['firstname'], 0, 20); |
147
|
|
|
$crypt['DeliveryAddress1'] = substr($order->delivery['street_address'], 0, 100); |
148
|
|
|
$crypt['DeliveryCity'] = substr($order->delivery['city'], 0, 40); |
149
|
|
|
$crypt['DeliveryPostCode'] = substr($order->delivery['postcode'], 0, 10); |
150
|
|
|
$crypt['DeliveryCountry'] = $order->delivery['country']['iso_code_2']; |
151
|
|
|
|
152
|
|
View Code Duplication |
if ($crypt['DeliveryCountry'] == 'US') { |
|
|
|
|
153
|
|
|
$crypt['DeliveryState'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], ''); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
if (tep_not_null(MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_EMAIL)) { |
157
|
|
|
$crypt['VendorEMail'] = substr(MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_EMAIL, 0, 255); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
switch (MODULE_PAYMENT_SAGE_PAY_FORM_SEND_EMAIL) { |
161
|
|
|
case 'No One': |
162
|
|
|
$crypt['SendEMail'] = 0; |
163
|
|
|
break; |
164
|
|
|
|
165
|
|
|
case 'Customer and Vendor': |
166
|
|
|
$crypt['SendEMail'] = 1; |
167
|
|
|
break; |
168
|
|
|
|
169
|
|
|
case 'Vendor Only': |
170
|
|
|
$crypt['SendEMail'] = 2; |
171
|
|
|
break; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if (tep_not_null(MODULE_PAYMENT_SAGE_PAY_FORM_CUSTOMER_EMAIL_MESSAGE)) { |
175
|
|
|
$crypt['eMailMessage'] = substr(MODULE_PAYMENT_SAGE_PAY_FORM_CUSTOMER_EMAIL_MESSAGE, 0, 7500); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$contents = array(); |
179
|
|
|
|
180
|
|
View Code Duplication |
foreach ($order->products as $product) { |
|
|
|
|
181
|
|
|
$product_name = $product['name']; |
182
|
|
|
|
183
|
|
|
if (isset($product['attributes'])) { |
184
|
|
|
foreach ($product['attributes'] as $att) { |
185
|
|
|
$product_name .= '; ' . $att['option'] . '=' . $att['value']; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$contents[] = str_replace(array(':', "\n", "\r", '&'), '', $product_name) . ':' . $product['qty'] . ':' . $this->format_raw($product['final_price']) . ':' . $this->format_raw(($product['tax'] / 100) * $product['final_price']) . ':' . $this->format_raw((($product['tax'] / 100) * $product['final_price']) + $product['final_price']) . ':' . $this->format_raw(((($product['tax'] / 100) * $product['final_price']) + $product['final_price']) * $product['qty']); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
View Code Duplication |
foreach ($this->getOrderTotalsSummary() as $ot) { |
|
|
|
|
193
|
|
|
$contents[] = str_replace(array(':', "\n", "\r", '&'), '', strip_tags($ot['title'])) . ':---:---:---:---:' . $this->format_raw($ot['value']); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$crypt['Basket'] = substr(sizeof($contents) . ':' . implode(':', $contents), 0, 7500); |
197
|
|
|
$crypt['Apply3DSecure'] = '0'; |
198
|
|
|
|
199
|
|
|
$crypt_string = ''; |
200
|
|
|
|
201
|
|
|
foreach ($crypt as $key => $value) { |
202
|
|
|
$crypt_string .= $key . '=' . trim($value) . '&'; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$crypt_string = substr($crypt_string, 0, -1); |
206
|
|
|
|
207
|
|
|
$params['Crypt'] = $this->encryptParams($crypt_string); |
208
|
|
|
|
209
|
|
|
foreach ($params as $key => $value) { |
210
|
|
|
$process_button_string .= HTML::hiddenField($key, $value); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $process_button_string; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
function before_process() { |
217
|
|
|
global $sage_pay_response; |
218
|
|
|
|
219
|
|
|
if (isset($_GET['crypt']) && tep_not_null($_GET['crypt'])) { |
220
|
|
|
$transaction_response = $this->decryptParams($_GET['crypt']); |
221
|
|
|
|
222
|
|
|
$string_array = explode('&', $transaction_response); |
223
|
|
|
$sage_pay_response = array('Status' => null); |
224
|
|
|
|
225
|
|
View Code Duplication |
foreach ($string_array as $string) { |
|
|
|
|
226
|
|
|
if (strpos($string, '=') != false) { |
|
|
|
|
227
|
|
|
$parts = explode('=', $string, 2); |
228
|
|
|
$sage_pay_response[trim($parts[0])] = trim($parts[1]); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
232
|
|
View Code Duplication |
if ( ($sage_pay_response['Status'] != 'OK') && ($sage_pay_response['Status'] != 'AUTHENTICATED') && ($sage_pay_response['Status'] != 'REGISTERED') ) { |
|
|
|
|
233
|
|
|
$this->sendDebugEmail($sage_pay_response); |
234
|
|
|
|
235
|
|
|
$error = $this->getErrorMessageNumber($sage_pay_response['StatusDetail']); |
236
|
|
|
|
237
|
|
|
OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . (tep_not_null($error) ? '&error=' . $error : '')); |
238
|
|
|
} |
239
|
|
|
} else { |
240
|
|
|
OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
function after_process() { |
245
|
|
|
global $insert_id, $sage_pay_response; |
246
|
|
|
|
247
|
|
|
$OSCOM_Db = Registry::get('Db'); |
248
|
|
|
|
249
|
|
|
$result = array(); |
250
|
|
|
|
251
|
|
|
if ( isset($sage_pay_response['VPSTxId']) ) { |
252
|
|
|
$result['ID'] = $sage_pay_response['VPSTxId']; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
if ( isset($sage_pay_response['CardType']) ) { |
256
|
|
|
$result['Card'] = $sage_pay_response['CardType']; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
if ( isset($sage_pay_response['AVSCV2']) ) { |
260
|
|
|
$result['AVS/CV2'] = $sage_pay_response['AVSCV2']; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
if ( isset($sage_pay_response['AddressResult']) ) { |
264
|
|
|
$result['Address'] = $sage_pay_response['AddressResult']; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
if ( isset($sage_pay_response['PostCodeResult']) ) { |
268
|
|
|
$result['Post Code'] = $sage_pay_response['PostCodeResult']; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
if ( isset($sage_pay_response['CV2Result']) ) { |
272
|
|
|
$result['CV2'] = $sage_pay_response['CV2Result']; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
if ( isset($sage_pay_response['3DSecureStatus']) ) { |
276
|
|
|
$result['3D Secure'] = $sage_pay_response['3DSecureStatus']; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
if ( isset($sage_pay_response['PayerStatus']) ) { |
280
|
|
|
$result['PayPal Payer Status'] = $sage_pay_response['PayerStatus']; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
if ( isset($sage_pay_response['AddressStatus']) ) { |
284
|
|
|
$result['PayPal Payer Address'] = $sage_pay_response['AddressStatus']; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
$result_string = ''; |
288
|
|
|
|
289
|
|
|
foreach ( $result as $k => $v ) { |
290
|
|
|
$result_string .= $k . ': ' . $v . "\n"; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$sql_data_array = array('orders_id' => $insert_id, |
294
|
|
|
'orders_status_id' => MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_ORDER_STATUS_ID, |
295
|
|
|
'date_added' => 'now()', |
296
|
|
|
'customer_notified' => '0', |
297
|
|
|
'comments' => trim($result_string)); |
298
|
|
|
|
299
|
|
|
$OSCOM_Db->save('orders_status_history', $sql_data_array); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
function get_error() { |
303
|
|
|
$message = OSCOM::getDef('module_payment_sage_pay_form_error_general'); |
304
|
|
|
|
305
|
|
|
$error_number = null; |
306
|
|
|
|
307
|
|
|
if ( isset($_GET['error']) && is_numeric($_GET['error']) && $this->errorMessageNumberExists($_GET['error']) ) { |
308
|
|
|
$error_number = $_GET['error']; |
309
|
|
|
} elseif (isset($_GET['crypt']) && tep_not_null($_GET['crypt'])) { |
310
|
|
|
$transaction_response = $this->decryptParams($_GET['crypt']); |
311
|
|
|
|
312
|
|
|
$string_array = explode('&', $transaction_response); |
313
|
|
|
$return = array('Status' => null); |
314
|
|
|
|
315
|
|
View Code Duplication |
foreach ($string_array as $string) { |
|
|
|
|
316
|
|
|
if (strpos($string, '=') != false) { |
|
|
|
|
317
|
|
|
$parts = explode('=', $string, 2); |
318
|
|
|
$return[trim($parts[0])] = trim($parts[1]); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$error = $this->getErrorMessageNumber($return['StatusDetail']); |
323
|
|
|
|
324
|
|
|
if ( is_numeric($error) && $this->errorMessageNumberExists($error) ) { |
325
|
|
|
$error_number = $error; |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|
329
|
|
View Code Duplication |
if ( isset($error_number) ) { |
|
|
|
|
330
|
|
|
// don't show an error message for user cancelled/aborted transactions |
331
|
|
|
if ( $error_number == '2013' ) { |
332
|
|
|
return false; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
$message = $this->getErrorMessage($error_number) . ' ' . OSCOM::getDef('module_payment_sage_pay_form_error_general'); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
$error = array('title' => OSCOM::getDef('module_payment_sage_pay_form_error_title'), |
339
|
|
|
'error' => $message); |
340
|
|
|
|
341
|
|
|
return $error; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
function check() { |
345
|
|
|
return defined('MODULE_PAYMENT_SAGE_PAY_FORM_STATUS'); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
View Code Duplication |
function install($parameter = null) { |
|
|
|
|
349
|
|
|
$OSCOM_Db = Registry::get('Db'); |
350
|
|
|
|
351
|
|
|
$params = $this->getParams(); |
352
|
|
|
|
353
|
|
|
if (isset($parameter)) { |
354
|
|
|
if (isset($params[$parameter])) { |
355
|
|
|
$params = array($parameter => $params[$parameter]); |
356
|
|
|
} else { |
357
|
|
|
$params = array(); |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
foreach ($params as $key => $data) { |
362
|
|
|
$sql_data_array = array('configuration_title' => $data['title'], |
363
|
|
|
'configuration_key' => $key, |
364
|
|
|
'configuration_value' => (isset($data['value']) ? $data['value'] : ''), |
365
|
|
|
'configuration_description' => $data['desc'], |
366
|
|
|
'configuration_group_id' => '6', |
367
|
|
|
'sort_order' => '0', |
368
|
|
|
'date_added' => 'now()'); |
369
|
|
|
|
370
|
|
|
if (isset($data['set_func'])) { |
371
|
|
|
$sql_data_array['set_function'] = $data['set_func']; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
if (isset($data['use_func'])) { |
375
|
|
|
$sql_data_array['use_function'] = $data['use_func']; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
$OSCOM_Db->save('configuration', $sql_data_array); |
379
|
|
|
} |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
function remove() { |
383
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
View Code Duplication |
function keys() { |
|
|
|
|
387
|
|
|
$keys = array_keys($this->getParams()); |
388
|
|
|
|
389
|
|
|
if ($this->check()) { |
390
|
|
|
foreach ($keys as $key) { |
391
|
|
|
if (!defined($key)) { |
392
|
|
|
$this->install($key); |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
return $keys; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
function getParams() { |
401
|
|
|
$OSCOM_Db = Registry::get('Db'); |
402
|
|
|
|
403
|
|
View Code Duplication |
if (!defined('MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_ORDER_STATUS_ID')) { |
|
|
|
|
404
|
|
|
$Qcheck = $OSCOM_Db->get('orders_status', 'orders_status_id', ['orders_status_name' => 'Sage Pay [Transactions]'], null, 1); |
405
|
|
|
|
406
|
|
|
if ($Qcheck->fetch() === false) { |
407
|
|
|
$Qstatus = $OSCOM_Db->get('orders_status', 'max(orders_status_id) as status_id'); |
408
|
|
|
|
409
|
|
|
$status_id = $Qstatus->valueInt('status_id') + 1; |
410
|
|
|
|
411
|
|
|
$languages = tep_get_languages(); |
412
|
|
|
|
413
|
|
|
foreach ($languages as $lang) { |
414
|
|
|
$OSCOM_Db->save('orders_status', [ |
415
|
|
|
'orders_status_id' => $status_id, |
416
|
|
|
'language_id' => $lang['id'], |
417
|
|
|
'orders_status_name' => 'Sage Pay [Transactions]', |
418
|
|
|
'public_flag' => 0, |
419
|
|
|
'downloads_flag' => 0 |
420
|
|
|
]); |
421
|
|
|
} |
422
|
|
|
} else { |
423
|
|
|
$status_id = $Qcheck->valueInt('orders_status_id'); |
424
|
|
|
} |
425
|
|
|
} else { |
426
|
|
|
$status_id = MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_ORDER_STATUS_ID; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
$params = array('MODULE_PAYMENT_SAGE_PAY_FORM_STATUS' => array('title' => 'Enable Sage Pay Form Module', |
430
|
|
|
'desc' => 'Do you want to accept Sage Pay Form payments?', |
431
|
|
|
'value' => 'True', |
432
|
|
|
'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '), |
433
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_LOGIN_NAME' => array('title' => 'Vendor Login Name', |
434
|
|
|
'desc' => 'The vendor login name to connect to the gateway with.'), |
435
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD' => array('title' => 'Encryption Password', |
436
|
|
|
'desc' => 'The encrpytion password to secure and verify transactions with.'), |
437
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_METHOD' => array('title' => 'Transaction Method', |
438
|
|
|
'desc' => 'The processing method to use for each transaction.', |
439
|
|
|
'value' => 'Authenticate', |
440
|
|
|
'set_func' => 'tep_cfg_select_option(array(\'Authenticate\', \'Deferred\', \'Payment\'), '), |
441
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_VENDOR_EMAIL' => array('title' => 'Vendor E-Mail Notification', |
442
|
|
|
'desc' => 'An e-mail address on which you can be contacted when a transaction completes. NOTE: If you wish to use multiple email addresses, you should add them using the colon character as a separator. e.g. [email protected]:[email protected]'), |
443
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_SEND_EMAIL' => array('title' => 'Send E-Mail Notifications', |
444
|
|
|
'desc' => 'Who to send e-mails to.', |
445
|
|
|
'value' => 'Customer and Vendor', |
446
|
|
|
'set_func' => 'tep_cfg_select_option(array(\'No One\', \'Customer and Vendor\', \'Vendor Only\'), '), |
447
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_CUSTOMER_EMAIL_MESSAGE' => array('title' => 'Customer E-Mail Message', |
448
|
|
|
'desc' => 'A message to the customer which is inserted into successful transaction e-mails only.', |
449
|
|
|
'use_func' => 'sage_pay_form_clip_text', |
450
|
|
|
'set_func' => 'sage_pay_form_textarea_field('), |
451
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_ORDER_STATUS_ID' => array('title' => 'Set Order Status', |
452
|
|
|
'desc' => 'Set the status of orders made with this payment module to this value', |
453
|
|
|
'value' => '0', |
454
|
|
|
'use_func' => 'tep_get_order_status_name', |
455
|
|
|
'set_func' => 'tep_cfg_pull_down_order_statuses('), |
456
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_ORDER_STATUS_ID' => array('title' => 'Transaction Order Status', |
457
|
|
|
'desc' => 'Include transaction information in this order status level', |
458
|
|
|
'value' => $status_id, |
459
|
|
|
'set_func' => 'tep_cfg_pull_down_order_statuses(', |
460
|
|
|
'use_func' => 'tep_get_order_status_name'), |
461
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_ZONE' => array('title' => 'Payment Zone', |
462
|
|
|
'desc' => 'If a zone is selected, only enable this payment method for that zone.', |
463
|
|
|
'value' => '0', |
464
|
|
|
'use_func' => 'tep_get_zone_class_title', |
465
|
|
|
'set_func' => 'tep_cfg_pull_down_zone_classes('), |
466
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_TRANSACTION_SERVER' => array('title' => 'Transaction Server', |
467
|
|
|
'desc' => 'Perform transactions on the production server or on the testing server.', |
468
|
|
|
'value' => 'Live', |
469
|
|
|
'set_func' => 'tep_cfg_select_option(array(\'Live\', \'Test\'), '), |
470
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_DEBUG_EMAIL' => array('title' => 'Debug E-Mail Address', |
471
|
|
|
'desc' => 'All parameters of an invalid transaction will be sent to this email address.'), |
472
|
|
|
'MODULE_PAYMENT_SAGE_PAY_FORM_SORT_ORDER' => array('title' => 'Sort order of display.', |
473
|
|
|
'desc' => 'Sort order of display. Lowest is displayed first.', |
474
|
|
|
'value' => '0')); |
475
|
|
|
|
476
|
|
|
return $params; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
// format prices without currency formatting |
480
|
|
View Code Duplication |
function format_raw($number, $currency_code = '', $currency_value = '') { |
|
|
|
|
481
|
|
|
global $currencies; |
482
|
|
|
|
483
|
|
|
if (empty($currency_code) || !$currencies->is_set($currency_code)) { |
484
|
|
|
$currency_code = $_SESSION['currency']; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
if (empty($currency_value) || !is_numeric($currency_value)) { |
488
|
|
|
$currency_value = $currencies->currencies[$currency_code]['value']; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', ''); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
function getOrderTotalsSummary() { |
495
|
|
|
global $order_total_modules; |
496
|
|
|
|
497
|
|
|
$order_total_array = array(); |
498
|
|
|
|
499
|
|
|
if (is_array($order_total_modules->modules)) { |
500
|
|
|
foreach ($order_total_modules->modules as $value) { |
501
|
|
|
$class = substr($value, 0, strrpos($value, '.')); |
502
|
|
|
if ($GLOBALS[$class]->enabled) { |
503
|
|
|
for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) { |
504
|
|
|
if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) { |
505
|
|
|
$order_total_array[] = array('code' => $GLOBALS[$class]->code, |
506
|
|
|
'title' => $GLOBALS[$class]->output[$i]['title'], |
507
|
|
|
'text' => $GLOBALS[$class]->output[$i]['text'], |
508
|
|
|
'value' => $GLOBALS[$class]->output[$i]['value'], |
509
|
|
|
'sort_order' => $GLOBALS[$class]->sort_order); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
return $order_total_array; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
function encryptParams($string) { |
520
|
|
|
// pad pkcs5 |
521
|
|
|
$blocksize = 16; |
522
|
|
|
|
523
|
|
|
$pad = $blocksize - (strlen($string) % $blocksize); |
524
|
|
|
|
525
|
|
|
$string .= str_repeat(chr($pad), $pad); |
526
|
|
|
|
527
|
|
|
// encrypt |
528
|
|
|
return '@' . strtoupper(bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD, $string, MCRYPT_MODE_CBC, MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD))); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
function decryptParams($string) { |
532
|
|
|
if ( substr($string, 0, 1) == '@' ) { |
533
|
|
|
$string = substr($string, 1); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
$string = pack('H*', $string); |
537
|
|
|
|
538
|
|
|
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD, $string, MCRYPT_MODE_CBC, MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
View Code Duplication |
function loadErrorMessages() { |
|
|
|
|
542
|
|
|
$errors = array(); |
543
|
|
|
|
544
|
|
|
if (is_file(dirname(__FILE__) . '/../../../ext/modules/payment/sage_pay/errors.php')) { |
545
|
|
|
include(dirname(__FILE__) . '/../../../ext/modules/payment/sage_pay/errors.php'); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
$this->_error_messages = $errors; |
|
|
|
|
549
|
|
|
} |
550
|
|
|
|
551
|
|
View Code Duplication |
function getErrorMessageNumber($string) { |
|
|
|
|
552
|
|
|
if (!isset($this->_error_messages)) { |
553
|
|
|
$this->loadErrorMessages(); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
$error = explode(' ', $string, 2); |
557
|
|
|
|
558
|
|
|
if (is_numeric($error[0]) && $this->errorMessageNumberExists($error[0])) { |
559
|
|
|
return $error[0]; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
return false; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
View Code Duplication |
function getErrorMessage($number) { |
|
|
|
|
566
|
|
|
if (!isset($this->_error_messages)) { |
567
|
|
|
$this->loadErrorMessages(); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
if (is_numeric($number) && $this->errorMessageNumberExists($number)) { |
571
|
|
|
return $this->_error_messages[$number]; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
return false; |
575
|
|
|
} |
576
|
|
|
|
577
|
|
View Code Duplication |
function errorMessageNumberExists($number) { |
|
|
|
|
578
|
|
|
if (!isset($this->_error_messages)) { |
579
|
|
|
$this->loadErrorMessages(); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
return (is_numeric($number) && isset($this->_error_messages[$number])); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
View Code Duplication |
function sendDebugEmail($response = array()) { |
|
|
|
|
586
|
|
|
if (tep_not_null(MODULE_PAYMENT_SAGE_PAY_FORM_DEBUG_EMAIL)) { |
587
|
|
|
$email_body = ''; |
588
|
|
|
|
589
|
|
|
if (!empty($response)) { |
590
|
|
|
$email_body .= 'RESPONSE:' . "\n\n" . print_r($response, true) . "\n\n"; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
if (!empty($_POST)) { |
594
|
|
|
$email_body .= '$_POST:' . "\n\n" . print_r($_POST, true) . "\n\n"; |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
if (!empty($_GET)) { |
598
|
|
|
$email_body .= '$_GET:' . "\n\n" . print_r($_GET, true) . "\n\n"; |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
if (!empty($email_body)) { |
602
|
|
|
$debugEmail = new Mail(MODULE_PAYMENT_SAGE_PAY_FORM_DEBUG_EMAIL, null, STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, 'Sage Pay Form Debug E-Mail'); |
603
|
|
|
$debugEmail->setBody($email_body); |
604
|
|
|
$debugEmail->send(); |
605
|
|
|
} |
606
|
|
|
} |
607
|
|
|
} |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
function sage_pay_form_clip_text($value) { |
611
|
|
|
if ( strlen($value) > 20 ) { |
612
|
|
|
$value = substr($value, 0, 20) . '..'; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
return $value; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
function sage_pay_form_textarea_field($value = '', $key = '') { |
619
|
|
|
return HTML::textareaField('configuration[' . $key . ']', 60, 5, $value); |
620
|
|
|
} |
621
|
|
|
?> |
|
|
|
|
622
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: