2017 © Pedro Peláez
 

library minfraud

MaxMind minFraud API

image

maxmind/minfraud

MaxMind minFraud API

  • Wednesday, July 4, 2018
  • by oschwald
  • Repository
  • 15 Watchers
  • 20 Stars
  • 105,810 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 10 Forks
  • 1 Open issues
  • 27 Versions
  • 13 % Grown

The README.md

MaxMind minFraud Factors, Insights, Score PHP API

Description

This package provides an API for the MaxMind minFraud Score, Insights, and Factors web services., (*1)

Install via Composer

We recommend installing this package with Composer., (*2)

Download Composer

To download Composer, run in the root directory of your project:, (*3)

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

You should now have the file composer.phar in your project directory., (*4)

Install Dependencies

Run in your project root:, (*5)

php composer.phar require maxmind/minfraud:~1.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., (*6)

Require Autoloader

After installing the dependencies, you need to require the Composer autoloader from your code:, (*7)

require 'vendor/autoload.php';

Install via Phar

Although we strongly recommend using Composer, we also provide a phar archive containing most of the dependencies for this API. The latest phar archive is available on our releases page., (*8)

Install Dependencies

Please note that you must have the PHP cURL extension installed to use this archive. For Debian based distributions, this can typically be found in the 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., (*9)

If you are missing this extension, you will see errors like the following:, (*10)

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

Require Package

To use the archive, just require it from your script:, (*11)

require 'minfraud.phar';

API Documentation

More detailed API documentation is available on our GitHub Page under the "API" tab., (*12)

Usage

This library provides access to both the minFraud (Score, Insights and Factors) and Report Transaction APIs., (*13)

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., (*14)

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

$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., (*16)

If there is a validation error in the data passed to a ->with* method, a \MaxMind\Exception 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., (*17)

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., (*18)

See the API documentation for more details., (*19)

minFraud Exceptions

All externally visible exceptions are in the \MaxMind\Exception namespace. The possible exceptions are:, (*20)

  • 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

<?php
require_once 'vendor/autoload.php';
use MaxMind\MinFraud;

# The constructor for MinFraud takes your account ID, your license key, and
# optionally an array of options.
$mf = new MinFraud(1, 'ABCD567890');

# Note that each ->with*() call returns a new immutable object. This means
# that if you separate the calls into separate statements without chaining,
# you should assign the return value to a variable each time.
$request = $mf->withDevice(
    ipAddress: '152.216.7.110',
    sessionAge: 3600.5,
    sessionId: 'foobar',
    userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
    acceptLanguage: 'en-US,en;q=0.8'
)->withEvent(
    transactionId: 'txn3134133',
    shopId: 's2123',
    time: '2012-04-12T23:20:50+00:00',
    type: 'purchase'
)->withAccount(
    userId: 3132,
    usernameMd5: '4f9726678c438914fa04bdb8c1a24088'
)->withEmail(
    address: 'test@maxmind.com',
    domain: 'maxmind.com'
)->withBilling(
    firstName: 'First',
    lastName: 'Last',
    company: 'Company',
    address: '101 Address Rd.',
    address2: 'Unit 5',
    city: 'New Haven',
    region: 'CT',
    country: 'US',
    postal: '06510',
    phoneNumber: '123-456-7890',
    phoneCountryCode: '1'
)->withShipping(
    firstName: 'ShipFirst',
    lastName: 'ShipLast',
    company: 'ShipCo',
    address: '322 Ship Addr. Ln.',
    address2: 'St. 43',
    city: 'Nowhere',
    region: 'OK',
    country: 'US',
    postal: '73003',
    phoneNumber: '123-456-0000',
    phoneCountryCode: '1',
    deliverySpeed: 'same_day'
)->withPayment(
    processor: 'stripe',
    wasAuthorized: false,
    declineCode: 'invalid number'
)->withCreditCard(
    issuerIdNumber: '411111',
    lastDigits: '7643',
    bankName: 'Bank of No Hope',
    bankPhoneCountryCode: '1',
    bankPhoneNumber: '123-456-1234',
    avsResult: 'Y',
    cvvResult: 'N',
    was3dSecureSuccessful: true
)->withOrder(
    amount: 323.21,
    currency: 'USD',
    discountCode: 'FIRST',
    isGift: true,
    hasGiftMessage: false,
    affiliateId: 'af12',
    subaffiliateId: 'saf42',
    referrerUri: 'http://www.amazon.com/'
)->withShoppingCartItem(
    category: 'pets',
    itemId: 'leash-0231',
    quantity: 2,
    price: 20.43
)->withShoppingCartItem(
    category: 'beauty',
    itemId: 'msc-1232',
    quantity: 1,
    price: 100.00
)->withCustomInputs([
   'section'            => 'news',
   'previous_purchases' => 19,
   'discount'           => 3.2,
   'previous_user'      => true,
]);

# To get the minFraud Factors response model, use ->factors():
$factorsResponse = $request->factors();

print($factorsResponse->subscores->emailAddress . "\n");

# To get the minFraud Insights response model, use ->insights():
$insightsResponse = $request->insights();

