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.
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.
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# If you want to use synchronous requests2client=Client(10,'LICENSEKEY');34# Or if you want to use asynchronous requests5async_client=AsyncClient(10,'LICENSEKEY');
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:
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.
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).
1<?php 2require_once'vendor/autoload.php'; 3useMaxMind\MinFraud; 4 5# The constructor for MinFraud takes your account ID, your license key, and
6# optionally an array of options.
7$mf=newMinFraud(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();100101print($insightsResponse->riskScore."\n");102print($insightsResponse->creditCard->issuer->name."\n");103104foreach($insightsResponse->warningsas$warning){105print($warning->warning."\n");106}107108# To get the minFraud Score response model, use ->score():
109$scoreResponse=$request->score();110111print($scoreResponse->riskScore."\n");112113foreach($scoreResponse->warningsas$warning){114print($warning->warning."\n");115}
1importasyncio# Only import asyncio if you are playing to do an asynchronous request 2fromminfraudimportAsyncClient,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. 96defclient(account_id,license_key): 97withClient(account_id,license_key)asclient: 98print(client.score(request)) 99print(client.insights(request))100print(client.factors(request))101102client(42,'license_key')103104# This example function uses an asynchronous AsyncClient object. The105# object can be used across multiple requests.106asyncdefasync_client(account_id,license_key):107withClient(account_id,license_key)asclient:108print(client.score(request))109print(client.insights(request))110print(client.factors(request))111112asyncio.run(async_client(42,'license_key'))
1# Prepare the request. 2assessment=Minfraud::Assessments.new( 3device:{ 4ip_address:'1.1.1.1', 5accept_language:'en-US,en;q=0.8', 6session_age:3600.5, 7session_id:'foo', 8user_agent:'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36', 9}, 10event:{ 11transaction_id:'txn3134133', 12shop_id:'s2123', 13time:'2012-04-12T23:20:50+00:00', 14type::purchase, 15}, 16account:{ 17user_id:'3132', 18username_md5:'4f9726678c438914fa04bdb8c1a24088', 19}, 20email:{ 21address:'test@maxmind.com', 22domain:'maxmind.com', 23}, 24billing:{ 25first_name:'First', 26last_name:'Last', 27company:'Company, Inc.', 28address:'1 Billing Address St.', 29address_2:'Unit 1', 30city:'Waltham', 31region:'MA', 32country:'US', 33postal:'02451', 34phone_number:'555-555-5555', 35phone_country_code:'1', 36}, 37shipping:{ 38first_name:'First', 39last_name:'Last', 40company:'Company, Inc.', 41address:'1 Shipping Address St.', 42address_2:'Unit 1', 43city:'Waltham', 44region:'MA', 45country:'US', 46postal:'02451', 47phone_number:'555-555-5555', 48phone_country_code:'1', 49delivery_speed::same_day, 50}, 51payment:{ 52processor::stripe, 53was_authorized:false, 54decline_code:'invalid number', 55}, 56credit_card:{ 57issuer_id_number:'411111', 58last_digits:'1234', 59bank_name:'Test Bank', 60bank_phone_country_code:'1', 61bank_phone_number:'555-555-5555', 62token:'abcd', 63avs_result:'Y', 64cvv_result:'N', 65}, 66order:{ 67amount:323.21, 68currency:'USD', 69discount_code:'FIRST', 70is_gift:true, 71has_gift_message:false, 72affiliate_id:'af12', 73subaffiliate_id:'saf42', 74referrer_uri:'http://www.amazon.com/', 75}, 76shopping_cart:[ 77{ 78category:'pets', 79item_id:'leash-0231', 80quantity:2, 81price:20.43, 82}, 83{ 84category:'beauty', 85item_id:'msc-1232', 86quantity:1, 87price:100.00, 88}, 89], 90custom_inputs:{ 91section:'news', 92previous_purchases:19, 93discount:3.2, 94previous_user:true, 95}, 96) 97 98# To get the Factors response model, use #factors. 99factors_model=assessment.factors.body100101factors_model.warnings.each{|w|putsw.warning}102103pfactors_model.subscores.email_address104pfactors_model.risk_score105106# To get the Insights response model, use #insights.107insights_model=assessment.insights.body108109insights_model.warnings.each{|w|putsw.warning}110111pinsights_model.credit_card.issuer.name112pinsights_model.risk_score113114# To get the Score response model, use #score.115score_model=assessment.score.body116117score_model.warnings.each{|w|putsw.warning}118119pscore_model.risk_score
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.