Permalink
Browse files

Reorganize and clean up ActiveResource classes

Added:
- Add Chargify::ProductFamily#coupons
- Add Chargify::ProductFamily#products
- Add Chargify::Customer::Subscription

Removed:
- Bump minimum ActiveResource version to 2.3.5
- Remove Chargify::Coupon.find_all_by_product_family_id
- Commented out all remote tests until they can be revived

Fixes:
- Scope Chargify::ProductFamily#products properly
- Scope Chargify::ProductFamily#components properly
- Scope Chargify::Customer#subscriptions properly
  • Loading branch information...
1 parent 550601d commit dc89f2fcd75cf40cb6d3db9ad05422f79d4b010f @shayfrendt shayfrendt committed Oct 26, 2011
Showing with 1,095 additions and 1,180 deletions.
  1. +1 −0 .gitignore
  2. +2 −13 Gemfile
  3. +26 −29 Gemfile.lock
  4. +29 −37 README.md
  5. +3 −6 Rakefile
  6. +0 −1 VERSION
  7. +25 −63 chargify_api_ares.gemspec
  8. +1 −1 {samples → examples}/coupons.rb
  9. +1 −1 {samples → examples}/customers.rb
  10. +2 −2 {samples → examples}/metered_components.rb
  11. +1 −1 {samples → examples}/products.rb
  12. +2 −2 {samples → examples}/subscriptions.rb
  13. +2 −3 {samples → examples}/transactions.rb
  14. +14 −319 lib/chargify_api_ares.rb
  15. +16 −0 lib/chargify_api_ares/config.rb
  16. +14 −0 lib/chargify_api_ares/resources/base.rb
  17. +4 −0 lib/chargify_api_ares/resources/component.rb
  18. +15 −0 lib/chargify_api_ares/resources/coupon.rb
  19. +21 −0 lib/chargify_api_ares/resources/customer.rb
  20. +4 −0 lib/chargify_api_ares/resources/payment_profile.rb
  21. +25 −0 lib/chargify_api_ares/resources/product.rb
  22. +34 −0 lib/chargify_api_ares/resources/product_family.rb
  23. +7 −0 lib/chargify_api_ares/resources/site.rb
  24. +4 −0 lib/chargify_api_ares/resources/statement.rb
  25. +119 −0 lib/chargify_api_ares/resources/subscription.rb
  26. +17 −0 lib/chargify_api_ares/resources/transaction.rb
  27. +11 −0 lib/chargify_api_ares/resources/usage.rb
  28. +0 −48 spec/components_spec.rb
  29. +0 −35 spec/coupon_spec.rb
  30. +0 −23 spec/customer_spec.rb
  31. +28 −24 spec/factories.rb
  32. +0 −33 spec/product_families_component_spec.rb
  33. +0 −29 spec/product_families_spec.rb
  34. +0 −23 spec/product_spec.rb
  35. +2 −2 {config → spec/remote}/remote.example.yml
  36. +445 −444 spec/remote/remote_spec.rb
  37. +29 −28 spec/remote/spec_helper.rb
  38. +1 −1 spec/{ → resources}/base_spec.rb
  39. +20 −0 spec/resources/coupon_spec.rb
  40. +36 −0 spec/resources/customer_spec.rb
  41. +57 −0 spec/resources/product_family_spec.rb
  42. +23 −0 spec/resources/product_spec.rb
  43. +2 −2 spec/{subscriptions_component_spec.rb → resources/subscription_component_spec.rb}
  44. +2 −2 spec/{ → resources}/subscription_spec.rb
  45. +44 −0 spec/resources/usage_spec.rb
  46. +6 −8 spec/spec_helper.rb
  47. 0 spec/{mocks → support}/fake_resource.rb
