Sha256: 9aec3bf0d64ca1eaaaf23aa8595f5fadd34a7a7badaa8f44b98991df0d4cd6c8

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Minfraud
  # Report is used to perform minFraud Report Transaction API requests.
  #
  # @see https://dev.maxmind.com/minfraud/report-a-transaction?lang=en
  class Report
    # The Report::Transaction component.
    #
    # @return [Minfraud::Components::Report::Transaction, nil]
    attr_accessor :transaction

    # @param params [Hash] Hash of parameters. The only supported key is
    #   +:transaction+, which should have a
    #   +Minfraud::Components::Report::Transaction+ as its value.
    def initialize(params = {})
      @transaction = params[:transaction]
    end

    # Perform a request to the minFraud Report Transaction API.
    #
    # @return [nil]
    #
    # @raise [JSON::ParserError] if there was invalid JSON in the response.
    #
    # @raise [Minfraud::AuthorizationError] If there was an authentication
    #   problem.
    #
    # @raise [Minfraud::ClientError] If there was a critical problem with one
    #   of your inputs.
    #
    # @raise [Minfraud::ServerError] If the server reported an error of some
    #   kind.
    def report_transaction
      response = nil
      body     = nil
      Minfraud.connection_pool.with do |client|
        response = client.post(
          '/minfraud/v2.0/transactions/report',
          json: @transaction.to_json,
        )

        body = response.to_s
      end

      endpoint = nil
      locales  = nil
      response = ::Minfraud::HTTPService::Response.new(
        endpoint,
        locales,
        response,
        body,
      )

      ::Minfraud::ErrorHandler.examine(response)

      nil
    end

    private

    def request
      @request ||= Request.new(::Minfraud::HTTPService.configuration)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
minfraud-2.7.1 lib/minfraud/report.rb
minfraud-2.7.0.beta1 lib/minfraud/report.rb
minfraud-2.6.0 lib/minfraud/report.rb
minfraud-2.5.0 lib/minfraud/report.rb
minfraud-2.4.0 lib/minfraud/report.rb
minfraud-2.3.0 lib/minfraud/report.rb
minfraud-2.2.0 lib/minfraud/report.rb
minfraud-2.1.0 lib/minfraud/report.rb
minfraud-2.0.0 lib/minfraud/report.rb