Skip to content

Commit

Permalink
Add Transaction Reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickCroninMM committed May 12, 2020
1 parent 92c89f4 commit 151c8d1
Show file tree
Hide file tree
Showing 6 changed files with 456 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/MinFraud/Validation/Rules/TransactionReport.php
@@ -0,0 +1,40 @@
<?php

namespace MaxMind\MinFraud\Validation\Rules;

use Respect\Validation\Rules\AbstractWrapper;
use Respect\Validation\Validator as v;

/**
* @internal
*/
class TransactionReport extends AbstractWrapper
{
public function __construct()
{
$this->validatable = v::keySet(
v::key('chargeback_code', v::stringType(), false),
v::key('ip_address', v::ip(), true),
v::key('maxmind_id', v::stringType()->length(8, 8), false),
v::key(
'minfraud_id',
v::regex('/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/'),
false
),
v::key('notes', v::stringType(), false),
v::key(
'tag',
v::in(
[
'not_fraud',
'suspected_fraud',
'spam_or_abuse',
'chargeback',
]
),
true
),
v::key('transaction_id', v::stringType(), false)
);
}
}
62 changes: 62 additions & 0 deletions src/ReportTransaction.php
@@ -0,0 +1,62 @@
<?php

namespace MaxMind;

use MaxMind\Exception\InvalidInputException;

class ReportTransaction extends ServiceClient
{
/**
* @param int $accountId Your MaxMind account ID
* @param string $licenseKey Your MaxMind license key
* @param array $options An array of options. Possible keys:
*
* * `host` - The host to use when connecting to the web service.
* * `userAgent` - The prefix for the User-Agent header to use in the
* request.
* * `caBundle` - The bundle of CA root certificates to use in the request.
* * `connectTimeout` - The connect timeout to use for the request.
* * `timeout` - The timeout to use for the request.
* * `proxy` - The HTTP proxy to use. May include a schema, port,
* username, and password, e.g., `http://username:password@127.0.0.1:10`.
* * `validateInput` - Default is `true`. Determines whether values passed
* to the `with*()` methods are validated. It is recommended that you
* leave validation on while developing and only (optionally) disable it
* before deployment.
*/
public function __construct(
$accountId,
$licenseKey,
$options = []
) {
parent::__construct($accountId, $licenseKey, $options);
}

/**
* @param array $values the transaction parameters
*
* @throws InvalidInputException when the request has missing or invalid
* data
* @throws AuthenticationException when there is an issue authenticating the
* request
* @throws InvalidRequestException when the request is invalid for some
* other reason, e.g., invalid JSON in the POST.
* @throws HttpException when an unexpected HTTP error occurs
* @throws WebServiceException when some other error occurs. This also
* serves as the base class for the above exceptions.
*/
public function reportTransaction($values)
{
$values = $this->cleanAndValidate('TransactionReport', $values);

if (!isset($values['ip_address'])) {
throw new InvalidInputException('Key ip_address must be present in request');
}
if (!isset($values['tag'])) {
throw new InvalidInputException('Key tag must be present in request');
}

$url = self::$basePath . 'transactions/report';
$this->client->post('ReportTransaction', $url, $values);
}
}
21 changes: 21 additions & 0 deletions tests/MaxMind/Test/ReportTransactionData.php
@@ -0,0 +1,21 @@
<?php

namespace MaxMind\Test;

class ReportTransactionData
{
public static function fullRequest()
{
return self::decodeFile('full-request.json');
}

public static function minimalRequest()
{
return self::decodeFile('minimal-request.json');
}

private static function decodeFile($file)
{
return json_decode(file_get_contents('tests/data/reporttransaction/' . $file), true);
}
}

0 comments on commit 151c8d1

Please sign in to comment.