Class: Cardgate::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/cardgate/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Callback

Returns a new instance of Callback.



7
8
9
10
11
# File 'lib/cardgate/callback.rb', line 7

def initialize(attributes = {})
  attributes.each do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def amount
  @amount
end

#currencyObject

Returns the value of attribute currency.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def currency
  @currency
end

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def hash
  @hash
end

#hash_keyObject

Returns the value of attribute hash_key.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def hash_key
  @hash_key
end

#is_testObject

Returns the value of attribute is_test.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def is_test
  @is_test
end

#refObject

Returns the value of attribute ref.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def ref
  @ref
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def status
  @status
end

#transaction_idObject

Returns the value of attribute transaction_id.



5
6
7
# File 'lib/cardgate/callback.rb', line 5

def transaction_id
  @transaction_id
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cardgate/callback.rb', line 28

def failed?
  [300, 301].include?(@status.to_i)
end

#recurring_failed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cardgate/callback.rb', line 32

def recurring_failed?
  @status.to_i == 310
end

#refund?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cardgate/callback.rb', line 36

def refund?
  @status.to_i == 400
end

#responseObject



20
21
22
# File 'lib/cardgate/callback.rb', line 20

def response
  "#{@transaction_id}.#{@status}"
end

#successful?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cardgate/callback.rb', line 24

def successful?
  [200, 210].include?(@status.to_i)
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/cardgate/callback.rb', line 13

def valid?
  hash_elements = [ @transaction_id, @currency, @amount, @ref, @status, @hash_key ]
  hash_elements.unshift 'TEST' if @is_test.to_i == 1

  Digest::MD5.hexdigest(hash_elements.join) == @hash
end