Class: Cardflex::TransactionGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/cardflex/transaction_gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gateway) ⇒ TransactionGateway

Returns a new instance of TransactionGateway.



5
6
7
8
# File 'lib/cardflex/transaction_gateway.rb', line 5

def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/cardflex/transaction_gateway.rb', line 3

def config
  @config
end

Instance Method Details

#_handle_query_response(res) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/cardflex/transaction_gateway.rb', line 34

def _handle_query_response(res)
  if res[:nm_response].keys.include?(:error_response)
    ErrorResponse.new(@gateway, :result => 3, :result_text => res[:nm_response][:error_response])
  else
    SuccessResponse.new(:transaction => Transaction.new(@gateway, res[:nm_response][:transaction]))
  end
end

#_handle_response(res) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/cardflex/transaction_gateway.rb', line 26

def _handle_response(res)
  if res[:response][:result] == '1'
    SuccessResponse.new(:transaction => Transaction.new(@gateway, res[:response]))
  else
    ErrorResponse.new(@gateway, res[:response])
  end
end

#query(attributes) ⇒ Object

Query API



17
18
19
20
21
22
23
24
# File 'lib/cardflex/transaction_gateway.rb', line 17

def query(attributes)
  unless username = @config.username && password = @config.password
    raise ArgumentError, 'missing username and/or password'
  end

  res = @config.http.get(attributes.merge(:username => username, :password => password))
  _handle_query_response(res)
end

#request(attributes) ⇒ Object

Three Step API



11
12
13
14
# File 'lib/cardflex/transaction_gateway.rb', line 11

def request(attributes)
  res = @config.http.post(attributes)
  _handle_response(res)
end