Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse fraud risk rules #274

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Added `Recurly_AccountAcquisition` [#259](https://github.com/recurly/recurly-client-php/pull/259)
* Added support for automated exports [#260](https://github.com/recurly/recurly-client-php/pull/260)
* Added support for shipping addresses [#269](https://github.com/recurly/recurly-client-php/pull/269)
* Adding support for `risk_rules_triggered` in `Recurly_FraudInfo` [#274](https://github.com/recurly/recurly-client-php/pull/274)

## Version 2.6.0 (August 9th, 2016)

Expand Down
9 changes: 9 additions & 0 deletions Tests/Recurly/Transaction_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function testGetTransaction() {
$this->assertInstanceOf('Recurly_FraudInfo', $transaction->fraud);
$this->assertEquals($transaction->fraud->score, 99);
$this->assertEquals($transaction->fraud->decision, 'DECLINE');

$risk_rules = $transaction->fraud->risk_rules_triggered;
$this->assertEquals(count($risk_rules), 2);

$this->assertEquals($risk_rules[0]->code, "848760");
$this->assertEquals($risk_rules[0]->message, "Review Non-Normal Network Type");

$this->assertEquals($risk_rules[1]->code, "404934");
$this->assertEquals($risk_rules[1]->message, "More than 4 unique Email Addresses");
}

public function testCreateTransactionFailed() {
Expand Down
10 changes: 10 additions & 0 deletions Tests/fixtures/transactions/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ Content-Type: application/xml; charset=utf-8
<fraud>
<score type="integer">99</score>
<decision>DECLINE</decision>
<risk_rules_triggered>
<rule>
<code>848760</code>
<message>Review Non-Normal Network Type</message>
</rule>
<rule>
<code>404934</code>
<message>More than 4 unique Email Addresses</message>
</rule>
</risk_rules_triggered>
</fraud>
<a name="refund" href="https://api.recurly.com/v2/transactions/abcdef1234567890" method="delete"/>
</transaction>
1 change: 1 addition & 0 deletions lib/recurly.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_once(dirname(__FILE__) . '/recurly/error_list.php');
require_once(dirname(__FILE__) . '/recurly/errors.php');
require_once(dirname(__FILE__) . '/recurly/fraud_info.php');
require_once(dirname(__FILE__) . '/recurly/fraud_risk_rule.php');
require_once(dirname(__FILE__) . '/recurly/link.php');
require_once(dirname(__FILE__) . '/recurly/pager.php');
require_once(dirname(__FILE__) . '/recurly/response.php');
Expand Down
2 changes: 2 additions & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ public function getLinks() {
'plan_code' => 'string',
'plan_codes' => 'array',
'pending_subscription' => 'Recurly_Subscription',
'risk_rules_triggered' => 'array',
'redemption' => 'Recurly_CouponRedemption',
'redemptions' => 'Recurly_CouponRedemptionList',
'rule' => 'Recurly_FraudRiskRule',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there is a way to just parse it into an array with keys. I could not find a way to do it but we could maybe add it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd need to use some class type just because of the way the values are assigned. So we could probably do stdClass but I think a named class is better form.

'setup_fee_in_cents' => 'Recurly_CurrencyList',
'shipping_address' => 'Recurly_ShippingAddress',
'shipping_addresses' => 'Recurly_ShippingAddressList',
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/fraud_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class Recurly_FraudInfo
{
var $score;
var $decision;
var $risk_rules_triggered;

public function __toString() {
return "<Recurly_FraudInfo score=\"{$this->score}\" decision={$this->decision}>";
return "<Recurly_FraudInfo score=\"{$this->score}\" decision=\"{$this->decision}\">";
}
}
14 changes: 14 additions & 0 deletions lib/recurly/fraud_risk_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Represents the <rule> object in <risk_rules_triggered>
*/
class Recurly_FraudRiskRule
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class name maybe too literal?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine

{
var $code;
var $message;

public function __toString() {
return "<Recurly_FraudRiskRule code=\"{$this->code}\" message=\"{$this->message}\">";
}
}