Evaluate a Transaction
Evaluating a transaction consists of setting up device tracking, creating an object that contains the details of the transaction, and then submitting the transaction to the minFraud service for evaluation.
Implementation
MaxMind offers and highly recommends using official client libraries to access our minFraud services. If you cannot or do not wish to use our client libraries, please review our minFraud API Documentation page for details on our JSON API.
1. Add device tracking to your site or app
The Device Tracking Add-On runs on a visiting device so that the minFraud service can assign a device ID and begin collecting fingerprint information. This helps detect fraudsters if they change or enable proxies while using your site or app.
Note that, in order to be effective, device tracking must be active when the IP address is captured for a minFraud query.
For web integration, place the following code in the footer of the HTML webpage
and replace MAXMIND_ACCOUNT_ID with your
MaxMind account ID:
1<script>
2 (function () {
3 var mmapiws = (window.__mmapiws = window.__mmapiws || {});
4 mmapiws.accountId = MAXMIND_ACCOUNT_ID;
5 var loadDeviceJs = function () {
6 var element = document.createElement('script');
7 element.async = true;
8 element.src = 'https://device.maxmind.com/js/device.js';
9 document.body.appendChild(element);
10 };
11 if (window.addEventListener) {
12 window.addEventListener('load', loadDeviceJs, false);
13 } else if (window.attachEvent) {
14 window.attachEvent('onload', loadDeviceJs);
15 }
16 })();
17</script>
A module snippet and an npm package are also available for sites targeting modern browsers. For Android apps, see the Android SDK guide.
2. Install the minFraud client library
We have a collection of officially supported libraries for you to interact with the minFraud API:
1// Install via NuGet
2Install-Package MaxMind.MinFraud
1// Install via Maven, recommended
2<dependency>
3 <groupId>com.maxmind.minfraud</groupId>
4 <artifactId>minfraud</artifactId>
5 <version>4.2.0</version>
6</dependency>
7
8// Or install via Gradle
9repositories {
10 mavenCentral()
11}
12dependencies {
13 implementation 'com.maxmind.minfraud:minfraud:4.2.0'
14}
1// Install via npm
2npm install @maxmind/minfraud-api-node
3
4// Or install via yarn
5yarn add @maxmind/minfraud-api-node
1# Install via Composer
2composer require maxmind/minfraud:~3.0
1# Install via pip
2pip install minfraud
1# Install as a gem
2gem install minfraud
3
4# Or add this to your Gemfile
5gem 'minfraud'
3. Create a minFraud client object
To interact with our API, you need to create a new client object. For this you will need your MaxMind account ID and license key:
1int accountId = 10;
2string licenseKey = "LICENSEKEY";
3
4var client = new WebServiceClient(accountId, licenseKey);
1int accountId = 10;
2String licenseKey = "LICENSEKEY";
3
4WebServiceClient client = new WebServiceClient.Builder(accountId, licenseKey).build();
1import * as minFraud from '@maxmind/minfraud-api-node';
2
3const accountId = '10';
4const licenseKey = 'LICENSEKEY';
5
6const client = new minFraud.Client(accountId, licenseKey);
1$accountId = 10;
2$licenseKey = 'LICENSEKEY';
3
4$client = new MinFraud($accountId, $licenseKey);
1from minfraud import Client, AsyncClient
2
3account_id = 10
4license_key = 'LICENSEKEY'
5
6# If you want to use synchronous requests
7client = Client(account_id, license_key)
8
9# Or if you want to use asynchronous requests
10async_client = AsyncClient(account_id, license_key)
1Minfraud.configure do |c|
2 c.account_id = 10
3 c.license_key = 'LICENSEKEY'
4 c.enable_validation = true
5end
4. Create a transaction object
The transaction object represents a customer’s transaction that you are sending to the minFraud service for evaluation. There are no mandatory fields, but including more information about the transaction improves the accuracy of the transaction’s evaluation. The following examples use the recommended minimum amount of information you should submit:
1var transaction = new Transaction
2{
3 Device = new Device
4 {
5 IPAddress = System.Net.IPAddress.Parse("1.1.1.1")
6 },
7 Email = new Email
8 {
9 Address = "test@maxmind.com",
10 Domain = "maxmind.com"
11 },
12 Billing = new Billing
13 {
14 FirstName = "First",
15 LastName = "Last",
16 Company = "Company, Inc.",
17 Address = "1 Billing Address St.",
18 Address2 = "Unit 1",
19 City = "Waltham",
20 Region = "MA",
21 Country = "US",
22 Postal = "02451",
23 PhoneNumber = "555-555-5555",
24 PhoneCountryCode = "1"
25 },
26 CreditCard = new CreditCard
27 {
28 IssuerIdNumber = "411111"
29 },
30 Shipping = new Shipping
31 {
32 FirstName = "First",
33 LastName = "Last",
34 Company = "Company Inc.",
35 Address = "1 Shipping Address St.",
36 Address2 = "Unit 1",
37 City = "Waltham",
38 Region = "MA",
39 Country = "US",
40 Postal = "02451",
41 PhoneNumber = "555-555-5555",
42 PhoneCountryCode = "1"
43 }
44};
1Transaction transaction = new Transaction.Builder(
2 new Device.Builder(InetAddress.getByName("1.1.1.1"))
3 .build()
4 ).billing(
5 new Billing.Builder()
6 .address("1 Billing Address St.")
7 .address2("Unit 1")
8 .city("Waltham")
9 .company("Company, Inc")
10 .firstName("First")
11 .lastName("Last")
12 .phoneCountryCode("1")
13 .phoneNumber("555-555-5555")
14 .postal("02451")
15 .region("MA")
16 .build()
17 ).creditCard(
18 new CreditCard.Builder()
19 .issuerIdNumber("411111")
20 .build()
21 ).email(
22 new Email.Builder()
23 .address("test@maxmind.com")
24 .domain("maxmind.com")
25 .build()
26 ).shipping(
27 new Shipping.Builder()
28 .address("1 Shipping Address St.")
29 .address2("Unit 1")
30 .city("Waltham")
31 .company("Company, Inc")
32 .firstName("First")
33 .lastName("Last")
34 .phoneCountryCode("1")
35 .phoneNumber("555-555-5555")
36 .postal("02451")
37 .region("MA")
38 .build()
39 ).build();
1import * as minFraud from '@maxmind/minfraud-api-node';
2
3let transaction;
4
5try {
6 transaction = new minFraud.Transaction({
7 device: new minFraud.Device({
8 ipAddress: '1.1.1.1',
9 }),
10 billing: new minFraud.Billing({
11 address: '1 Billing Address St.',
12 address2: 'Unit 1',
13 city: 'Waltham',
14 company: 'Company, Inc.',
15 country: 'US',
16 firstName: 'First',
17 lastName: 'Last',
18 phoneCountryCode: '1',
19 phoneNumber: '555-555-5555',
20 postal: '02451',
21 region: 'MA',
22 }),
23 creditCard: new minFraud.CreditCard({
24 issuerIdNumber: '411111',
25 }),
26 email: new minFraud.Email({
27 address: 'test@maxmind.com',
28 domain: 'maxmind.com',
29 }),
30 shipping: new minFraud.Shipping({
31 address: '1 Shipping Address St.',
32 address2: 'Unit 1',
33 city: 'Waltham',
34 company: 'Company, Inc.',
35 country: 'US',
36 firstName: 'First',
37 lastName: 'Last',
38 phoneCountryCode: '1',
39 phoneNumber: '555-555-5555',
40 postal: '02451',
41 region: 'MA',
42 }),
43 });
44} catch (error) {
45 // handle the error
46}
1$request = $client->withDevice(
2 ipAddress: '1.1.1.1'
3)->withBilling(
4 firstName: 'First',
5 lastName: 'Last',
6 company: 'Company',
7 address: '1 Billing Address St.',
8 address2: 'Unit 1',
9 city: 'Waltham',
10 region: 'MA',
11 country: 'US',
12 postal: '02451',
13 phoneNumber: '555-555-5555',
14 phoneCountryCode: '1'
15)->withCreditCard(
16 issuerIdNumber: '411111'
17)->withEmail(
18 address: 'test@maxmind.com',
19 domain: 'maxmind.com'
20)->withShipping(
21 firstName: 'First',
22 lastName: 'Last',
23 company: 'Company',
24 address: '1 Shipping Address St.',
25 address2: 'Unit 1',
26 city: 'Waltham',
27 region: 'MA',
28 country: 'US',
29 postal: '02451',
30 phoneNumber: '555-555-5555',
31 phoneCountryCode: '1'
32);
1request = {
2 'device': {
3 'ip_address': '1.1.1.1',
4 },
5 'billing': {
6 'first_name': 'First',
7 'last_name': 'Last',
8 'company': 'Company, Inc.',
9 'address': '1 Billing Address St.',
10 'address_2': 'Unit 1',
11 'city': 'Waltham',
12 'region': 'MA',
13 'country': 'US',
14 'postal': '02451',
15 'phone_country_code': '1',
16 'phone_number': '555-555-5555',
17 },
18 'credit_card': {
19 'issuer_id_number': '411111'
20 },
21 'email': {
22 'address': '977577b140bfb7c516e4746204fbdb01',
23 'domain': 'maxmind.com'
24 },
25 'shipping': {
26 'first_name': 'First',
27 'last_name': 'Last',
28 'company': 'Company, Inc.',
29 'address': '1 Shipping Address St.',
30 'address_2': 'Unit 1',
31 'city': 'Waltham',
32 'region': 'MA',
33 'country': 'US',
34 'postal': '02451',
35 'phone_country_code': '1',
36 'phone_number': '555-555-5555',
37 }
38}
1assessment = Minfraud::Assessments.new(
2 device: {
3 ip_address: '1.1.1.1',
4 },
5 billing: {
6 first_name: 'First',
7 last_name: 'Last',
8 company: 'Company, Inc.',
9 address: '1 Billing Address St.',
10 address_2: 'Unit 1',
11 city: 'Waltham',
12 region: 'MA',
13 country: 'US',
14 postal: '02451',
15 phone_number: '555-555-5555',
16 phone_country_code: '1',
17 },
18 credit_card: {
19 issuer_id_number: '411111',
20 },
21 email: {
22 address: 'test@maxmind.com',
23 domain: 'maxmind.com',
24 },
25 shipping: {
26 first_name: 'First',
27 last_name: 'Last',
28 company: 'Company, Inc.',
29 address: '1 Shipping Address St.',
30 address_2: 'Unit 1',
31 city: 'Waltham',
32 region: 'MA',
33 country: 'US',
34 postal: '02451',
35 phone_number: '555-555-5555',
36 phone_country_code: '1',
37 },
38)
5. Submit the transaction object for evaluation
Our client libraries provide a distinct method for each minFraud service. Use the appropriate method to submit the transaction object to the minFraud Score, Insights, or Factors service.
1// minFraud Score
2var score = await client.ScoreAsync(transaction);
3
4// minFraud Insights
5var insights = await client.InsightsAsync(transaction);
6
7// minFraud Factors
8var factors = await client.FactorsAsync(transaction);
1// minFraud Score
2ScoreResponse score = client.score(transaction);
3
4// minFraud Insights
5InsightsResponse insights = client.insights(transaction);
6
7// minFraud Factors
8FactorsResponse factors = client.factors(transaction);
1// minFraud Score
2client.score(transaction).then(scoreResponse => ...);
3
4// minFraud Insights
5client.insights(transaction).then(insightsResponse => ...);
6
7// minFraud Factors
8client.factors(transaction).then(factorsResponse => ...);
1// minFraud Score
2$scoreResponse = $request->score();
3
4// minFraud Insights
5$insightsResponse = $request->insights();
6
7// minFraud Factors
8$factorsResponse = $request->factors();
1# minFraud Score - Synchronous
2score_response = client.score(request)
3
4# minFraud Score - Asynchronous
5score_response = await async_client.score(request)
6
7# minFraud Insights - Synchronous
8insights_response = client.insights(request)
9
10# minFraud Insights - Asynchronous
11insights_response = await async_client.insights(request)
12
13# minFraud Factors - Synchronous
14factors_response = client.factors(request)
15
16# minFraud Factors - Asynchronous
17factors_response = await async_client.factors(request)
1# minFraud Score
2score_model = assessment.score.body
3
4# minFraud Insights
5insights_model = assessment.insights.body
6
7# minFraud Factors
8factors_model = assessment.factors.body
Validation and error handling
By default, our client libraries will throw an exception if any of the transaction object’s values are invalid. The exception is thrown when the object is constructed; the python library will raise an error when the minFraud service method is called.
If the minFraud request fails, our client libraries will throw an exception, raise an error (python), or reject the promise (node).
For more information on errors and exceptions, including their types and descriptions, go to the specific library’s documentation page.
Full examples
1using MaxMind.MinFraud;
2using MaxMind.MinFraud.Request;
3using System;
4using System.Collections.Generic;
5using System.Net;
6using System.Threading.Tasks;
7
8public class MinFraudExample
9{
10 static void Main()
11 {
12 MinFraudAsync().Wait();
13 }
14
15 static public async Task MinFraudAsync()
16 {
17 var transaction = new Transaction
18 {
19 Device = new Device
20 {
21 IPAddress = IPAddress.Parse("1.1.1.1"),
22 UserAgent = "Mozilla/5.0 (X11; Linux x86_64)",
23 AcceptLanguage = "en-US,en;q=0.8",
24 SessionAge = 3600,
25 SessionId = "a333a4e127f880d8820e56a66f40717c"
26 },
27 Event = new Event
28 {
29 TransactionId = "txn3134133",
30 ShopId = "s2123",
31 Time = new DateTimeOffset(2014, 4, 12, 23, 20, 50, 52, new TimeSpan(0)),
32 Type = EventType.Purchase
33 },
34 Account = new Account
35 {
36 UserId = "3132",
37 Username = "fred"
38 },
39 Email = new Email
40 {
41 Address = "test@maxmind.com",
42 Domain = "maxmind.com"
43 },
44 Billing = new Billing
45 {
46 FirstName = "First",
47 LastName = "Last",
48 Company = "Company, Inc.",
49 Address = "1 Billing Address St.",
50 Address2 = "Unit 1",
51 City = "Waltham",
52 Region = "MA",
53 Country = "US",
54 Postal = "02451",
55 PhoneNumber = "555-555-5555",
56 PhoneCountryCode = "1"
57 },
58 Shipping = new Shipping
59 {
60 FirstName = "First",
61 LastName = "Last",
62 Company = "Company Inc.",
63 Address = "1 Shipping Address St.",
64 Address2 = "Unit 1",
65 City = "Waltham",
66 Region = "MA",
67 Country = "US",
68 Postal = "02451",
69 PhoneNumber = "555-555-5555",
70 PhoneCountryCode = "1",
71 DeliverySpeed = ShippingDeliverySpeed.SameDay
72 },
73 Payment = new Payment
74 {
75 Processor = PaymentProcessor.Stripe,
76 WasAuthorized = false,
77 DeclineCode = "invalid number"
78 },
79 CreditCard = new CreditCard
80 {
81 IssuerIdNumber = "411111",
82 BankName = "Test Bank",
83 BankPhoneCountryCode = "1",
84 BankPhoneNumber = "555-555-5555",
85 AvsResult = 'Y',
86 CvvResult = 'N',
87 LastDigits = "1234",
88 Token = "123456abc1234"
89 },
90 Order = new Order
91 {
92 Amount = 323.21m,
93 Currency = "USD",
94 DiscountCode = "FIRST",
95 AffiliateId = "af12",
96 SubaffiliateId = "saf42",
97 ReferrerUri = new Uri("http://www.amazon.com/"),
98 IsGift = true,
99 HasGiftMessage = true
100 },
101 ShoppingCart = new List<ShoppingCartItem>
102 {
103 new ShoppingCartItem
104 {
105 Category = "pets",
106 ItemId = "ad23232",
107 Quantity = 2,
108 Price = 20.43m
109 },
110 new ShoppingCartItem
111 {
112 Category = "beauty",
113 ItemId = "bst112",
114 Quantity = 1,
115 Price = 100.00m
116 }
117 },
118 CustomInputs = new CustomInputs.Builder
119 {
120 { "float_input", 12.1d},
121 { "integer_input", 3123},
122 { "string_input", "This is a string input."},
123 { "boolean_input", true},
124 }.Build()
125 };
126
127 // If you are making multiple requests, a single WebServiceClient
128 // should be shared across requests to allow connection reuse. The
129 // class is thread safe.
130 //
131 // Replace "6" with your account ID and "ABCD567890" with your license
132 // key.
133 using (var client = new WebServiceClient(6, "ABCD567890"))
134 {
135 // Use `InsightsAsync` if querying Insights; `FactorsAsync` if querying Factors
136 var score = await client.ScoreAsync(transaction);
137 Console.WriteLine(score);
138 }
139 }
140}
1Transaction request = new Transaction.Builder(
2 new Device.Builder(InetAddress.getByName("1.1.1.1"))
3 .acceptLanguage("en-US")
4 .sessionAge(3600.6)
5 .sessionId("foobar")
6 .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36")
7 .build()
8 ).account(
9 new Account.Builder()
10 .userId("usr-123")
11 .username("fraudster9")
12 .build()
13 ).billing(
14 new Billing.Builder()
15 .address("1 Billing Address St.")
16 .address2("Unit 1")
17 .city("Waltham")
18 .company("Company, Inc")
19 .firstName("First")
20 .lastName("Last")
21 .phoneCountryCode("1")
22 .phoneNumber("555-555-5555")
23 .postal("02451")
24 .region("MA")
25 .build()
26 ).creditCard(
27 new CreditCard.Builder()
28 .avsResult('N')
29 .bankName("Test Bank")
30 .bankPhoneCountryCode("1")
31 .bankPhoneNumber("555-555-5555")
32 .cvvResult('Y')
33 .issuerIdNumber("411111")
34 .lastDigits("1234")
35 .token("123456abc1234")
36 .build()
37 ).email(
38 new Email.Builder()
39 .address("fraud@ster.com")
40 .domain("ster.com")
41 .build()
42 ).event(
43 new Event.Builder()
44 .shopId("2432")
45 .time(new Date())
46 .transactionId("tr1242")
47 .type(Event.Type.ACCOUNT_CREATION)
48 .build()
49 ).order(
50 new Order.Builder()
51 .affiliateId("af5")
52 .amount(new BigDecimal(Double.toString(1.1)))
53 .currency("USD")
54 .discountCode("10OFF")
55 .referrerUri(new URI("https://www.google.com/"))
56 .subaffiliateId("saf9")
57 .isGift(true)
58 .hasGiftMessage(true)
59 .build()
60 ).payment(
61 new Payment.Builder()
62 .declineCode("invalid")
63 .processor(Payment.Processor.ADYEN)
64 .wasAuthorized(false)
65 .build()
66 ).shipping(
67 new Shipping.Builder()
68 .address("1 Shipping Address St.")
69 .address2("Unit 1")
70 .city("Waltham")
71 .company("Company, Inc")
72 .firstName("First")
73 .lastName("Last")
74 .phoneCountryCode("1")
75 .phoneNumber("555-555-5555")
76 .postal("02451")
77 .region("MA")
78 .deliverySpeed(Shipping.DeliverySpeed.EXPEDITED)
79 .build()
80 ).addShoppingCartItem(
81 new ShoppingCartItem.Builder()
82 .category("TOYS")
83 .itemId("t-132")
84 .price(1.1)
85 .quantity(100)
86 .build()
87 ).addShoppingCartItem(
88 new ShoppingCartItem.Builder()
89 .category("COSMETICS")
90 .itemId("c-12312")
91 .price(3.)
92 .quantity(1)
93 .build()
94 ).customInputs(
95 new CustomInputs.Builder()
96 .put("float_input", 12.1)
97 .put("integer_input", 3123)
98 .put("string_input", "This is a string input.")
99 .put("boolean_input", true)
100 .build()
101 ).build();
102
103WebServiceClient client = new WebServiceClient.Builder(6, "ABCD567890").build();
104
105// use `client.insights` or `client.factors` for Insights and Factors respectively
106System.out.println(client.score(request));
1import { URL } from 'url'; // Used for order.referrerUri
2import * as minFraud from '@maxmind/minfraud-api-node';
3// const minFraud = require('@maxmind/minfraud-api-node');
4
5// client is reusable
6const client = new minFraud.Client('1234', 'LICENSEKEY');
7
8let transaction;
9
10try {
11 transaction = new minFraud.Transaction({
12 device: new minFraud.Device({
13 ipAddress: '1.1.1.1',
14 acceptLanguage: 'en-US,en;q=0.8',
15 sessionAge: 3600,
16 sessionId: 'a333a4e127f880d8820e56a66f40717c',
17 userAgent: 'Mozilla/5.0 (X11; Linux x86_64)',
18 }),
19 event: new minFraud.Event({
20 shopId: 'shop',
21 time: new Date(Date.now()),
22 transactionId: 'txn1234',
23 type: minFraud.Constants.EventType.PayoutChange,
24 }),
25 account: new minFraud.Account({
26 userId: 'user123',
27 username: 'userperson',
28 }),
29 email: new minFraud.Email({
30 address: 'foo@bar.com',
31 domain: 'bar.com',
32 }),
33 billing: new minFraud.Billing({
34 address: '1 Billing Address St.',
35 address2: 'Unit 1',
36 city: 'Waltham',
37 company: 'Company, Inc.',
38 country: 'US',
39 firstName: 'First',
40 lastName: 'Last',
41 phoneCountryCode: '1',
42 phoneNumber: '555-555-5555',
43 postal: '02451',
44 region: 'MA',
45 }),
46 shipping: new minFraud.Shipping({
47 address: '1 Shipping Address St.',
48 address2: 'Unit 1',
49 city: 'Waltham',
50 company: 'Company, Inc.',
51 country: 'US',
52 deliverySpeed: minFraud.Constants.DeliverySpeed.Expedited,
53 firstName: 'First',
54 lastName: 'Last',
55 phoneCountryCode: '1',
56 phoneNumber: '555-555-5555',
57 postal: '02451',
58 region: 'MA',
59 }),
60 payment: new minFraud.Payment({
61 declineCode: 'A',
62 processor: minFraud.Constants.Processor.ConceptPayments,
63 wasAuthorized: true,
64 }),
65 creditCard: new minFraud.CreditCard({
66 avsResult: 'A',
67 bankName: 'Test bank',
68 bankPhoneCountryCode: '1',
69 bankPhoneNumber: '555-555-5555',
70 cvvResult: 'B',
71 issuerIdNumber: '411111',
72 lastDigits: '1234',
73 token: 'a_token',
74 }),
75 order: new minFraud.Order({
76 affiliateId: 'robotnet',
77 amount: 22.99,
78 currency: 'USD',
79 discountCode: 'COUPONS',
80 hasGiftMessage: true,
81 isGift: true,
82 referrerUri: new URL('https://robots.com/swarms'),
83 subaffiliateId: 'swarm',
84 }),
85 shoppingCart: [
86 new minFraud.ShoppingCartItem({
87 category: 'screws',
88 itemId: 'sc123',
89 price: 9.99,
90 quantity: 100,
91 }),
92 new minFraud.ShoppingCartItem({
93 category: 'screws',
94 itemId: 'sc123',
95 price: 9.99,
96 quantity: 100,
97 }),
98 ],
99 customInputs: [
100 new minFraud.CustomInput('key', 'value'),
101 new minFraud.CustomInput('key_2', true),
102 new minFraud.CustomInput('key_3', 100),
103 ],
104 });
105} catch (error) {
106 // handle the error
107}
108
109// Use `client.insights` or `client.factors` for Insights and Factors respectively
110client.score(transaction).then((response) => {
111 console.log(response.riskScore); // 50
112 console.log(response.ipAddress.risk); // 50
113});
1<?php
2require_once 'vendor/autoload.php';
3use MaxMind\MinFraud;
4
5# The constructor for MinFraud takes your account ID, your license key, and
6# optionally an array of options.
7$mf = new MinFraud(1, 'ABCD567890');
8
9# Note that each ->with*() call returns a new immutable object. This means
10# that if you separate the calls into separate statements without chaining,
11# you should assign the return value to a variable each time.
12$request = $mf->withDevice(
13 ipAddress: '1.1.1.1',
14 sessionAge: 3600.5,
15 sessionId: 'foobar',
16 userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
17 acceptLanguage: 'en-US,en;q=0.8'
18)->withEvent(
19 transactionId: 'txn3134133',
20 shopId: 's2123',
21 time: '2012-04-12T23:20:50+00:00',
22 type: 'purchase'
23)->withAccount(
24 userId: 3132,
25 usernameMd5: '4f9726678c438914fa04bdb8c1a24088'
26)->withEmail(
27 address: 'test@maxmind.com',
28 domain: 'maxmind.com'
29)->withBilling(
30 firstName: 'First',
31 lastName: 'Last',
32 company: 'Company',
33 address: '1 Billing Address St.',
34 address2: 'Unit 1',
35 city: 'Waltham',
36 region: 'MA',
37 country: 'US',
38 postal: '02451',
39 phoneNumber: '555-555-5555',
40 phoneCountryCode: '1'
41)->withShipping(
42 firstName: 'First',
43 lastName: 'Last',
44 company: 'Company',
45 address: '1 Shipping Address St.',
46 address2: 'Unit 1',
47 city: 'Waltham',
48 region: 'MA',
49 country: 'US',
50 postal: '02451',
51 phoneNumber: '555-555-5555',
52 phoneCountryCode: '1',
53 deliverySpeed: 'same_day'
54)->withPayment(
55 processor: 'stripe',
56 wasAuthorized: false,
57 declineCode: 'invalid number'
58)->withCreditCard(
59 issuerIdNumber: '411111',
60 lastDigits: '1234',
61 bankName: 'Test Bank',
62 bankPhoneCountryCode: '1',
63 bankPhoneNumber: '555-555-5555',
64 avsResult: 'Y',
65 cvvResult: 'N',
66 token: '123456abc1234'
67)->withOrder(
68 amount: 323.21,
69 currency: 'USD',
70 discountCode: 'FIRST',
71 isGift: true,
72 hasGiftMessage: true,
73 affiliateId: 'af12',
74 subaffiliateId: 'saf42',
75 referrerUri: 'http://www.amazon.com/'
76)->withShoppingCartItem(
77 category: 'pets',
78 itemId: 'leash-0231',
79 quantity: 2,
80 price: 20.43
81)->withShoppingCartItem(
82 category: 'beauty',
83 itemId: 'msc-1232',
84 quantity: 1,
85 price: 100.00
86)->withCustomInputs([
87 'section' => 'news',
88 'previous_purchases' => 19,
89 'discount' => 3.2,
90 'previous_user' => true,
91]);
92
93# To get the minFraud Factors response model, use ->factors():
94$factorsResponse = $request->factors();
95
96foreach ($factorsResponse->riskScoreReasons as $riskScoreReason) {
97 print($riskScoreReason->multiplier . "\n");
98 foreach ($riskScoreReason->reasons as $reason) {
99 print($reason->code . ': ' . $reason->reason . "\n");
100 }
101}
102
103# To get the minFraud Insights response model, use ->insights():
104$insightsResponse = $request->insights();
105
106print($insightsResponse->riskScore . "\n");
107print($insightsResponse->creditCard->issuer->name . "\n");
108
109foreach ($insightsResponse->warnings as $warning) {
110 print($warning->warning . "\n");
111}
112
113# To get the minFraud Score response model, use ->score():
114$scoreResponse = $request->score();
115
116print($scoreResponse->riskScore . "\n");
117
118foreach ($scoreResponse->warnings as $warning) {
119 print($warning->warning . "\n");
120}
1import asyncio # Only needed for asynchronous requests
2from minfraud import AsyncClient, Client
3
4request = {
5 'device': {
6 'ip_address': '1.1.1.1',
7 'accept_language': 'en-US,en;q=0.8',
8 'session_age': 3600,
9 'session_id': 'a333a4e127f880d8820e56a66f40717c',
10 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36'
11 },
12 'event': {
13 'shop_id': 's2123',
14 'type': 'purchase',
15 'transaction_id': 'txn3134133',
16 'time': '2014-04-12T23:20:50.052+00:00'
17 },
18 'account': {
19 'user_id': '3132',
20 'username_md5': '570a90bfbf8c7eab5dc5d4e26832d5b1'
21 },
22 'email': {
23 'address': '977577b140bfb7c516e4746204fbdb01',
24 'domain': 'maxmind.com'
25 },
26 'billing': {
27 'first_name': 'First',
28 'last_name': 'Last',
29 'company': 'Company, Inc.',
30 'address': '1 Billing Address St.',
31 'address_2': 'Unit 1',
32 'city': 'Waltham',
33 'region': 'MA',
34 'country': 'US',
35 'postal': '02451',
36 'phone_country_code': '1',
37 'phone_number': '555-555-5555',
38 },
39 'shipping': {
40 'first_name': 'First',
41 'last_name': 'Last',
42 'company': 'Company, Inc.',
43 'address': '1 Shipping Address St.',
44 'address_2': 'Unit 1',
45 'city': 'Waltham',
46 'region': 'MA',
47 'country': 'US',
48 'postal': '02451',
49 'phone_country_code': '1',
50 'phone_number': '555-555-5555',
51 'delivery_speed': 'same_day',
52 },
53 'credit_card': {
54 'bank_phone_country_code': '1',
55 'avs_result': 'Y',
56 'bank_phone_number': '555-555-5555',
57 'last_digits': '1234',
58 'cvv_result': 'N',
59 'bank_name': 'Test Bank',
60 'issuer_id_number': '411111',
61 'token': '123456abc1234'
62 },
63 'payment': {
64 'decline_code': 'invalid number',
65 'was_authorized': False,
66 'processor': 'stripe'
67 },
68 'shopping_cart': [{
69 'category': 'pets',
70 'quantity': 2,
71 'price': 20.43,
72 'item_id': 'lsh12'
73 }, {
74 'category': 'beauty',
75 'quantity': 1,
76 'price': 100.0,
77 'item_id': 'ms12'
78 }],
79 'order': {
80 'affiliate_id': 'af12',
81 'referrer_uri': 'http://www.amazon.com/',
82 'subaffiliate_id': 'saf42',
83 'discount_code': 'FIRST',
84 'currency': 'USD',
85 'amount': 323.21,
86 'is_gift': True,
87 'has_gift_message': True
88 },
89 'custom_inputs': {
90 'section': 'news',
91 'num_of_previous_purchases': 19,
92 'discount': 3.2,
93 'previous_user': True
94 }
95}
96
97# This example function uses a synchronous Client object. The object
98# can be used across multiple requests.
99def sync_example(account_id, license_key):
100 with Client(account_id, license_key) as client:
101 print(client.score(request))
102 print(client.insights(request))
103 print(client.factors(request))
104
105sync_example(42, 'license_key')
106
107# This example function uses an asynchronous AsyncClient object. The
108# object can be used across multiple requests.
109async def async_example(account_id, license_key):
110 async with AsyncClient(account_id, license_key) as client:
111 print(await client.score(request))
112 print(await client.insights(request))
113 print(await client.factors(request))
114
115asyncio.run(async_example(42, 'license_key'))
1require 'minfraud'
2
3# Configure the client.
4Minfraud.configure do |c|
5 c.account_id = 10
6 c.license_key = 'LICENSEKEY'
7 c.enable_validation = true
8end
9
10# Prepare the request.
11assessment = Minfraud::Assessments.new(
12 device: {
13 ip_address: '1.1.1.1',
14 accept_language: 'en-US,en;q=0.8',
15 session_age: 3600.5,
16 session_id: 'foo',
17 user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
18 },
19 event: {
20 transaction_id: 'txn3134133',
21 shop_id: 's2123',
22 time: '2012-04-12T23:20:50+00:00',
23 type: :purchase,
24 },
25 account: {
26 user_id: '3132',
27 username_md5: '4f9726678c438914fa04bdb8c1a24088',
28 },
29 email: {
30 address: 'test@maxmind.com',
31 domain: 'maxmind.com',
32 },
33 billing: {
34 first_name: 'First',
35 last_name: 'Last',
36 company: 'Company, Inc.',
37 address: '1 Billing Address St.',
38 address_2: 'Unit 1',
39 city: 'Waltham',
40 region: 'MA',
41 country: 'US',
42 postal: '02451',
43 phone_number: '555-555-5555',
44 phone_country_code: '1',
45 },
46 shipping: {
47 first_name: 'First',
48 last_name: 'Last',
49 company: 'Company, Inc.',
50 address: '1 Shipping Address St.',
51 address_2: 'Unit 1',
52 city: 'Waltham',
53 region: 'MA',
54 country: 'US',
55 postal: '02451',
56 phone_number: '555-555-5555',
57 phone_country_code: '1',
58 delivery_speed: :same_day,
59 },
60 payment: {
61 processor: :stripe,
62 was_authorized: false,
63 decline_code: 'invalid number',
64 },
65 credit_card: {
66 issuer_id_number: '411111',
67 last_digits: '1234',
68 bank_name: 'Test Bank',
69 bank_phone_country_code: '1',
70 bank_phone_number: '555-555-5555',
71 token: 'abcd',
72 avs_result: 'Y',
73 cvv_result: 'N',
74 },
75 order: {
76 amount: 323.21,
77 currency: 'USD',
78 discount_code: 'FIRST',
79 is_gift: true,
80 has_gift_message: true,
81 affiliate_id: 'af12',
82 subaffiliate_id: 'saf42',
83 referrer_uri: 'http://www.amazon.com/',
84 },
85 shopping_cart: [
86 {
87 category: 'pets',
88 item_id: 'leash-0231',
89 quantity: 2,
90 price: 20.43,
91 },
92 {
93 category: 'beauty',
94 item_id: 'msc-1232',
95 quantity: 1,
96 price: 100.00,
97 },
98 ],
99 custom_inputs: {
100 section: 'news',
101 previous_purchases: 19,
102 discount: 3.2,
103 previous_user: true,
104 },
105)
106
107# To get the Factors response model, use #factors.
108factors_model = assessment.factors.body
109
110factors_model.warnings.each { |w| puts w.warning }
111
112factors_model.risk_score_reasons.each do |risk_score_reason|
113 p risk_score_reason.multiplier
114 risk_score_reason.reasons.each do |reason|
115 p "#{reason.code}: #{reason.reason}"
116 end
117end
118p factors_model.risk_score
119
120# To get the Insights response model, use #insights.
121insights_model = assessment.insights.body
122
123insights_model.warnings.each { |w| puts w.warning }
124
125p insights_model.credit_card.issuer.name
126p insights_model.risk_score
127
128# To get the Score response model, use #score.
129score_model = assessment.score.body
130
131score_model.warnings.each { |w| puts w.warning }
132
133p score_model.risk_score
Links to MaxMind client APIs
The following APIs are developed and maintained by MaxMind. See our guide on developing for the community if you have questions about creating or sharing your own unofficial clients or integrations.
| Language or Framework | Package Repository | Documentation | Version Control |
|---|---|---|---|
| .NET (C#) | NuGet | GitHub Pages | GitHub |
| Java | Maven Central | GitHub Pages | GitHub |
| Node.js | NPM | GitHub Pages | GitHub |
| Perl (deprecated) | metacpan | metacpan | GitHub |
| PHP | Packagist | GitHub Pages | GitHub |
| Python | PyPI | Read the Docs | GitHub |
| Ruby | RubyGems.org | RubyDoc.info | GitHub |