Class: Comgate::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/comgate/response.rb

Constant Summary collapse

RESPONSE_CODES =
{
  0 => "OK",
  1100 => "unknown error",
  1102 => "the specified language is not supported",
  1103 => "method incorrectly specified",
  1104 => "unable to load payment",
  1107 => "payment price is not supported",
  1200 => "database error",
  1301 => "unknown e-shop",
  1303 => "the link or language is missing",
  1304 => "invalid category",
  1305 => "product description is missing",
  1306 => "select the correct method",
  1308 => "the selected payment method is not allowed",
  1309 => "incorrect amount",
  1310 => "unknown currency",
  1311 => "invalid e-shop bank account identifier",
  1316 => "e-shop does not allow recurring payments",
  1317 => "invalid method - does not support recurring payments",
  1318 => "initial payment not found",
  1319 => "can not create a payment, a problem on the part of the bank",
  1399 => "unexpected result from database",
  1400 => "wrong query",
  1401 => "the refunded payment is in the CANCELED state",
  # or 1401 =>"Transaction FVN0-NS40-NA5B has not been authorized, current status: READY"
  1402 => "refund amount higher than allowed",
  1500 => "unexpected error"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caller_result, params_conversion_hash = {}) ⇒ Response

Returns a new instance of Response.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/comgate/response.rb', line 37

def initialize(caller_result, params_conversion_hash = {})
  @params_conversion_hash = params_conversion_hash

  @http_code = caller_result[:http_code].to_i
  @errors = fill_error_messages(caller_result[:errors])
  @redirect_to = caller_result[:redirect_to]

  converted_body = convert_comgate_params_to_data(caller_result[:response_body])

  case converted_body
  when Hash
    @hash = converted_body
    @transaction_id = converted_body[:transaction_id]
    @array = nil
  when Array
    @array = converted_body
    @hash = nil
  end
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



34
35
36
# File 'lib/comgate/response.rb', line 34

def array
  @array
end

#errorsObject

Returns the value of attribute errors.



34
35
36
# File 'lib/comgate/response.rb', line 34

def errors
  @errors
end

#hashObject

Returns the value of attribute hash.



34
35
36
# File 'lib/comgate/response.rb', line 34

def hash
  @hash
end

#http_codeObject

Returns the value of attribute http_code.



34
35
36
# File 'lib/comgate/response.rb', line 34

def http_code
  @http_code
end

#params_conversion_hashObject (readonly)

Returns the value of attribute params_conversion_hash.



35
36
37
# File 'lib/comgate/response.rb', line 35

def params_conversion_hash
  @params_conversion_hash
end

#redirect_toObject

Returns the value of attribute redirect_to.



34
35
36
# File 'lib/comgate/response.rb', line 34

def redirect_to
  @redirect_to
end

#transaction_idObject

Returns the value of attribute transaction_id.



34
35
36
# File 'lib/comgate/response.rb', line 34

def transaction_id
  @transaction_id
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/comgate/response.rb', line 61

def error?
  !errors.nil?
end

#redirect?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/comgate/response.rb', line 57

def redirect?
  !redirect_to.nil?
end