Skip to content

Commit

Permalink
Fixed config conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Fordham committed Apr 19, 2011
2 parents 17018a3 + 41fec67 commit 7f0a41a
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -5,7 +5,7 @@ gem "rails", "3.0.5"

gem "sqlite3"
gem 'haml'

gem 'will_paginate'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
gem RUBY_VERSION.include?('1.9') ? 'ruby-debug19' : 'ruby-debug'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/saasaparilla/admin/plans_controller.rb
@@ -1,5 +1,7 @@
class Saasaparilla::Admin::PlansController < ApplicationController
unloadable

include Authorization::InstanceMethods

# GET /plans
# GET /plans.xml
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/saasaparilla/admin/subscriptions_controller.rb
@@ -0,0 +1,21 @@
class Saasaparilla::Admin::SubscriptionsController < ActionController::Base

unloadable

include Authorization::InstanceMethods

# GET /admin/subscriptions
def index
@subscriptions = Subscription.all.paginate(:page => params[:page], :per_page => 20, :order => "created_at DESC")
end

def show
@subscription = Subscription.find(params[:id])
end






end
7 changes: 7 additions & 0 deletions app/controllers/saasaparilla/subscription_controller.rb
Expand Up @@ -2,6 +2,7 @@ class Saasaparilla::SubscriptionController < ApplicationController
unloadable

before_filter :get_subscription, :only => [:show, :destroy]
before_filter :require_no_subscription, :only => [:new]
#overide with authorization
def new
@subscription = current_billable.build_subscription
Expand Down Expand Up @@ -44,6 +45,12 @@ def destroy
end

private
def require_no_subscription
unless current_billable.subscription.nil?
flash[:error] = "You already have a subscription"
redirect_to subscription_path
end
end
def get_subscription
@subscription = current_billable.subscription
if @subscription.nil?
Expand Down
6 changes: 3 additions & 3 deletions app/models/credit_card.rb
Expand Up @@ -34,9 +34,9 @@ def validate_card
when "Last name cannot be empty"
errors[:card_name] = "cannot be empty"
when "Month is not a valid month"
errors[:expiration_date] = "- Month is not a valid month"
errors[:expiry_month] = "Month is not a valid month"
when "Year expired"
errors[:expiration_date] = "- Year expired"
errors[:expiry_year] = "Year expired"
when "Number is not a valid credit card number"
errors[:card_number] = "is not a valid credit card number"
when "Verification value is required"
Expand Down Expand Up @@ -83,14 +83,14 @@ def mask_card_number
end

def update_payment_profile

unless new_record?
@profile = {:customer_profile_id => subscription.customer_cim_id,
:payment_profile => {:customer_payment_profile_id => subscription.customer_payment_profile_id,
:bill_to => subscription.contact_info.to_hash,
:payment => {:credit_card => active_merchant_card}
}
}

response = GATEWAYCIM.update_customer_payment_profile(@profile)
if response.success?
return true
Expand Down
32 changes: 32 additions & 0 deletions app/models/subscription.rb
Expand Up @@ -45,6 +45,15 @@ class Subscription < ActiveRecord::Base
plan.billing_period.downcase == period.downcase
end
end

ContactInfo.column_names.each do |col|
unless col.include? "id"
define_method "#{col}" do
contact_info.send(col)
end
end
end

class << self
def find_and_bill_recurring_subscriptions
#find_all_subscriptions need billing
Expand All @@ -68,6 +77,27 @@ def find_and_invoice_subscriptions
end


def last_transaction_date
@transaction = transactions.recent.first
if @transaction.nil?
"-"
else
@transaction.created_at.to_s(:month_day_year)
end
end

def last_transaction_amount
@transaction = transactions.recent.first
if @transaction.nil?
"-"
else
@transaction.amount
end
end

def plan_name
plan.name
end
def initial_bill
if Saasaparilla::CONFIG["trial_period"] > 0
set_next_billing_date(Saasaparilla::CONFIG["trial_period"])
Expand Down Expand Up @@ -174,8 +204,10 @@ def create_cim_profile
#Login to the gateway using your credentials in environment.rb
#setup the user object to save
@profile = {:profile => profile}

#send the create message to the gateway API
response = ::GATEWAYCIM.create_customer_profile(@profile)

if response.success? and response.authorization
self.customer_cim_id = response.authorization
return true
Expand Down
2 changes: 1 addition & 1 deletion app/models/transaction.rb
Expand Up @@ -21,7 +21,7 @@ def response=(response)
scope :successful, lambda {
where("success = ?", true)
}
scope :recent, order("created_at DESC")

private
def generate_billing_activity
Expand Down
@@ -0,0 +1,7 @@
%tr
%td= subscription.email
%td= subscription.created_at.to_s(:month_day_year)
%td= subscription.last_transaction_date
%td= subscription.status
%td= subscription.plan_name
%td= link_to "Show Detail", admin_subscription_path(subscription)
13 changes: 13 additions & 0 deletions app/views/saasaparilla/admin/subscriptions/index.html.haml
@@ -0,0 +1,13 @@
%h1 Listing Subscriptions

%table
%tr
%th Email
%th Sign up
%th Last Transaction Date
%th Status
%th Plan

= render :partial => "subscription", :collection => @subscriptions

= will_paginate @subscriptions
28 changes: 28 additions & 0 deletions app/views/saasaparilla/admin/subscriptions/show.html.haml
@@ -0,0 +1,28 @@
%h1 Subscription Detail

%h2 Subscriber Contact Info
%p
= "#{@subscription.first_name} #{@subscription.last_name}"
%br
= @subscription.address
%br
= "#{@subscription.city}, #{@subscription.state} #{@subscription.zip}"
%br
= "#{@subscription.phone_number}"

