Class: Cardgate::Gateway

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/cardgate/gateway.rb', line 8

def api_key
  @api_key
end

.environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/cardgate/gateway.rb', line 8

def environment
  @environment
end

.merchantObject

Returns the value of attribute merchant.



8
9
10
# File 'lib/cardgate/gateway.rb', line 8

def merchant
  @merchant
end

.request_loggerObject

Returns the value of attribute request_logger.



8
9
10
# File 'lib/cardgate/gateway.rb', line 8

def request_logger
  @request_logger
end

Class Method Details

.connectionObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cardgate/gateway.rb', line 23

def self.connection
  raise Cardgate::Exception, 'Merchant and/or API key not set' if !self.merchant || !self.api_key

  Faraday.new(url: self.request_url, ssl: { verify: !is_test_environment? } ) do |faraday|
    faraday.request  :json
    faraday.response :json
    faraday.response :logger if request_logger == true
    faraday.adapter  Faraday.default_adapter
    faraday.basic_auth self.merchant, self.api_key
  end
end

.is_test_environment?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/cardgate/gateway.rb', line 11

def self.is_test_environment?
  self.environment == :test
end

.request_urlObject



15
16
17
18
19
20
21
# File 'lib/cardgate/gateway.rb', line 15

def self.request_url
  if self.is_test_environment?
    Cardgate::TEST_URL
  else
    Cardgate::LIVE_URL
  end
end