View
1 .gitignore
@@ -1,3 +1,4 @@
config/remote.yml
+spec/remote/remote.yml
pkg
.rvmrc
View
15 Gemfile
@@ -1,15 +1,4 @@
source :rubygems
-gem 'activeresource', '>= 2.3.4'
-
-group :test do
- gem 'rake', '~> 0.9.2'
- gem 'rspec', '~> 2.6.0'
- gem 'fuubar', '~> 0.0.6'
- gem 'factory_girl', '~> 2.2.0'
- gem 'fakeweb', '~> 1.3.0'
- gem 'faker', '~> 1.0.1'
- gem 'guard-rspec', '~> 0.5.0', :require => false
- gem 'growl', '~> 1.0.3', :require => false
- gem 'rb-fsevent', '~> 0.4.2', :require => false
-end
+# Specify your gem's dependencies in chargify_api_ares.gemspec
+gemspec
View
55 Gemfile.lock
@@ -1,60 +1,57 @@
+PATH
+ remote: .
+ specs:
+ chargify_api_ares (0.5.0)
+ activeresource (>= 2.3.5)
+
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.1.0.rc5)
- activesupport (= 3.1.0.rc5)
- bcrypt-ruby (~> 2.1.4)
+ activemodel (3.1.1)
+ activesupport (= 3.1.1)
builder (~> 3.0.0)
i18n (~> 0.6)
- activeresource (3.1.0.rc5)
- activemodel (= 3.1.0.rc5)
- activesupport (= 3.1.0.rc5)
- activesupport (3.1.0.rc5)
+ activeresource (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ activesupport (3.1.1)
multi_json (~> 1.0)
- bcrypt-ruby (2.1.4)
builder (3.0.0)
- diff-lcs (1.1.2)
- factory_girl (2.2.0)
+ diff-lcs (1.1.3)
+ factory_girl (2.1.2)
activesupport
faker (1.0.1)
i18n (~> 0.4)
fakeweb (1.3.0)
- fuubar (0.0.6)
- rspec (~> 2.0)
- rspec-instafail (~> 0.1.8)
- ruby-progressbar (~> 0.0.10)
growl (1.0.3)
- guard (0.8.7)
+ guard (0.8.8)
thor (~> 0.14.6)
guard-rspec (0.5.0)
guard (>= 0.8.4)
i18n (0.6.0)
multi_json (1.0.3)
- rake (0.9.2)
+ rake (0.9.2.2)
rb-fsevent (0.4.3.1)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.4)
- rspec-expectations (2.6.0)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
- rspec-instafail (0.1.8)
- rspec-mocks (2.6.0)
- ruby-progressbar (0.0.10)
+ rspec-mocks (2.7.0)
thor (0.14.6)
PLATFORMS
ruby
DEPENDENCIES
- activeresource (>= 2.3.4)
- factory_girl (~> 2.2.0)
+ chargify_api_ares!
+ factory_girl (~> 2.1.0)
faker (~> 1.0.1)
fakeweb (~> 1.3.0)
- fuubar (~> 0.0.6)
growl (~> 1.0.3)
guard-rspec (~> 0.5.0)
rake (~> 0.9.2)
rb-fsevent (~> 0.4.2)
- rspec (~> 2.6.0)
+ rspec (~> 2.7.0)
View
66 README.md
@@ -1,31 +1,30 @@
Chargify API wrapper for Ruby (using ActiveResource) [![build status](https://secure.travis-ci.org/grasshopperlabs/chargify_api_ares.png)](http://travis-ci.org/grasshopperlabs/chargify_api_ares)
====================================================
-chargify_api_ares
------------------
-
This is a Ruby wrapper for the [Chargify](http://chargify.com) API that leverages ActiveResource.
+
It allows you to interface with the Chargify API using simple ActiveRecord-like syntax, i.e.:
- Chargify::Subscription.create(
- :customer_reference => 'moklett',
- :product_handle => 'chargify-api-ares-test',
- :credit_card_attributes => {
- :first_name => "Michael",
- :last_name => "Klett",
- :expiration_month => 1,
- :expiration_year => 2010,
- :full_number => "1234-1234-1234-1234"
- }
- )
-
- subscription.credit_card_attributes = {:expiration_year => 2013}
- subscription.save
-
- subscription.cancel
+``` ruby
+Chargify::Subscription.create(
+ :customer_reference => 'moklett',
+ :product_handle => 'chargify-api-ares-test',
+ :credit_card_attributes => {
+ :first_name => "Michael",
+ :last_name => "Klett",
+ :expiration_month => 1,
+ :expiration_year => 2010,
+ :full_number => "1234-1234-1234-1234"
+ }
+)
+
+subscription.credit_card_attributes = { :expiration_year => 2013 }
+subscription.save
-See the `samples` directory for more usage examples.
+subscription.cancel
+```
+See the `examples` directory for more usage examples.
### Installation
@@ -35,31 +34,24 @@ You can install this library as a gem using the following command:
$ gem install chargify_api_ares
-
-### Requirements
-
-This library requires ActiveResource version 2.3.4 or greater.
-
-$ gem install activeresource
-
-
### Usage
Simply require this library before you use it:
- require 'chargify_api_ares'
+``` ruby
+require 'chargify_api_ares'
+```
-
If you're using Rails, you could include this gem in your configuration, i.e. in `environment.rb`
- config.gem 'chargify_api_ares'
+``` ruby
+config.gem 'chargify_api_ares'
+```
-
Now you'll have access to classes the interact with the Chargify API, such as:
-`Chargify::Product`
-`Chargify::Customer`
-`Chargifiy::Subscription`
+* `Chargify::Product`
+* `Chargify::Customer`
+* `Chargify::Subscription`
-Check out the examples in the `samples` directory. If you're not familiar with how ActiveResource works,
-you may be interested in some [ActiveResource Documentation](http://apidock.com/rails/ActiveResource/Base)
+Check out the examples in the `examples` directory. If you're not familiar with how ActiveResource works, you may be interested in some [ActiveResource Documentation](http://apidock.com/rails/ActiveResource/Base)
View
9 Rakefile
@@ -1,9 +1,6 @@
-require 'rake'
+require 'bundler'
+Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
-desc 'Run the spec suite'
-RSpec::Core::RakeTask.new('spec') {|t|
- t.rspec_opts = ['--colour', '--format Fuubar']
-}
-
+RSpec::Core::RakeTask.new(:spec)
task :default => :spec
View
1 VERSION
@@ -1 +0,0 @@
-0.3.9
View
88 chargify_api_ares.gemspec
@@ -1,69 +1,31 @@
Gem::Specification.new do |s|
- s.name = %q{chargify_api_ares}
- s.version = "0.4.4"
-
+ s.specification_version = 3 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.rubygems_version = '1.3.7'
+
+ s.name = 'chargify_api_ares'
+ s.version = '0.4.4'
+ s.date = '2011-10-25'
+ s.summary = 'A Chargify API wrapper for Ruby using ActiveResource'
+ s.description = ''
s.authors = ["Michael Klett", "Nathan Verni", "Rodrigo Franco", "Shay Frendt"]
- s.date = %q{2011-10-25}
- s.description = %q{}
- s.email = %q{support@chargify.com}
- s.extra_rdoc_files = [
- "LICENSE.txt",
- "README.md"
- ]
- s.files = [
- ".gitignore",
- "LICENSE.txt",
- "README.md",
- "Rakefile",
- "VERSION",
- "chargify_api_ares.gemspec",
- "config/remote.example.yml",
- "lib/chargify_api_ares.rb",
- "samples/customers.rb",
- "samples/metered_components.rb",
- "samples/products.rb",
- "samples/subscriptions.rb",
- "samples/transactions.rb",
- "spec/base_spec.rb",
- "spec/components_spec.rb",
- "spec/customer_spec.rb",
- "spec/factories.rb",
- "spec/mocks/fake_resource.rb",
- "spec/product_spec.rb",
- "spec/remote/remote_spec.rb",
- "spec/remote/spec_helper.rb",
- "spec/spec.opts",
- "spec/spec_helper.rb",
- "spec/subscription_spec.rb",
- "spec/subscriptions_component_spec.rb"
- ]
- s.homepage = %q{http://github.com/grasshopperlabs/chargify_api_ares}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{A Chargify API wrapper for Ruby using ActiveResource}
- s.test_files = [
- "spec/base_spec.rb",
- "spec/components_spec.rb",
- "spec/customer_spec.rb",
- "spec/factories.rb",
- "spec/mocks/fake_resource.rb",
- "spec/product_spec.rb",
- "spec/remote/remote_spec.rb",
- "spec/remote/spec_helper.rb",
- "spec/spec_helper.rb",
- "spec/subscription_spec.rb",
- "spec/subscriptions_component_spec.rb"
- ]
+ s.email = 'support@chargify.com'
+ s.homepage = 'http://github.com/grasshopperlabs/chargify_api_ares'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_paths = %w[lib]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ # Runtime Dependencies
+ s.add_runtime_dependency('activeresource', '>= 2.3.5')
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
+ # Development Dependencies
+ s.add_development_dependency('rake', '~> 0.9.2')
+ s.add_development_dependency('rspec', '~> 2.7.0')
+ s.add_development_dependency('factory_girl', '~> 2.1.0')
+ s.add_development_dependency('fakeweb', '~> 1.3.0')
+ s.add_development_dependency('faker', '~> 1.0.1')
+ s.add_development_dependency('guard-rspec', '~> 0.5.0')
+ s.add_development_dependency('growl', '~> 1.0.3')
+ s.add_development_dependency('rb-fsevent', '~> 0.4.2')
end
View
2 samples/coupons.rb → examples/coupons.rb
@@ -3,7 +3,7 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
View
2 samples/customers.rb → examples/customers.rb
@@ -3,7 +3,7 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
View
4 samples/metered_components.rb → examples/metered_components.rb
@@ -3,7 +3,7 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
@@ -32,4 +32,4 @@
x = Chargify::Usage.find(:last, :params => {:subscription_id => subscription.id, :component_id => component.id})
-puts x.memo == d
+puts x.memo == d
View
2 samples/products.rb → examples/products.rb
@@ -3,7 +3,7 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
View
4 samples/subscriptions.rb → examples/subscriptions.rb
@@ -3,7 +3,7 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
@@ -50,4 +50,4 @@
# Cancel a subscription
subscription.cancel
subscription.reload
-# => #<Chargify::Subscription:0x1020ed4b0 @prefix_options={}, @attributes={"cancellation_message"=>nil, "activated_at"=>Tue Nov 17 16:00:17 UTC 2009, "expires_at"=>nil, "updated_at"=>Tue Nov 17 16:00:17 UTC 2009, "credit_card"=>#<Chargify::Subscription::CreditCard:0x10234f168 @prefix_options={}, @attributes={"card_type"=>"bogus", "expiration_year"=>2015, "masked_card_number"=>"XXXX-XXXX-XXXX-2", "first_name"=>"Michael", "expiration_month"=>1, "last_name"=>"Klett"}>, "product"=>#<Chargify::Product:0x10234f370 @prefix_options={}, @attributes={"price_in_cents"=>0, "name"=>"Chargify API Ares Test", "handle"=>"chargify-api-ares-test", "product_family"=>#<Chargify::Product::ProductFamily:0x102354708 @prefix_options={}, @attributes={"name"=>"Chargify API ARes Test", "handle"=>"chargify-api-ares-test", "id"=>79, "accounting_code"=>nil}>, "id"=>153, "accounting_code"=>nil, "interval_unit"=>"month", "interval"=>1}>, "credit_card_attributes"=>{:full_number=>"2", :expiration_year=>"2015"}, "trial_ended_at"=>nil, "id"=>331, "current_period_ends_at"=>Thu Dec 17 16:00:17 UTC 2009, "product_handle"=>"chargify-api-ares-test", "customer"=>#<Chargify::Customer:0x10234f730 @prefix_options={}, @attributes={"reference"=>"moklett", "updated_at"=>Tue Nov 17 15:51:02 UTC 2009, "id"=>331, "first_name"=>"Michael", "organization"=>"Chargify", "last_name"=>"Klett", "email"=>"moklett@example.com", "created_at"=>Tue Nov 17 15:51:02 UTC 2009}>, "trial_started_at"=>nil, "balance_in_cents"=>0, "current_period_started_at"=>Tue Nov 17 16:00:17 UTC 2009, "state"=>"canceled", "created_at"=>Tue Nov 17 16:00:17 UTC 2009, "customer_reference"=>"moklett"}>
+# => #<Chargify::Subscription:0x1020ed4b0 @prefix_options={}, @attributes={"cancellation_message"=>nil, "activated_at"=>Tue Nov 17 16:00:17 UTC 2009, "expires_at"=>nil, "updated_at"=>Tue Nov 17 16:00:17 UTC 2009, "credit_card"=>#<Chargify::Subscription::CreditCard:0x10234f168 @prefix_options={}, @attributes={"card_type"=>"bogus", "expiration_year"=>2015, "masked_card_number"=>"XXXX-XXXX-XXXX-2", "first_name"=>"Michael", "expiration_month"=>1, "last_name"=>"Klett"}>, "product"=>#<Chargify::Product:0x10234f370 @prefix_options={}, @attributes={"price_in_cents"=>0, "name"=>"Chargify API Ares Test", "handle"=>"chargify-api-ares-test", "product_family"=>#<Chargify::Product::ProductFamily:0x102354708 @prefix_options={}, @attributes={"name"=>"Chargify API ARes Test", "handle"=>"chargify-api-ares-test", "id"=>79, "accounting_code"=>nil}>, "id"=>153, "accounting_code"=>nil, "interval_unit"=>"month", "interval"=>1}>, "credit_card_attributes"=>{:full_number=>"2", :expiration_year=>"2015"}, "trial_ended_at"=>nil, "id"=>331, "current_period_ends_at"=>Thu Dec 17 16:00:17 UTC 2009, "product_handle"=>"chargify-api-ares-test", "customer"=>#<Chargify::Customer:0x10234f730 @prefix_options={}, @attributes={"reference"=>"moklett", "updated_at"=>Tue Nov 17 15:51:02 UTC 2009, "id"=>331, "first_name"=>"Michael", "organization"=>"Chargify", "last_name"=>"Klett", "email"=>"moklett@example.com", "created_at"=>Tue Nov 17 15:51:02 UTC 2009}>, "trial_started_at"=>nil, "balance_in_cents"=>0, "current_period_started_at"=>Tue Nov 17 16:00:17 UTC 2009, "state"=>"canceled", "created_at"=>Tue Nov 17 16:00:17 UTC 2009, "customer_reference"=>"moklett"}>
View
5 samples/transactions.rb → examples/transactions.rb
@@ -3,15 +3,14 @@
require 'chargify_api_ares'
# You could load your credentials from a file...
-chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
+chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'chargify.yml'))
Chargify.configure do |c|
c.subdomain = chargify_config['subdomain']
c.api_key = chargify_config['api_key']
end
-
# Retrieve a list of all your customers
subscription = Chargify::Subscription.find(:all).first
-transactions = subscription.transactions
+transactions = subscription.transactions
View
333 lib/chargify_api_ares.rb
@@ -1,319 +1,14 @@
-# Chargify API Wrapper using ActiveResource.
-#
-require 'thread'
-
-begin
- require 'active_resource'
-rescue LoadError
- begin
- require 'rubygems'
- require 'active_resource'
- rescue LoadError
- abort <<-ERROR
-The 'activeresource' library could not be loaded. If you have RubyGems
-installed you can install ActiveResource by doing "gem install activeresource".
-ERROR
- end
-end
-
-
-# Version check
-module Chargify
- MIN_VERSION = '2.3.4'
-end
-require 'active_resource/version'
-unless Gem::Version.new(ActiveResource::VERSION::STRING) >= Gem::Version.new(Chargify::MIN_VERSION)
- abort <<-ERROR
- ActiveResource version #{Chargify::MIN_VERSION} or greater is required.
- ERROR
-end
-
-# Patch ActiveResource version 2.3.4
-if ActiveResource::VERSION::STRING == '2.3.4'
- module ActiveResource
- class Base
- def save
- save_without_validation
- true
- rescue ResourceInvalid => error
- case error.response['Content-Type']
- when /application\/xml/
- errors.from_xml(error.response.body)
- when /application\/json/
- errors.from_json(error.response.body)
- end
- false
- end
- end
- end
-end
-
-
-module Chargify
-
- class << self
- attr_accessor :subdomain, :api_key, :site, :format, :timeout
-
- def configure
- yield self
-
- Base.user = api_key
- Base.password = 'X'
- Base.timeout = timeout unless (timeout.blank?)
-
- self.site ||= "https://#{subdomain}.chargify.com"
-
- Base.site = site
- Subscription::Component.site = site + "/subscriptions/:subscription_id"
- Subscription::Statement.site = site + "/subscriptions/:subscription_id"
- Subscription::Transaction.site = site + "/subscriptions/:subscription_id"
- Coupon.site = site + "/product_families/:product_family_id"
- ProductFamily::Component.site = site + "/product_families/:product_family_id"
- end
- end
-
- class Base < ActiveResource::Base
- self.format = :xml
-
- def self.element_name
- name.split(/::/).last.underscore
- end
-
- def to_xml(options = {})
- options.merge!(:dasherize => false)
- super
- end
- end
-
- class Site < Base
- def self.clear_data!(params = {})
- post(:clear_data, params)
- end
- end
-
- class Customer < Base
- def self.find_by_reference(reference)
- Customer.new get(:lookup, :reference => reference)
- end
-
- def subscriptions(params = {})
- params.merge!({:customer_id => self.id})
- Subscription.find(:all, :params => params)
- end
-
- def payment_profiles(params = {})
- params.merge!({:customer_id => self.id})
- PaymentProfile.find(:all, :params => params)
- end
- end
-
- class Subscription < Base
- def self.find_by_customer_reference(reference)
- customer = Customer.find_by_reference(reference)
- find(:first, :params => {:customer_id => customer.id})
- end
-
- # Strip off nested attributes of associations before saving, or type-mismatch errors will occur
- def save
- self.attributes.delete('customer')
- self.attributes.delete('product')
- self.attributes.delete('credit_card')
- super
- end
-
- def cancel
- destroy
- end
-
- def component(id)
- Component.find(id, :params => {:subscription_id => self.id})
- end
-
- def components(params = {})
- params.merge!({:subscription_id => self.id})
- Component.find(:all, :params => params)
- end
-
- def payment_profile
- self.respond_to?('credit_card') ? credit_card : nil
- end
-
- # Perform a one-time charge on an existing subscription.
- # For more information, please see the one-time charge API docs available
- # at: http://support.chargify.com/faqs/api/api-charges
- def charge(attrs = {})
- post :charges, {}, attrs.to_xml(:root => :charge)
- end
-
- def credit(attrs = {})
- post :credits, {}, attrs.to_xml(:root => :credit)
- end
-
- def refund(attrs = {})
- post :refunds, {}, attrs.to_xml(:root => :refund)
- end
-
- def reactivate(params = {})
- put :reactivate, params
- end
-
- def reset_balance
- put :reset_balance
- end
-
- def migrate(attrs = {})
- post :migrations, :migration => attrs
- end
-
- def statement(id)
- statement = Chargify::Statement.find(id)
- raise ActiveResource::ResourceNotFound.new(nil) if (statement.subscription_id != self.id)
- statement
- end
-
- def statements(params = {})
- params.merge!(:subscription_id => self.id)
- Statement.find(:all, :params => params)
- end
-
- def transactions(params = {})
- params.merge!(:subscription_id => self.id)
- Transaction.find(:all, :params => params)
- end
-
- def adjustment(attrs = {})
- post :adjustments, {}, attrs.to_xml(:root => :adjustment)
- end
-
- def add_coupon(code)
- post :add_coupon, :code => code
- end
-
- def remove_coupon(code)
- delete :remove_coupon, :code => code
- end
-
- class Component < Base
- # All Subscription Components are considered already existing records, but the id isn't used
- def id
- self.component_id
- end
- end
-
- class Statement < Base
- end
-
- class Transaction < Base
- def full_refund(attrs = {})
- return false if self.transaction_type != 'payment'
-
- attrs.merge!(:amount_in_cents => self.amount_in_cents)
- self.refund(attrs)
- end
-
- def refund(attrs = {})
- return false if self.transaction_type != 'payment'
-
- attrs.merge!(:payment_id => self.id)
- Subscription.find(self.prefix_options[:subscription_id]).refund(attrs)
- end
- end
- end
-
- class Product < Base
- def self.find_by_handle(handle)
- Product.new get(:lookup, :handle => handle)
- end
-
- protected
-
- # Products are created in the scope of a ProductFamily, i.e. /product_families/nnn/products
- #
- # This alters the collection path such that it uses the product_family_id that is set on the
- # attributes.
- def create
- pfid = begin
- self.product_family_id
- rescue NoMethodError
- 0
- end
- connection.post("/product_families/#{pfid}/products.#{self.class.format.extension}", encode, self.class.headers).tap do |response|
- self.id = id_from_response(response)
- load_attributes_from_response(response)
- end
- end
- end
-
- class ProductFamily < Base
- def self.find_by_handle(handle, attributes = {})
- ProductFamily.find(:one, :from => :lookup, :params => { :handle => handle })
- end
-
- def products(params = {})
- params.merge!(:product_family_id => self.id)
- Product.find(:all, :params => params)
- end
-
- class Component < Base
- end
-
- def components(params = {})
- params.merge!({:product_family_id => self.id})
- ::Chargify::ProductFamily::Component.find(:all, :params => params)
- end
-
- end
-
- class Usage < Base
- def subscription_id=(i)
- self.prefix_options[:subscription_id] = i
- end
- def component_id=(i)
- self.prefix_options[:component_id] = i
- end
- end
-
- class Component < Base
- end
-
- class Statement < Base
- end
-
- class Transaction < Base
- def full_refund(attrs = {})
- return false if self.transaction_type != 'payment'
-
- attrs.merge!(:amount_in_cents => self.amount_in_cents)
- self.refund(attrs)
- end
-
- def refund(attrs = {})
- return false if self.transaction_type != 'payment'
-
- attrs.merge!(:payment_id => self.id)
- Subscription.find(self.subscription_id).refund(attrs)
- end
- end
-
- class PaymentProfile < Base
- end
-
- class Coupon < Base
- def self.find_all_by_product_family_id(product_family_id)
- Coupon.find(:all, :params => { :product_family_id => product_family_id })
- end
-
- def self.find_by_product_family_id_and_code(product_family_id, code)
- Coupon.new get(:lookup, :product_family_id => product_family_id, :code => code)
- end
-
- def usage
- get :usage
- end
-
- def archive
- self.destroy
- end
- end
-
-end
+require 'active_resource'
+require 'chargify_api_ares/config'
+require 'chargify_api_ares/resources/base'
+require 'chargify_api_ares/resources/component'
+require 'chargify_api_ares/resources/coupon'
+require 'chargify_api_ares/resources/customer'
+require 'chargify_api_ares/resources/payment_profile'
+require 'chargify_api_ares/resources/product'
+require 'chargify_api_ares/resources/product_family'
+require 'chargify_api_ares/resources/site'
+require 'chargify_api_ares/resources/statement'
+require 'chargify_api_ares/resources/subscription'
+require 'chargify_api_ares/resources/transaction'
+require 'chargify_api_ares/resources/usage'
View
16 lib/chargify_api_ares/config.rb
@@ -0,0 +1,16 @@
+module Chargify
+ class << self
+ attr_accessor :subdomain, :api_key, :site, :format, :timeout
+
+ def configure
+ yield self
+
+ Base.user = api_key
+ Base.password = 'X'
+ Base.timeout = timeout unless (timeout.blank?)
+
+ self.site ||= "https://#{subdomain}.chargify.com"
+ Base.site = site
+ end
+ end
+end
View
14 lib/chargify_api_ares/resources/base.rb
@@ -0,0 +1,14 @@
+module Chargify
+ class Base < ActiveResource::Base
+ self.format = :xml
+
+ def self.element_name
+ name.split(/::/).last.underscore
+ end
+
+ def to_xml(options = {})
+ options.merge!(:dasherize => false)
+ super
+ end
+ end
+end
View
4 lib/chargify_api_ares/resources/component.rb
@@ -0,0 +1,4 @@
+module Chargify
+ class Component < Base
+ end
+end
View
15 lib/chargify_api_ares/resources/coupon.rb
@@ -0,0 +1,15 @@
+module Chargify
+ class Coupon < Base
+ def self.find_by_product_family_id_and_code(product_family_id, code)
+ Coupon.new get(:lookup, :product_family_id => product_family_id, :code => code)
+ end
+
+ def usage
+ get :usage
+ end
+
+ def archive
+ self.destroy
+ end
+ end
+end
View
21 lib/chargify_api_ares/resources/customer.rb
@@ -0,0 +1,21 @@
+module Chargify
+ class Customer < Base
+ def self.find_by_reference(reference)
+ Customer.new get(:lookup, :reference => reference)
+ end
+
+ class Subscription < Base
+ self.prefix = "/customers/:customer_id/"
+ end
+
+ def subscriptions(params = {})
+ params.merge!({:customer_id => self.id})
+ Subscription.find(:all, :params => params)
+ end
+
+ def payment_profiles(params = {})
+ params.merge!({:customer_id => self.id})
+ PaymentProfile.find(:all, :params => params)
+ end
+ end
+end
View
4 lib/chargify_api_ares/resources/payment_profile.rb
@@ -0,0 +1,4 @@
+module Chargify
+ class PaymentProfile < Base
+ end
+end
View
25 lib/chargify_api_ares/resources/product.rb
@@ -0,0 +1,25 @@
+module Chargify
+ class Product < Base
+ def self.find_by_handle(handle)
+ Product.new get(:lookup, :handle => handle)
+ end
+
+ protected
+
+ # Products are created in the scope of a ProductFamily, i.e. /product_families/nnn/products
+ #
+ # This alters the collection path such that it uses the product_family_id that is set on the
+ # attributes.
+ def create
+ pfid = begin
+ self.product_family_id
+ rescue NoMethodError
+ 0
+ end
+ connection.post("/product_families/#{pfid}/products.#{self.class.format.extension}", encode, self.class.headers).tap do |response|
+ self.id = id_from_response(response)
+ load_attributes_from_response(response)
+ end
+ end
+ end
+end
View
34 lib/chargify_api_ares/resources/product_family.rb
@@ -0,0 +1,34 @@
+module Chargify
+ class ProductFamily < Base
+ def self.find_by_handle(handle, attributes = {})
+ ProductFamily.find(:one, :from => :lookup, :params => { :handle => handle })
+ end
+
+ class Product < Base
+ self.prefix = "/product_families/:product_family_id/"
+ end
+
+ class Component < Base
+ self.prefix = "/product_families/:product_family_id/"
+ end
+
+ class Coupon < Base
+ self.prefix = "/product_families/:product_family_id/"
+ end
+
+ def products(params = {})
+ params.merge!(:product_family_id => self.id)
+ ::Chargify::ProductFamily::Product.find(:all, :params => params)
+ end
+
+ def components(params = {})
+ params.merge!({:product_family_id => self.id})
+ ::Chargify::ProductFamily::Component.find(:all, :params => params)
+ end
+
+ def coupons(params = {})
+ params.merge!(:product_family_id => self.id)
+ ::Chargify::ProductFamily::Coupon.find(:all, :params => params)
+ end
+ end
+end
View
7 lib/chargify_api_ares/resources/site.rb
@@ -0,0 +1,7 @@
+module Chargify
+ class Site < Base
+ def self.clear_data!(params = {})
+ post(:clear_data, params)
+ end
+ end
+end
View
4 lib/chargify_api_ares/resources/statement.rb
@@ -0,0 +1,4 @@
+module Chargify
+ class Statement < Base
+ end
+end
View
119 lib/chargify_api_ares/resources/subscription.rb
@@ -0,0 +1,119 @@
+module Chargify
+ class Subscription < Base
+ def self.find_by_customer_reference(reference)
+ customer = Customer.find_by_reference(reference)
+ find(:first, :params => {:customer_id => customer.id})
+ end
+
+ # Strip off nested attributes of associations before saving, or type-mismatch errors will occur
+ def save
+ self.attributes.delete('customer')
+ self.attributes.delete('product')
+ self.attributes.delete('credit_card')
+ super
+ end
+
+ def cancel
+ destroy
+ end
+
+ def component(id)
+ Component.find(id, :params => {:subscription_id => self.id})
+ end
+
+ def components(params = {})
+ params.merge!({:subscription_id => self.id})
+ Component.find(:all, :params => params)
+ end
+
+ def payment_profile
+ self.respond_to?('credit_card') ? credit_card : nil
+ end
+
+ # Perform a one-time charge on an existing subscription.
+ # For more information, please see the one-time charge API docs available
+ # at: http://support.chargify.com/faqs/api/api-charges
+ def charge(attrs = {})
+ post :charges, {}, attrs.to_xml(:root => :charge)
+ end
+
+ def credit(attrs = {})
+ post :credits, {}, attrs.to_xml(:root => :credit)
+ end
+
+ def refund(attrs = {})
+ post :refunds, {}, attrs.to_xml(:root => :refund)
+ end
+
+ def reactivate(params = {})
+ put :reactivate, params
+ end
+
+ def reset_balance
+ put :reset_balance
+ end
+
+ def migrate(attrs = {})
+ post :migrations, :migration => attrs
+ end
+
+ def statement(id)
+ statement = Chargify::Statement.find(id)
+ raise ActiveResource::ResourceNotFound.new(nil) if (statement.subscription_id != self.id)
+ statement
+ end
+
+ def statements(params = {})
+ params.merge!(:subscription_id => self.id)
+ Statement.find(:all, :params => params)
+ end
+
+ def transactions(params = {})
+ params.merge!(:subscription_id => self.id)
+ Transaction.find(:all, :params => params)
+ end
+
+ def adjustment(attrs = {})
+ post :adjustments, {}, attrs.to_xml(:root => :adjustment)
+ end
+
+ def add_coupon(code)
+ post :add_coupon, :code => code
+ end
+
+ def remove_coupon(code)
+ delete :remove_coupon, :code => code
+ end
+
+ class Component < Base
+ self.prefix = "/subscriptions/:subscription_id/"
+
+ # All Subscription Components are considered already existing records, but the id isn't used
+ def id
+ self.component_id
+ end
+ end
+
+ class Statement < Base
+ self.prefix = "/subscriptions/:subscription_id/"
+ end
+
+ class Transaction < Base
+ self.prefix = "/subscriptions/:subscription_id/"
+
+ def full_refund(attrs = {})
+ return false if self.transaction_type != 'payment'
+
+ attrs.merge!(:amount_in_cents => self.amount_in_cents)
+ self.refund(attrs)
+ end
+
+ def refund(attrs = {})
+ return false if self.transaction_type != 'payment'
+
+ attrs.merge!(:payment_id => self.id)
+ Subscription.find(self.prefix_options[:subscription_id]).refund(attrs)
+ end
+ end
+ end
+end
View
17 lib/chargify_api_ares/resources/transaction.rb
@@ -0,0 +1,17 @@
+module Chargify
+ class Transaction < Base
+ def full_refund(attrs = {})
+ return false if self.transaction_type != 'payment'
+
+ attrs.merge!(:amount_in_cents => self.amount_in_cents)
+ self.refund(attrs)
+ end
+
+ def refund(attrs = {})
+ return false if self.transaction_type != 'payment'
+
+ attrs.merge!(:payment_id => self.id)
+ Subscription.find(self.subscription_id).refund(attrs)
+ end
+ end
+end
View
11 lib/chargify_api_ares/resources/usage.rb
@@ -0,0 +1,11 @@
+module Chargify
+ class Usage < Base
+ def subscription_id=(i)
+ self.prefix_options[:subscription_id] = i
+ end
+
+ def component_id=(i)
+ self.prefix_options[:component_id] = i
+ end
+ end
+end
View
48 spec/components_spec.rb
@@ -1,48 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Chargify::Component do
- describe "Recording usage" do
- before do
- @subscription = Factory(:subscription)
- @component = Factory(:component)
- @now = DateTime.now.to_s
- end
-
- it "should create a usage record" do
- u = Chargify::Usage.new
- u.subscription_id = @subscription.id
- u.component_id = @component.id
- u.quantity = 5
- u.memo = @now
- u.save
-
- component = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
- component.memo.should == @now
- component.quantity.should == 5
- end
- end
-
- describe "Listing usages" do
- before do
- @subscription = Factory(:subscription)
- @component = Factory(:component)
- @now = DateTime.now.to_s
- create_usage
- end
-
- it "should return all usages for a component and subscription" do
- component = Chargify::Usage.find(:last, :params => {:subscription_id => @subscription.id, :component_id => @component.id})
- component.quantity.should == 5
- end
- end
-
- def create_usage
- u = Chargify::Usage.new
- u.subscription_id = @subscription.id
- u.component_id = @component.id
- u.quantity = 5
- u.memo = @now
- u.save
- end
-end
-
View
35 spec/coupon_spec.rb
@@ -1,35 +0,0 @@
-require 'spec_helper'
-
-describe Chargify::Coupon do
- context '.find_by_product_family_id_and_code' do
- let(:existing_coupon) { Factory.build(:coupon, :code => '20OFF') }
-
- before do
- FakeWeb.register_uri(:get, "#{test_domain}/product_families/10/coupons/lookup.xml?code=#{existing_coupon.code}", :body => existing_coupon.attributes.to_xml)
- end
-
- it "finds the correct coupon by product family and code" do
- Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF').should == existing_coupon
- end
-
- it "is an instance of Chargify::Coupon" do
- coupon = Chargify::Coupon.find_by_product_family_id_and_code(10, '20OFF')
- coupon.should be_instance_of(Chargify::Coupon)
- end
- end
-
- context '.find_all_by_product_family_id' do
- let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
- let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
-
- before do
- FakeWeb.register_uri(:get, "#{test_domain}/product_families/5/coupons.xml", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
- end
-
- it "returns all of the coupons for a product family" do
- coupons = Chargify::Coupon.find_all_by_product_family_id(5)
- coupons.count.should == 2
- coupons.map{|c| c.should be_instance_of(Chargify::Coupon)}
- end
- end
-end
View
23 spec/customer_spec.rb
@@ -1,23 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Chargify::Customer do
-
- context 'find by reference' do
- before do
- @reference = 'ref0123'
- @existing_customer = Factory(:customer, :reference => @reference, :id => FactoryGirl.generate(:customer_id))
- FakeWeb.register_uri(:get, "#{test_domain}/customers/lookup.xml?reference=#{@existing_customer.reference}", :body => @existing_customer.attributes.to_xml)
- end
-
- it 'finds the correct customer by reference' do
- customer = Chargify::Customer.find_by_reference(@reference)
- customer.should eql(@existing_customer)
- end
-
- it 'is an instance of Chargify::Customer' do
- customer = Chargify::Customer.find_by_reference(@reference)
- customer.should be_instance_of(Chargify::Customer)
- end
- end
-
-end
View
52 spec/factories.rb
@@ -2,46 +2,50 @@
sequence :email do |n|
"customer#{n}@example.com"
end
-
+
+ sequence :product_name do |n|
+ "Product #{n}"
+ end
+
sequence :customer_id do |n|
n
end
-
- factory :customer, :class => Chargify::Customer do |c|
- c.first_name { Faker::Name.first_name }
- c.last_name { Faker::Name.last_name }
- c.email { FactoryGirl.generate(:email) }
- c.organization { Faker::Company.name }
- c.created_at { 2.days.ago }
- c.updated_at { 1.hour.ago }
+
+ sequence :subscription_id do |n|
+ n
end
-
-
+
sequence :product_id do |n|
n
end
- sequence :product_name do |n|
- "Product #{n}"
+ factory :customer, :class => Chargify::Customer do |f|
+ f.first_name { Faker::Name.first_name }
+ f.last_name { Faker::Name.last_name }
+ f.email { FactoryGirl.generate(:email) }
+ f.organization { Faker::Company.name }
+ f.created_at { 2.days.ago }
+ f.updated_at { 1.hour.ago }
end
- factory :product, :class => Chargify::Product do |p|
- p.name { FactoryGirl.generate(:product_name) }
+ factory :product, :class => Chargify::Product do |f|
+ f.name { FactoryGirl.generate(:product_name) }
end
- sequence :subscription_id do |n|
- n
+ factory :product_family, :class => Chargify::ProductFamily do |f|
+ f.name { Faker::Name.name }
+ f.handle 'mining'
end
- factory :subscription, :class => Chargify::Subscription do |s|
- s.balance_in_cents 500
- s.current_period_ends_at 3.days.from_now
+ factory :subscription, :class => Chargify::Subscription do |f|
+ f.balance_in_cents 500
+ f.current_period_ends_at 3.days.from_now
end
- factory :subscription_with_extra_attrs, :parent => :subscription do |swea|
- swea.customer Chargify::Customer.new
- swea.product Chargify::Product.new
- swea.credit_card "CREDIT CARD"
+ factory :subscription_with_extra_attrs, :parent => :subscription do |f|
+ f.customer Chargify::Customer.new
+ f.product Chargify::Product.new
+ f.credit_card "CREDIT CARD"
end
factory :component, :class => Chargify::Component do |f|
View
33 spec/product_families_component_spec.rb
@@ -1,33 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Chargify::Subscription::Component do
- before(:each) do
- @product_family = Chargify::ProductFamily.new(:id => 1)
- @component = Chargify::ProductFamily::Component.new(
- :id => 2,
- :name => "Purple Widgets",
- :pricing_scheme => "per_unit",
- :product_family_id => 1,
- :unit_name => "purple widget",
- :unit_price => 2.99,
- :kind => "quantity_based_component",
- :prices => []
- )
-
- @product_family_components = [ @component ]
-
- end
-
- describe "listing subscription components" do
- before(:each) do
- FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}.xml", :body => @product_family.to_xml)
- FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}/components.xml", :body => @product_family_components.to_xml(:root => 'components'))
- end
-
- it "returns an array of components from Chargify::ProductFamily.find(1).components" do
- product_family = Chargify::ProductFamily.find(@product_family.id)
- product_family.components.should == @product_family_components
- end
-
- end
-end
View
29 spec/product_families_spec.rb
@@ -1,29 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Chargify::ProductFamily do
- context "#find_by_handle" do
- let(:product_family) { Chargify::ProductFamily.new(:id => 1, :handle => 'farming') }
-
- before(:each) do
- FakeWeb.register_uri(:get, "#{test_domain}/product_families/lookup.xml?handle=#{product_family.handle}", :body => product_family.to_xml)
- end
-
- it "returns a product family" do
- Chargify::ProductFamily.find_by_handle('farming').should == product_family
- end
- end
-
- context "#products" do
- let(:product_1) { Factory(:product) }
- let(:product_2) { Factory(:product) }
- let(:product_family) { Chargify::ProductFamily.new(:id => 1, :handle => 'farming') }
-
- before(:each) do
- FakeWeb.register_uri(:get, "#{test_domain}/products.xml?product_family_id=#{product_family.id}", :body => [product_1.attributes, product_2.attributes].to_xml)
- end
-
- it "returns the products belonging to the product family" do
- product_family.products.should =~ [product_1, product_2]
- end
- end
-end
View
23 spec/product_spec.rb
@@ -1,23 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe Chargify::Product do
-
- context 'find by handle' do
- before do
- @handle = 'handle1'
- @existing_product = Factory(:product, :handle => @handle, :id => FactoryGirl.generate(:product_id))
- FakeWeb.register_uri(:get, "#{test_domain}/products/lookup.xml?handle=#{@existing_product.handle}", :body => @existing_product.attributes.to_xml)
- end
-
- it 'finds the correct product by handle' do
- product = Chargify::Product.find_by_handle(@handle)
- product.should eql(@existing_product)
- end
-
- it 'is an instance of Chargify::Product' do
- product = Chargify::Product.find_by_handle(@handle)
- product.should be_instance_of(Chargify::Product)
- end
- end
-
-end
View
4 config/remote.example.yml → spec/remote/remote.example.yml
@@ -1,7 +1,7 @@
-# Copy this file to config/remote.yml and make adjustments as necessary.
+# Copy this file to spec/remote/remote.yml and make adjustments as necessary.
#
# Note: Remote tests will only work when configured to run on a test site that uses the Bogus gateway.
# Warning: all data in the site specified by 'subdomain' will be cleared and replaced with test data.
run_tests: true
subdomain: yoursubdomain
-api_key: xxx
+api_key: xxx
View
889 spec/remote/remote_spec.rb
@@ -1,514 +1,515 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+# TODO: Fix remote specs
+# require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-if run_remote_tests?
- describe "Remote" do
- before(:all) do
- clear_site_data
- setup_plans
- setup_customer
- end
+# if run_remote_tests?
+# describe "Remote" do
+# before(:all) do
+# clear_site_data
+# setup_plans
+# setup_customer
+# end
- describe "creating a new subscription to a product with a trial" do
- context "when providing valid attributes for the customer and the payment profile" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => valid_customer_attributes,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- end
+# describe "creating a new subscription to a product with a trial" do
+# context "when providing valid attributes for the customer and the payment profile" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@basic_plan.handle,
+# :customer_attributes => valid_customer_attributes,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# end
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
+# it "successfully creates the subscription" do
+# @subscription.should be_a(Chargify::Subscription)
+# end
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
- end
+# it "sets the current_period_started_at attribute to now" do
+# @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
+# end
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
- end
+# it "sets the current_period_ends_at attribute to 1 month from now" do
+# @subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
+# end
- it "is in the trialing state" do
- @subscription.state.should == 'trialing'
- end
- end
- end
+# it "is in the trialing state" do
+# @subscription.state.should == 'trialing'
+# end
+# end
+# end
- describe "creating a new subscription to a product without a trial" do
- context "when providing an existing customer reference and valid payment profile attributes" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- end
+# describe "creating a new subscription to a product without a trial" do
+# context "when providing an existing customer reference and valid payment profile attributes" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# end
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
+# it "successfully creates the subscription" do
+# @subscription.should be_a(Chargify::Subscription)
+# end
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
- end
+# it "sets the current_period_started_at attribute to now" do
+# @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
+# end
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
- end
+# it "sets the current_period_ends_at attribute to 1 month from now" do
+# @subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
+# end
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
+# it "is in the active state" do
+# @subscription.state.should == 'active'
+# end
- it "belongs to the existing customer" do
- @subscription.customer.should == @@johnadoe
- end
- end
+# it "belongs to the existing customer" do
+# @subscription.customer.should == @@johnadoe
+# end
+# end
- context "when providing an existing customer reference and an existing payment profile" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_id => @@johnadoes_credit_card.id.to_s
- )
- end
- end
+# context "when providing an existing customer reference and an existing payment profile" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_id => @@johnadoes_credit_card.id.to_s
+# )
+# end
+# end
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
+# it "successfully creates the subscription" do
+# @subscription.should be_a(Chargify::Subscription)
+# end
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
+# it "is in the active state" do
+# @subscription.state.should == 'active'
+# end
- it "belongs to the existing customer" do
- @subscription.customer.should == @@johnadoe
- end
+# it "belongs to the existing customer" do
+# @subscription.customer.should == @@johnadoe
+# end
- it "uses the provided credit card" do
- expected_card = Chargify::PaymentProfile.find(@@johnadoes_credit_card.id)
- @subscription.payment_profile.id.should == @@johnadoes_credit_card.id
- @subscription.payment_profile.attributes.should == expected_card.attributes
- end
- end
+# it "uses the provided credit card" do
+# expected_card = Chargify::PaymentProfile.find(@@johnadoes_credit_card.id)
+# @subscription.payment_profile.id.should == @@johnadoes_credit_card.id
+# @subscription.payment_profile.attributes.should == expected_card.attributes
+# end
+# end
- context "when providing valid attributes for the customer and attributes for a credit card that cannot be stored" do
- before(:each) do
- @customer_attributes = valid_customer_attributes.dup
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => @customer_attributes,
- :payment_profile_attributes => unstorable_payment_profile_attributes
- )
- end
- end
+# context "when providing valid attributes for the customer and attributes for a credit card that cannot be stored" do
+# before(:each) do
+# @customer_attributes = valid_customer_attributes.dup
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@basic_plan.handle,
+# :customer_attributes => @customer_attributes,
+# :payment_profile_attributes => unstorable_payment_profile_attributes
+# )
+# end
+# end
- it "does not create the subscription" do
- @subscription.should_not be_valid
- end
+# it "does not create the subscription" do
+# @subscription.should_not be_valid
+# end
- it "does not create the customer" do
- lambda {
- Chargify::Customer.find_by_reference(@customer_attributes[:reference])
- }.should raise_error(ActiveResource::ResourceNotFound)
- end
- end
+# it "does not create the customer" do
+# lambda {
+# Chargify::Customer.find_by_reference(@customer_attributes[:reference])
+# }.should raise_error(ActiveResource::ResourceNotFound)
+# end
+# end
- end
+# end
- describe "importing a subscription to a product with a trial and a next billing date 10 days from now" do
- context "when giving valid attributes for the customer and the payment profile" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => valid_customer_attributes,
- :payment_profile_attributes => pretokenized_card_attributes,
- :next_billing_at => ten_days_from_now.utc
- )
- end
- end
+# describe "importing a subscription to a product with a trial and a next billing date 10 days from now" do
+# context "when giving valid attributes for the customer and the payment profile" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@basic_plan.handle,
+# :customer_attributes => valid_customer_attributes,
+# :payment_profile_attributes => pretokenized_card_attributes,
+# :next_billing_at => ten_days_from_now.utc
+# )
+# end
+# end
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
+# it "successfully creates the subscription" do
+# @subscription.should be_a(Chargify::Subscription)
+# end
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
- end
+# it "sets the current_period_started_at attribute to now" do
+# @subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
+# end
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_close(ten_days_from_now.utc, approximately)
- end
+# it "sets the current_period_ends_at attribute to 1 month from now" do
+# @subscription.current_period_ends_at.utc.should be_close(ten_days_from_now.utc, approximately)
+# end
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
- end
- end
+# it "is in the active state" do
+# @subscription.state.should == 'active'
+# end
+# end
+# end
- describe "creating failed subscriptions" do
- context "due to providing payment profile attribtues for a card that will be declined" do
- before(:each) do
- @customer_attributes = valid_customer_attributes.dup
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_attributes => @customer_attributes,
- :payment_profile_attributes => declined_payment_profile_attributes
- )
- end
- end
+# describe "creating failed subscriptions" do
+# context "due to providing payment profile attribtues for a card that will be declined" do
+# before(:each) do
+# @customer_attributes = valid_customer_attributes.dup
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_attributes => @customer_attributes,
+# :payment_profile_attributes => declined_payment_profile_attributes
+# )
+# end
+# end
- it "does not create the subscription" do
- @subscription.should_not be_valid
- end
+# it "does not create the subscription" do
+# @subscription.should_not be_valid
+# end
- it "does not create the customer" do
- lambda {
- Chargify::Customer.find_by_reference(@customer_attributes[:reference])
- }.should raise_error(ActiveResource::ResourceNotFound)
- end
- end
- end
+# it "does not create the customer" do
+# lambda {
+# Chargify::Customer.find_by_reference(@customer_attributes[:reference])
+# }.should raise_error(ActiveResource::ResourceNotFound)
+# end
+# end
+# end
- describe "cancelling a subscription" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- @subscription.cancel
- end
+# describe "cancelling a subscription" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# @subscription.cancel
+# end
- it "is in the canceled state" do
- Chargify::Subscription.find(@subscription.id).state.should == 'canceled'
- end
- end
+# it "is in the canceled state" do
+# Chargify::Subscription.find(@subscription.id).state.should == 'canceled'
+# end
+# end
- describe "reactivating a subscriptions" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- @subscription.cancel
- @subscription.reload.state.should == 'canceled'
- @subscription.reactivate
- end
+# describe "reactivating a subscriptions" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# @subscription.cancel
+# @subscription.reload.state.should == 'canceled'
+# @subscription.reactivate
+# end
- it "puts it in the active state" do
- @subscription.reload.state.should == 'active'
- end
- end
+# it "puts it in the active state" do
+# @subscription.reload.state.should == 'active'
+# end
+# end
- describe "adding a one time charge" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- end
- it "creates a charge and payment" do
- lambda{
- @subscription.charge(:amount => 7, :memo => 'One Time Charge')
- }.should change{@subscription.reload.transactions.size}.by(2)
- @subscription.transactions.first.amount_in_cents.should == 700
- end
- end
+# describe "adding a one time charge" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# end
+# it "creates a charge and payment" do
+# lambda{
+# @subscription.charge(:amount => 7, :memo => 'One Time Charge')
+# }.should change{@subscription.reload.transactions.size}.by(2)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# end
+# end
- describe "adding a credit" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
- end
+# describe "adding a credit" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
+# end
- it "creates a credit" do
- lambda{
- @subscription.credit(:amount => 7, :memo => 'credit')
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == -700
- end
- end
+# it "creates a credit" do
+# lambda{
+# @subscription.credit(:amount => 7, :memo => 'credit')
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == -700
+# end
+# end
- describe "adding a refund" do
- before(:each) do
- @subscription = create_once(:subscription) do
- Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
+# describe "adding a refund" do
+# before(:each) do
+# @subscription = create_once(:subscription) do
+# Chargify::Subscription.create(
+# :product_handle => @@pro_plan.handle,
+# :customer_reference => @@johnadoe.reference,
+# :payment_profile_attributes => good_payment_profile_attributes
+# )
+# end
- @subscription.charge(:amount => 7, :memo => 'One Time Charge')
- @subscription.reload
- end
+# @subscription.charge(:amount => 7, :memo => 'One Time Charge')
+# @subscription.reload
+# end
- it "creates a refund" do
- lambda{
- @subscription.refund :payment_id => @subscription.transactions[0].id, :amount => 7,
- :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == 700
- @subscription.transactions.first.transaction_type.should == 'refund'
- end
+# it "creates a refund" do
+# lambda{
+# @subscription.refund :payment_id => @subscription.transactions[0].id, :amount => 7,
+# :memo => 'Refunding One Time Charge'
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# @subscription.transactions.first.transaction_type.should == 'refund'
+# end
- context "via subscription payment (Chargify::Subscription::Transaction)" do
- before :each do
- @payment = @subscription.transactions.first
- end
+# context "via subscription payment (Chargify::Subscription::Transaction)" do
+# before :each do
+# @payment = @subscription.transactions.first
+# end
- it "creates a refund" do
- lambda{
- @payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == 700
- @subscription.transactions.first.transaction_type.should == 'refund'
- end
+# it "creates a refund" do
+# lambda{
+# @payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# @subscription.transactions.first.transaction_type.should == 'refund'
+# end
- it "creates a full refund" do
- lambda{
- @payment.full_refund :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == 700
- @subscription.transactions.first.transaction_type.should == 'refund'
- end
- end
+# it "creates a full refund" do
+# lambda{
+# @payment.full_refund :memo => 'Refunding One Time Charge'
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# @subscription.transactions.first.transaction_type.should == 'refund'
+# end
+# end
- context "via site payment (Chargify::Transaction)" do
- before :each do
- @site_payment = Chargify::Transaction.find(:first)
- end
+# context "via site payment (Chargify::Transaction)" do
+# before :each do
+# @site_payment = Chargify::Transaction.find(:first)
+# end
- it "creates a refund" do
- lambda{
- @site_payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == 700
- @subscription.transactions.first.transaction_type.should == 'refund'
- end
+# it "creates a refund" do
+# lambda{
+# @site_payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# @subscription.transactions.first.transaction_type.should == 'refund'
+# end
- it "creates a full refund" do
- lambda{
- @site_payment.full_refund :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- @subscription.transactions.first.amount_in_cents.should == 700
- @subscription.transactions.first.transaction_type.should == 'refund'
- end
- end
- end
+# it "creates a full refund" do
+# lambda{
+# @site_payment.full_refund :memo => 'Refunding One Time Charge'
+# }.should change{@subscription.reload.transactions.size}.by(1)
+# @subscription.transactions.first.amount_in_cents.should == 700
+# @subscription.transactions.first.transaction_type.should == 'refund'
+# end
+# end
+# end
- def already_cleared_site_data?
- @@already_cleared_site_data ||= nil
- @@already_cleared_site_data == true
- end
+# def already_cleared_site_data?
+# @@already_cleared_site_data ||= nil
+# @@already_cleared_site_data == true
+# end
- def cleared_site_data!
- @@already_cleared_site_data = true
- end
+# def cleared_site_data!
+# @@already_cleared_site_data = true
+# end
- def clear_site_data
- return if already_cleared_site_data?
- begin
- Chargify::Site.clear_data!
- cleared_site_data!
- rescue ActiveResource::ForbiddenAccess
- raise StandardError.new("Remote specs may only be run against a site in test mode")
- end
- end
+# def clear_site_data
+# return if already_cleared_site_data?
+# begin
+# Chargify::Site.clear_data!
+# cleared_site_data!
+# rescue ActiveResource::ForbiddenAccess
+# raise StandardError.new("Remote specs may only be run against a site in test mode")
+# end
+# end
- # Create Basic and Pro products in the Acme Projects family
- def setup_plans
- begin
- @@acme_projects ||= Chargify::ProductFamily.find_by_handle('acme-projects')
- rescue ActiveResource::ResourceNotFound
- @@acme_projects = Chargify::ProductFamily.new(
- :name => "Acme Projects"
- )
- result = @@acme_projects.save
- result.should be_true
- end
+# # Create Basic and Pro products in the Acme Projects family
+# def setup_plans
+# begin
+# @@acme_projects ||= Chargify::ProductFamily.find_by_handle('acme-projects')
+# rescue ActiveResource::ResourceNotFound
+# @@acme_projects = Chargify::ProductFamily.new(
+# :name => "Acme Projects"
+# )
+# result = @@acme_projects.save
+# result.should be_true
+# end
- begin
- @@basic_plan ||= Chargify::Product.find_by_handle('basic')
- rescue ActiveResource::ResourceNotFound
- @@basic_plan = Chargify::Product.new(
- :product_family_id => @@acme_projects.id,
- :name => "Basic Plan",
- :handle => "basic",
- :price_in_cents => 1000,
- :interval => 1,
- :interval_unit => 'month',
- :trial_interval => 1,
- :trial_interval_unit => 'month',
- :trial_price_in_cents => 0
- )
- result = @@basic_plan.save
- result.should be_true
- end
+# begin
+# @@basic_plan ||= Chargify::Product.find_by_handle('basic')
+# rescue ActiveResource::ResourceNotFound
+# @@basic_plan = Chargify::Product.new(
+# :product_family_id => @@acme_projects.id,
+# :name => "Basic Plan",
+# :handle => "basic",
+# :price_in_cents => 1000,
+# :interval => 1,
+# :interval_unit => 'month',
+# :trial_interval => 1,
+# :trial_interval_unit => 'month',
+# :trial_price_in_cents => 0
+# )
+# result = @@basic_plan.save
+# result.should be_true
+# end
- begin
- @@pro_plan ||= Chargify::Product.find_by_handle('pro')
- rescue ActiveResource::ResourceNotFound
- @@pro_plan = Chargify::Product.new(
- :product_family_id => @@acme_projects.id,
- :name => "Pro Plan",
- :handle => "pro",
- :price_in_cents => 5000,
- :interval => 1,
- :interval_unit => 'month'
- )
- result = @@pro_plan.save
- result.should be_true
- end
- end
+# begin
+# @@pro_plan ||= Chargify::Product.find_by_handle('pro')
+# rescue ActiveResource::ResourceNotFound
+# @@pro_plan = Chargify::Product.new(
+# :product_family_id => @@acme_projects.id,
+# :name => "Pro Plan",
+# :handle => "pro",
+# :price_in_cents => 5000,
+# :interval => 1,
+# :interval_unit => 'month'
+# )
+# result = @@pro_plan.save
+# result.should be_true
+# end
+# end
- def setup_customer
- # Create a customer
- begin
- @@johnadoe ||= Chargify::Customer.find_by_reference('a')
- rescue ActiveResource::ResourceNotFound
- @@johnadoe = Chargify::Customer.new(valid_customer_attributes)
- result = @@johnadoe.save
- result.should be_true
+# def setup_customer
+# # Create a customer
+# begin
+# @@johnadoe ||= Chargify::Customer.find_by_reference('a')
+# rescue ActiveResource::ResourceNotFound
+# @@johnadoe = Chargify::Customer.new(valid_customer_attributes)
+# result = @@johnadoe.save
+# result.should be_true
- @@johnadoes_credit_card = Chargify::PaymentProfile.new(
- good_payment_profile_attributes.merge(:customer_id => @@johnadoe.id)
- )
- result = @@johnadoes_credit_card.save
- result.should be_true
- end
- end
+# @@johnadoes_credit_card = Chargify::PaymentProfile.new(
+# good_payment_profile_attributes.merge(:customer_id => @@johnadoe.id)
+# )
+# result = @@johnadoes_credit_card.save
+# result.should be_true
+# end
+# end
- def now
- Time.now
- end
+# def now
+# Time.now
+# end
- def one_month_from_now
- Time.now + 1.month
- end
+# def one_month_from_now
+# Time.now + 1.month
+# end
- def ten_days_from_now
- 10.days.from_now
- end
+# def ten_days_from_now
+# 10.days.from_now
+# end
- # Gives a reasonable range for time comparisons
- def approximately
- @approximately ||= 5.minutes
- end
+# # Gives a reasonable range for time comparisons
+# def approximately
+# @approximately ||= 5.minutes
+# end
- def valid_customer_attributes
- initial = next_customer_initial
- {
- :first_name => "John #{initial.upcase}",
- :last_name => "Doe",
- :email => "john.#{initial}.doe@example.com",
- :reference => initial
- }
- end
+# def valid_customer_attributes
+# initial = next_customer_initial
+# {
+# :first_name => "John #{initial.upcase}",
+# :last_name => "Doe",
+# :email => "john.#{initial}.doe@example.com",