%h2 Subscription Details
%p
="Status: "
= @subscription.status
%br
= "Balance: "
= number_to_currency(@subscription.balance)
%br
= "Last Invoiced: "
= @subscription.invoiced_on.to_s(:month_day_year) unless @subscription.invoiced_on.nil?
%br
= "Last Transaction Date: "
= @subscription.last_transaction_date
%br
= "Last Transaction Amount: "
= number_to_currency(@subscription.last_transaction_amount)
@@ -1,14 +1,13 @@
%h2 Billing info

/ = f.input :first_name
/ = f.input :last_name

= f.input :card_type, :collection => CreditCard::CARD_TYPES, :include_blank => false
- if f.object.new_record?
= f.input :card_number
- else
= f.input :card_number, :input_html => {:value => ""}
= f.input :expiry_month, :collection => CreditCard::MONTHS
= f.input :expiry_year, :collection => CreditCard::YEARS
= f.input :expiry_year, :collection => CreditCard::YEARS, :error_html => { :id => "subscription_credit_card_attributes_expiry_date_error"}
= f.input :card_verification


1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -2,6 +2,7 @@

scope '/admin', :name_prefix => 'admin' do
resources :plans, :controller => "saasaparilla/admin/plans"
resources :subscriptions, :controller => "saasaparilla/admin/subscriptions"
end

resource :subscription, :controller => "saasaparilla/subscription"
Expand Down
23 changes: 23 additions & 0 deletions lib/extensions/action_controller/authorization.rb
@@ -0,0 +1,23 @@
module Authorization
module ClassMethods

end
module InstanceMethods
def self.included(base)
if Saasaparilla::CONFIG["authorization"] == "cancan"
base.rescue_from CanCan::AccessDenied do |exception|
redirect_to '/'
flash[:error] = exception.to_s
end
base.load_and_authorize_resource
end
# Override this module an initializer with Authorization::InstanceMethods.module_eval and add your own authorization
# base.before_filter :custom_method
end


# def custom_method

# end
end
end
Expand Up @@ -76,7 +76,7 @@ def self.up

create_table :transactions do |t|
t.string :action
t.integer :amount
t.float :amount
t.boolean :success
t.string :authorization
t.string :message
Expand Down
Expand Up @@ -5,6 +5,7 @@ development:
auth_dot_net_login: login
auth_dot_net_password: pass
include_free_account: false
authorization: cancan

test:
grace_period: 10
Expand All @@ -13,11 +14,13 @@ test:
auth_dot_net_login: login
auth_dot_net_password: pass
include_free_account: false

authorization: none

production:
grace_period: 10
from_email: test@dev.com
trial_period: 0
auth_dot_net_login: login
auth_dot_net_password: pass
include_free_account: false
include_free_account: false
authorization: cancan
14 changes: 10 additions & 4 deletions lib/saasaparilla.rb
@@ -1,8 +1,14 @@
module Saasaparilla
require 'saasaparilla/engine' if defined?(Rails)
end

require 'saasaparilla/engine' if defined?(Rails)
require 'extensions/billable'

require 'country_select/lib/country_select'
require 'extensions/active_record/statuses'
require 'extensions/active_record/nested_attributes'
require 'extensions/active_record/nested_attributes'

module Saasaparilla




end
6 changes: 5 additions & 1 deletion lib/saasaparilla/engine.rb
Expand Up @@ -5,7 +5,7 @@
require 'yaml'

require "dynamic_attributes"

require 'extensions/action_controller/authorization'
module Saasaparilla
class Engine < Rails::Engine

Expand All @@ -17,8 +17,12 @@ class Engine < Rails::Engine
Saasaparilla::CONFIG = YAML.load(raw_config)[RAILS_ENV]
end
require 'initializers/auth_dot_net'


end



end

end
1 change: 1 addition & 0 deletions saasaparilla.gemspec
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |s|
#s.add_runtime_dependency(%q<saasaparilla>, [">= 0"])
#s.add_runtime_dependency(%q<rails>, ["= 3.0.5"])
#s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
s.add_runtime_dependency(%q<will_paginate>, [">=0"])
s.add_runtime_dependency(%q<haml>, [">= 0"])
s.add_runtime_dependency(%q<jquery-rails>, [">= 0"])
s.add_runtime_dependency(%q<dynamic_attributes>, [">= 0"])
Expand Down
11 changes: 8 additions & 3 deletions spec/dummy/config/saasaparilla.yml
Expand Up @@ -5,17 +5,22 @@ development:
auth_dot_net_login: 4fQ6B3Uyz
auth_dot_net_password: 4QH8JM8929epy2gt
include_free_account: true

authorization: none

test:
grace_period: 10
from_email: test@dev.com
trial_period: 0
include_free_account: false

auth_dot_net_login: user
auth_dot_net_password: pass
authorization: none

production:
grace_period: 10
from_email: test@dev.com
trial_period: 0
auth_dot_net_login: user
auth_dot_net_password: pass
include_free_account: false
include_free_account: false
authorization: cancan
15 changes: 12 additions & 3 deletions spec/models/subscription_spec.rb
Expand Up @@ -151,11 +151,19 @@
@subscription.status.should == "canceled"

end

it 'should return last transaction date' do
@subscription.save
@subscription.last_transaction_date.should == Date.today.to_s(:month_day_year)
end

it 'should return - if no transactions on last transaction date' do
@subscription.last_transaction_date.should == '-'
end


end
it 'should return plan name' do
@subscription.plan_name.should == "Gold"
end
end

describe 'billing' do
before(:each) do
Expand Down Expand Up @@ -353,6 +361,7 @@
@subscription1.billing_activities.last.invoice.invoice_line_items.first.to.should == @subscription1.billing_date
end


end
end

Expand Down

0 comments on commit 7f0a41a

Please sign in to comment.