|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
5
|
|
|
* @package: ecommerce |
|
6
|
|
|
* @sub-package: model |
|
7
|
|
|
**/ |
|
8
|
|
|
class OrderStep_FraudCheck extends OrderStep implements OrderStepInterface |
|
9
|
|
|
{ |
|
10
|
|
|
public static $db = [ |
|
11
|
|
|
'MinOrderValue' => 'Int', |
|
12
|
|
|
'MinFraudService' => 'Enum("Score,Insights","Score")' |
|
13
|
|
|
]; |
|
14
|
|
|
|
|
15
|
|
|
private static $defaults = [ |
|
|
|
|
|
|
16
|
|
|
'CustomerCanEdit' => 0, |
|
17
|
|
|
'CustomerCanCancel' => 0, |
|
18
|
|
|
'CustomerCanPay' => 0, |
|
19
|
|
|
'Name' => 'Fraud Check for Order', |
|
20
|
|
|
'Code' => 'FRAUD_CHECK', |
|
21
|
|
|
'ShowAsInProcessOrder' => 1, |
|
22
|
|
|
'HideStepFromCustomer' => 1 |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The OrderStatusLog that is relevant to the particular step. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $relevantLogEntryClassName = 'OrderStatusLog_MinFraudStatusLog'; |
|
31
|
|
|
|
|
32
|
|
|
public function getCMSFields() |
|
33
|
|
|
{ |
|
34
|
|
|
$fields = parent::getCMSFields(); |
|
35
|
|
|
|
|
36
|
|
|
$fields->addFieldToTab( |
|
37
|
|
|
'Root.Main', |
|
38
|
|
|
HeaderField::create('MinFraudHeader', 'MaxMind Min Fraud Settings') |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$fields->addFieldToTab( |
|
42
|
|
|
'Root.Main', |
|
43
|
|
|
NumericField::create('MinOrderValue', 'Minimum Order Value', 0)->setRightTitle('The Risk Score will only be retrieved for orders with a total greater than the value in this field.') |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$fields->addFieldToTab( |
|
47
|
|
|
'Root.Main', |
|
48
|
|
|
OptionsetField::create( |
|
49
|
|
|
'MinFraudService', |
|
50
|
|
|
'Min Fraud Service', |
|
51
|
|
|
$this->dbObject('MinFraudService')->enumValues() |
|
52
|
|
|
)->setRightTitle( |
|
53
|
|
|
' |
|
54
|
|
|
The MinFraud service that will be used to check if an order potentially fraudulent.<br> |
|
55
|
|
|
Compare the <a href="https://www.maxmind.com/en/minfraud-service-comparison" target="_blank">services</a> to decide which one you should use. |
|
56
|
|
|
' |
|
57
|
|
|
) |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$fields->removeByName('DeferHeader'); |
|
61
|
|
|
$fields->removeByName('DeferTimeInSeconds'); |
|
62
|
|
|
$fields->removeByName('DeferFromSubmitTime'); |
|
63
|
|
|
|
|
64
|
|
|
return $fields; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
*initStep: |
|
69
|
|
|
* makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
|
70
|
|
|
* should be able to run this function many times to check if the step is ready. |
|
71
|
|
|
* |
|
72
|
|
|
* @see Order::doNextStatus |
|
73
|
|
|
* |
|
74
|
|
|
* @param Order object |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool - true if the current step is ready to be run... |
|
77
|
|
|
**/ |
|
78
|
|
|
public function initStep(Order $order) |
|
79
|
|
|
{ |
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
*doStep: |
|
86
|
|
|
* should only be able to run this function once |
|
87
|
|
|
* (init stops you from running it twice - in theory....) |
|
88
|
|
|
* runs the actual step. |
|
89
|
|
|
* |
|
90
|
|
|
* @see Order::doNextStatus |
|
91
|
|
|
* |
|
92
|
|
|
* @param Order object |
|
93
|
|
|
* |
|
94
|
|
|
* @return bool - true if run correctly. |
|
95
|
|
|
**/ |
|
96
|
|
|
public function doStep(Order $order) |
|
97
|
|
|
{ |
|
98
|
|
|
if ($order->getTotal() < $this->MinOrderValue) { |
|
|
|
|
|
|
99
|
|
|
return true; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$className = $this->getRelevantLogEntryClassName(); |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
if (class_exists($className)) { |
|
|
|
|
|
|
105
|
|
|
$obj = $className::create(); |
|
106
|
|
|
if (is_a($obj, Object::getCustomClass('OrderStatusLog'))) { |
|
107
|
|
|
$obj->OrderID = $order->ID; |
|
108
|
|
|
$obj->Title = $this->Name; |
|
|
|
|
|
|
109
|
|
|
$obj->ServiceType = $this->MinFraudService; |
|
|
|
|
|
|
110
|
|
|
$obj->write(); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
*nextStep: |
|
119
|
|
|
* returns the next step (after it checks if everything is in place for the next step to run...). |
|
120
|
|
|
* |
|
121
|
|
|
* @see Order::doNextStatus |
|
122
|
|
|
* |
|
123
|
|
|
* @param Order $order |
|
124
|
|
|
* |
|
125
|
|
|
* @return OrderStep | Null (next step OrderStep object) |
|
|
|
|
|
|
126
|
|
|
**/ |
|
127
|
|
|
public function nextStep(Order $order) |
|
128
|
|
|
{ |
|
129
|
|
|
return parent::nextStep($order); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* For some ordersteps this returns true... |
|
134
|
|
|
* |
|
135
|
|
|
* @return bool |
|
136
|
|
|
**/ |
|
137
|
|
|
protected function hasCustomerMessage() |
|
138
|
|
|
{ |
|
139
|
|
|
return false; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Explains the current order step. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
protected function myDescription() |
|
148
|
|
|
{ |
|
149
|
|
|
return 'Checks for possible fraudulent orders using the minFraud API provided by MaxMind'; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|