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