Coder Social home page Coder Social logo

heeby / minfraud-api-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxmind/minfraud-api-java

0.0 1.0 0.0 840 KB

Java API for minFraud Insights and Score

Home Page: http://maxmind.github.io/minfraud-api-java

License: Apache License 2.0

Shell 1.28% Java 98.72%

minfraud-api-java's Introduction

MaxMind minFraud Score, Insights, and Factors Java API

Description

This package provides an API for the MaxMind minFraud Score, Insights, and Factors web services.

Installation

We recommend installing this package with Maven. To do this, add the dependency to your pom.xml:

    <dependency>
        <groupId>com.maxmind.minfraud</groupId>
        <artifactId>minfraud</artifactId>
        <version>1.0.0</version>
    </dependency>

API Documentation

API documentation is viewable on our GitHub Page under the API tab.

Usage

To use this API, first create a new WebServiceClient object. The constructor takes your MaxMind user ID, license key, and an optional options array as arguments. For example:

WebServiceClient client = new WebServiceClient.Builder(6, "ABCD567890").build();

Then create a new Transaction object. This represents the transaction that you are sending to minFraud. The class is instantiated using an inner builder class, Transaction.Builder. Each builder method takes a corresponding request model object. Each of these objects is similarly built up with corresponding builder classes. For example:

Transaction transaction = new Transaction.Builder(
        new Device.Builder(InetAddress.getByName("1.1.1.1")).build()
    ).email(
        new Email.Builder()
            .address("[email protected]")
            .build()
    ).build();

After creating the transaction object, send a Score request by calling the score method:

ScoreResponse score = client.score(transaction);

an Insights request by calling insights method:

InsightsResponse insights = client.insights(transaction);

an Factors request by calling factors method:

FactorsResponse factors = client.factors(transaction);

If the request succeeds, a model object will be returned for the endpoint. If the request fails, an exception will be thrown.

See the API documentation for more details.

Exceptions

Runtime exceptions:

  • IllegalArgumentException - This will be thrown when an illegal argument is passed to a builder method. For instance, a country code that is not two capital letters.

Checked exceptions:

  • AuthenticationException - This will be thrown when the server is unable to authenticate the request, e.g., if the license key or user ID is invalid.
  • InsufficientFundsException - This will be thrown when your account is out of funds.
  • InvalidRequestException - This will be thrown when the server rejects the request for another reason such as invalid JSON in the POST.
  • PermissionRequiredException - This will be thrown when permission is required to use the service.
  • MinFraudException - This will be thrown when the server returns an unexpected response. This also serves as the base class for the above checked exceptions.
  • HttpException -This will be thrown when an unexpected HTTP error occurs such as an internal server error or other unexpected status code.

Example

Transaction request = new Transaction.Builder(
        new Device.Builder(InetAddress.getByName("1.1.1.1"))
            .acceptLanguage("en-US")
            .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36")
            .build()
    ).account(
        new Account.Builder()
            .userId("usr-123")
            .username("fraudster9")
            .build()
    ).billing(
        new Billing.Builder()
            .address("11 Wall St.")
            .address2("Apt 1")
            .city("New Haven")
            .company("Company, Inc")
            .firstName("Mike")
            .lastName("Smith")
            .phoneCountryCode("1")
            .phoneNumber("321-321-3211")
            .postal("06510")
            .region("CT")
            .build()
    ).creditCard(
        new CreditCard.Builder()
            .avsResult('N')
            .bankName("BanK of New Haven")
            .bankPhoneCountryCode("1")
            .bankPhoneNumber("313-231-3213")
            .cvvResult('Y')
            .issuerIdNumber("213312")
            .last4Digits("3211")
            .build()
    ).email(
        new Email.Builder()
            .address("[email protected]")
            .domain("ster.com")
            .build()
    ).event(
        new Event.Builder()
            .shopId("2432")
            .time(new Date())
            .transactionId("tr1242")
            .type(Event.Type.ACCOUNT_CREATION)
            .build()
    ).order(
        new Order.Builder()
            .affiliateId("af5")
            .amount(new BigDecimal(Double.toString(1.1)))
            .currency("USD")
            .discountCode("10OFF")
            .referrerUri("http://www.google.com/")
            .subaffiliateId("saf9")
            .build()
    ).payment(
        new Payment.Builder()
            .declineCode("invalid")
            .processor(Payment.Processor.ADYEN)
            .wasAuthorized(false)
            .build()
    ).shipping(
        new Shipping.Builder()
            .region("MN")
            .postal("55455")
            .phoneNumber("313-545-3113")
            .phoneCountryCode("1")
            .deliverySpeed(Shipping.DeliverySpeed.EXPEDITED)
            .address("32 Washington Ave.")
            .address2("18")
            .city("Minneapolis")
            .company("MinnCo")
            .firstName("John")
            .lastName("Doe")
            .build()
    ).addShoppingCartItem(
        new ShoppingCartItem.Builder()
            .category("TOYS")
            .itemId("t-132")
            .price(1.1)
            .quantity(100)
            .build()
    ).addShoppingCartItem(
        new ShoppingCartItem.Builder()
            .category("COSMETICS")
            .itemId("c-12312")
            .price(3.)
            .quantity(1)
            .build()
    ).build();

WebServiceClient client = new WebServiceClient.Builder(6, "ABCD567890").build();


System.out.println(client.insights(request));

Support

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.

Requirements

This code requires Java 7.

Contributing

Patches and pull requests are encouraged. Please include unit tests whenever possible.

Versioning

This API uses Semantic Versioning.

Copyright and License

This software is Copyright (c) 2015-2016 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0.

minfraud-api-java's People

Contributors

oschwald avatar autarch avatar andyjack avatar rafl avatar mateu avatar eilara avatar 2shortplanks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.