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>1.15.0</version>
6</dependency>
7
8// Or install via Gradle
9repositories {
10 mavenCentral()
11}
12dependencies {
13 compile 'com.maxmind.minfraud:minfraud:1.15.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:~1.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:
1var client = new WebServiceClient(10, "LICENSEKEY");
1WebServiceClient client = new WebServiceClient.Builder(10, "LICENSEKEY").build();
1const client = new minFraud.Client('10', 'LICENSEKEY');
1$client = new MinFraud(10, 'LICENSEKEY');
1# If you want to use synchronous requests
2client = Client(10, 'LICENSEKEY');
3
4# Or if you want to use asynchronous requests
5async_client = AsyncClient(10, 'LICENSEKEY');
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 device: new Device(System.Net.IPAddress.Parse("1.1.1.1")),
3 email:
4 new Email(
5 address: "test@maxmind.com",
6 domain: "maxmind.com"
7 ),
8 billing:
9 new Billing(
10 address: "1 Billing Address St.",
11 firstName: "First",
12 lastName: "Last",
13 company: "Company, Inc.",
14 address2: "Unit 1",
15 city: "Waltham",
16 region: "MA",
17 country: "US",
18 postal: "02451",
19 phoneNumber: "555-555-5555",
20 phoneCountryCode: "1"
21 ),
22 creditCard:
23 new CreditCard(
24 issuerIdNumber: "411111",
25 ),
26 shipping:
27 new Shipping(
28 firstName: "First",
29 lastName: "Last",
30 company: "Company Inc.",
31 address: "1 Shipping Address St.",
32 address2: "Unit 1",
33 city: "Waltham",
34 region: "MA",
35 country: "US",
36 postal: "02451",
37 phoneNumber: "555-555-5555",
38 phoneCountryCode: "1",
39 )
40);
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();
1let transaction;
2
3try {
4 transaction = new minFraud.Transaction({
5 device: new minFraud.Device({
6 ipAddress: "1.1.1.1",
7 }),
8 billing: new minFraud.Billing({
9 address: '1 Billing Address St.',
10 address2: 'Unit 1',
11 city: 'Waltham',
12 company: 'Company, Inc.',
13 country: 'US',
14 firstName: 'First',
15 lastName: 'Last',
16 phoneCountryCode: '1',
17 phoneNumber: '555-555-5555',
18 postal: '02451',
19 region: 'MA',
20 }),
21 creditCard: new minFraud.CreditCard({
22 issuerIdNumber: '411111',
23 }),
24 email: new minFraud.Email({
25 address: 'test@maxmind.com',
26 domain: 'maxmind.com',
27 }),
28 shipping: new minFraud.Shipping({
29 address: '1 Shipping Address St.',
30 address2: 'Unit 1',
31 city: 'Waltham',
32 company: 'Company, Inc.',
33 country: 'US',
34 firstName: 'First',
35 lastName: 'Last',
36 phoneCountryCode: '1',
37 phoneNumber: '555-555-5555',
38 postal: '02451',
39 region: 'MA',
40 }),
41 })
42} catch(error) {
43 // handle the error
44}
1$request = $client->withDevice([
2 'ip_address' => '1.1.1.1',
3])->withBilling([
4 'first_name' => 'First',
5 'last_name' => 'Last',
6 'company' => 'Company',
7 'address' => '1 Billing Address St.',
8 'address_2' => 'Unit 1',
9 'city' => 'Waltham',
10 'region' => 'MA',
11 'country' => 'US',
12 'postal' => '02451',
13 'phone_number' => '555-555-5555',
14 'phone_country_code' => '1',
15])->withCreditCard([
16 'issuer_id_number' => '411111',
17])->withEmail([
18 'address' => 'test@maxmind.com',
19 'domain' => 'maxmind.com',
20])->withShipping([
21 'first_name' => 'First',
22 'last_name' => 'Last',
23 'company' => 'Company',
24 'address' => '1 Shipping Address St.',
25 'address_2' => 'Unit 1',
26 'city' => 'Waltham',
27 'region' => 'MA',
28 'country' => 'US',
29 'postal' => '02451',
30 'phone_number' => '555-555-5555',
31 'phone_country_code' => '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 - Aynchronous
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 libaries 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 libraires 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.Threading.Tasks;
6
7public class MinFraudExample
8{
9 static void Main()
10 {
11 MinFraudAsync().Wait();
12 }
13
14 static public async Task MinFraudAsync()
15 {
16 var transaction = new Transaction(
17 device: new Device(System.Net.IPAddress.Parse("1.1.1.1"),
18 userAgent:
19 "Mozilla/5.0 (X11; Linux x86_64)",
20 acceptLanguage: "en-US,en;q=0.8",
21 sessionAge: 3600,
22 sessionId: "a333a4e127f880d8820e56a66f40717c"
23 ),
24 userEvent:
25 new Event
26 (
27 transactionId: "txn3134133",
28 shopId: "s2123",
29 time: new DateTimeOffset(2014, 4, 12, 23, 20, 50, 52, new TimeSpan(0)),
30 type: EventType.Purchase
31 ),
32 account:
33 new Account(
34 userId: "3132",
35 username: "fred"
36 ),
37 email:
38 new Email(
39 address: "test@maxmind.com",
40 domain: "maxmind.com"
41 ),
42 billing:
43 new Billing(
44 address: "1 Billing Address St.",
45 firstName: "First",
46 lastName: "Last",
47 company: "Company, Inc.",
48 address2: "Unit 1",
49 city: "Waltham",
50 region: "MA",
51 country: "US",
52 postal: "02451",
53 phoneNumber: "555-555-5555",
54 phoneCountryCode: "1"
55 ),
56 shipping:
57 new Shipping(
58 firstName: "First",
59 lastName: "Last",
60 company: "Company Inc.",
61 address: "1 Shipping Address St.",
62 address2: "Unit 1",
63 city: "Waltham",
64 region: "MA",
65 country: "US",
66 postal: "02451",
67 phoneNumber: "555-555-5555",
68 phoneCountryCode: "1",
69 deliverySpeed: ShippingDeliverySpeed.SameDay
70 ),
71 payment:
72 new Payment(
73 processor: PaymentProcessor.Stripe,
74 wasAuthorized: false,
75 declineCode: "invalid number"
76 ),
77 creditCard:
78 new CreditCard(
79 issuerIdNumber: "411111",
80 bankName: "Test Bank",
81 bankPhoneCountryCode: "1",
82 bankPhoneNumber: "555-555-5555",
83 avsResult: 'Y',
84 cvvResult: 'N',
85 last4Digits: "1234"
86 ),
87 order:
88 new Order(
89 amount: 323.21m,
90 currency: "USD",
91 discountCode: "FIRST",
92 affiliateId: "af12",
93 subaffiliateId: "saf42",
94 referrerUri: new Uri("http://www.amazon.com/")
95 ),
96 shoppingCart: new List<ShoppingCartItem>
97 {
98 new ShoppingCartItem(
99 category: "pets",
100 itemId: "ad23232",
101 quantity: 2,
102 price: 20.43m
103 ),
104 new ShoppingCartItem(
105 category: "beauty",
106 itemId: "bst112",
107 quantity: 1,
108 price: 100.00m
109 )
110 },
111 customInputs: new CustomInputs.Builder
112 {
113 { "float_input", 12.1d},
114 { "integer_input", 3123},
115 { "string_input", "This is a string input."},
116 { "boolean_input", true},
117 }.Build()
118 );
119
120 // If you are making multiple requests, a single WebServiceClient
121 // should be shared across requests to allow connection reuse. The
122 // class is thread safe.
123 //
124 // Replace "6" with your account ID and "ABCD567890" with your license
125 // key.
126 using (var client = new WebServiceClient(6, "ABCD567890"))
127 {
128 // Use `InsightsAsync` if querying Insights; `FactorsAsync` if querying Factors
129 var score = await client.ScoreAsync(transaction);
130 Console.WriteLine(score);
131 }
132 }
133}
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 .last4Digits("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 last4digits: '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 'ip_address' => '1.1.1.1',
14 'session_age' => 3600.5,
15 'session_id' => 'foobar',
16 'user_agent' =>
17 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
18 'accept_language' => 'en-US,en;q=0.8',
19])->withEvent([
20 'transaction_id' => 'txn3134133',
21 'shop_id' => 's2123',
22 'time' => '2012-04-12T23:20:50+00:00',
23 'type' => 'purchase',
24])->withAccount([
25 'user_id' => 3132,
26 'username_md5' => '4f9726678c438914fa04bdb8c1a24088',
27])->withEmail([
28 'address' => 'test@maxmind.com',
29 'domain' => 'maxmind.com',
30])->withBilling([
31 'first_name' => 'First',
32 'last_name' => 'Last',
33 'company' => 'Company',
34 'address' => '1 Billing Address St.',
35 'address_2' => 'Unit 1',
36 'city' => 'Waltham',
37 'region' => 'MA',
38 'country' => 'US',
39 'postal' => '02451',
40 'phone_number' => '555-555-5555',
41 'phone_country_code' => '1',
42])->withShipping([
43 'first_name' => 'First',
44 'last_name' => 'Last',
45 'company' => 'Company',
46 'address' => '1 Shipping Address St.',
47 'address_2' => 'Unit 1',
48 'city' => 'Waltham',
49 'region' => 'MA',
50 'country' => 'US',
51 'postal' => '02451',
52 'phone_number' => '555-555-5555',
53 'phone_country_code' => '1',
54 'delivery_speed' => 'same_day',
55])->withPayment([
56 'processor' => 'stripe',
57 'was_authorized' => false,
58 'decline_code' => 'invalid number',
59])->withCreditCard([
60 'issuer_id_number' => '411111',
61 'last_digits' => '1234',
62 'bank_name' => 'Test Bank',
63 'bank_phone_country_code' => '1',
64 'bank_phone_number' => '555-555-5555',
65 'avs_result' => 'Y',
66 'cvv_result' => 'N',
67])->withOrder([
68 'amount' => 323.21,
69 'currency' => 'USD',
70 'discount_code' => 'FIRST',
71 'is_gift' => true,
72 'has_gift_message' => false,
73 'affiliate_id' => 'af12',
74 'subaffiliate_id' => 'saf42',
75 'referrer_uri' => 'http://www.amazon.com/',
76])->withShoppingCartItem([
77 'category' => 'pets',
78 'item_id' => 'leash-0231',
79 'quantity' => 2,
80 'price' => 20.43,
81])->withShoppingCartItem([
82 'category' => 'beauty',
83 'item_id' => '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
96print($factorsResponse->subscores->email . "\n");
97
98# To get the minFraud Insights response model, use ->insights():
99$insightsResponse = $request->insights();
100
101print($insightsResponse->riskScore . "\n");
102print($insightsResponse->creditCard->issuer->name . "\n");
103
104foreach ($insightsResponse->warnings as $warning) {
105 print($warning->warning . "\n");
106}
107
108# To get the minFraud Score response model, use ->score():
109$scoreResponse = $request->score();
110
111print($scoreResponse->riskScore . "\n");
112
113foreach ($scoreResponse->warnings as $warning) {
114 print($warning->warning . "\n");
115}
1 import asyncio # Only import asyncio if you are playing to do an asynchronous request
2 from minfraud import AsyncClient, Client
3
4 request = {
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.
96 def client(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
102 client(42, 'license_key')
103
104 # This example function uses an asynchronous AsyncClient object. The
105 # object can be used across multiple requests.
106 async def async_client(account_id, license_key):
107 with Client(account_id, license_key) as client:
108 print(client.score(request))
109 print(client.insights(request))
110 print(client.factors(request))
111
112 asyncio.run(async_client(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
103p factors_model.subscores.email_address
104p factors_model.risk_score
105
106# To get the Insights response model, use #insights.
107insights_model = assessment.insights.body
108
109insights_model.warnings.each { |w| puts w.warning }
110
111p insights_model.credit_card.issuer.name
112p insights_model.risk_score
113
114# To get the Score response model, use #score.
115score_model = assessment.score.body
116
117score_model.warnings.each { |w| puts w.warning }
118
119p 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 |