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(account, 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://#{account}.#{::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
|