Evaluate a Transaction
Evaluating a transaction consists of setting up device tracking on your website, 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 website
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 browsing your website.
Note that, in order to be effective, the Device Tracking Add-on must, at a minimum, be included on the page where the IP address is captured for a minFraud query.
Place the following code in the footer of the HTML webpage and replace
INSERT_MAXMIND_ACCOUNT_ID_HERE with your
MaxMind account ID:
1<script>
2 (function () {
3 var mmapiws = (window.__mmapiws = window.__mmapiws || {});
4 mmapiws.accountId = 'INSERT_MAXMIND_ACCOUNT_ID_HERE';
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>
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.0.0</version>
6</dependency>
7
8// Or install via Gradle
9repositories {
10 mavenCentral()
11}
12dependencies {
13 implementation 'com.maxmind.minfraud:minfraud:4.0.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'
4end
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 },
89 Order = new Order
90 {
91 Amount = 323.21m,
92 Currency = "USD",
93 DiscountCode = "FIRST",
94 AffiliateId = "af12",
95 SubaffiliateId = "saf42",
96 ReferrerUri = new Uri("http://www.amazon.com/")
97 },
98 ShoppingCart = new List<ShoppingCartItem>
99 {
100 new ShoppingCartItem
101 {
102 Category = "pets",
103 ItemId = "ad23232",
104 Quantity = 2,
105 Price = 20.43m
106 },
107 new ShoppingCartItem
108 {
109 Category = "beauty",
110 ItemId = "bst112",
111 Quantity = 1,
112 Price = 100.00m
113 }
114 },
115 CustomInputs = new CustomInputs.Builder
116 {
117 { "float_input", 12.1d},
118 { "integer_input", 3123},
119 { "string_input", "This is a string input."},
120 { "boolean_input", true},
121 }.Build()
122 };
123
124 // If you are making multiple requests, a single WebServiceClient
125 // should be shared across requests to allow connection reuse. The
126 // class is thread safe.
127 //
128 // Replace "6" with your account ID and "ABCD567890" with your license
129 // key.
130 using (var client = new WebServiceClient(6, "ABCD567890"))
131 {
132 // Use `InsightsAsync` if querying Insights; `FactorsAsync` if querying Factors
133 var score = await client.ScoreAsync(transaction);
134 Console.WriteLine(score);
135 }
136 }
137}
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 .build()
36 ).email(
37 new Email.Builder()
38 .address("fraud@ster.com")
39 .domain("ster.com")
40 .build()
41 ).event(
42 new Event.Builder()
43 .shopId("2432")
44 .time(new Date())
45 .transactionId("tr1242")
46 .type(Event.Type.ACCOUNT_CREATION)
47 .build()
48 ).order(
49 new Order.Builder()
50 .affiliateId("af5")
51 .amount(new BigDecimal(Double.toString(1.1)))
52 .currency("USD")
53 .discountCode("10OFF")
54 .referrerUri(new URI("https://www.google.com/"))
55 .subaffiliateId("saf9")
56 .build()
57 ).payment(
58 new Payment.Builder()
59 .declineCode("invalid")
60 .processor(Payment.Processor.ADYEN)
61 .wasAuthorized(false)
62 .build()
63 ).shipping(
64 new Shipping.Builder()
65 .address("1 Shipping Address St.")
66 .address2("Unit 1")
67 .city("Waltham")
68 .company("Company, Inc")
69 .firstName("First")
70 .lastName("Last")
71 .phoneCountryCode("1")
72 .phoneNumber("555-555-5555")
73 .postal("02451")
74 .region("MA")
75 .deliverySpeed(Shipping.DeliverySpeed.EXPEDITED)
76 .build()
77 ).addShoppingCartItem(
78 new ShoppingCartItem.Builder()
79 .category("TOYS")
80 .itemId("t-132")
81 .price(1.1)
82 .quantity(100)
83 .build()
84 ).addShoppingCartItem(
85 new ShoppingCartItem.Builder()
86 .category("COSMETICS")
87 .itemId("c-12312")
88 .price(3.)
89 .quantity(1)
90 .build()
91 ).customInputs(
92 new CustomInputs.Builder()
93 .put("float_input", 12.1)
94 .put("integer_input", 3123)
95 .put("string_input", "This is a string input.")
96 .put("boolean_input", true)
97 .build()
98 ).build();
99
100WebServiceClient client = new WebServiceClient.Builder(6, "ABCD567890").build();
101
102// use `client.insights` or `client.factors` for Insights and Factors respectively
103System.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 is required
13 device: new minFraud.Device({
14 ipAddress: '1.1.1.1',
15 acceptLanguage: 'en-US,en;q=0.8',
16 sessionAge: 3600,
17 sessionId: 'a333a4e127f880d8820e56a66f40717c',
18 userAgent: 'Mozilla/5.0 (X11; Linux x86_64)',
19 }),
20 event: new minFraud.Event({
21 shopId: 'shop',
22 time: new Date(Date.now()),
23 transactionId: 'txn1234',
24 type: minFraud.Constants.EventType.PayoutChange,
25 }),
26 account: new minFraud.Account({
27 userId: 'user123',
28 username: 'userperson',
29 }),
30 email: new minFraud.Email({
31 address: 'foo@bar.com',
32 domain: 'bar.com',
33 }),
34 billing: new minFraud.Billing({
35 address: '1 Billing Address St.',
36 address2: 'Unit 1',
37 city: 'Waltham',
38 company: 'Company, Inc.',
39 country: 'US',
40 firstName: 'First',
41 lastName: 'Last',
42 phoneCountryCode: '1',
43 phoneNumber: '555-555-5555',
44 postal: '02451',
45 region: 'MA',
46 }),
47 shipping: new minFraud.Shipping({
48 address: '1 Shipping Address St.',
49 address2: 'Unit 1',
50 city: 'Waltham',
51 company: 'Company, Inc.',
52 country: 'US',
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)->withOrder(
67 amount: 323.21,
68 currency: 'USD',
69 discountCode: 'FIRST',
70 isGift: true,
71 hasGiftMessage: false,
72 affiliateId: 'af12',
73 subaffiliateId: 'saf42',
74 referrerUri: 'http://www.amazon.com/'
75)->withShoppingCartItem(
76 category: 'pets',
77 itemId: 'leash-0231',
78 quantity: 2,
79 price: 20.43
80)->withShoppingCartItem(
81 category: 'beauty',
82 itemId: 'msc-1232',
83 quantity: 1,
84 price: 100.00
85)->withCustomInputs([
86 'section' => 'news',
87 'previous_purchases' => 19,
88 'discount' => 3.2,
89 'previous_user' => true,
90]);
91
92# To get the minFraud Factors response model, use ->factors():
93$factorsResponse = $request->factors();
94
95foreach ($factorsResponse->riskScoreReasons as $riskScoreReason) {
96 print($riskScoreReason->multiplier . "\n");
97 foreach ($riskScoreReason->reasons as $reason) {
98 print($reason->code . ': ' . $reason->reason . "\n");
99 }
100}
101
102# To get the minFraud Insights response model, use ->insights():
103$insightsResponse = $request->insights();
104
105print($insightsResponse->riskScore . "\n");
106print($insightsResponse->creditCard->issuer->name . "\n");
107
108foreach ($insightsResponse->warnings as $warning) {
109 print($warning->warning . "\n");
110}
111
112# To get the minFraud Score response model, use ->score():
113$scoreResponse = $request->score();
114
115print($scoreResponse->riskScore . "\n");
116
117foreach ($scoreResponse->warnings as $warning) {
118 print($warning->warning . "\n");
119}
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 },
62 'payment': {
63 'decline_code': 'invalid number',
64 'was_authorized': False,
65 'processor': 'stripe'
66 },
67 'shopping_cart': [{
68 'category': 'pets',
69 'quantity': 2,
70 'price': 20.43,
71 'item_id': 'lsh12'
72 }, {
73 'category': 'beauty',
74 'quantity': 1,
75 'price': 100.0,
76 'item_id': 'ms12'
77 }],
78 'order': {
79 'affiliate_id': 'af12',
80 'referrer_uri': 'http://www.amazon.com/',
81 'subaffiliate_id': 'saf42',
82 'discount_code': 'FIRST',
83 'currency': 'USD',
84 'amount': 323.21
85 },
86 'custom_inputs': {
87 'section': 'news',
88 'num_of_previous_purchases': 19,
89 'discount': 3.2,
90 'previous_user': True
91 }
92}
93
94# This example function uses a synchronous Client object. The object
95# can be used across multiple requests.
96def sync_example(account_id, license_key):
97 with Client(account_id, license_key) as client:
98 print(client.score(request))
99 print(client.insights(request))
100 print(client.factors(request))
101
102sync_example(42, 'license_key')
103
104# This example function uses an asynchronous AsyncClient object. The
105# object can be used across multiple requests.
106async def async_example(account_id, license_key):
107 async with AsyncClient(account_id, license_key) as client:
108 print(await client.score(request))
109 print(await client.insights(request))
110 print(await client.factors(request))
111
112asyncio.run(async_example(42, 'license_key'))
1# Prepare the request.
2assessment = Minfraud::Assessments.new(
3 device: {
4 ip_address: '1.1.1.1',
5 accept_language: 'en-US,en;q=0.8',
6 session_age: 3600.5,
7 session_id: 'foo',
8 user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
9 },
10 event: {
11 transaction_id: 'txn3134133',
12 shop_id: 's2123',
13 time: '2012-04-12T23:20:50+00:00',
14 type: :purchase,
15 },
16 account: {
17 user_id: '3132',
18 username_md5: '4f9726678c438914fa04bdb8c1a24088',
19 },
20 email: {
21 address: 'test@maxmind.com',
22 domain: 'maxmind.com',
23 },
24 billing: {
25 first_name: 'First',
26 last_name: 'Last',
27 company: 'Company, Inc.',
28 address: '1 Billing Address St.',
29 address_2: 'Unit 1',
30 city: 'Waltham',
31 region: 'MA',
32 country: 'US',
33 postal: '02451',
34 phone_number: '555-555-5555',
35 phone_country_code: '1',
36 },
37 shipping: {
38 first_name: 'First',
39 last_name: 'Last',
40 company: 'Company, Inc.',
41 address: '1 Shipping Address St.',
42 address_2: 'Unit 1',
43 city: 'Waltham',
44 region: 'MA',
45 country: 'US',
46 postal: '02451',
47 phone_number: '555-555-5555',
48 phone_country_code: '1',
49 delivery_speed: :same_day,
50 },
51 payment: {
52 processor: :stripe,
53 was_authorized: false,
54 decline_code: 'invalid number',
55 },
56 credit_card: {
57 issuer_id_number: '411111',
58 last_digits: '1234',
59 bank_name: 'Test Bank',
60 bank_phone_country_code: '1',
61 bank_phone_number: '555-555-5555',
62 token: 'abcd',
63 avs_result: 'Y',
64 cvv_result: 'N',
65 },
66 order: {
67 amount: 323.21,
68 currency: 'USD',
69 discount_code: 'FIRST',
70 is_gift: true,
71 has_gift_message: false,
72 affiliate_id: 'af12',
73 subaffiliate_id: 'saf42',
74 referrer_uri: 'http://www.amazon.com/',
75 },
76 shopping_cart: [
77 {
78 category: 'pets',
79 item_id: 'leash-0231',
80 quantity: 2,
81 price: 20.43,
82 },
83 {
84 category: 'beauty',
85 item_id: 'msc-1232',
86 quantity: 1,
87 price: 100.00,
88 },
89 ],
90 custom_inputs: {
91 section: 'news',
92 previous_purchases: 19,
93 discount: 3.2,
94 previous_user: true,
95 },
96)
97
98# To get the Factors response model, use #factors.
99factors_model = assessment.factors.body
100
101factors_model.warnings.each { |w| puts w.warning }
102
103factors_model.risk_score_reasons.each do |risk_score_reason|
104 p risk_score_reason.multiplier
105 risk_score_reason.reasons.each do |reason|
106 p "#{reason.code}: #{reason.reason}"
107 end
108end
109p factors_model.risk_score
110
111# To get the Insights response model, use #insights.
112insights_model = assessment.insights.body
113
114insights_model.warnings.each { |w| puts w.warning }
115
116p insights_model.credit_card.issuer.name
117p insights_model.risk_score
118
119# To get the Score response model, use #score.
120score_model = assessment.score.body
121
122score_model.warnings.each { |w| puts w.warning }
123
124p 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 |