saasaparilla 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/Gemfile +36 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/controllers/saasaparilla/admin/plans_controller.rb +87 -0
- data/app/controllers/saasaparilla/admin/subscriptions_controller.rb +34 -0
- data/app/controllers/saasaparilla/admin/transactions_controller.rb +14 -0
- data/app/controllers/saasaparilla/application_controller.rb +4 -0
- data/app/controllers/saasaparilla/billing_history_controller.rb +9 -0
- data/app/controllers/saasaparilla/contact_info_controller.rb +31 -0
- data/app/controllers/saasaparilla/credit_card_controller.rb +41 -0
- data/app/controllers/saasaparilla/invoices_controller.rb +19 -0
- data/app/controllers/saasaparilla/payments_controller.rb +71 -0
- data/app/controllers/saasaparilla/plans_controller.rb +34 -0
- data/app/controllers/saasaparilla/subscription_controller.rb +71 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/plans_helper.rb +2 -0
- data/app/helpers/saasaparilla/billing_history_helper.rb +4 -0
- data/app/mailers/saasaparilla/notifier.rb +38 -0
- data/app/models/billing_activity.rb +12 -0
- data/app/models/contact_info.rb +107 -0
- data/app/models/credit_card.rb +109 -0
- data/app/models/invoice.rb +31 -0
- data/app/models/invoice_line_item.rb +3 -0
- data/app/models/payment.rb +39 -0
- data/app/models/plan.rb +36 -0
- data/app/models/subscription.rb +363 -0
- data/app/models/transaction.rb +32 -0
- data/app/views/layouts/saasaparilla.html.haml +9 -0
- data/app/views/saasaparilla/admin/plans/_form.html.haml +45 -0
- data/app/views/saasaparilla/admin/plans/edit.html.erb +4 -0
- data/app/views/saasaparilla/admin/plans/index.html.erb +31 -0
- data/app/views/saasaparilla/admin/plans/new.html.haml +4 -0
- data/app/views/saasaparilla/admin/plans/show.html.haml +20 -0
- data/app/views/saasaparilla/admin/subscriptions/_subscription.html.haml +7 -0
- data/app/views/saasaparilla/admin/subscriptions/index.html.haml +14 -0
- data/app/views/saasaparilla/admin/subscriptions/show.html.haml +52 -0
- data/app/views/saasaparilla/admin/transactions/_transaction.html.haml +6 -0
- data/app/views/saasaparilla/admin/transactions/index.html.haml +16 -0
- data/app/views/saasaparilla/billing_history/_billing_activity.html.haml +10 -0
- data/app/views/saasaparilla/billing_history/show.html.haml +11 -0
- data/app/views/saasaparilla/contact_info/edit.html.haml +8 -0
- data/app/views/saasaparilla/credit_card/edit.html.haml +18 -0
- data/app/views/saasaparilla/invoices/show.html.haml +17 -0
- data/app/views/saasaparilla/notifier/billing_failed.html.haml +5 -0
- data/app/views/saasaparilla/notifier/billing_successful.html.haml +5 -0
- data/app/views/saasaparilla/notifier/invoice_created.html.haml +24 -0
- data/app/views/saasaparilla/notifier/pending_cancellation_notice.html.haml +6 -0
- data/app/views/saasaparilla/notifier/subscription_canceled.html.haml +4 -0
- data/app/views/saasaparilla/notifier/subscription_created.html.haml +5 -0
- data/app/views/saasaparilla/payments/edit.html.haml +10 -0
- data/app/views/saasaparilla/payments/new.html.haml +10 -0
- data/app/views/saasaparilla/payments/show.html.haml +8 -0
- data/app/views/saasaparilla/plans/edit.html.haml +34 -0
- data/app/views/saasaparilla/subscription/_contact_info_form.html.haml +19 -0
- data/app/views/saasaparilla/subscription/_credit_card_form.html.haml +10 -0
- data/app/views/saasaparilla/subscription/new.html.haml +24 -0
- data/app/views/saasaparilla/subscription/show.html.haml +73 -0
- data/autotest/discover.rb +2 -0
- data/config/routes.rb +27 -0
- data/lib/country_select/MIT-LICENSE +20 -0
- data/lib/country_select/README +15 -0
- data/lib/country_select/init.rb +1 -0
- data/lib/country_select/install.rb +2 -0
- data/lib/country_select/lib/country_select.rb +88 -0
- data/lib/country_select/uninstall.rb +1 -0
- data/lib/extensions/action_controller/base.rb +7 -0
- data/lib/extensions/active_record/nested_attributes.rb +36 -0
- data/lib/extensions/active_record/statuses.rb +16 -0
- data/lib/extensions/billable.rb +12 -0
- data/lib/generators/saasaparilla/install/install_generator.rb +29 -0
- data/lib/generators/saasaparilla/install/templates/create_saasaparilla_tables.rb +106 -0
- data/lib/generators/saasaparilla/install/templates/saasaparilla.yml +32 -0
- data/lib/initializers/auth_dot_net.rb +25 -0
- data/lib/initializers/simple_form.rb +77 -0
- data/lib/initializers/time_format.rb +3 -0
- data/lib/saasaparilla.rb +16 -0
- data/lib/saasaparilla/authentication.rb +18 -0
- data/lib/saasaparilla/authorization.rb +26 -0
- data/lib/saasaparilla/engine.rb +30 -0
- data/lib/saasaparilla/version.rb +3 -0
- data/saasaparilla.gemspec +48 -0
- data/spec/.livereload +21 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/model/user.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/simple_form.rb +77 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/locales/simple_form.en.yml +24 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/saasaparilla.yml +32 -0
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/jquery.js +8374 -0
- data/spec/dummy/public/javascripts/jquery.min.js +16 -0
- data/spec/dummy/public/javascripts/rails.js +159 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/MIT-LICENSE +20 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/README +32 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/Rakefile +23 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/init.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/install.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_cim_gateway_test.rb +492 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_gateway_test.rb +133 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/paypal_express_gateway_test.rb +138 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/tasks/activemerchant_testing_tasks.rake +4 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/activemerchant_testing_test.rb +8 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/test_helper.rb +3 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/uninstall.rb +1 -0
- data/spec/factories/factories.rb +75 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mailers/notifier_spec.rb +167 -0
- data/spec/models/billing_activity_spec.rb +27 -0
- data/spec/models/contact_info_spec.rb +32 -0
- data/spec/models/credit_card_spec.rb +57 -0
- data/spec/models/invoice_line_item_spec.rb +7 -0
- data/spec/models/invoice_spec.rb +25 -0
- data/spec/models/payment_spec.rb +29 -0
- data/spec/models/plan_spec.rb +16 -0
- data/spec/models/subscription_spec.rb +414 -0
- data/spec/requests/admin_plans_spec.rb +32 -0
- data/spec/requests/admin_subscriptions_spec.rb +31 -0
- data/spec/requests/billing_history_spec.rb +26 -0
- data/spec/requests/contact_info_controller_spec.rb +42 -0
- data/spec/requests/credit_cards_spec.rb +79 -0
- data/spec/requests/invoices_spec.rb +23 -0
- data/spec/requests/payments_spec.rb +89 -0
- data/spec/requests/subscription_plans_spec.rb +34 -0
- data/spec/requests/subscriptions_spec.rb +80 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/spec_helpers/spec_helpers.rb +8 -0
- metadata +611 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
gem "rails", "3.0.5"
|
5
|
+
|
6
|
+
gem "sqlite3"
|
7
|
+
gem 'haml'
|
8
|
+
gem 'will_paginate'
|
9
|
+
|
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'
|
12
|
+
|
13
|
+
gem "jquery-rails"
|
14
|
+
gem "dynamic_attributes"
|
15
|
+
gem "authlogic"
|
16
|
+
gem 'activemerchant'
|
17
|
+
gem 'simple_form'
|
18
|
+
gem 'dynamic_form'
|
19
|
+
gem 'state_machine'
|
20
|
+
gem 'bartt-ssl_requirement', :require => 'ssl_requirement'
|
21
|
+
gem 'i18n'
|
22
|
+
group :development, :test do
|
23
|
+
gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'
|
24
|
+
gem "autotest-growl"
|
25
|
+
gem "autotest-fsevent"
|
26
|
+
gem "autotest-rails"
|
27
|
+
gem "factory_girl_rails", ">= 1.0.1"
|
28
|
+
gem "rspec-rails"
|
29
|
+
|
30
|
+
gem 'database_cleaner'
|
31
|
+
gem 'spork'
|
32
|
+
gem 'launchy'
|
33
|
+
gem 'shoulda'
|
34
|
+
gem 'ZenTest'
|
35
|
+
gem 'email_spec'
|
36
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'Saasaparilla'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
# begin
|
28
|
+
# require "jeweler"
|
29
|
+
# Jeweler::Tasks.new do |gem|
|
30
|
+
# gem.name = "saasaparilla"
|
31
|
+
# gem.summary = "Saas engine"
|
32
|
+
# gem.files = Dir["{lib}/**/*", "{app}/**/*", "{config}/**/*"]
|
33
|
+
# # other fields that would normally go in your gemspec
|
34
|
+
# # like authors, email and has_rdoc can also be included here
|
35
|
+
#
|
36
|
+
# end
|
37
|
+
# rescue
|
38
|
+
# puts "Jeweler or one of its dependencies is not installed."
|
39
|
+
# end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class Saasaparilla::Admin::PlansController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
include Authentication::InstanceMethods
|
4
|
+
include Authorization::InstanceMethods
|
5
|
+
|
6
|
+
# GET /plans
|
7
|
+
# GET /plans.xml
|
8
|
+
def index
|
9
|
+
@plans = Plan.all
|
10
|
+
|
11
|
+
respond_to do |format|
|
12
|
+
format.html # index.html.erb
|
13
|
+
format.xml { render :xml => @plans }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /plans/1
|
18
|
+
# GET /plans/1.xml
|
19
|
+
def show
|
20
|
+
@plan = Plan.find(params[:id])
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # show.html.erb
|
24
|
+
format.xml { render :xml => @plan }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /plans/new
|
29
|
+
# GET /plans/new.xml
|
30
|
+
def new
|
31
|
+
@plan = Plan.new
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
format.html # new.html.erb
|
35
|
+
format.xml { render :xml => @plan }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# GET /plans/1/edit
|
40
|
+
def edit
|
41
|
+
@plan = Plan.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
# POST /plans
|
45
|
+
# POST /plans.xml
|
46
|
+
def create
|
47
|
+
@plan = Plan.new(params[:plan])
|
48
|
+
|
49
|
+
respond_to do |format|
|
50
|
+
if @plan.save
|
51
|
+
format.html { redirect_to(admin_plans_path, :notice => 'Plan was successfully created.') }
|
52
|
+
format.xml { render :xml => @plan, :status => :created, :location => @plan }
|
53
|
+
else
|
54
|
+
format.html { render :action => "new" }
|
55
|
+
format.xml { render :xml => @plan.errors, :status => :unprocessable_entity }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# PUT /plans/1
|
61
|
+
# PUT /plans/1.xml
|
62
|
+
def update
|
63
|
+
@plan = Plan.find(params[:id])
|
64
|
+
|
65
|
+
respond_to do |format|
|
66
|
+
if @plan.update_attributes(params[:plan])
|
67
|
+
format.html { redirect_to(admin_plans_path, :notice => 'Plan was successfully updated.') }
|
68
|
+
format.xml { head :ok }
|
69
|
+
else
|
70
|
+
format.html { render :action => "edit" }
|
71
|
+
format.xml { render :xml => @plan.errors, :status => :unprocessable_entity }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# DELETE /plans/1
|
77
|
+
# DELETE /plans/1.xml
|
78
|
+
def destroy
|
79
|
+
@plan = Plan.find(params[:id])
|
80
|
+
@plan.destroy
|
81
|
+
|
82
|
+
respond_to do |format|
|
83
|
+
format.html { redirect_to(admin_plans_url) }
|
84
|
+
format.xml { head :ok }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Saasaparilla::Admin::SubscriptionsController < ApplicationController
|
2
|
+
|
3
|
+
unloadable
|
4
|
+
include Authentication::InstanceMethods
|
5
|
+
include Authorization::InstanceMethods
|
6
|
+
|
7
|
+
# GET /admin/subscriptions
|
8
|
+
def index
|
9
|
+
@subscriptions = Subscription.all.paginate(:page => params[:page], :per_page => 20, :order => "created_at DESC")
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@subscription = Subscription.find(params[:id])
|
14
|
+
end
|
15
|
+
|
16
|
+
def toggle_no_charge
|
17
|
+
@subscription = Subscription.find(params[:id])
|
18
|
+
@subscription.toggle!(:no_charge)
|
19
|
+
redirect_to admin_subscription_path(@subscription)
|
20
|
+
if @subscription.no_charge
|
21
|
+
flash[:notice] = "Subscription will not be charged."
|
22
|
+
else
|
23
|
+
flash[:notice] = "Subscription will now be charged."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def cancel
|
28
|
+
@subscription = Subscription.find(params[:id])
|
29
|
+
@subscription.cancel
|
30
|
+
redirect_to admin_subscription_path(@subscription)
|
31
|
+
flash[:notice] = "Subscription was canceled."
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Saasaparilla::Admin::TransactionsController < ApplicationController
|
2
|
+
|
3
|
+
unloadable
|
4
|
+
include Authentication::InstanceMethods
|
5
|
+
include Authorization::InstanceMethods
|
6
|
+
|
7
|
+
# GET /admin/subscriptions
|
8
|
+
def index
|
9
|
+
@subscription = Subscription.find(params[:subscription_id])
|
10
|
+
@transactions = @subscription.transactions.paginate(:page => params[:page], :per_page => 20, :order => "created_at DESC")
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Saasaparilla::ContactInfoController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
include Authentication::InstanceMethods
|
4
|
+
before_filter :get_subscription
|
5
|
+
before_filter :get_contact_info
|
6
|
+
|
7
|
+
def edit
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
if @contact_info.update_attributes(params[:contact_info])
|
13
|
+
flash[:notice] = "Contact info was successfully updated."
|
14
|
+
redirect_to subscription_path
|
15
|
+
else
|
16
|
+
flash[:error] = "An error has occurred when trying to update your contact info."
|
17
|
+
render :action => "edit"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def get_subscription
|
24
|
+
@subscription = current_billable.subscription
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_contact_info
|
28
|
+
@contact_info = @subscription.contact_info
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Saasaparilla::CreditCardController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
include Authentication::InstanceMethods
|
4
|
+
ssl_required :edit, :update
|
5
|
+
before_filter :set_subscription
|
6
|
+
before_filter :set_credit_cards
|
7
|
+
|
8
|
+
|
9
|
+
def edit
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
begin
|
15
|
+
if @subscription.credit_card.update_attributes(params[:credit_card])
|
16
|
+
flash[:notice] = "Your credit card was successfully updated."
|
17
|
+
redirect_to subscription_path
|
18
|
+
else
|
19
|
+
# @credit_card = @credit_card.reload_with_errors
|
20
|
+
render :action => "edit"
|
21
|
+
flash[:error] = "Your credit card could not be updated due to errors. Please review the form and correct them."
|
22
|
+
end
|
23
|
+
rescue Exception => e
|
24
|
+
flash[:error] = e.message
|
25
|
+
render :action => "edit"
|
26
|
+
flash.discard
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def set_subscription
|
33
|
+
@subscription = current_billable.subscription
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_credit_cards
|
37
|
+
@credit_card = @subscription.credit_card
|
38
|
+
@current_card = @credit_card.clone
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Saasaparilla::InvoicesController < ApplicationController
|
2
|
+
|
3
|
+
unloadable
|
4
|
+
include Authentication::InstanceMethods
|
5
|
+
before_filter :get_invoice
|
6
|
+
def show
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def get_invoice
|
12
|
+
@invoice = Invoice.find(params[:id])
|
13
|
+
|
14
|
+
unless @invoice.billing_activity.subscription == current_billable.subscription
|
15
|
+
flash[:error] = "Unauthorized to access this invoice"
|
16
|
+
redirect_to subscription_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Saasaparilla::PaymentsController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
include Authentication::InstanceMethods
|
4
|
+
ssl_required :new, :create, :edit, :update, :show
|
5
|
+
before_filter :get_subscription
|
6
|
+
before_filter :get_payment, :only => [:edit, :update]
|
7
|
+
before_filter :check_pending, :only => [:edit, :update]
|
8
|
+
def new
|
9
|
+
@payment = @subscription.payments.build
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@payment = @subscription.payments.build(params[:payment])
|
14
|
+
if @payment.save
|
15
|
+
redirect_to edit_subscription_payment_path(@payment)
|
16
|
+
else
|
17
|
+
render :action => "new"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
|
27
|
+
begin
|
28
|
+
if @payment.update_attributes(params[:payment])
|
29
|
+
flash[:notice] = "Thank you, your payment has been processed."
|
30
|
+
redirect_to subscription_payment_path
|
31
|
+
else
|
32
|
+
flash[:error] = "An error has occured when trying to process your payment."
|
33
|
+
render :action => "edit"
|
34
|
+
end
|
35
|
+
rescue Exception => e
|
36
|
+
flash[:error] = e.message
|
37
|
+
render :action => "edit"
|
38
|
+
flash.discard
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def show
|
43
|
+
@payment = @subscription.payments.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def get_subscription
|
51
|
+
@subscription = current_billable.subscription
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_payment
|
55
|
+
|
56
|
+
@payment = @subscription.payments.find(params[:id])
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_pending
|
61
|
+
unless @payment.pending?
|
62
|
+
flash[:error] = "Payment has already been paid."
|
63
|
+
redirect_to new_subscription_payment_path
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Saasaparilla::PlansController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
include Authentication::InstanceMethods
|
4
|
+
before_filter :get_subscription, :only => [:edit, :update]
|
5
|
+
|
6
|
+
def edit
|
7
|
+
@plans = Plan.all(:order => 'price ASC')
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
if params[:subscription][:plan_id] == ""
|
12
|
+
@subscription.cancel
|
13
|
+
redirect_to(subscription_path, :notice => 'You have been downgraded to the free plan.')
|
14
|
+
return
|
15
|
+
elsif @subscription.downgrade_plan_to(params[:subscription][:plan_id])
|
16
|
+
redirect_to(subscription_path, :notice => 'Plan was successfully changed.')
|
17
|
+
else
|
18
|
+
render :action => "edit"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_subscription
|
25
|
+
@subscription = current_billable.subscription
|
26
|
+
if @subscription.nil?
|
27
|
+
flash[:error] = "You do not have a current subscription"
|
28
|
+
redirect_to new_subscription_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
end
|