Module: Nihaopay::Api::ClassMethods

Defined in:
lib/nihaopay/mixins/api.rb

Instance Method Summary collapse

Instance Method Details

#authorizationObject



20
21
22
# File 'lib/nihaopay/mixins/api.rb', line 20

def authorization
  { 'Authorization' => "Bearer #{merchant_token}" }
end

#base_urlObject



16
17
18
# File 'lib/nihaopay/mixins/api.rb', line 16

def base_url
  "#{host}/#{VERSION}"
end

#hostObject



12
13
14
# File 'lib/nihaopay/mixins/api.rb', line 12

def host
  Nihaopay.test_mode ? TEST_HOST : LIVE_HOST
end

#merchant_tokenObject



24
25
26
# File 'lib/nihaopay/mixins/api.rb', line 24

def merchant_token
  @token || Nihaopay.token
end

#validate_collection!(response) ⇒ Object



34
35
36
37
38
# File 'lib/nihaopay/mixins/api.rb', line 34

def validate_collection!(response)
  return if response.parsed_response['transactions']
  parsed_response = response.parsed_response.map { |k, v| "#{k}: #{v}" }.join(', ')
  fail Nihaopay::TransactionError, parsed_response
end

#validate_resource!(response) ⇒ Object



28
29
30
31
32
# File 'lib/nihaopay/mixins/api.rb', line 28

def validate_resource!(response)
  return if response.parsed_response['id']
  parsed_response = response.parsed_response.map { |k, v| "#{k}: #{v}" }.join(', ')
  fail Nihaopay::TransactionError, parsed_response
end