Class: Twocheckout::API

Inherits:
Object
  • Object
show all
Defined in:
lib/twocheckout/api.rb

Constant Summary collapse

PROD_BASE =
'https://www.2checkout.com'.freeze
API_VERSION =
'1'.freeze

Class Method Summary collapse

Class Method Details

.credentials=(opts) ⇒ Object



9
10
11
12
13
14
# File 'lib/twocheckout/api.rb', line 9

def self.credentials=(opts)
  @username = opts[:username]
  @password = opts[:password]
  @private_key = opts[:private_key]
  @seller_id = opts[:seller_id]
end

.request(http_method, api_call, params = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/twocheckout/api.rb', line 16

def self.request(http_method, api_call, params = nil)
  opts = set_opts(http_method, api_call, params)
  begin
    response = RestClient::Request.execute(opts)
    JSON.parse(response)
  rescue => e
    error_hash = JSON.parse(e.response)
    if error_hash['exception']
      raise TwocheckoutError.new(error_hash['exception']['errorMsg'], error_hash['exception']['errorCode'])
    else
      raise TwocheckoutError.new(error_hash['errors'][0]['message'])
    end
  end
end