Skip to content

Commit

Permalink
Add disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Nov 22, 2016
1 parent 85fb741 commit d2ddaf0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

1.3.0 (2016-11-22)
------------------

* The disposition was added to the minFraud response models. This is used to
return the disposition of the transaction as set by the custom rules for the
account.

1.2.0 (2016-11-11)
------------------

Expand Down
38 changes: 38 additions & 0 deletions src/MinFraud/Model/Disposition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace MaxMind\MinFraud\Model;

/**
* Model with the disposition set by custom rules.
*
* In order to receive a disposition, you must be use the minFraud custom
* rules.
*
* @property-read string|null $action The action to take on the transaction as
* defined by your custom rules. The current set of values are "accept",
* "manual_review", and "reject". If you do not have custom rules set up,
* `null` will be returned.
*
* @property-read string|null $reason The reason for the action. The current
* possible values are "custom_rule", "block_list", and "default". If you do
* not have custom rules set up, `null` will be returned.
*/
class Disposition extends AbstractModel
{
/**
* @internal
*/
protected $action;

/**
* @internal
*/
protected $reason;

public function __construct($response, $locales = ['en'])
{
parent::__construct($response, $locales);
$this->action = $this->safeArrayLookup($response['action']);
$this->reason = $this->safeArrayLookup($response['reason']);
}
}
10 changes: 10 additions & 0 deletions src/MinFraud/Model/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* never return a risk score of 0, since all transactions have the possibility
* of being fraudulent. Likewise we never return a risk score of 100.
*
* @property-read \MaxMind\MinFraud\Model\Disposition disposition An object
* containing the disposition set by custom rules.
*
* @property-read \MaxMind\MinFraud\Model\ScoreIpAddress $ipAddress An object
* containing the IP risk for the transaction.
*
Expand All @@ -35,6 +38,11 @@
*/
class Score extends AbstractModel
{
/**
* @internal
*/
protected $disposition;

/**
* @internal
*/
Expand Down Expand Up @@ -74,6 +82,8 @@ public function __construct($response, $locales = ['en'])
{
parent::__construct($response, $locales);

$this->disposition
= new Disposition($this->safeArrayLookup($response['disposition']));
$this->fundsRemaining = $this->safeArrayLookup($response['funds_remaining']);
$this->queriesRemaining = $this->safeArrayLookup($response['queries_remaining']);
$this->id = $this->safeArrayLookup($response['id']);
Expand Down
35 changes: 35 additions & 0 deletions tests/MaxMind/Test/MinFraud/Model/DispositionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace MaxMind\Test\MinFraud\Model;

use MaxMind\MinFraud\Model\Disposition;

class DispositionTest extends \PHPUnit_Framework_TestCase
{
public function testDisposition()
{
$array = [
'action' => 'manual_review',
'reason' => 'custom_rule',
];
$disposition = new Disposition($array);

$this->assertSame(
$array['action'],
$disposition->action,
'action'
);

$this->assertSame(
$array['reason'],
$disposition->reason,
'reason'
);

$this->assertSame(
$array,
$disposition->jsonSerialize(),
'correctly implements JsonSerializable'
);
}
}
6 changes: 6 additions & 0 deletions tests/MaxMind/Test/MinFraud/Model/ScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public function testScoreProperties()
'credits remaining'
);

$this->assertSame(
$array['disposition']['action'],
$score->disposition->action,
'disposition action'
);

$this->assertSame(
$array['ip_address']['risk'],
$score->ipAddress->risk,
Expand Down
4 changes: 4 additions & 0 deletions tests/data/factors-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"risk_score": 0.01,
"funds_remaining": 10.00,
"queries_remaining": 1000,
"disposition": {
"action": "reject",
"reason": "custom_rule"
},
"ip_address": {
"risk": 0.01,
"city": {
Expand Down
4 changes: 4 additions & 0 deletions tests/data/insights-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"risk_score": 0.01,
"funds_remaining": 10.00,
"queries_remaining": 1000,
"disposition": {
"action": "reject",
"reason": "custom_rule"
},
"ip_address": {
"risk": 0.01,
"city": {
Expand Down
4 changes: 4 additions & 0 deletions tests/data/score-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"id": "27d26476-e2bc-11e4-92b8-962e705b4af5",
"funds_remaining": 10.00,
"queries_remaining": 1000,
"disposition": {
"action": "reject",
"reason": "custom_rule"
},
"ip_address": {
"risk": 99
},
Expand Down

0 comments on commit d2ddaf0

Please sign in to comment.