arraypress / maxmind-minfraud
A PHP library for integrating with the MaxMind minFraud Score API in WordPress, providing fraud risk scoring (0-99), IP reputation, and email/billing/shipping risk signals. Built around WordPress's HTTP API with transient caching.
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-05-06 13:05:34 UTC
README
A focused PHP library for the MaxMind minFraud Score API, built for WordPress with wp_remote_post and transient caching. No external HTTP dependencies. Drop-in for fraud-scoring at checkout, on signup, or anywhere a 0-99 risk score is useful.
Features
- ðŊ One thing well â wraps the minFraud Score endpoint (the cheapest of MaxMind's three minFraud tiers, returns the 0-99 risk score)
- ð° Funds-aware â surfaces
funds_remaining/queries_remainingfrom every successful response so you can wire up budget alerts - ðĶ Stable error handling â distinguishes transport / auth / quota failures via
WP_Errorrather than coercing them into a 0 score - ðŠķ Zero deps â only PHP and WordPress's HTTP API
- ð Transient caching â repeat lookups within a 10-minute window cost zero API calls
- ðĶ Predictable response shape â getter-friendly Score wrapper that won't break when MaxMind extends the JSON
Requirements
- PHP 7.4 or later
- WordPress 5.0 or later
- MaxMind account + minFraud license key
Installation
composer require arraypress/maxmind-minfraud
Quick start
use ArrayPress\MaxMind\MinFraud\Client; $client = new Client( '123456', 'your-license-key' ); $result = $client->check_score( [ 'device' => [ 'ip_address' => '203.0.113.42' ], 'email' => [ 'address' => 'alice@example.com' ], 'billing' => [ 'country' => 'US', 'region' => 'CA', 'city' => 'Los Angeles', 'postal' => '90210', ], ] ); if ( is_wp_error( $result ) ) { error_log( 'minFraud failed: ' . $result->get_error_message() ); return; } if ( $result->is_high_risk() ) { // 75+ risk score â block / hold the order } $score = $result->get_risk_score(); // 42.5 $query_id = $result->get_query_id(); // for cross-referencing in MaxMind dashboard $funds = $result->get_funds_remaining(); // USD remaining on the account $warnings = $result->get_warnings(); // any non-fatal warnings
Configuration
$client = new Client( 'account-id', 'license-key', [ 'cache_enabled' => true, // default true 'cache_ttl' => 600, // seconds; default 10 min 'cache_prefix' => 'mm_', // transient key prefix ] );
Request payload
The check_score() payload mirrors MaxMind's spec. The minimum is device.ip_address, but pass everything you have â minFraud's score quality scales with how much context you give it.
Useful fields beyond the basics:
$client->check_score( [ 'device' => [ 'ip_address' => '203.0.113.42', 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', ], 'email' => [ 'address' => 'alice@example.com' ], 'account' => [ 'user_id' => '42' ], 'billing' => [ 'country' => 'US', 'postal' => '90210' ], 'shipping' => [ 'country' => 'US', 'postal' => '90210' ], 'payment' => [ 'processor' => 'stripe' ], 'event' => [ 'type' => 'purchase' ], ] );
Error handling
Errors come back as WP_Error rather than an empty Score, so you don't accidentally treat an auth failure like a 0 score:
$result = $client->check_score( $payload ); if ( is_wp_error( $result ) ) { $code = $result->get_error_code(); // 'minfraud_api_error', 'minfraud_bad_response', etc. $message = $result->get_error_message(); $data = $result->get_error_data(); // includes HTTP status when relevant // Fall back to your own rules, log, etc. }
Possible error codes:
minfraud_missing_credentialsâ account ID / license key not providedminfraud_api_errorâ MaxMind returned a non-2xx with an error bodyminfraud_bad_responseâ couldn't decode the JSONhttp_request_failedâ WordPress transport error (passed through verbatim)
Why not the official SDK?
MaxMind ships an official PHP SDK that you can absolutely use. This library exists for projects that want a smaller surface area â it's framework-aware (transient cache, wp_remote_* transport, no Composer-level Guzzle / PSR-7 deps) and exposes only the Score endpoint, which is what most rule engines actually need.
If you need Insights or Factors (subscores for IP location, email reputation, device, etc.), use the official SDK or open an issue.
License
GPL-2.0-or-later