-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92c89f4
commit 151c8d1
Showing
6 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.