Class: SpookAndPay::SubmissionError

Inherits:
Object
  • Object
show all
Defined in:
lib/spook_and_pay/submission_error.rb

Overview

Class used to encapsulate the details of an error related to some interaction with the provider. It is generic in that it might apply to a specific part of the payload or it might capture more general details.

It will also attempt translate errors into a human readable string. Where it cannot, it still exposes the raw results from the provider allowing debugging.

Constant Summary collapse

ERROR_MESSAGES =

A constant which defines the acceptable types of errors and which is also used to generate specific messages. Where the error is unknown, the consumer of this library will be directed to use the raw error generated by the underlying libraries.

{
  :credit_card => {
    :number_required            => "number is required",
    :number_invalid             => "number is invalid",
    :number_too_short           => "number must be between 12 and 19 digits",
    :name_required              => "name is required",
    :type_not_accepted          => "card type is not accepted by this merchant",
    :expiration_month_invalid   => "expiration month is invalid",
    :expiration_month_expired   => "expiration month has expired",
    :expiration_month_required  => "expiration month is required",
    :expiration_year_invalid    => "expiration year is invalid",
    :expiration_year_expired    => "expiration year has expired",
    :expiration_year_required   => "expiration year is required",
    :cvv_invalid                => "CVV must be three digits",
    :cvv_required               => "CVV is required"
  },
  :transaction => {
    :cannot_capture => "must be authorized in order to capture funds",
    :cannot_refund  => "must be settled in order to refund",
    :cannot_void    => "must be authorized or settled in order to void",
    :card_declined  => "cannot process transaction; card has been declined"
  },
  :unknown => {
    :unknown => "please refer to the #raw attribute of this error"
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, error_type, field, raw) ⇒ SubmissionError

Generates a new error. Based on the target and error type, it can generate the appropriate error messages or otherwise fall back.

Parameters:

  • Symbol

    target

  • Symbol

    error_type

  • field (Symbol, nil)
  • Class

    raw



51
52
53
54
55
56
# File 'lib/spook_and_pay/submission_error.rb', line 51

def initialize(target, error_type, field, raw)
  @error_type = error_type
  @target = target
  @field = field
  @raw = raw
end

Instance Attribute Details

#error_typeObject (readonly)

Basic attributes



42
43
44
# File 'lib/spook_and_pay/submission_error.rb', line 42

def error_type
  @error_type
end

#fieldObject (readonly)

Basic attributes



42
43
44
# File 'lib/spook_and_pay/submission_error.rb', line 42

def field
  @field
end

#messageObject (readonly)

Generates a human readable error message based on the target and error type.

Returns:

  • String



42
43
44
# File 'lib/spook_and_pay/submission_error.rb', line 42

def message
  @message
end

#rawObject (readonly)

Basic attributes



42
43
44
# File 'lib/spook_and_pay/submission_error.rb', line 42

def raw
  @raw
end

#targetObject (readonly)

Basic attributes



42
43
44
# File 'lib/spook_and_pay/submission_error.rb', line 42

def target
  @target
end

Instance Method Details

#unknown?true, false

Indicates if this is an error that we don’t know anything about.

Returns:

  • (true, false)


61
62
63
# File 'lib/spook_and_pay/submission_error.rb', line 61

def unknown?
  @error_type == :unknown
end