Class: AlphaCard::AlphaCardResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/alpha_card/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'
DECLINED =

Decline response code

'2'
ERROR =

Error response code

'3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ AlphaCardResponse

AlphaCardResponse constructor.

Examples:

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

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

Parameters:

  • response_body (String)

    Alpha Card Gateway response body text



30
31
32
# File 'lib/alpha_card/alpha_card_response.rb', line 30

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/alpha_card_response.rb', line 9

def data
  @data
end

Instance Method Details

#codeString

The code of the Alpha Card Gateway response.

Examples:


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

#=> '100'

Returns:

  • (String)

    code of the response



76
77
78
# File 'lib/alpha_card/alpha_card_response.rb', line 76

def code
  @data['response_code']
end

#declined?Bool

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

Examples:


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

#=> true

Returns:

  • (Bool)

    true if request was declined



110
111
112
# File 'lib/alpha_card/alpha_card_response.rb', line 110

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:


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

#=> true

Returns:

  • (Bool)

    true if request has some errors



127
128
129
# File 'lib/alpha_card/alpha_card_response.rb', line 127

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

#success?Bool

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

Examples:


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

#=> true

Returns:

  • (Bool)

    true if request if successful



93
94
95
# File 'lib/alpha_card/alpha_card_response.rb', line 93

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

#textString

The text of the Alpha Card Gateway response.

Examples:


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

#=> 'Test'

Returns:

  • (String)

    text of the response



45
46
47
# File 'lib/alpha_card/alpha_card_response.rb', line 45

def text
  @data['responsetext']
end

#transaction_idString

The ID of the transaction. Can be used to process refund operation.

Examples:


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

#=> '123'

Returns:

  • (String)

    transaction ID



61
62
63
# File 'lib/alpha_card/alpha_card_response.rb', line 61

def transaction_id
  @data['transactionid']
end