Module: BillingClient

Defined in:
lib/billing_client.rb

Constant Summary collapse

ApiError =
Class.new(StandardError)
ConfigError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.check_code(account, product_code, code, reference) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/billing_client.rb', line 5

def self.check_code(, product_code, code, reference)

  raise ConfigError, "Config not found, run \"rails g billing_client\" first!" if ::BILLING_CONFIG.try(:[], 'host').blank?
  uri = URI.join("http://#{}.#{::BILLING_CONFIG['host']}", "/api/products/#{product_code}/can_use",).to_s

  response = RestClient.get uri, :params => {:customer_code => code, :reference_object => reference}

  response = JSON.parse(response, :symbolize_names => true)

  if response[:status].to_s == "200"
    true
  else
    raise ApiError, response[:errors].try(:join, ', ')
  end
end