PHPackages                             maxmind/minfraud - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. maxmind/minfraud

ActiveLibrary[Security](/categories/security)

maxmind/minfraud
================

MaxMind minFraud API

v3.6.0(3mo ago)582.1M—1.5%18[2 issues](https://github.com/maxmind/minfraud-api-php/issues)6Apache-2.0PHPPHP &gt;=8.1CI passing

Since Jun 18Pushed 1mo ago15 watchersCompare

[ Source](https://github.com/maxmind/minfraud-api-php)[ Packagist](https://packagist.org/packages/maxmind/minfraud)[ Docs](https://github.com/maxmind/minfraud-api-php)[ RSS](/packages/maxmind-minfraud/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (50)Used By (6)

MaxMind minFraud PHP API
========================

[](#maxmind-minfraud-php-api)

Description
-----------

[](#description)

This package provides an API for the [MaxMind minFraud web services](https://dev.maxmind.com/minfraud/).

Install via Composer
--------------------

[](#install-via-composer)

We recommend installing this package with [Composer](https://getcomposer.org/).

### Download Composer

[](#download-composer)

To download Composer, run in the root directory of your project:

```
curl -sS https://getcomposer.org/installer | php
```

You should now have the file `composer.phar` in your project directory.

### Install Dependencies

[](#install-dependencies)

Run in your project root:

```
php composer.phar require maxmind/minfraud:^3.6.0

```

You should now have the files `composer.json` and `composer.lock` as well as the directory `vendor` in your project directory. If you use a version control system, `composer.json` should be added to it.

### Require Autoloader

[](#require-autoloader)

After installing the dependencies, you need to require the Composer autoloader from your code:

```
require 'vendor/autoload.php';
```

Install via Phar
----------------

[](#install-via-phar)

Although we strongly recommend using Composer, we also provide a [phar archive](https://php.net/manual/en/book.phar.php) containing most of the dependencies for this API. The latest phar archive is available on [our releases page](https://github.com/maxmind/minfraud-api-php/releases).

### Install Dependencies

[](#install-dependencies-1)

Please note that you must have the PHP [cURL extension](https://php.net/manual/en/book.curl.php) installed to use this archive. For Debian based distributions, this can typically be found in the `php-curl` package. For other operating systems, please consult the relevant documentation. After installing the extension you may need to restart your web server.

If you are missing this extension, you will see errors like the following:

```
PHP Fatal error:  Uncaught Error: Call to undefined function MaxMind\WebService\curl_version()

```

### Require Package

[](#require-package)

To use the archive, just require it from your script:

```
require 'minfraud.phar';
```

API Documentation
-----------------

[](#api-documentation)

More detailed API documentation is available on [our GitHub Page](https://maxmind.github.io/minfraud-api-php/) under the "API" tab.

Usage
-----

[](#usage)

This library provides access to both the [minFraud (Score, Insights and Factors)](https://dev.maxmind.com/minfraud/)and [Report Transaction](https://dev.maxmind.com/minfraud/report-transaction/)APIs.

### minFraud API

[](#minfraud-api)

To use the minFraud API, create a new `\MaxMind\MinFraud` object. The constructor takes your MaxMind account ID, license key, and an optional `options` array as arguments. This object is immutable. See the API documentation for the possible options.

For instance, to use the Sandbox web service instead of the production web service, you can provide the host option:

```
$mf = new MinFraud(1, 'ABCD567890', [ 'host' => 'sandbox.maxmind.com' ]);
```

Build up the request using the `->with*` methods as shown below. Each method call returns a new object. The previous object is not modified.

If there is a validation error in the data passed to a `->with*` method, an exception in the `\MaxMind\Exception` namespace will be thrown. This validation can be disabled by setting `validateInput` to `false` in the options array for `\MaxMind\MinFraud`, but it is recommended that you keep it on at least through development as it will help ensure that you are sending valid data to the web service.

After creating the request object, send a Score request by calling `->score()`, an Insights request by calling `->insights()`, or a Factors request by calling `->factors()`. If the request succeeds, a model object will be returned for the endpoint. If the request fails, an exception will be thrown.

See the API documentation for more details.

#### minFraud Exceptions

[](#minfraud-exceptions)

All externally visible exceptions are in the `\MaxMind\Exception` namespace. The possible exceptions are:

- `InvalidInputException` - This will be thrown when a `->with*` method is called with invalid input data.
- `AuthenticationException` - This will be thrown on calling `->score()`, `->insights()`, or `->factors()` when the server is unable to authenticate the request, e.g., if the license key or account ID is invalid.
- `InsufficientFundsException` - This will be thrown on calling `->score()`, `->insights()`, or `->factors()` when your account is out of funds.
- `InvalidRequestException` - This will be thrown on calling `->score()`, `->insights()`, or `->factors()` when the server rejects the request for another reason such as invalid JSON in the POST.
- `HttpException` - This will be thrown on calling `->score()`, `->insights()`, or `->factors()` when an unexpected HTTP error occurs such as a firewall interfering with the request to the server.
- `WebServiceException` - This will be thrown on calling `->score()`, `->insights()`, or `->factors()` when some other error occurs. This also serves as the base class for the above exceptions.

#### minFraud Example

[](#minfraud-example)

```
