tellimus 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +152 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/tellimus/application.js +13 -0
- data/app/assets/stylesheets/tellimus/application.css +13 -0
- data/app/assets/stylesheets/tellimus/pricing-table.scss +78 -0
- data/app/concerns/tellimus/plan.rb +8 -0
- data/app/concerns/tellimus/subscription.rb +275 -0
- data/app/controllers/tellimus/application_controller.rb +6 -0
- data/app/controllers/tellimus/subscriptions_controller.rb +189 -0
- data/app/helpers/tellimus/application_helper.rb +20 -0
- data/app/views/layouts/tellimus/application.html.erb +13 -0
- data/app/views/tellimus/subscriptions/_braintree_js.html.erb +8 -0
- data/app/views/tellimus/subscriptions/_card.html.erb +26 -0
- data/app/views/tellimus/subscriptions/_pricing_table.html.erb +40 -0
- data/app/views/tellimus/subscriptions/_social_proof.html.erb +11 -0
- data/app/views/tellimus/subscriptions/edit.html.erb +7 -0
- data/app/views/tellimus/subscriptions/index.html.erb +2 -0
- data/app/views/tellimus/subscriptions/new.html.erb +1 -0
- data/app/views/tellimus/subscriptions/show.html.erb +15 -0
- data/app/views/tellimus/subscriptions/unauthorized.html.erb +1 -0
- data/config/environment.rb +0 -0
- data/config/locales/en.yml +58 -0
- data/config/routes.rb +10 -0
- data/lib/generators/tellimus/install_generator.rb +66 -0
- data/lib/generators/tellimus/templates/app/models/plan.rb +6 -0
- data/lib/generators/tellimus/templates/app/models/subscription.rb +7 -0
- data/lib/generators/tellimus/templates/config/initializers/tellimus.rb +14 -0
- data/lib/generators/tellimus/views_generator.rb +31 -0
- data/lib/tasks/tellimus_tasks.rake +12 -0
- data/lib/tellimus/engine.rb +20 -0
- data/lib/tellimus/errors.rb +4 -0
- data/lib/tellimus/version.rb +3 -0
- data/lib/tellimus.rb +83 -0
- data/spec/concerns/tellimus/plan_spec.rb +39 -0
- data/spec/concerns/tellimus/subscription_spec.rb +0 -0
- data/spec/controllers/tellimus/subscriptions_controller.rb +21 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/plan.rb +7 -0
- data/spec/dummy/app/models/subscription.rb +6 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/tellimus/subscriptions/_social_proof.html.erb +11 -0
- data/spec/dummy/config/application.rb +55 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +32 -0
- data/spec/dummy/config/environments/production.rb +69 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +0 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -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/tellimus.rb +14 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +59 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130318201927_create_customers.rb +8 -0
- data/spec/dummy/db/migrate/20130318204455_create_subscriptions.rb +15 -0
- data/spec/dummy/db/migrate/20130318204458_create_plans.rb +14 -0
- data/spec/dummy/db/migrate/20130520163946_add_interval_to_plan.rb +5 -0
- data/spec/dummy/db/schema.rb +44 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +59 -0
- data/spec/dummy/log/test.log +48 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/customers.yml +7 -0
- data/spec/dummy/test/unit/customer_test.rb +7 -0
- data/spec/dummy/tmp/development_secret.txt +1 -0
- data/spec/spec_helper.rb +30 -0
- metadata +306 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
module Tellimus
|
2
|
+
class SubscriptionsController < ApplicationController
|
3
|
+
before_action :load_owner
|
4
|
+
before_action :show_existing_subscription, only: [:index, :new, :create], unless: :no_owner?
|
5
|
+
before_action :load_subscription, only: [:show, :cancel, :edit, :update]
|
6
|
+
before_action :load_plans, only: [:index, :edit]
|
7
|
+
|
8
|
+
def load_plans
|
9
|
+
@plans = ::Plan.order(:display_order)
|
10
|
+
end
|
11
|
+
|
12
|
+
def unauthorized
|
13
|
+
render status: 401, template: "tellimus/subscriptions/unauthorized"
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_owner
|
18
|
+
unless params[:owner_id].nil?
|
19
|
+
if current_owner.present?
|
20
|
+
|
21
|
+
# we need to try and look this owner up via the find method so that we're
|
22
|
+
# taking advantage of any override of the find method that would be provided
|
23
|
+
# by older versions of friendly_id. (support for newer versions default behavior
|
24
|
+
# below.)
|
25
|
+
|
26
|
+
searched_owner = current_owner.class.find(params[:owner_id]) rescue nil
|
27
|
+
|
28
|
+
# if we couldn't find them that way, check whether there is a new version of
|
29
|
+
# friendly_id in place that we can use to look them up by their slug.
|
30
|
+
# in christoph's words, "why?!" in my words, "warum?!!!"
|
31
|
+
# (we debugged this together on skype.)
|
32
|
+
if searched_owner.nil? && current_owner.class.respond_to?(:friendly)
|
33
|
+
searched_owner = current_owner.class.friendly.find(params[:owner_id]) rescue nil
|
34
|
+
end
|
35
|
+
|
36
|
+
if current_owner.try(:id) == searched_owner.try(:id)
|
37
|
+
@owner = current_owner
|
38
|
+
else
|
39
|
+
return unauthorized
|
40
|
+
end
|
41
|
+
else
|
42
|
+
return unauthorized
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def no_owner?
|
48
|
+
@owner.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_subscription
|
52
|
+
ownership_attribute = :"#{Tellimus.subscriptions_owned_by}_id"
|
53
|
+
@subscription = ::Subscription.where(ownership_attribute => current_owner.id).find_by_id(params[:id])
|
54
|
+
|
55
|
+
# also, if cancan methods are available, we should use that to authorize.
|
56
|
+
|
57
|
+
return @subscription.present? ? @subscription : unauthorized
|
58
|
+
end
|
59
|
+
|
60
|
+
# the following three methods allow us to show the pricing table before someone has an account.
|
61
|
+
# by default these support devise, but they can be overriden to support others.
|
62
|
+
def current_owner
|
63
|
+
# e.g. "self.current_user"
|
64
|
+
send "current_#{Tellimus.subscriptions_owned_by}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def current_owned_through_or_by
|
68
|
+
# e.g. "self.current_user"
|
69
|
+
send "current_#{Tellimus.subscriptions_owned_through_or_by}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def redirect_to_sign_up
|
73
|
+
# this is a Devise default variable and thus should not change its name
|
74
|
+
# when we change subscription owners from :user to :company
|
75
|
+
session["#{Tellimus.subscriptions_owned_through_or_by}_return_to"] = new_subscription_path(plan: params[:plan])
|
76
|
+
redirect_to new_registration_path(Tellimus.subscriptions_owned_through_or_by.to_s)
|
77
|
+
end
|
78
|
+
|
79
|
+
def index
|
80
|
+
|
81
|
+
# don't bother showing the index if they've already got a subscription.
|
82
|
+
if current_owner and current_owner.subscription.present?
|
83
|
+
redirect_to tellimus.edit_owner_subscription_path(current_owner, current_owner.subscription)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Don't prep a subscription unless a user is authenticated.
|
87
|
+
unless no_owner?
|
88
|
+
# we should also set the owner of the subscription here.
|
89
|
+
@subscription = ::Subscription.new({Tellimus.owner_id_sym => @owner.id})
|
90
|
+
@subscription.subscription_owner = @owner
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def new
|
96
|
+
if no_owner?
|
97
|
+
|
98
|
+
if defined?(Devise)
|
99
|
+
|
100
|
+
# by default these methods support devise.
|
101
|
+
if current_owner
|
102
|
+
redirect_to new_owner_subscription_path(current_owner, plan: params[:plan])
|
103
|
+
else
|
104
|
+
redirect_to_sign_up
|
105
|
+
end
|
106
|
+
|
107
|
+
else
|
108
|
+
raise I18n.t('tellimus.failure.feature_depends_on_devise')
|
109
|
+
end
|
110
|
+
@braintree_client_token = Tellimus.gateway.client_token.generate
|
111
|
+
else
|
112
|
+
@subscription = ::Subscription.new
|
113
|
+
@subscription.plan = ::Plan.find(params[:plan])
|
114
|
+
@braintree_client_token = Tellimus.gateway.client_token.generate
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def show_existing_subscription
|
119
|
+
if @owner.subscription.present?
|
120
|
+
redirect_to owner_subscription_path(@owner, @owner.subscription)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def create
|
125
|
+
|
126
|
+
@subscription = ::Subscription.new(subscription_params)
|
127
|
+
@subscription.payment_method_nonce = params[:payment_method_nonce]
|
128
|
+
@subscription.subscription_owner = @owner
|
129
|
+
|
130
|
+
if @subscription.save
|
131
|
+
flash[:notice] = after_new_subscription_message
|
132
|
+
redirect_to after_new_subscription_path
|
133
|
+
else
|
134
|
+
flash[:error] = I18n.t('tellimus.failure.problem_processing_transaction')
|
135
|
+
render :new
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def show
|
140
|
+
end
|
141
|
+
|
142
|
+
def cancel
|
143
|
+
flash[:notice] = I18n.t('tellimus.confirmations.subscription_cancelled')
|
144
|
+
@subscription.plan_id = nil
|
145
|
+
@subscription.save
|
146
|
+
redirect_to owner_subscription_path(@owner, @subscription)
|
147
|
+
end
|
148
|
+
|
149
|
+
def edit
|
150
|
+
@braintree_client_token = Tellimus.gateway.client_token.generate
|
151
|
+
end
|
152
|
+
|
153
|
+
def update
|
154
|
+
@subscription.payment_method_nonce = params[:payment_method_nonce]
|
155
|
+
if @subscription.update(subscription_params)
|
156
|
+
flash[:notice] = I18n.t('tellimus.confirmations.subscription_updated')
|
157
|
+
redirect_to owner_subscription_path(@owner, @subscription)
|
158
|
+
else
|
159
|
+
flash[:error] = I18n.t('tellimus.failure.problem_processing_transaction')
|
160
|
+
render :edit
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def subscription_params
|
166
|
+
|
167
|
+
# If strong_parameters is around, use that.
|
168
|
+
if defined?(ActionController::StrongParameters)
|
169
|
+
params.require(:subscription).permit(:plan_id, :braintree_id, :current_price, :credit_card_token, :card_type, :last_two)
|
170
|
+
else
|
171
|
+
# Otherwise, let's hope they're using attr_accessible to protect their models!
|
172
|
+
params[:subscription]
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
def after_new_subscription_path
|
178
|
+
return super(@owner, @subscription) if defined?(super)
|
179
|
+
owner_subscription_path(@owner, @subscription)
|
180
|
+
end
|
181
|
+
|
182
|
+
def after_new_subscription_message
|
183
|
+
controller = ::ApplicationController.new
|
184
|
+
controller.respond_to?(:new_subscription_notice_message) ?
|
185
|
+
controller.try(:new_subscription_notice_message) :
|
186
|
+
I18n.t('tellimus.confirmations.subscription_upgraded')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tellimus
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
def plan_price(plan)
|
5
|
+
"#{number_to_currency(plan.price)}/#{plan_interval(plan)}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def plan_interval(plan)
|
9
|
+
interval = %w(month year week 6-month 3-month).include?(plan.interval) ? plan.interval.delete('-') : 'month'
|
10
|
+
I18n.t("tellimus.plan_intervals.#{interval}")
|
11
|
+
end
|
12
|
+
|
13
|
+
# returns TRUE if the controller belongs to Tellimus
|
14
|
+
# false in all other cases, for convenience when executing filters
|
15
|
+
# in the main application
|
16
|
+
def tellimus_controller?
|
17
|
+
is_a? Tellimus::ApplicationController
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Tellimus</title>
|
5
|
+
<%= stylesheet_link_tag "tellimus/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "tellimus/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
|
12
|
+
</body>
|
13
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<% content_for :tellimus do %>
|
2
|
+
<%= render('tellimus/subscriptions/braintree_js.html.erb').html_safe %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<%= form_for @subscription, url: url, html: {id: 'payment-form', class: 'form-horizontal'} do |f| %>
|
6
|
+
|
7
|
+
<fieldset id="form-fieldset">
|
8
|
+
|
9
|
+
<legend><%= title %></legend>
|
10
|
+
|
11
|
+
<%= f.hidden_field :plan_id %>
|
12
|
+
|
13
|
+
</fieldset>
|
14
|
+
|
15
|
+
<div class="control-group">
|
16
|
+
<div class="controls">
|
17
|
+
<% if Tellimus.free_trial? %>
|
18
|
+
<button type="submit" class="btn btn-primary submit-button"><%= t('koudoku.payment.save_billing_info') %></button>
|
19
|
+
<% else %>
|
20
|
+
<button type="submit" class="btn btn-primary submit-button" id='submit-button'><%= t('koudoku.payment.upgrade_account') %></button>
|
21
|
+
<% end %>
|
22
|
+
<%= link_to t('koudoku.payment.cancel'), owner_subscriptions_path(@owner), class: 'btn' %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<% end %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<ul class="thumbnails tellimus-pricing-table">
|
2
|
+
<% @plans.each do |plan| %>
|
3
|
+
<li class="span3 plan <%= 'plan-primary' if plan.highlight? %>">
|
4
|
+
<div class="thumbnail">
|
5
|
+
<div class="caption">
|
6
|
+
<h3><%= plan.name %></h3>
|
7
|
+
<h4><%= plan_price(plan) %></h4>
|
8
|
+
<div class="call-to-action">
|
9
|
+
<% if @subscription.nil? %>
|
10
|
+
<%= link_to Tellimus.free_trial? ? t('tellimus.plan_difference.start_trial') : t('tellimus.subscriptions.sign_up'), tellimus.new_subscription_path(plan: plan.id), class: "btn btn-success btn-large" %>
|
11
|
+
<% elsif @subscription.persisted? %>
|
12
|
+
<% if @subscription.plan == plan %>
|
13
|
+
<%= form_for @subscription, url: owner_subscription_path(@owner, @subscription) do |f| %>
|
14
|
+
<%= f.submit t('tellimus.plan_difference.selected'), class: "btn btn-large", disabled: 'disabled' %>
|
15
|
+
<% end %>
|
16
|
+
<% else %>
|
17
|
+
<%= form_for @subscription, url: owner_subscription_path(@owner, @subscription) do |f| %>
|
18
|
+
<%= f.hidden_field :plan_id, value: plan.id %>
|
19
|
+
<%= f.submit @subscription.describe_difference(plan), class: "btn btn-success btn-large" %>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
22
|
+
<% else %>
|
23
|
+
<%= link_to Tellimus.free_trial? ? t('tellimus.plan_difference.start_trial') : t('tellimus.plan_difference.upgrade'), new_owner_subscription_path(@owner, plan: plan.id), class: "btn btn-success btn-large" %>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
<ul class="features">
|
27
|
+
<% if Tellimus.free_trial? %>
|
28
|
+
<li class='muted'><%= t('tellimus.subscriptions.free_trial_for_days', days: Tellimus.free_trial_length) %></li>
|
29
|
+
<% end %>
|
30
|
+
<%= BlueCloth.new(plan.features.gsub(/\n/, "\n\n")).to_html.gsub(/<(\/?)p>/, '<\1li>').html_safe %>
|
31
|
+
</ul>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</li>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<li class="span3 social-proof">
|
38
|
+
<%= render 'tellimus/subscriptions/social_proof' %>
|
39
|
+
</li>
|
40
|
+
</ul>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<blockquote>
|
2
|
+
<h4><%= t('tellimus.social_proof.testimonial1.quote') %></h4> — <%= t('tellimus.social_proof.testimonial1.person') %>
|
3
|
+
</blockquote>
|
4
|
+
|
5
|
+
<blockquote>
|
6
|
+
<h4><%= t('tellimus.social_proof.testimonial2.quote') %></h4> — <%= t('tellimus.social_proof.testimonial2.person') %>
|
7
|
+
</blockquote>
|
8
|
+
|
9
|
+
<blockquote>
|
10
|
+
<h4><%= t('tellimus.social_proof.testimonial3.quote') %></h4> — <%= t('tellimus.social_proof.testimonial3.person') %>
|
11
|
+
</blockquote>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<% if params['update'] == 'card' %>
|
2
|
+
<%= render 'card', title: t('tellimus.payment.update_payment_information'), url: owner_subscription_path(@owner, @subscription) %>
|
3
|
+
<% else %>
|
4
|
+
<h1><%= t('tellimus.subscriptions.which_plan_is_best') %></h1>
|
5
|
+
<%= render 'pricing_table' %>
|
6
|
+
<p><%= t('tellimus.subscriptions.cancel_your_subscription_note_html', :link => (link_to t('koudoku.subscriptions.cancel_your_subscription'), cancel_owner_subscription_path(@owner, @subscription), method: :post)) %></p>
|
7
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'card', title: (Tellimus.free_trial? ? t('tellimus.subscriptions.start_trial') : t('tellimus.subscriptions.upgrade_your_account')), url: owner_subscriptions_path(@owner) %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% if @subscription.plan.present? %>
|
2
|
+
<h2><%= t('tellimus.subscriptions.subscribed') %></h2>
|
3
|
+
<p><%= t('tellimus.subscriptions.subscribed_to_plan', :plan => @subscription.plan.name) %></p>
|
4
|
+
<%= link_to t('tellimus.subscriptions.choose_other_plan'), edit_owner_subscription_path(@owner, @subscription), class: 'btn' %>
|
5
|
+
<% else %>
|
6
|
+
<h2><%= t('tellimus.subscriptions.no_subscription') %></h2>
|
7
|
+
<p><%= t('tellimus.subscriptions.not_subscribed_to_plan') %></p>
|
8
|
+
<%= link_to t('tellimus.subscriptions.choose_plan'), edit_owner_subscription_path(@owner, @subscription), class: 'btn' %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<br><br>
|
12
|
+
|
13
|
+
<h4><%= t('tellimus.payment.payment_information') %></h4>
|
14
|
+
<p><%= t('tellimus.payment.card_on_file', payment_signature: @subscription.payment_signature, payment_type: @subscription.payment_type) %></p>
|
15
|
+
<%= link_to t('tellimus.payment.update_payment_information'), edit_owner_subscription_path(@owner, @subscription, update: 'card'), class: 'btn' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= t('tellimus.failure.unauthorized') %></h1>
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
tellimus:
|
6
|
+
confirmations:
|
7
|
+
feature_depends_on_devise: "This feature depends on Devise for authentication."
|
8
|
+
subscription_cancelled: "You've successfully cancelled your subscription."
|
9
|
+
subscription_updated: "You've successfully updated your subscription."
|
10
|
+
subscription_upgraded: "You've been successfully upgraded."
|
11
|
+
failure:
|
12
|
+
problem_processing_transaction: "There was a problem processing this transaction."
|
13
|
+
unauthorized: "Unauthorized"
|
14
|
+
plan_intervals:
|
15
|
+
month: "month"
|
16
|
+
year: "year"
|
17
|
+
week: "week"
|
18
|
+
6month: "half-year"
|
19
|
+
3month: "quarter"
|
20
|
+
plan_difference:
|
21
|
+
downgrade: "Downgrade"
|
22
|
+
selected: "Selected"
|
23
|
+
start_trial: "Start Trial"
|
24
|
+
upgrade: "Upgrade"
|
25
|
+
payment:
|
26
|
+
cancel: "Cancel"
|
27
|
+
card_number: "Card Number"
|
28
|
+
card_on_file: "The %{payment_type} on file for your account: %{payment_signature}."
|
29
|
+
cvc: "CVC"
|
30
|
+
expiration: "Expiration (MM/YYYY)"
|
31
|
+
payment_information: "Payment Information"
|
32
|
+
save_billing_info: "Save Billing Information"
|
33
|
+
upgrade_account: "Upgrade Your Account"
|
34
|
+
update_payment_information: "Update Your Payment Information"
|
35
|
+
social_proof:
|
36
|
+
testimonial1:
|
37
|
+
person: "Person at Place"
|
38
|
+
quote: "\"Some Great Quote\""
|
39
|
+
testimonial2:
|
40
|
+
person: "Person at Place"
|
41
|
+
quote: "\"This is a great service and you've been the best ever! Thanks!\""
|
42
|
+
testimonial3:
|
43
|
+
person: "Person at Place"
|
44
|
+
quote: "\"I love you guys and you're the best! You're the best!\""
|
45
|
+
subscriptions:
|
46
|
+
cancel_your_subscription: "cancel your subscription"
|
47
|
+
cancel_your_subscription_note_html: "You can also %{link}."
|
48
|
+
choose_other_plan: "Choose Another Plan"
|
49
|
+
choose_plan: "Choose A Plan"
|
50
|
+
free_trial_for_days: "%{days}-day Free Trial"
|
51
|
+
no_subscription: "No Subscription"
|
52
|
+
not_subscribed_to_plan: "You are not subscribed to a paid plan."
|
53
|
+
sign_up: "Sign up"
|
54
|
+
start_trial: "Start Your Free Trial"
|
55
|
+
subscribed: "You're Subscribed!"
|
56
|
+
subscribed_to_plan: "You're currently subscribed to the %{plan} plan."
|
57
|
+
upgrade_your_account: "Upgrade Your Account"
|
58
|
+
which_plan_is_best: "What Plan Is Best For You?"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# this generator based on rails_admin's install generator.
|
2
|
+
# https://www.github.com/sferik/rails_admin/master/lib/generators/rails_admin/install_generator.rb
|
3
|
+
|
4
|
+
require 'rails/generators'
|
5
|
+
|
6
|
+
# http://guides.rubyonrails.org/generators.html
|
7
|
+
# http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
|
8
|
+
|
9
|
+
module Tellimus
|
10
|
+
class InstallGenerator < Rails::Generators::Base
|
11
|
+
|
12
|
+
def self.source_paths
|
13
|
+
[Tellimus::Engine.root, File.expand_path("../templates", __FILE__)]
|
14
|
+
end
|
15
|
+
|
16
|
+
include Rails::Generators::Migration
|
17
|
+
|
18
|
+
argument :subscription_owner_model, :type => :string, :required => false, :desc => "Owner of the subscription"
|
19
|
+
desc "Tellimus installation generator"
|
20
|
+
|
21
|
+
# Override the attr_accessor generated by 'argument' so that
|
22
|
+
# subscription_owner_model is always returned lowercase.
|
23
|
+
def subscription_owner_model
|
24
|
+
@subscription_owner_model ? @subscription_owner_model.downcase : "user"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def install
|
29
|
+
|
30
|
+
unless defined?(Tellimus)
|
31
|
+
gem("tellimus")
|
32
|
+
end
|
33
|
+
|
34
|
+
require "securerandom"
|
35
|
+
template "config/initializers/tellimus.rb"
|
36
|
+
|
37
|
+
# Generate subscription.
|
38
|
+
generate("model", "subscription braintree_id:string braintree_customer_id:string plan_id:integer payment_signature:string payment_type:string current_price:float #{subscription_owner_model}_id:integer")
|
39
|
+
template "app/models/subscription.rb"
|
40
|
+
|
41
|
+
# Add the plans.
|
42
|
+
generate("model", "plan name:string braintree_id:string price:float interval:string features:text highlight:boolean display_order:integer")
|
43
|
+
template "app/models/plan.rb"
|
44
|
+
|
45
|
+
# Update the owner relationship.
|
46
|
+
inject_into_class "app/models/#{subscription_owner_model}.rb", subscription_owner_model.camelize.constantize,
|
47
|
+
"# Added by Tellimus.\n has_one :subscription\n\n"
|
48
|
+
|
49
|
+
# Install the pricing table.
|
50
|
+
copy_file "app/views/tellimus/subscriptions/_social_proof.html.erb"
|
51
|
+
|
52
|
+
# Add webhooks to the route.
|
53
|
+
|
54
|
+
route <<-RUBY
|
55
|
+
|
56
|
+
# Added by Tellimus.
|
57
|
+
mount Tellimus::Engine, at: 'tellimus'
|
58
|
+
scope module: 'tellimus' do
|
59
|
+
get 'pricing' => 'subscriptions#index', as: 'pricing'
|
60
|
+
end
|
61
|
+
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Tellimus.setup do |config|
|
2
|
+
config.subscriptions_owned_by = :<%= subscription_owner_model %>
|
3
|
+
config.braintree_public_key = ENV['BRAINTREE_PUBLIC_KEY']
|
4
|
+
config.braintree_private_key = ENV['BRAINTREE_PRIVATE_KEY']
|
5
|
+
config.braintree_merchant_id = ENV['BRAINTREE_MERCHANT_ID']
|
6
|
+
config.braintree_environment = ENV['BRAINTREE_ENVIRONMENT']
|
7
|
+
|
8
|
+
# config.prorate = false # Default is true, set to false to disable prorating subscriptions
|
9
|
+
# config.free_trial_length = 30
|
10
|
+
|
11
|
+
# Specify layout you want to use for the subscription pages, default is application
|
12
|
+
config.layout = 'application'
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# this generator based on rails_admin's install generator.
|
2
|
+
# https://www.github.com/sferik/rails_admin/master/lib/generators/rails_admin/install_generator.rb
|
3
|
+
|
4
|
+
require 'rails/generators'
|
5
|
+
|
6
|
+
# http://guides.rubyonrails.org/generators.html
|
7
|
+
# http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
|
8
|
+
|
9
|
+
module Tellimus
|
10
|
+
class ViewsGenerator < Rails::Generators::Base
|
11
|
+
|
12
|
+
# Not sure what this does.
|
13
|
+
source_root "#{Tellimus::Engine.root}/app/views/tellimus/subscriptions"
|
14
|
+
|
15
|
+
include Rails::Generators::Migration
|
16
|
+
|
17
|
+
desc "Tellimus installation generator"
|
18
|
+
|
19
|
+
def install
|
20
|
+
|
21
|
+
# all entries in app/views/tellimus/subscriptions without . and ..
|
22
|
+
# ==> all FILES in the directory
|
23
|
+
files_to_copy = Dir.entries("#{Tellimus::Engine.root}/app/views/tellimus/subscriptions") - %w[. ..]
|
24
|
+
files_to_copy.each do |file|
|
25
|
+
copy_file file, "app/views/tellimus/subscriptions/#{file}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'braintree'
|
2
|
+
require 'bluecloth'
|
3
|
+
module Tellimus
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace Tellimus
|
6
|
+
config.generators do |g|
|
7
|
+
g.test_framework :rspec, :fixture => false
|
8
|
+
g.fixture_replacement :factory_bot, :dir => 'spec/factories'
|
9
|
+
g.assets false
|
10
|
+
g.helper false
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer 'tellimus.action_controller' do |app|
|
14
|
+
ActiveSupport.on_load :action_controller do
|
15
|
+
include Tellimus::ApplicationHelper
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|