Class: CCBill::DynamicPricing
- Inherits:
-
Object
- Object
- CCBill::DynamicPricing
- Defined in:
- lib/ccbill_ruby/dynamic_pricing.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DynamicPricing
constructor
A new instance of DynamicPricing.
- #url ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ DynamicPricing
Returns a new instance of DynamicPricing.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 7 def initialize( = {}) = modify_params() self.config = CCBill.configuration self.variables = { account: config.account, sub_account: config.sub_account, currency_code: config.default_currency }.merge() end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 5 def config @config end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 5 def errors @errors end |
#variables ⇒ Object
Returns the value of attribute variables.
5 6 7 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 5 def variables @variables end |
Instance Method Details
#url ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 18 def url raise DynamicPricingError.new(errors.join(' ')) if !valid? variables[:form_digest] = encode_form_digest config.endpoint + config.flexform_id + '?' + URI.encode_www_form(transformed_variables) end |
#valid? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ccbill_ruby/dynamic_pricing.rb', line 26 def valid? @errors = [] required_fields.each do |field| @errors << "#{field} is required." if !variables[field] end unless (2.96..99.99).include?(variables[:initial_price].to_f) @errors << 'Price must be between $2.95 and $100.' end @errors.empty? end |