Class: AlphaCard::Response

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

Overview

Implementation of Alpha Card Services response. Contains all the data, that Alpha Card Gateway returned for the request.

Constant Summary collapse

APPROVED =

Success response code

'1'.freeze
DECLINED =

Decline response code

'2'.freeze
ERROR =

Error response code

'3'.freeze
CVV_RESPONSES =

Messages for CVV response codes

YAML.load_file(File.expand_path('../data/cvv_responses.yml', __FILE__)).freeze
AVS_RESPONSES =

Messages for AVS response codes

YAML.load_file(File.expand_path('../data/avs_responses.yml', __FILE__)).freeze
RESPONSE_MESSAGES =

AlphaCard response messages

YAML.load_file(File.expand_path('../data/response_messages.yml', __FILE__)).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ Response

Alpha Card Response constructor.

Examples:

AlphaCard::Response.new('response=1&responsetext=Test')

#=> #<AlphaCard::Response:0x00000003f2b568 @data={"response"=>"1", "responsetext"=>"Test"}>

Parameters:

  • response_body (String)

    Alpha Card Gateway response body text



39
40
41
# File 'lib/alpha_card/response.rb', line 39

def initialize(response_body)
  @data = Rack::Utils.parse_query(response_body)
end

Instance Attribute Details

#dataObject (readonly)

Alpha Card Gateway response as a Hash.



9
10
11
# File 'lib/alpha_card/response.rb', line 9

def data
  @data
end

Instance Method Details

#auth_codeString

Transaction authorization code.

Examples:


response = AlphaCardResponse.new("response=1&authcode=083319")
response.code

#=> '083319'

Returns:

  • (String)

    auth code



129
130
131
# File 'lib/alpha_card/response.rb', line 129

def auth_code
  @data['authcode']
end

#avs_responseString

AVS response message.

Examples:


response = AlphaCardResponse.new("avsresponse=A")
response.avs_response

#=> 'Address match only'

Returns:

  • (String)

    AVS response message



225
226
227
# File 'lib/alpha_card/response.rb', line 225

def avs_response
  AVS_RESPONSES[@data['avsresponse']]
end

#codeString

Numeric mapping of processor responses.

Examples:


response = AlphaCardResponse.new("response=1&response_code=100")
response.code

#=> '100'

Returns:

  • (String)

    code of the response



114
115
116
# File 'lib/alpha_card/response.rb', line 114

def code
  @data['response_code']
end

#credit_card_auth_messageString

Credit Card Authorization Message based on returned code in accordance with the Global Payment Systems Credit Card Authorization Codes (codes.yml).

Examples:


response = AlphaCardResponse.new("response_text=AP")
response.credit_card_auth_message

#=> 'Approved or completed successfully'

Returns:

  • (String)

    auth message



144
145
146
# File 'lib/alpha_card/response.rb', line 144

def credit_card_auth_message
  AlphaCard::CREDIT_CARD_CODES[text]
end

#cvv_responseString

CVV response message.

Examples:


response = AlphaCardResponse.new("cvvresponse=M")
response.cvv_response

#=> 'CVV2/CVC2 match'

Returns:

  • (String)

    CVV response message



210
211
212
# File 'lib/alpha_card/response.rb', line 210

def cvv_response
  CVV_RESPONSES[@data['cvvresponse']]
end

#declined?Bool

Indicate the state of the request to the Alpha Card Gateway. Returns true if request was declined.

Examples:


response = AlphaCardResponse.new("response=2")
response.declined?

#=> true

Returns:

  • (Bool)

    true if request was declined



178
179
180
# File 'lib/alpha_card/response.rb', line 178

def declined?
  @data['response'] == DECLINED
end

#error?Bool

Indicate the state of the request to the Alpha Card Gateway. Returns true if request has some errors.

Examples:


response = AlphaCardResponse.new("response=3")
response.error?

#=> true

Returns:

  • (Bool)

    true if request has some errors



195
196
197
# File 'lib/alpha_card/response.rb', line 195

def error?
  @data['response'] == ERROR
end

#messageString

Response message by response code.

Examples:


response = AlphaCardResponse.new("response_code=>300")
response.message

#=> 'Transaction was rejected by gateway'

Returns:

  • (String)

    response message



69
70
71
# File 'lib/alpha_card/response.rb', line 69

def message
  RESPONSE_MESSAGES[code]
end

#order_idString

The original order id passed in the transaction request.

Examples:


response = AlphaCardResponse.new("response=1&orderid=123")
response.order_id

#=> '123'

Returns:

  • (String)

    Order ID



99
100
101
# File 'lib/alpha_card/response.rb', line 99

def order_id
  @data['orderid']
end

#success?Bool

Indicate the state of the request to the Alpha Card Gateway. Returns true if request was approved.

Examples:


response = AlphaCardResponse.new("response=1")
response.success?

#=> true

Returns:

  • (Bool)

    true if request if successful



161
162
163
# File 'lib/alpha_card/response.rb', line 161

def success?
  @data['response'] == APPROVED
end

#textString

Textual response of the Alpha Card Gateway.

Examples:


response = AlphaCardResponse.new("response=1&responsetext=Test")
response.text

#=> 'Test'

Returns:

  • (String)

    text of the response



54
55
56
# File 'lib/alpha_card/response.rb', line 54

def text
  @data['responsetext']
end

#transaction_idString

Payment gateway transaction ID.

Examples:


response = AlphaCardResponse.new("response=1&transactionid=123")
response.transaction_id

#=> '123'

Returns:

  • (String)

    transaction ID



84
85
86
# File 'lib/alpha_card/response.rb', line 84

def transaction_id
  @data['transactionid']
end