Node.js API for MaxMind minFraud Score, Insights, and Factors
This package provides an API for the MaxMind minFraud Score, Insights, and Factors web services.
MaxMind has tested this API with Node.js versions 8 and 10. We aim to support active LTS versions of Node.js, as well as the latest stable release.
yarn add @maxmind/minfraud-api-node
If you are not able to use
yarn, you may also use
npm install @maxmind/minfraud-api-node
Documentation for this API can be found here
To use this API, first create a new
Client object. The constructor
takes your MaxMind account ID and license key. For example:
const client = "1234" "LICENSEKEY";
Then create a new
Transaction object. This represents the transaction that
you are sending to minFraud. Each transaction property is instantiated by creating
a new instance of each property's class. For example:
const transaction =device:ipAddress: '184.108.40.206'email:address: 'firstname.lastname@example.org'domain: 'bar.com'
If Transaction instantiation fails, an
ArgumentError is thrown. This is usually
due to invalid property values, a missing Device object, or a Device object
with either an invalid or missing IP Address.
After creating the Transaction object, you can send a Score, Insights, or Factors request, which returns a Promise that contains the corresponding model:
// minFraud Scoreclient;// minFraud Insightsclient;// minFraud Factorsclient;
If the request fails, an error object will be returned in the catch in the form of:
code: stringerror: string
Errors and Exceptions
Thrown by the request and transaction models:
ArgumentError- Thrown when invalid data is passed to the Transaction and Transaction property constructors.
In addition to the response errors returned by the web API, we also return:
code: 'SERVER_ERROR'error: <string>code: 'HTTP_STATUS_CODE_ERROR'error: <string>code: 'INVALID_RESPONSE_BODY'error: <string>
; // Used for `order.referrerUri;// const minFraud = require('@maxmind/minfraud-api-node');// client is reusableconst client = "1234" "LICENSEKEY";let transaction;trytransaction =// device is requireddevice:ipAddress: "220.127.116.11"event:shopId: 'shop'time: DatetransactionId: 'txn1234'type: minFraudConstantsEventTypePayoutChangeaccount:userId: 'user123'username: 'userperson'email:address: 'email@example.com'domain: 'bar.com'billing:address: '123 Robot Ave.'address2: 'Suite 10011'city: 'Waltham'company: 'Robots Inc.'country: 'US'firstName: 'Robot'lastName: 'Bar'phoneCountryCode: '1'phoneNumber: '321-321-3211'postal: '12345'region: 'MA'shipping:address: '123 Robot Ave.'address2: 'Suite 10011'city: 'Waltham'company: 'Robots Inc.'country: 'US'deliverySpeed: minFraudConstantsDeliverySpeedExpeditedfirstName: 'Robot'lastName: 'Bar'phoneCountryCode: '1'phoneNumber: '321-321-3211'postal: '12345'region: 'MA'payment:declineCode: 'A'processor: minFraudConstantsProcessorConceptPaymentswasAuthorized: truecreditCard:avsResult: 'A'bankName: 'Foo Bank'bankPhoneCountryCode: '1'bankPhoneNumber: '123-123-1234'cvvResult: 'B'issuerIdNumber: '123456'last4digits: '1234'token: 'a_token'order:affiliateId: 'robotnet'amount: 2299currency: 'USD'discountCode: 'COUPONS'hasGiftMessage: trueisGift: truereferrerUri: ''subaffiliateId: 'swarm'shoppingCart:category: 'screws'itemId: 'sc123'price: 999quantity: 100category: 'screws'itemId: 'sc123'price: 999quantity: 100customInputs:'key' 'value''key_2' true'key_3' 100catcherror// handle the errorclient;
Please report all issues with this code using the GitHub issue tracker.
If you are having an issue with the minFraud service that is not specific to the client API, please see our support page.
Patches and pull requests are encouraged. Please include unit tests whenever possible.
This API uses Semantic Versioning.
Copyright and License
This software is Copyright (c) 2019 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0.