|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
6
|
|
|
* @package: ecommerce |
|
7
|
|
|
* @sub-package: model |
|
8
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
9
|
|
|
**/ |
|
10
|
|
|
class OrderStatusLog_SecurityCheck extends OrderStatusLog |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
private static $days_ago_to_check = 14; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
private static $db = array( |
|
|
|
|
|
|
15
|
|
|
'Bad' => 'Boolean', |
|
16
|
|
|
'Risks' => 'HTMLText', |
|
17
|
|
|
'SubTotal' => 'Currency', |
|
18
|
|
|
'Check1' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
19
|
|
|
'Check2' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
20
|
|
|
'Check3' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
21
|
|
|
'Check4' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
22
|
|
|
'Check5' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
23
|
|
|
'Check6' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
24
|
|
|
'Check7' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
25
|
|
|
'Check8' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
26
|
|
|
'Check9' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
27
|
|
|
'Check10' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
28
|
|
|
'Check11' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
29
|
|
|
'Check12' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
33
|
|
|
'BlacklistItems' => 'EcommerceSecurityBaseClass' |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* this array works as follows |
|
38
|
|
|
* array( |
|
39
|
|
|
* Check1 => array( |
|
40
|
|
|
* "Title" => "Customer Has Paid", |
|
41
|
|
|
* "MinSubTotal" => 10, |
|
42
|
|
|
* "Explanation" => "Check Payment system for $$$ coming in" |
|
43
|
|
|
* ), |
|
44
|
|
|
* Check2 => array( |
|
45
|
|
|
* "Title" => "Address Exists", |
|
46
|
|
|
* "MinSubTotal" => 50, |
|
47
|
|
|
* "Explanation" => "Check Payment system for $$$ coming in" |
|
48
|
|
|
* ) |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $checks_required = array(); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
55
|
|
|
'Type' => 'Type', |
|
56
|
|
|
'SubTotal' => 'SubTotal', |
|
57
|
|
|
'SecurityCleared' => 'Security Cleared' |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
private static $casting = array( |
|
|
|
|
|
|
61
|
|
|
'SecurityCleared' => 'Boolean' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
65
|
|
|
'InternalUseOnly' => true |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
69
|
|
|
'Bad' => 'Fraudulent' |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
private static $singular_name = 'Security Check'; |
|
|
|
|
|
|
73
|
|
|
public function i18n_singular_name() |
|
74
|
|
|
{ |
|
75
|
|
|
return self::$singular_name; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private static $plural_name = 'Security Checks'; |
|
|
|
|
|
|
79
|
|
|
public function i18n_plural_name() |
|
80
|
|
|
{ |
|
81
|
|
|
return self::$plural_name; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function canCreate($member = null) |
|
85
|
|
|
{ |
|
86
|
|
|
return false; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function canEdit($member = null) |
|
90
|
|
|
{ |
|
91
|
|
|
return parent::canEdit($member); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* CMS Fields |
|
96
|
|
|
* @return FieldList |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getCMSFields() |
|
99
|
|
|
{ |
|
100
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
101
|
|
|
if ($order) { |
|
102
|
|
|
$member = $order->Member(); |
|
103
|
|
|
$fields = parent::getCMSFields(); |
|
104
|
|
|
$fields->addFieldToTab( |
|
105
|
|
|
'Root.Main', |
|
106
|
|
|
HeaderField::create( |
|
107
|
|
|
'BadHeading', |
|
108
|
|
|
'Mark as Fraud' |
|
109
|
|
|
), |
|
110
|
|
|
'Bad' |
|
111
|
|
|
); |
|
112
|
|
|
$fields->addFieldToTab( |
|
113
|
|
|
'Root.Main', |
|
114
|
|
|
HeaderField::create( |
|
115
|
|
|
'BadHeading', |
|
116
|
|
|
'Risks' |
|
117
|
|
|
), |
|
118
|
|
|
'Risks' |
|
119
|
|
|
); |
|
120
|
|
|
$riskField = $fields->dataFieldByName('Risks'); |
|
121
|
|
|
$riskField->setTitle(''); |
|
122
|
|
|
if ($member) { |
|
123
|
|
|
$previousOrders = Order::get() |
|
124
|
|
|
->filter( |
|
125
|
|
|
array( |
|
126
|
|
|
'MemberID' => $member->ID |
|
127
|
|
|
) |
|
128
|
|
|
) |
|
129
|
|
|
->exclude( |
|
130
|
|
|
array('ID' => $order->ID) |
|
131
|
|
|
); |
|
132
|
|
|
if ($previousOrders->count()) { |
|
133
|
|
|
$fields->addFieldToTab( |
|
134
|
|
|
"Root.PreviousOrders", |
|
135
|
|
|
new GridField( |
|
136
|
|
|
'PreviousOrdersList', |
|
137
|
|
|
'Previous Orders', |
|
138
|
|
|
$previousOrders |
|
139
|
|
|
) |
|
140
|
|
|
); |
|
141
|
|
|
} else { |
|
142
|
|
|
$fields->addFieldToTab( |
|
143
|
|
|
"Root.PreviousOrders", |
|
144
|
|
|
HeaderField::create( |
|
145
|
|
|
'NoPreviousOrders', |
|
146
|
|
|
'This customer does not have any previous orders' |
|
147
|
|
|
) |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
$allFields = array(); |
|
153
|
|
|
for ($i = 1; $i < 13; $i++) { |
|
154
|
|
|
$allFields["Check".$i] = "Check".$i; |
|
155
|
|
|
} |
|
156
|
|
|
$checks = $this->Config()->get('checks_required'); |
|
157
|
|
|
$fields->addFieldToTab( |
|
|
|
|
|
|
158
|
|
|
"Root.Required", |
|
159
|
|
|
HeaderField::create('RequiredChecksHeader', 'Required Checks'), |
|
160
|
|
|
'Note' |
|
161
|
|
|
); |
|
162
|
|
|
$fields->addFieldToTab( |
|
163
|
|
|
"Root.NotRequired", |
|
164
|
|
|
HeaderField::create('UnrequiredChecksHeader', 'Optional Checks'), |
|
165
|
|
|
'Note' |
|
166
|
|
|
); |
|
167
|
|
|
$hasRequiredChecks = false; |
|
168
|
|
|
$hasUnrequiredChecks = false; |
|
169
|
|
|
$memberIsWhitelisted = $this->memberIsWhitelisted(); |
|
170
|
|
|
foreach ($checks as $fieldName => $details) { |
|
171
|
|
|
unset($allFields[$fieldName]); |
|
172
|
|
|
if (floatval($this->SubTotal) > floatval($details['SubTotalMin'])) { |
|
|
|
|
|
|
173
|
|
|
$hasRequiredChecks = true; |
|
174
|
|
|
$fields->addFieldToTab( |
|
175
|
|
|
'Root.Required', |
|
176
|
|
|
$myField = $fields->dataFieldByName($fieldName) |
|
177
|
|
|
); |
|
178
|
|
|
} else { |
|
179
|
|
|
$hasUnrequiredChecks = true; |
|
180
|
|
|
$fields->addFieldToTab( |
|
181
|
|
|
'Root.NotRequired', |
|
182
|
|
|
$myField = $fields->dataFieldByName($fieldName) |
|
183
|
|
|
); |
|
184
|
|
|
} |
|
185
|
|
|
$originalOptions = $myField->getSource(); |
|
186
|
|
|
if ($memberIsWhitelisted) { |
|
|
|
|
|
|
187
|
|
|
//.. |
|
188
|
|
|
} else { |
|
189
|
|
|
unset($originalOptions['Whitelisted Customer']); |
|
190
|
|
|
} |
|
191
|
|
|
if (! $this->$fieldName) { |
|
192
|
|
|
$this->$fieldName = 'To do'; |
|
193
|
|
|
} |
|
194
|
|
|
$fields->replaceField( |
|
195
|
|
|
$myField->ID(), |
|
|
|
|
|
|
196
|
|
|
OptionsetField::create( |
|
197
|
|
|
$myField->ID(), |
|
198
|
|
|
$details['Title'], |
|
199
|
|
|
$originalOptions |
|
200
|
|
|
) |
|
201
|
|
|
); |
|
202
|
|
|
if (! empty($details['Description'])) { |
|
203
|
|
|
$myField->setRighTitle($details['Description']); |
|
|
|
|
|
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
foreach ($allFields as $fieldToRemove) { |
|
207
|
|
|
$fields->removeByName($fieldToRemove); |
|
208
|
|
|
} |
|
209
|
|
|
if (! $hasUnrequiredChecks) { |
|
210
|
|
|
$fields->addFieldToTab( |
|
211
|
|
|
"Root.NotRequired", |
|
212
|
|
|
HeaderField::create('UnrequiredChecksHeader', 'There are no optional checks for this order.'), |
|
213
|
|
|
'Note' |
|
214
|
|
|
); |
|
215
|
|
|
} |
|
216
|
|
|
if (! $hasRequiredChecks) { |
|
217
|
|
|
$fields->addFieldToTab( |
|
218
|
|
|
"Root.Required", |
|
219
|
|
|
HeaderField::create('RequiredChecksHeader', 'There are no required checks for this order.'), |
|
220
|
|
|
'Note' |
|
221
|
|
|
); |
|
222
|
|
|
} |
|
223
|
|
|
$fields->removeFieldFromTab('Root.Main', 'AuthorID'); |
|
224
|
|
|
$fields->removeFieldFromTab('Root.Main', 'Title'); |
|
225
|
|
|
$fields->removeFieldFromTab('Root.Main', 'InternalUseOnly'); |
|
226
|
|
|
$fields->makeFieldReadonly('Risks'); |
|
227
|
|
|
$fields->makeFieldReadonly('SubTotal'); |
|
228
|
|
|
return $fields; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
protected $warningMessages = array(); |
|
232
|
|
|
|
|
233
|
|
|
protected function collateRisks() |
|
234
|
|
|
{ |
|
235
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
236
|
|
|
$billingAddress = $order->BillingAddress(); |
|
237
|
|
|
$shippingAddress = $order->ShippingAddress(); |
|
238
|
|
|
$member = $order->Member(); |
|
239
|
|
|
$payments = $order->Payments(); |
|
240
|
|
|
$html = ''; |
|
241
|
|
|
|
|
242
|
|
|
$similarArray = array(); |
|
243
|
|
|
|
|
244
|
|
|
$daysAgo = $this->Config()->get('days_ago_to_check'); |
|
245
|
|
|
$timeFilter = array('Created:GreaterThan' => date('Y-m-d', strtotime('-'.$daysAgo.' days')).' 00:00:00'); |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
//check emails from user |
|
249
|
|
|
$emailArray = array(); |
|
250
|
|
|
if ($member) { |
|
251
|
|
|
if ($member->Email) { |
|
252
|
|
|
$emailArray[] = $member->Email; |
|
253
|
|
|
if (OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member)) { |
|
254
|
|
|
$html .= '<h4 style="background-color: green; color: white; font-size: 20px; padding: 5px;">This customer is whitelisted</h4>'; |
|
255
|
|
|
} else { |
|
256
|
|
|
$html .= '<h4>This customer is NOT whitelisted</h4>'; |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
//are there any orders with the same Member.email in the last seven days... |
|
261
|
|
|
$otherOrders = Order::get_datalist_of_orders_with_submit_record() |
|
|
|
|
|
|
262
|
|
|
->filter( |
|
263
|
|
|
array_merge( |
|
264
|
|
|
array('MemberID' => $member->ID), |
|
265
|
|
|
$timeFilter |
|
266
|
|
|
) |
|
267
|
|
|
) |
|
268
|
|
|
->innerJoin('') |
|
269
|
|
|
->exclude(array('ID' => $order->ID)); |
|
270
|
|
View Code Duplication |
foreach ($otherOrders as $otherOrder) { |
|
|
|
|
|
|
271
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
272
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
273
|
|
|
} |
|
274
|
|
|
$similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
|
275
|
|
|
} |
|
276
|
|
|
//check emails from billing address |
|
277
|
|
|
$emailArray = array(); |
|
278
|
|
|
if ($billingAddress) { |
|
279
|
|
|
if ($billingAddress->Email) { |
|
280
|
|
|
$emailArray[] = $billingAddress->Email; |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
//are there any orders with the same Billing.Email in the last seven days... |
|
284
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
285
|
|
|
array('Email' => $emailArray) + $timeFilter |
|
286
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
287
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
288
|
|
|
$otherOrder = $address->Order(); |
|
289
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
290
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
291
|
|
|
} |
|
292
|
|
|
$similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
|
293
|
|
|
} |
|
294
|
|
|
//adding all emails to security checks |
|
295
|
|
|
$this->blacklistCheck($emailArray, 'EcommerceSecurityEmail'); |
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
//phones |
|
299
|
|
|
$phoneArray = array(); |
|
300
|
|
|
if ($billingAddress) { |
|
301
|
|
|
if ($billingAddress->Phone) { |
|
302
|
|
|
$phoneArray[] = $billingAddress->Phone; |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
if ($shippingAddress) { |
|
306
|
|
|
if ($shippingAddress->ShippingPhone) { |
|
307
|
|
|
$phoneArray[] = $shippingAddress->ShippingPhone; |
|
308
|
|
|
} |
|
309
|
|
|
} |
|
310
|
|
|
//are there any orders with the same phone in the last xxx days... |
|
311
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
312
|
|
|
array('Phone' => $phoneArray) + $timeFilter |
|
313
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
314
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
315
|
|
|
$otherOrder = $address->Order(); |
|
316
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
317
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
318
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
319
|
|
|
} |
|
320
|
|
|
$similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
|
321
|
|
|
} |
|
322
|
|
|
} |
|
323
|
|
|
$otherShippingAddresses = ShippingAddress::get()->filter( |
|
324
|
|
|
array('ShippingPhone' => $phoneArray) + $timeFilter |
|
325
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
326
|
|
View Code Duplication |
foreach ($otherShippingAddresses as $address) { |
|
|
|
|
|
|
327
|
|
|
$otherOrder = $address->Order(); |
|
328
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
329
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
330
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
331
|
|
|
} |
|
332
|
|
|
$similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
//adding all emails to security checks |
|
336
|
|
|
$this->blacklistCheck($phoneArray, 'EcommerceSecurityPhone'); |
|
337
|
|
|
|
|
338
|
|
|
//addresses |
|
339
|
|
|
$addressArray = array(); |
|
340
|
|
|
if ($billingAddress) { |
|
341
|
|
|
if ($billingAddress->Address) { |
|
342
|
|
|
$addressArray[] = $billingAddress->Address; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
if ($shippingAddress) { |
|
346
|
|
|
if ($shippingAddress->ShippingAddress) { |
|
347
|
|
|
$addressArray[] = $shippingAddress->ShippingAddress; |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
//are there any orders with the same address in the last xxx days... |
|
351
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
352
|
|
|
array('Address' => $addressArray) + $timeFilter |
|
353
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
354
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
355
|
|
|
$otherOrder = $address->Order(); |
|
356
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
357
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
358
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
359
|
|
|
} |
|
360
|
|
|
$similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
|
361
|
|
|
} |
|
362
|
|
|
} |
|
363
|
|
|
$otherShippingAddresses = ShippingAddress::get() |
|
364
|
|
|
->filter( |
|
365
|
|
|
array('ShippingAddress' => $addressArray) + $timeFilter |
|
366
|
|
|
) |
|
367
|
|
|
->exclude(array('OrderID' => $order->ID)); |
|
368
|
|
View Code Duplication |
foreach ($otherShippingAddresses as $address) { |
|
|
|
|
|
|
369
|
|
|
$otherOrder = $address->Order(); |
|
370
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
371
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
372
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
373
|
|
|
} |
|
374
|
|
|
$similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
$this->blacklistCheck($addressArray, 'EcommerceSecurityAddress'); |
|
378
|
|
|
|
|
379
|
|
|
|
|
380
|
|
|
//IP |
|
381
|
|
|
$ipArray = array(); |
|
382
|
|
|
$ipProxyArray = array(); |
|
383
|
|
|
if ($payments) { |
|
384
|
|
|
foreach ($payments as $payment) { |
|
385
|
|
|
if(strlen($payment->IP) > 10) { |
|
386
|
|
|
$ipArray[] = $payment->IP; |
|
387
|
|
|
} |
|
388
|
|
|
if(strlen($payment->ProxyIP) > 10) { |
|
389
|
|
|
$ipProxyArray[] = $payment->ProxyIP; |
|
390
|
|
|
} |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
View Code Duplication |
if(count($ipArray)) { |
|
|
|
|
|
|
394
|
|
|
//are there any orders with the same IP in the xxx seven days... |
|
395
|
|
|
$otherPayments = EcommercePayment::get()->filter( |
|
396
|
|
|
array('IP' => $ipArray) + $timeFilter |
|
397
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
398
|
|
|
foreach ($otherPayments as $payment) { |
|
399
|
|
|
$otherOrder = $payment->Order(); |
|
400
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
401
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
402
|
|
|
} |
|
403
|
|
|
$similarArray[$otherOrder->ID]["IP"] = $otherOrder; |
|
404
|
|
|
} |
|
405
|
|
|
$this->blacklistCheck($ipArray, 'EcommerceSecurityIP'); |
|
406
|
|
|
} |
|
407
|
|
View Code Duplication |
if(count($ipProxyArray)) { |
|
|
|
|
|
|
408
|
|
|
//are there any orders with the same Proxy in the xxx seven days... |
|
409
|
|
|
$otherPayments = EcommercePayment::get()->filter( |
|
410
|
|
|
array('ProxyIP' => $ipProxyArray) + $timeFilter |
|
411
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
412
|
|
|
foreach ($otherPayments as $payment) { |
|
413
|
|
|
$otherOrder = $payment->Order(); |
|
414
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
415
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
416
|
|
|
} |
|
417
|
|
|
$similarArray[$otherOrder->ID]["ProxyIP"] = $otherOrder; |
|
418
|
|
|
} |
|
419
|
|
|
$this->blacklistCheck($ipProxyArray, 'EcommerceSecurityProxyIP'); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
|
|
423
|
|
|
if (count($this->warningMessages)) { |
|
424
|
|
|
$html .= '<h4 style="color: red;">Blacklisted Details</h4><ul class="SecurityCheckListOfRisks warnings" style="color: red;">'; |
|
425
|
|
|
foreach ($this->warningMessages as $warningMessage) { |
|
426
|
|
|
$html .= $warningMessage; |
|
427
|
|
|
} |
|
428
|
|
|
$html .= '</ul>'; |
|
429
|
|
|
} else { |
|
430
|
|
|
$html .= '<h4>No Blacklisted Data Present</h4>'; |
|
431
|
|
|
} |
|
432
|
|
|
if (count($similarArray)) { |
|
433
|
|
|
$days = $this->Config()->get('days_ago_to_check'); |
|
434
|
|
|
$html .= '<h4>Similar orders in the last '.$days.' days</h4><ul class="SecurityCheckListOfRisks otherRisks">'; |
|
435
|
|
|
foreach ($similarArray as $orderID => $fields) { |
|
436
|
|
|
//we just loop this so we can get the order ... |
|
437
|
|
|
foreach ($fields as $tempOrder) { |
|
438
|
|
|
break; |
|
439
|
|
|
} |
|
440
|
|
|
$html .= '<li><a href="'.$tempOrder->CMSEditLink().'">'.$tempOrder->getTitle().'</a>: with same '.implode(', and with same ', array_keys($fields)).'</li>'; |
|
|
|
|
|
|
441
|
|
|
} |
|
442
|
|
|
$html .= '</ul>'; |
|
443
|
|
|
} else { |
|
444
|
|
|
$html .= '<p class="message good">There were no similar orders in the last '.$daysAgo.' days</p>'; |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
return $html; |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
public function getSecurityCleared() |
|
451
|
|
|
{ |
|
452
|
|
|
return DBField::create_field('Boolean', ($this->pass() ? true : false)); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* |
|
457
|
|
|
* |
|
458
|
|
|
* |
|
459
|
|
|
* @param Order $order |
|
|
|
|
|
|
460
|
|
|
* @return bool |
|
461
|
|
|
*/ |
|
462
|
|
|
public function pass() |
|
463
|
|
|
{ |
|
464
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
465
|
|
|
if (! $order) { |
|
466
|
|
|
return false; |
|
467
|
|
|
} |
|
468
|
|
|
$checks = $this->Config()->get('checks_required'); |
|
469
|
|
|
$fieldsAvailable = $this->stat('db'); |
|
470
|
|
|
foreach ($checks as $fieldName => $fieldDetails) { |
|
471
|
|
|
if (floatval($this->SubTotal) > floatval($fieldDetails['SubTotalMin'])) { |
|
|
|
|
|
|
472
|
|
|
if (! isset($fieldsAvailable[$fieldName])) { |
|
473
|
|
|
user_error('bad field ....'); |
|
474
|
|
|
} |
|
475
|
|
|
// there is a check that needs to be TRUE, but is not ... |
|
476
|
|
|
if ($this->$fieldName == 'Done' || $this->$fieldName == 'Whitelisted Customer') { |
|
|
|
|
|
|
477
|
|
|
} else { |
|
478
|
|
|
return false; |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
return true; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
private static $_saved_already = 0; |
|
486
|
|
|
|
|
487
|
|
|
public function onAfterWrite() |
|
488
|
|
|
{ |
|
489
|
|
|
parent::onAfterWrite(); |
|
490
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
491
|
|
|
if (self::$_saved_already < 3) { |
|
492
|
|
|
self::$_saved_already++; |
|
493
|
|
|
if ($order && $order->exists()) { |
|
494
|
|
|
$this->SubTotal = $order->getSubTotal(); |
|
|
|
|
|
|
495
|
|
|
$this->Risks = $this->collateRisks(); |
|
|
|
|
|
|
496
|
|
|
$this->write(); |
|
497
|
|
|
} else { |
|
498
|
|
|
$this->SubTotal = 9999; |
|
|
|
|
|
|
499
|
|
|
$this->Risks = "Error"; |
|
|
|
|
|
|
500
|
|
|
$this->write(); |
|
501
|
|
|
} |
|
502
|
|
|
if($this->memberIsWhitelisted()) { |
|
503
|
|
|
for ($i = 1; $i < 13; $i++) { |
|
504
|
|
|
$field = "Check".$i; |
|
505
|
|
|
$this->$field = 'Whitelisted Customer'; |
|
506
|
|
|
} |
|
507
|
|
|
$this->write(); |
|
508
|
|
|
} |
|
509
|
|
|
} |
|
510
|
|
|
if($this->Bad) { |
|
|
|
|
|
|
511
|
|
|
foreach($this->BlacklistItems() as $blacklistItem) { |
|
|
|
|
|
|
512
|
|
|
$blacklistItem->Status = 'Bad'; |
|
513
|
|
|
$blacklistItem->write(); |
|
514
|
|
|
} |
|
515
|
|
|
if ($order && $order->exists()) { |
|
516
|
|
|
$order->Archive(true); |
|
517
|
|
|
} |
|
518
|
|
|
} |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
/** |
|
522
|
|
|
* |
|
523
|
|
|
* @param EcommerceSecurityBaseClass $obj |
|
524
|
|
|
* @return bool return true if the status of the object is `Bad` |
|
525
|
|
|
*/ |
|
526
|
|
|
protected function checkSecurityObject($obj) |
|
527
|
|
|
{ |
|
528
|
|
|
if ($obj->Status == 'Bad') { |
|
|
|
|
|
|
529
|
|
|
return false; |
|
530
|
|
|
} |
|
531
|
|
|
return true; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* caching variable only... |
|
536
|
|
|
* |
|
537
|
|
|
* @var null | bool |
|
538
|
|
|
*/ |
|
539
|
|
|
private $_memberIsWhitelisted = null; |
|
540
|
|
|
|
|
541
|
|
|
protected function memberIsWhitelisted() |
|
542
|
|
|
{ |
|
543
|
|
|
if ($this->_memberIsWhitelisted === null) { |
|
544
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
545
|
|
|
if ($order && $order->exists()) { |
|
546
|
|
|
$member = $order->Member(); |
|
547
|
|
|
if ($member && $member->exists()) { |
|
548
|
|
|
$this->_memberIsWhitelisted = OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member); |
|
|
|
|
|
|
549
|
|
|
} |
|
550
|
|
|
} |
|
551
|
|
|
} |
|
552
|
|
|
return $this->_memberIsWhitelisted; |
|
553
|
|
|
} |
|
554
|
|
|
|
|
555
|
|
|
protected function blacklistCheck($arrayOfValues, $securityClass) |
|
556
|
|
|
{ |
|
557
|
|
|
//adding all emails to security checks |
|
558
|
|
|
foreach ($arrayOfValues as $value) { |
|
559
|
|
|
if ($value) { |
|
560
|
|
|
$obj = $securityClass::find_or_create(array("Title" => $value)); |
|
561
|
|
|
if($obj->exists()) { |
|
562
|
|
|
$this->BlacklistItems()->add($obj); |
|
|
|
|
|
|
563
|
|
|
if ($obj->hasRisks()) { |
|
564
|
|
|
$title = $obj->i18n_singular_name(); |
|
565
|
|
|
$this->warningMessages[] = '<li><strong>'.$title.':</strong> '.$value.'<li>'; |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
} |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
} |
|
574
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.