Skip to content

Commit 377c519

Browse files
committed
Add disposition
1 parent a5f8541 commit 377c519

File tree

7 files changed

+167
-36
lines changed

7 files changed

+167
-36
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
History
44
-------
55

6+
1.3.0 (2016-11-21)
7+
++++++++++++++++++
8+
9+
* The disposition was added to the minFraud response models. This is used to
10+
return the disposition of the transaction as set by the custom rules for the
11+
account.
12+
613
1.2.0 (2016-11-14)
714
++++++++++++++++++
815

minfraud/models.py

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This module contains models for the minFraud response object.
66
77
"""
8+
#pylint:disable=too-many-lines
89
from collections import namedtuple
910
from functools import update_wrapper
1011

@@ -25,8 +26,9 @@ def _inflate_to_namedtuple(orig_cls):
2526
ntup = namedtuple(name, keys)
2627
ntup.__name__ = name + 'NamedTuple'
2728
ntup.__new__.__defaults__ = (None, ) * len(keys)
28-
new_cls = type(name, (ntup, orig_cls), {'__slots__': (),
29-
'__doc__': orig_cls.__doc__})
29+
new_cls = type(name, (ntup, orig_cls),
30+
{'__slots__': (),
31+
'__doc__': orig_cls.__doc__})
3032
update_wrapper(_inflate_to_namedtuple, new_cls)
3133
orig_new = new_cls.__new__
3234

@@ -81,8 +83,8 @@ class GeoIP2Location(geoip2.records.Location):
8183
"""
8284

8385
__doc__ += geoip2.records.Location.__doc__
84-
_valid_attributes = geoip2.records.Location._valid_attributes.union(set(
85-
['local_time']))
86+
_valid_attributes = geoip2.records.Location._valid_attributes.union(
87+
set(['local_time']))
8688

8789

8890
class GeoIP2Country(geoip2.records.Country):
@@ -103,8 +105,8 @@ class GeoIP2Country(geoip2.records.Country):
103105
"""
104106

105107
__doc__ += geoip2.records.Country.__doc__
106-
_valid_attributes = geoip2.records.Country._valid_attributes.union(set(
107-
['is_high_risk']))
108+
_valid_attributes = geoip2.records.Country._valid_attributes.union(
109+
set(['is_high_risk']))
108110

109111

110112
class IPAddress(geoip2.models.Insights):
@@ -274,7 +276,7 @@ class Device(object):
274276
This number represents our confidence that the ``device_id`` refers to
275277
a unique device as opposed to a cluster of similar devices. A confidence
276278
of 0.01 indicates very low confidence that the device is unique, whereas
277-
99 indicates very high confidence.
279+
99 indicates very high confidence.
278280
279281
:type: float | None
280282
@@ -297,7 +299,42 @@ class Device(object):
297299
"""
298300

299301
__slots__ = ()
300-
_fields = {'confidence': None, 'id': None, 'last_seen': None, }
302+
_fields = {
303+
'confidence': None,
304+
'id': None,
305+
'last_seen': None,
306+
}
307+
308+
309+
@_inflate_to_namedtuple
310+
class Disposition(object):
311+
"""Information about disposition for the request as set by custom rules.
312+
313+
In order to receive a disposition, you must be use the minFraud custom
314+
rules.
315+
316+
.. attribute:: action
317+
318+
The action to take on the transaction as defined by your custom rules.
319+
The current set of values are "accept", "manual_review", and "reject".
320+
If you do not have custom rules set up, ``None`` will be returned.
321+
322+
:type: str | None
323+
324+
.. attribute:: reason
325+
326+
The reason for the action. The current possible values are
327+
"custom_rule", "block_list", and "default". If you do not have custom
328+
rules set up, ``None`` will be returned.
329+
330+
:type: str | None
331+
"""
332+
333+
__slots__ = ()
334+
_fields = {
335+
'action': None,
336+
'reason': None,
337+
}
301338

302339

