saasaparilla 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -0
- data/Gemfile +5 -5
- data/app/controllers/saasaparilla/admin/subscriptions_controller.rb +1 -1
- data/app/controllers/saasaparilla/subscription_controller.rb +1 -2
- data/app/models/billing_activity.rb +2 -0
- data/app/models/contact_info.rb +2 -0
- data/app/models/credit_card.rb +2 -0
- data/app/models/invoice.rb +2 -0
- data/app/models/invoice_line_item.rb +2 -1
- data/app/models/plan.rb +2 -0
- data/app/models/subscription.rb +18 -6
- data/app/models/transaction.rb +1 -0
- data/app/views/saasaparilla/notifier/invoice_created.html.haml +1 -0
- data/app/views/saasaparilla/subscription/new.html.haml +2 -2
- data/config/routes.rb +11 -11
- data/lib/saasaparilla/engine.rb +1 -1
- data/lib/saasaparilla/version.rb +1 -1
- data/spec/dummy/config/saasaparilla.yml +2 -2
- data/spec/dummy/public/javascripts/jquery_ujs.js +373 -0
- data/spec/factories/factories.rb +1 -1
- data/spec/mailers/notifier_spec.rb +1 -1
- data/spec/models/credit_card_spec.rb +2 -2
- data/spec/models/plan_spec.rb +3 -1
- data/spec/models/subscription_spec.rb +3 -3
- data/spec/requests/admin_subscriptions_spec.rb +2 -1
- data/spec/requests/billing_history_spec.rb +1 -0
- data/spec/requests/credit_cards_spec.rb +1 -1
- data/spec/requests/subscriptions_spec.rb +5 -4
- data/spec/spec_helper.rb +4 -1
- metadata +160 -51
- data/spec/dummy/public/javascripts/rails.js +0 -159
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@saasaparilla
|
data/Gemfile
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
|
-
gem "rails", "3.0.
|
4
|
+
gem "rails", "3.0.6"
|
5
5
|
|
6
6
|
gem "sqlite3"
|
7
7
|
gem 'haml'
|
8
8
|
gem 'will_paginate'
|
9
|
-
|
9
|
+
gem "pry"
|
10
10
|
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
11
|
-
gem RUBY_VERSION.include?('1.9') ? 'ruby-debug19' : 'ruby-debug'
|
11
|
+
#gem RUBY_VERSION.include?('1.9') ? 'ruby-debug19' : 'ruby-debug'
|
12
12
|
|
13
13
|
gem "jquery-rails"
|
14
14
|
gem "dynamic_attributes"
|
15
15
|
gem "authlogic"
|
16
|
-
gem 'activemerchant', "
|
16
|
+
gem 'activemerchant', "1.20.0"
|
17
17
|
gem 'simple_form'
|
18
18
|
gem 'dynamic_form'
|
19
19
|
gem 'state_machine'
|
@@ -24,7 +24,7 @@ group :development, :test do
|
|
24
24
|
gem "autotest-growl"
|
25
25
|
gem "autotest-fsevent"
|
26
26
|
gem "autotest-rails"
|
27
|
-
gem "factory_girl_rails", "
|
27
|
+
gem "factory_girl_rails", "1.0.1"
|
28
28
|
gem "rspec-rails"
|
29
29
|
|
30
30
|
gem 'database_cleaner'
|
@@ -6,7 +6,7 @@ class Saasaparilla::Admin::SubscriptionsController < ApplicationController
|
|
6
6
|
|
7
7
|
# GET /admin/subscriptions
|
8
8
|
def index
|
9
|
-
@subscriptions = Subscription.
|
9
|
+
@subscriptions = Subscription.paginate(:page => params[:page], :per_page => 20, :order => "created_at DESC")
|
10
10
|
end
|
11
11
|
|
12
12
|
def show
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Saasaparilla::SubscriptionController < ApplicationController
|
2
2
|
unloadable
|
3
|
-
ssl_required :new, :create, :show
|
3
|
+
ssl_required :new, :create, :show if Rails.env == "production"
|
4
4
|
include Authentication::InstanceMethods
|
5
5
|
before_filter :get_subscription, :only => [:show, :destroy, :reactivate]
|
6
6
|
|
@@ -14,7 +14,6 @@ class Saasaparilla::SubscriptionController < ApplicationController
|
|
14
14
|
|
15
15
|
def create
|
16
16
|
@subscription = current_billable.build_subscription(params[:subscription])
|
17
|
-
|
18
17
|
begin
|
19
18
|
if @subscription.save
|
20
19
|
redirect_to subscription_path
|
@@ -3,6 +3,8 @@ class BillingActivity < ActiveRecord::Base
|
|
3
3
|
has_one :invoice
|
4
4
|
has_one :transaction
|
5
5
|
|
6
|
+
attr_accessible :action, :amount, :response, :subscription, :invoice, :message
|
7
|
+
|
6
8
|
MESSAGES = {:success => "Thank you for your payment."}
|
7
9
|
scope :recent, order("created_at DESC")
|
8
10
|
|
data/app/models/contact_info.rb
CHANGED
@@ -5,6 +5,8 @@ class ContactInfo < ActiveRecord::Base
|
|
5
5
|
validates_format_of :email, :with => ::Authlogic::Regex.email
|
6
6
|
validates_presence_of :email
|
7
7
|
|
8
|
+
attr_accessible :first_name, :last_name, :email, :address, :city, :state, :zip, :country, :phone_area_code, :phone_prefix, :phone_suffix, :phone_number
|
9
|
+
|
8
10
|
with_options :if => :require_billing_address? do |contact_info|
|
9
11
|
contact_info.validates_presence_of :address
|
10
12
|
contact_info.validates_presence_of :city
|
data/app/models/credit_card.rb
CHANGED
@@ -18,6 +18,8 @@ class CreditCard < ActiveRecord::Base
|
|
18
18
|
MONTHS = (1..12).to_a
|
19
19
|
YEARS = ((Date.today.year)..(Date.today.year + 8)).to_a
|
20
20
|
|
21
|
+
attr_accessible :card_type, :card_number, :expiry_month, :expiry_year, :card_verification
|
22
|
+
|
21
23
|
belongs_to :subscription
|
22
24
|
|
23
25
|
before_save :mask_card_number
|
data/app/models/invoice.rb
CHANGED
@@ -9,6 +9,7 @@ class Invoice < ActiveRecord::Base
|
|
9
9
|
|
10
10
|
|
11
11
|
def amount
|
12
|
+
|
12
13
|
invoice_line_items.sum(:price)
|
13
14
|
end
|
14
15
|
|
@@ -25,6 +26,7 @@ class Invoice < ActiveRecord::Base
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def send_invoice_created_email
|
29
|
+
|
28
30
|
Saasaparilla::Notifier.invoice_created(billing_activity.subscription, self).deliver
|
29
31
|
end
|
30
32
|
|
data/app/models/plan.rb
CHANGED
data/app/models/subscription.rb
CHANGED
@@ -11,10 +11,12 @@ class Subscription < ActiveRecord::Base
|
|
11
11
|
belongs_to :billable, :polymorphic => true
|
12
12
|
has_one :credit_card
|
13
13
|
accepts_nested_attributes_for :credit_card
|
14
|
+
before_validation :set_status
|
15
|
+
before_validation :set_credit_card_name
|
16
|
+
before_create :set_status
|
14
17
|
before_create :create_cim_profile
|
15
18
|
before_create :create_payment_profile
|
16
|
-
|
17
|
-
before_validation :set_credit_card_name
|
19
|
+
|
18
20
|
before_create :set_initial_balance
|
19
21
|
after_rollback :delete_profile
|
20
22
|
after_create :initial_bill
|
@@ -23,6 +25,7 @@ class Subscription < ActiveRecord::Base
|
|
23
25
|
validates_presence_of :plan, :message => "can't be blank"
|
24
26
|
validates_associated :credit_card, :contact_info, :on => :create
|
25
27
|
|
28
|
+
attr_accessible :plan_id, :contact_info_attributes, :credit_card_attributes, :billing_date, :status, :invoice, :invoiced_on, :balance, :plan, :downgrade_to_plan
|
26
29
|
|
27
30
|
scope :active, where("status != ?", "canceled")
|
28
31
|
|
@@ -32,7 +35,7 @@ class Subscription < ActiveRecord::Base
|
|
32
35
|
|
33
36
|
scope :all_invoiceable, lambda {|date|
|
34
37
|
#find all subscriptions not been invoiced within the last month
|
35
|
-
where("billing_date <= ? and (invoiced_on > ? OR invoiced_on is null)
|
38
|
+
where("billing_date <= ? and (invoiced_on > ? OR invoiced_on is null)", date + 5.days, (date - 1.months).to_time)
|
36
39
|
}
|
37
40
|
|
38
41
|
scope :all_paid, where("no_charge != ?", true)
|
@@ -75,6 +78,10 @@ class Subscription < ActiveRecord::Base
|
|
75
78
|
end
|
76
79
|
end
|
77
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
78
85
|
|
79
86
|
def downgrade
|
80
87
|
self.plan = downgrade_to_plan
|
@@ -137,9 +144,10 @@ class Subscription < ActiveRecord::Base
|
|
137
144
|
|
138
145
|
|
139
146
|
def invoice!
|
147
|
+
|
140
148
|
add_to_balance(plan.price)
|
141
149
|
create_invoice
|
142
|
-
self.update_attributes(:invoiced_on => Date.today)
|
150
|
+
self.update_attributes!(:invoiced_on => Date.today)
|
143
151
|
#if invoice_subscription
|
144
152
|
# set_next_invoice_date()
|
145
153
|
end
|
@@ -176,10 +184,11 @@ class Subscription < ActiveRecord::Base
|
|
176
184
|
private
|
177
185
|
|
178
186
|
def create_invoice
|
179
|
-
@invoice = Invoice.create(:subscription => self, :price => plan.price, :from => get_beginning_of_billing_cycle, :to => billing_date)
|
187
|
+
@invoice = Invoice.create!(:subscription => self, :price => plan.price, :from => get_beginning_of_billing_cycle, :to => billing_date)
|
180
188
|
end
|
181
189
|
|
182
190
|
def get_beginning_of_billing_cycle
|
191
|
+
|
183
192
|
if monthly?
|
184
193
|
return billing_date - 1.months
|
185
194
|
elsif annually?
|
@@ -272,7 +281,9 @@ class Subscription < ActiveRecord::Base
|
|
272
281
|
end
|
273
282
|
|
274
283
|
def set_status
|
275
|
-
self.status
|
284
|
+
unless self.status.present?
|
285
|
+
self.status = "active"
|
286
|
+
end
|
276
287
|
end
|
277
288
|
|
278
289
|
def set_initial_balance
|
@@ -286,6 +297,7 @@ class Subscription < ActiveRecord::Base
|
|
286
297
|
:customer_profile_id => customer_cim_id,
|
287
298
|
:customer_payment_profile_id => customer_payment_profile_id})
|
288
299
|
|
300
|
+
|
289
301
|
transaction = self.transactions.create(:action => "purchase", :amount => amount, :response => response, :subscription => self)
|
290
302
|
if response.success?
|
291
303
|
self.update_attributes(:balance => balance - amount)
|
data/app/models/transaction.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
.saasaparilla
|
2
2
|
%h1 Create Subscription
|
3
3
|
|
4
|
-
= simple_form_for @subscription, :url => subscription_path(:secure =>
|
4
|
+
= simple_form_for @subscription, :url => subscription_path(:secure => Rails.env == "production") do |f|
|
5
5
|
|
6
6
|
.info
|
7
7
|
%h2 Plan
|
8
|
-
= f.association :plan, :as => '
|
8
|
+
= f.association :plan, :as => 'radio_buttons', :label => false
|
9
9
|
|
10
10
|
|
11
11
|
= f.simple_fields_for :contact_info, @subscription.contact_info do |cif|
|
data/config/routes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
|
4
|
-
resources :plans
|
5
|
-
resources :subscriptions
|
3
|
+
namespace "admin", :module => 'saasaparilla/admin' do
|
4
|
+
resources :plans
|
5
|
+
resources :subscriptions do
|
6
6
|
get 'cancel', :on => :member
|
7
7
|
get 'toggle_no_charge', :on => :member
|
8
|
-
resources :transactions, :
|
8
|
+
resources :transactions, :only => [:index]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -13,13 +13,13 @@ Rails.application.routes.draw do
|
|
13
13
|
get 'reactivate', :on => :member
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
resources :payments
|
18
|
-
resource :credit_card, :controller => "
|
19
|
-
resource :plan,
|
20
|
-
resource :contact_info, :controller => "
|
21
|
-
resource :billing_history, :controller => "
|
22
|
-
resources :invoices
|
16
|
+
namespace 'subscription', :module => "saasaparilla" do
|
17
|
+
resources :payments
|
18
|
+
resource :credit_card, :controller => "credit_card"
|
19
|
+
resource :plan, :only => [:edit, :update]
|
20
|
+
resource :contact_info, :controller => "contact_info"
|
21
|
+
resource :billing_history, :controller => "billing_history"
|
22
|
+
resources :invoices
|
23
23
|
end
|
24
24
|
|
25
25
|
|
data/lib/saasaparilla/engine.rb
CHANGED
@@ -16,7 +16,7 @@ module Saasaparilla
|
|
16
16
|
require 'initializers/time_format'
|
17
17
|
if File.exists?(Rails.root.to_s + "/config/saasaparilla.yml")
|
18
18
|
raw_config = File.read(Rails.root.to_s + "/config/saasaparilla.yml")
|
19
|
-
Saasaparilla::CONFIG = YAML.load(raw_config)[
|
19
|
+
Saasaparilla::CONFIG = YAML.load(raw_config)[Rails.env]
|
20
20
|
end
|
21
21
|
require 'initializers/auth_dot_net'
|
22
22
|
|
data/lib/saasaparilla/version.rb
CHANGED
@@ -14,8 +14,8 @@ test:
|
|
14
14
|
from_email: test@dev.com
|
15
15
|
trial_period: 0
|
16
16
|
include_free_account: false
|
17
|
-
auth_dot_net_login:
|
18
|
-
auth_dot_net_password:
|
17
|
+
auth_dot_net_login: 96CsW6wJ
|
18
|
+
auth_dot_net_password: 4m74Fc7nk2BX4743
|
19
19
|
authorization: none
|
20
20
|
require_billing_address: true
|
21
21
|
require_phone_number: true
|