1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Pachico\MaxMind\MinFraudChargeback. (https://github.com/pachico/maxmind-minfraud-chargeback) |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/pachico/maxmind-minfraud-chargeback for the canonical source repository |
7
|
|
|
* @copyright Copyright (c) 2016-2017 Mariano F.co Benítez Mulet. (https://github.com/pachico/) |
8
|
|
|
* @license https://raw.githubusercontent.com/pachico/maxmind-minfraud-chargeback/master/LICENSE.md MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pachico\MaxMind\MinFraudChargeback; |
12
|
|
|
|
13
|
|
|
use Webmozart\Assert\Assert; |
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* This is a namespaced container for the values a chargeback can have |
18
|
|
|
*/ |
19
|
|
|
class Chargeback |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Indicates transaction is unlikely fraudulent |
23
|
|
|
*/ |
24
|
|
|
const NOT_FRAUD = 'not_fraud'; |
25
|
|
|
/** |
26
|
|
|
* Indicates transaction is suspectedly fraudulent |
27
|
|
|
*/ |
28
|
|
|
const SUSPECTED_FRAUD = 'suspected_fraud'; |
29
|
|
|
/** |
30
|
|
|
* Indicates transaction is likely fraudulent |
31
|
|
|
*/ |
32
|
|
|
const KNOWN_FRAUD = 'known_fraud'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $ipAddress; |
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $chargebackCode; |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $fraudScore; |
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $maxmindId; |
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $minfraudId; |
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $transactionId; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $ipAddress The IP address of the customer placing the order. |
61
|
|
|
* This should be passed as a string like “44.55.66.77” or “2001:db8::2:1”. |
62
|
|
|
* |
63
|
|
|
* @throws InvalidArgumentException |
64
|
|
|
*/ |
65
|
33 |
|
public function __construct($ipAddress) |
66
|
|
|
{ |
67
|
33 |
|
Assert::stringNotEmpty($ipAddress); |
68
|
|
|
|
69
|
33 |
|
$this->ipAddress = $ipAddress; |
70
|
33 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param A string which is provided by your payment processor |
74
|
|
|
* indicating the reason for the chargeback. |
75
|
|
|
* @see https://en.wikipedia.org/wiki/Chargeback#Reason_codes |
76
|
|
|
* |
77
|
|
|
* @throws InvalidArgumentException |
78
|
|
|
* |
79
|
|
|
* @return Chargeback |
80
|
|
|
*/ |
81
|
1 |
|
public function setChargebackCode($chargebackCode) |
82
|
|
|
{ |
83
|
1 |
|
Assert::stringNotEmpty($chargebackCode); |
84
|
|
|
|
85
|
1 |
|
$this->chargebackCode = $chargebackCode; |
86
|
|
|
|
87
|
1 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $fraudScore A string indicating the likelihood that |
92
|
|
|
* a transaction may be fraudulent. |
93
|
|
|
* Possible values: ‘not_fraud’, ‘suspected_fraud’, ‘known_fraud’. |
94
|
|
|
* |
95
|
|
|
* @throws InvalidArgumentException |
96
|
|
|
* |
97
|
|
|
* @return Chargeback |
98
|
|
|
*/ |
99
|
4 |
|
public function setFraudScore($fraudScore) |
100
|
|
|
{ |
101
|
4 |
|
if (!in_array($fraudScore, [ |
102
|
4 |
|
static::KNOWN_FRAUD, |
103
|
4 |
|
static::NOT_FRAUD, |
104
|
|
|
static::SUSPECTED_FRAUD |
105
|
4 |
|
])) { |
106
|
1 |
|
throw new InvalidArgumentException('Invalid fraud score.'); |
107
|
|
|
} |
108
|
|
|
|
109
|
3 |
|
$this->fraudScore = $fraudScore; |
110
|
|
|
|
111
|
3 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $maxmindId A unique eight character string identifying |
116
|
|
|
* a minFraud Standard or Premium request. These IDs are returned in the |
117
|
|
|
* maxmindID field of a response for a successful minFraud request. |
118
|
|
|
* This field is not required, but you are encouraged to provide it, if possible. |
119
|
|
|
* |
120
|
|
|
* @throws InvalidArgumentException |
121
|
|
|
* |
122
|
|
|
* @return Chargeback |
123
|
|
|
*/ |
124
|
1 |
|
public function setMaxmindId($maxmindId) |
125
|
|
|
{ |
126
|
1 |
|
Assert::length($maxmindId, 8); |
127
|
|
|
|
128
|
1 |
|
$this->maxmindId = $maxmindId; |
129
|
|
|
|
130
|
1 |
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $minfraudId A UUID that identifies a minFraud Score, |
135
|
|
|
* minFraud Insights, or minFraud Factors request. |
136
|
|
|
* This ID is returned at /id in the response. |
137
|
|
|
* This field is not required, but you are encouraged to provide it if |
138
|
|
|
* the request was made to one of these services. |
139
|
|
|
* |
140
|
|
|
* @throws InvalidArgumentException |
141
|
|
|
* |
142
|
|
|
* @return Chargeback |
143
|
|
|
*/ |
144
|
1 |
|
public function setMinfraudId($minfraudId) |
145
|
|
|
{ |
146
|
1 |
|
Assert::length($minfraudId, 36); |
147
|
|
|
|
148
|
1 |
|
$this->minfraudId = $minfraudId; |
149
|
|
|
|
150
|
1 |
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $transactionId The transaction ID you originally passed to minFraud. |
155
|
|
|
* This field is not required, but you are encouraged to provide it or |
156
|
|
|
* the transaction’s maxmind_id or minfraud_id. |
157
|
|
|
* |
158
|
|
|
* @throws InvalidArgumentException |
159
|
|
|
* |
160
|
|
|
* @return Chargeback |
161
|
|
|
*/ |
162
|
1 |
|
public function setTransactionId($transactionId) |
163
|
|
|
{ |
164
|
1 |
|
Assert::stringNotEmpty($transactionId); |
165
|
|
|
|
166
|
1 |
|
$this->transactionId = $transactionId; |
167
|
|
|
|
168
|
1 |
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return array An array with properties in key=>value fashion |
173
|
|
|
*/ |
174
|
11 |
|
public function toArray() |
175
|
|
|
{ |
176
|
|
|
$array = [ |
177
|
11 |
|
'ip_address' => $this->ipAddress |
178
|
11 |
|
]; |
179
|
|
|
|
180
|
11 |
|
if ($this->chargebackCode) { |
181
|
1 |
|
$array['chargeback_code'] = $this->chargebackCode; |
182
|
1 |
|
} |
183
|
|
|
|
184
|
11 |
|
if ($this->fraudScore) { |
185
|
3 |
|
$array['fraud_score'] = $this->fraudScore; |
186
|
3 |
|
} |
187
|
|
|
|
188
|
11 |
|
if ($this->maxmindId) { |
189
|
1 |
|
$array['maxmind_id'] = $this->maxmindId; |
190
|
1 |
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
11 |
|
if ($this->minfraudId) { |
194
|
1 |
|
$array['minfraud_id'] = $this->minfraudId; |
195
|
1 |
|
} |
196
|
|
|
|
197
|
11 |
|
if ($this->transactionId) { |
198
|
1 |
|
$array['transaction_id'] = $this->transactionId; |
199
|
1 |
|
} |
200
|
|
|
|
201
|
11 |
|
return $array; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|