print($insightsResponse->riskScore . "\n");
print($insightsResponse->creditCard->issuer->name . "\n");

foreach ($insightsResponse->warnings as $warning) {
    print($warning->warning . "\n");
}

# To get the minFraud Score response model, use ->score():
$scoreResponse = $request->score();

print($scoreResponse->riskScore . "\n");

foreach ($scoreResponse->warnings as $warning) {
    print($warning->warning . "\n");
}

Report Transactions API

MaxMind encourages the use of this API as data received through this channel is used to continually improve the accuracy of our fraud detection algorithms., (*21)

To use the Report Transactions API, create a new \MaxMind\MinFraud\ReportTransaction object. The constructor takes your MaxMind account ID, license key, and an optional options array as arguments. This object is immutable. You then send one or more reports using the ->report method as shown below., (*22)

If there is a validation error in the data passed to the ->report method, a \MaxMind\Exception will be thrown. This validation can be disabled by setting validateInput to false in the options array for \MaxMind\MinFraud\ReportTransaction, 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., (*23)

If the report is successful, nothing is returned. If the report fails, an exception with be thrown., (*24)

See the API documentation for more details., (*25)

Report Transaction Exceptions

All externally visible exceptions are in the \MaxMind\Exception namespace. The possible exceptions are:, (*26)

  • InvalidInputException - This will be thrown when the ->report() method is called with invalid input data or when the required fields are missing. The required fields are tag and one or more of the following: ipAddress, maxmindId, minfraudId, or transactionId.
  • AuthenticationException - This will be thrown on calling ->report(), when the server is unable to authenticate the request, e.g., if the license key or account ID is invalid.
  • InvalidRequestException - This will be thrown on calling ->report() when the server rejects the request for another reason such as invalid JSON in the POST.
  • HttpException - This will be thrown on calling ->report() when an unexpected HTTP error occurs such as a firewall interfering with the request to the server.
  • WebServiceException - This will be thrown on calling ->report() when some other error occurs. This also serves as the base class for the above exceptions.

Report Transaction Example

<?php
require_once 'vendor/autoload.php';
use MaxMind\MinFraud\ReportTransaction;

# The constructor for ReportTransaction takes your account ID, your license key,
# and optionally an array of options.
$rt = new ReportTransaction(1, 'ABCD567890');

$rt->report(
    ipAddress: '152.216.7.110',
    tag: 'chargeback',
    chargebackCode: 'UA02',
    minfraudId: '26ae87e4-5112-4f76-b0f7-4132d45d72b2',
    maxmindId: 'aBcDeFgH',
    notes: 'Found due to non-existent shipping address',
    transactionId: 'cart123456789'
);

Support

Please report all issues with this code using the GitHub issue tracker., (*27)

If you are having an issue with the minFraud service that is not specific to the client API, please see our support page., (*28)

Requirements

This code requires PHP 8.1 or greater. Older versions of PHP are not supported., (*29)

There are several other dependencies as defined in the composer.json file., (*30)

Contributing

Patches and pull requests are encouraged. All code should follow the PSR-2 style guidelines. Please include unit tests whenever possible., (*31)

Versioning

This API uses Semantic Versioning., (*32)

This software is Copyright (c) 2015-2024 by MaxMind, Inc., (*33)

This is free software, licensed under the Apache License, Version 2.0., (*34)

The Versions

04/07 2018

dev-master

9999999-dev https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

04/07 2018

dev-greg/fix-test

dev-greg/fix-test https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

24/05 2018

dev-greg/fix-hhvm-tests

dev-greg/fix-hhvm-tests https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

10/04 2018

v1.7.0

1.7.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

23/03 2018

dev-greg/new-payment-processors

dev-greg/new-payment-processors https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

13/02 2018

dev-greg/account-id

dev-greg/account-id https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

19/01 2018

v1.6.0

1.6.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

18/01 2018

dev-greg/is-in-eu

dev-greg/is-in-eu https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

30/10 2017

v1.5.0

1.5.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

10/07 2017

v1.4.0

1.4.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

19/06 2017

dev-rafl/new-payment-processors

dev-rafl/new-payment-processors https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

11/01 2017

dev-greg/custom-rules

dev-greg/custom-rules https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

22/11 2016

v1.3.0

1.3.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

11/11 2016

v1.2.0

1.2.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

18/10 2016

v1.1.1

1.1.1.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

11/10 2016

v1.1.0

1.1.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

15/09 2016

v1.0.0

1.0.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

17/08 2016

v0.6.2

0.6.2.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

11/06 2016

v0.6.1

0.6.1.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

09/06 2016

v0.6.0

0.6.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

23/05 2016

v0.5.0

0.5.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

20/01 2016

v0.4.0

0.4.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

10/08 2015

v0.3.0

0.3.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

21/07 2015

v0.2.2

0.2.2.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

30/06 2015

v0.2.1

0.2.1.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

29/06 2015

v0.2.0

0.2.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud

18/06 2015

v0.1.0

0.1.0.0 https://github.com/maxmind/minfraud-api-php

MaxMind minFraud API

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Gregory Oschwald

maxmind fraud minfraud