saasaparilla 0.1.8 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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.5"
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', ">= 1.20.0"
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", ">= 1.0.1"
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.all.paginate(:page => params[:page], :per_page => 20, :order => "created_at DESC")
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
 
@@ -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
@@ -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
@@ -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
 
@@ -1,3 +1,4 @@
1
1
  class InvoiceLineItem < ActiveRecord::Base
2
2
  belongs_to :invoice
3
- end
3
+ attr_accessible :description, :from, :to, :price
4
+ end
data/app/models/plan.rb CHANGED
@@ -7,6 +7,8 @@ class Plan < ActiveRecord::Base
7
7
 
8
8
  has_many :subscriptions
9
9
 
10
+ attr_accessible :name, :price, :billing_period
11
+
10
12
  BILLING_PERIODS = ["Monthly", "Annually"]
11
13
 
12
14
  def respond_to?(method_sym, include_private = false)
@@ -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
- before_validation :set_status, :on => :create
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) and id not in (select id from subscriptions where invoiced_on > ?) ", date + 5.days, (date - 1.months).to_time, date - 5.days)
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 = "active"
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)
@@ -5,6 +5,7 @@ class Transaction < ActiveRecord::Base
5
5
  belongs_to :billing_activity
6
6
  after_create :generate_billing_activity
7
7
 
8
+ attr_accessible :action, :amount, :response, :subscription
8
9
 
9
10
  def response=(response)
10
11
  self.success = response.success?
@@ -4,6 +4,7 @@
4
4
  = "You will be billed in 5 days for the following:"
5
5
 
6
6
  %table
7
+
7
8
  - @invoice.invoice_line_items.each do |item|
8
9
  %tr
9
10
  %td
@@ -1,11 +1,11 @@
1
1
  .saasaparilla
2
2
  %h1 Create Subscription
3
3
 
4
- = simple_form_for @subscription, :url => subscription_path(:secure => true) do |f|
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 => 'radio', :label => false
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
- scope '/admin', :name_prefix => 'admin' do
4
- resources :plans, :controller => "saasaparilla/admin/plans"
5
- resources :subscriptions, :controller => "saasaparilla/admin/subscriptions" do
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, :controller => "saasaparilla/admin/transactions", :only => [:index]
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
- scope '/subscription', :name_prefix => 'subscription' do
17
- resources :payments, :controller => "saasaparilla/payments"
18
- resource :credit_card, :controller => "saasaparilla/credit_card"
19
- resource :plan, :controller => "saasaparilla/plans", :only => [:edit, :update]
20
- resource :contact_info, :controller => "saasaparilla/contact_info"
21
- resource :billing_history, :controller => "saasaparilla/billing_history"
22
- resources :invoices, :controller => "saasaparilla/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
 
@@ -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)[RAILS_ENV]
19
+ Saasaparilla::CONFIG = YAML.load(raw_config)[Rails.env]
20
20
  end
21
21
  require 'initializers/auth_dot_net'
22
22
 
@@ -1,3 +1,3 @@
1
1
  module Saasaparilla
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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: 4fQ6B3Uyz
18
- auth_dot_net_password: 4QH8JM8929epy2gt
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