303340
@_inflate_to_namedtuple
@@ -322,7 +359,10 @@ class Email(object):
322359
"""
323360

324361
__slots__ = ()
325-
_fields = {'is_free': None, 'is_high_risk': None, }
362+
_fields = {
363+
'is_free': None,
364+
'is_high_risk': None,
365+
}
326366

327367

328368
@_inflate_to_namedtuple
@@ -467,7 +507,8 @@ class ShippingAddress(object):
467507
This property is ``True`` if the postal code
468508
provided with the address is in the city for the address. The property is
469509
``False`` when the postal code is not in the city. If the address was
470-
not provided, could not be parsed, or was not in USA, the property will be ``None``.
510+
not provided, could not be parsed, or was not in USA, the property will
511+
be ``None``.
471512
472513
:type: bool | None
473514
@@ -546,7 +587,11 @@ class ServiceWarning(object):
546587
"""
547588

548589
__slots__ = ()
549-
_fields = {'code': None, 'warning': None, 'input_pointer': None, }
590+
_fields = {
591+
'code': None,
592+
'warning': None,
593+
'input_pointer': None,
594+
}
550595

551596

552597
@_inflate_to_namedtuple
@@ -762,6 +807,13 @@ class Factors(object):
762807
763808
:type: Device
764809
810+
.. attribute:: disposition
811+
812+
A :class:`.Disposition` object containing the disposition for the
813+
request as set by custom rules.
814+
815+
:type: Disposition
816+
765817
.. attribute:: email
766818
767819
A :class:`.Email` object containing information about the email address
@@ -798,6 +850,7 @@ class Factors(object):
798850
_fields = {
799851
'billing_address': BillingAddress,
800852
'credit_card': CreditCard,
853+
'disposition': Disposition,
801854
'funds_remaining': None,
802855
'device': Device,
803856
'email': Email,
@@ -870,6 +923,13 @@ class Insights(object):
870923
871924
:type: Device
872925
926+
.. attribute:: disposition
927+
928+
A :class:`.Disposition` object containing the disposition for the
929+
request as set by custom rules.
930+
931+
:type: Disposition
932+
873933
.. attribute:: email
874934
875935
A :class:`.Email` object containing information about the email address
@@ -902,6 +962,7 @@ class Insights(object):
902962
'billing_address': BillingAddress,
903963
'credit_card': CreditCard,
904964
'device': Device,
965+
'disposition': Disposition,
905966
'email': Email,
906967
'funds_remaining': None,
907968
'id': None,
@@ -958,6 +1019,13 @@ class Score(object):
9581019
9591020
:type: float
9601021
1022+
.. attribute:: disposition
1023+
1024+
A :class:`.Disposition` object containing the disposition for the
1025+
request as set by custom rules.
1026+
1027+
:type: Disposition
1028+
9611029
.. attribute:: ip_address
9621030
9631031
A :class:`.ScoreIPAddress` object containing IP address risk.
@@ -967,6 +1035,7 @@ class Score(object):
9671035

9681036
__slots__ = ()
9691037
_fields = {
1038+
'disposition': Disposition,
9701039
'funds_remaining': None,
9711040
'id': None,
9721041
'ip_address': ScoreIPAddress,

minfraud/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# objects below. Given the consistent use of them, the current names seem
2222
# preferable to blindly following pylint.
2323
#
24-
# pylint: disable=invalid-name,redefined-variable-type
24+
# pylint: disable=invalid-name,redefined-variable-type,undefined-variable
2525

2626
if sys.version_info[0] >= 3:
2727
_unicode_or_printable_ascii = str

tests/data/factors-response.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"risk_score": 0.01,
44
"funds_remaining": 10.00,
55
"queries_remaining": 1000,
6+
"disposition": {
7+
"action": "reject",
8+
"reason": "custom_rule"
9+
},
610
"ip_address": {
711
"risk": 0.01,
812
"city": {

tests/data/insights-response.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"risk_score": 0.01,
44
"funds_remaining": 10.00,
55
"queries_remaining": 1000,
6+
"disposition": {
7+
"action": "reject",
8+
"reason": "custom_rule"
9+
},
610
"ip_address": {
711
"risk": 0.01,
812
"city": {

tests/data/score-response.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"id": "27d26476-e2bc-11e4-92b8-962e705b4af5",
44
"funds_remaining": 10.00,
55
"queries_remaining": 1000,
6+
"disposition": {
7+
"action": "reject",
8+
"reason": "custom_rule"
9+
},
610
"ip_address": {
711
"risk": 99
812
},

0 commit comments

Comments
 (0)