tang 0.2.2 → 0.2.4
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.
- checksums.yaml +4 -4
- data/Rakefile +3 -3
- data/app/controllers/tang/account/application_controller.rb +2 -4
- data/app/controllers/tang/account/cards_controller.rb +11 -8
- data/app/controllers/tang/account/coupons_controller.rb +1 -1
- data/app/controllers/tang/account/receipts_controller.rb +10 -4
- data/app/controllers/tang/account/subscriptions_controller.rb +11 -8
- data/app/controllers/tang/admin/application_controller.rb +4 -4
- data/app/controllers/tang/admin/coupons_controller.rb +18 -14
- data/app/controllers/tang/admin/customers_controller.rb +16 -16
- data/app/controllers/tang/admin/dashboard_controller.rb +1 -1
- data/app/controllers/tang/admin/invoices_controller.rb +6 -6
- data/app/controllers/tang/admin/payments_controller.rb +9 -9
- data/app/controllers/tang/admin/plans_controller.rb +21 -19
- data/app/controllers/tang/admin/search_controller.rb +15 -14
- data/app/controllers/tang/admin/subscriptions_controller.rb +16 -17
- data/app/controllers/tang/plans_controller.rb +1 -1
- data/app/helpers/tang/application_helper.rb +22 -28
- data/app/jobs/tang/import_charges_job.rb +4 -8
- data/app/jobs/tang/import_coupons_job.rb +3 -3
- data/app/jobs/tang/import_customers_job.rb +15 -13
- data/app/jobs/tang/import_invoices_job.rb +7 -7
- data/app/jobs/tang/import_plans_job.rb +4 -6
- data/app/jobs/tang/import_subscriptions_job.rb +4 -4
- data/app/mailers/application_mailer.rb +1 -1
- data/app/mailers/tang/stripe_mailer.rb +8 -9
- data/app/mailers/tang/subscription_mailer.rb +4 -1
- data/app/models/concerns/tang/customer.rb +32 -32
- data/app/models/tang/card.rb +7 -8
- data/app/models/tang/charge.rb +28 -50
- data/app/models/tang/coupon.rb +27 -25
- data/app/models/tang/invoice.rb +16 -17
- data/app/models/tang/invoice_item.rb +16 -18
- data/app/models/tang/plan.rb +31 -16
- data/app/models/tang/subscription.rb +34 -42
- data/app/services/tang/apply_customer_discount.rb +2 -2
- data/app/services/tang/apply_subscription_discount.rb +2 -2
- data/app/services/tang/cancel_subscription.rb +2 -2
- data/app/services/tang/change_subscription.rb +4 -4
- data/app/services/tang/create_coupon.rb +3 -5
- data/app/services/tang/create_invoice.rb +2 -2
- data/app/services/tang/create_plan.rb +9 -8
- data/app/services/tang/create_subscription.rb +18 -15
- data/app/services/tang/delete_card.rb +3 -3
- data/app/services/tang/delete_coupon.rb +3 -3
- data/app/services/tang/delete_customer.rb +2 -2
- data/app/services/tang/delete_plan.rb +2 -2
- data/app/services/tang/fail_invoice.rb +5 -6
- data/app/services/tang/pay_invoice.rb +2 -3
- data/app/services/tang/refresh_invoice_pdf.rb +9 -0
- data/app/services/tang/remove_customer_discount.rb +2 -2
- data/app/services/tang/remove_subscription_discount.rb +3 -3
- data/app/services/tang/save_card.rb +8 -9
- data/app/services/tang/update_coupon.rb +3 -5
- data/app/services/tang/update_customer.rb +4 -4
- data/app/services/tang/update_plan.rb +3 -5
- data/app/services/tang/update_subscription.rb +3 -5
- data/app/validators/future_validator.rb +4 -4
- data/app/views/tang/account/cards/show.html.erb +1 -1
- data/app/views/tang/account/receipts/_receipt.html.erb +1 -1
- data/app/views/tang/account/subscriptions/show.html.erb +14 -3
- data/app/views/tang/admin/coupons/show.html.erb +1 -1
- data/app/views/tang/admin/customers/show.html.erb +2 -2
- data/app/views/tang/admin/plans/show.html.erb +1 -1
- data/app/views/tang/admin/subscriptions/show.html.erb +2 -2
- data/app/views/tang/plans/index.html.erb +1 -1
- data/config/initializers/stripe.rb +2 -2
- data/config/initializers/stripe_event.rb +38 -33
- data/config/routes.rb +3 -1
- data/db/migrate/20160928154410_create_versions.rb +4 -4
- data/db/migrate/20160928161623_create_tang_stripe_webhooks.rb +1 -1
- data/db/migrate/20160928173328_create_tang_plans.rb +1 -1
- data/db/migrate/20160929152510_create_tang_coupons.rb +1 -1
- data/db/migrate/20160929152541_add_customer_fields.rb +1 -1
- data/db/migrate/20160929171640_create_tang_subscriptions.rb +2 -2
- data/db/migrate/20160929174251_create_tang_cards.rb +1 -1
- data/db/migrate/20161003035434_create_tang_invoices.rb +1 -1
- data/db/migrate/20161114181651_create_tang_invoice_items.rb +1 -1
- data/db/migrate/20161115201106_create_tang_charges.rb +1 -1
- data/db/migrate/20170523122759_add_group_to_plans.rb +1 -1
- data/db/migrate/20170701162853_add_stripe_indexes.rb +1 -1
- data/db/migrate/20170731010913_add_subscription_indexes.rb +1 -1
- data/db/migrate/20200827001523_add_invoice_pdf_to_invoices.rb +1 -1
- data/db/migrate/20230530172604_add_enable_customer_emails.rb +6 -0
- data/lib/generators/tang/install_generator.rb +1 -1
- data/lib/generators/templates/create_tang.rb +2 -2
- data/lib/tang/engine.rb +1 -1
- data/lib/tang/version.rb +1 -1
- data/lib/tang.rb +6 -6
- data/lib/tasks/cucumber.rake +50 -51
- data/lib/tasks/tang_tasks.rake +3 -3
- metadata +42 -30
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6c00e737bbd192088ebffd71f41793412c58ccaf3c71365c08c5e5d024346ab
|
|
4
|
+
data.tar.gz: '00954182108869f7fdbedab739d8a5ea51794279b4881bac6518e9b66c79f02c'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9616e9c1b253806fdc536fcb58f6f9f3afa3d848dca7ae945a04afc288df3cc8bb549faee196ff098d83f67942f102f5342a55da2bc04d6c045424dad9cab27f
|
|
7
|
+
data.tar.gz: 3cd81024f490c012b331131b4e6b8377714df41799883b7ace034603b2434083b35b719fb61e31404e72d2375a33d2542a81bc5a8d72292d574cdae0f23a0509
|
data/Rakefile
CHANGED
|
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
APP_RAKEFILE = File.expand_path(
|
|
17
|
+
APP_RAKEFILE = File.expand_path('../spec/tang_app/Rakefile', __FILE__)
|
|
18
18
|
load 'rails/tasks/engine.rake'
|
|
19
19
|
|
|
20
20
|
load 'rails/tasks/statistics.rake'
|
|
@@ -26,7 +26,7 @@ load './lib/tasks/tang_tasks.rake'
|
|
|
26
26
|
begin
|
|
27
27
|
require 'rspec/core/rake_task'
|
|
28
28
|
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
|
|
29
|
-
task :
|
|
29
|
+
task cucumber: 'app:cucumber'
|
|
30
30
|
task default: [:spec, :cucumber]
|
|
31
31
|
rescue LoadError
|
|
32
32
|
puts 'rspec/core/rake_task not required'
|
|
@@ -53,5 +53,5 @@ namespace :rails do
|
|
|
53
53
|
Dir.chdir('spec/tang_app') do
|
|
54
54
|
system('rails c')
|
|
55
55
|
end
|
|
56
|
-
end
|
|
56
|
+
end
|
|
57
57
|
end
|
|
@@ -3,12 +3,10 @@ module Tang
|
|
|
3
3
|
before_action :ensure_customer
|
|
4
4
|
|
|
5
5
|
def ensure_customer
|
|
6
|
-
authenticate_user! if
|
|
6
|
+
authenticate_user! if respond_to?(:authenticate_user!)
|
|
7
7
|
@current_customer = current_user
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
@current_customer
|
|
12
|
-
end
|
|
10
|
+
attr_reader :current_customer
|
|
13
11
|
end
|
|
14
12
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Account::CardsController < Account::ApplicationController
|
|
5
5
|
before_action :set_card, only: [:show, :destroy]
|
|
6
6
|
|
|
7
7
|
def show
|
|
8
|
-
@can_delete_card = current_customer.stripe_id.present? &&
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
@can_delete_card = current_customer.stripe_id.present? &&
|
|
9
|
+
current_customer.subscription.nil? &&
|
|
10
|
+
@card.present?
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def new
|
|
@@ -44,17 +44,20 @@ module Tang
|
|
|
44
44
|
|
|
45
45
|
def destroy
|
|
46
46
|
if current_customer.subscription.nil?
|
|
47
|
-
@card.
|
|
48
|
-
|
|
47
|
+
if @card.present?
|
|
48
|
+
@card.destroy
|
|
49
|
+
redirect_to account_card_url, notice: 'Card was successfully removed.'
|
|
50
|
+
else
|
|
51
|
+
redirect_to account_card_url, notice: 'We could not find a card to remove.'
|
|
52
|
+
end
|
|
49
53
|
else
|
|
50
|
-
redirect_to account_card_url, notice: 'You cannot remove your card with an active subscription.'
|
|
54
|
+
redirect_to account_card_url, notice: 'You cannot remove your card with an active subscription.'
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
private
|
|
55
59
|
|
|
56
60
|
def set_card
|
|
57
|
-
logger.debug "SET CARD CALLED"
|
|
58
61
|
@card = current_customer.card
|
|
59
62
|
end
|
|
60
63
|
end
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Account::ReceiptsController < Account::ApplicationController
|
|
5
5
|
def index
|
|
6
|
-
@invoices = current_customer.invoices
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
@invoices = current_customer.invoices
|
|
7
|
+
.paginate(page: params[:page])
|
|
8
|
+
.order(date: :desc)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def download
|
|
12
|
+
invoice = Invoice.find(params[:id])
|
|
13
|
+
invoice = RefreshInvoicePdf.call(invoice)
|
|
14
|
+
redirect_to invoice.invoice_pdf
|
|
9
15
|
end
|
|
10
16
|
end
|
|
11
17
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Account::SubscriptionsController < Account::ApplicationController
|
|
5
5
|
before_action :set_subscription, only: [:show, :edit, :update, :destroy]
|
|
6
6
|
|
|
7
7
|
def show
|
|
8
|
-
|
|
9
|
-
render :not_stripe and return
|
|
10
|
-
end
|
|
8
|
+
render :not_stripe and return unless current_customer.stripe_enabled?
|
|
11
9
|
|
|
12
10
|
@plans = Plan.where(interval: 'month').order(:order)
|
|
13
11
|
|
|
14
12
|
if @subscription.present? && @subscription.plan.present?
|
|
15
|
-
|
|
16
|
-
@
|
|
13
|
+
puts "subscription present and plan present"
|
|
14
|
+
@next_plan = @plans.where('tang_plans.order > ?', @subscription.plan.order).first
|
|
15
|
+
@previous_plan = @plans.where('tang_plans.order < ?', @subscription.plan.order).last
|
|
17
16
|
else
|
|
17
|
+
puts "subscription not present or plan not present"
|
|
18
18
|
@next_plan = @plans.first
|
|
19
19
|
@previous_plan = nil
|
|
20
20
|
end
|
|
@@ -31,6 +31,7 @@ module Tang
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def create
|
|
34
|
+
# TODO: check how it's possible to get here without a stripe_token
|
|
34
35
|
plan = Plan.find(subscription_params[:plan])
|
|
35
36
|
@subscription = CreateSubscription.call(
|
|
36
37
|
plan,
|
|
@@ -61,8 +62,9 @@ module Tang
|
|
|
61
62
|
redirect_to account_subscription_path, notice: 'Subscription was successfully changed.'
|
|
62
63
|
else
|
|
63
64
|
@plans = Plan.order(:order)
|
|
64
|
-
@next_plan = @plans.where(
|
|
65
|
-
@previous_plan = @plans.where(
|
|
65
|
+
@next_plan = @plans.where('tang_plans.order > ?', @subscription.plan.order).first
|
|
66
|
+
@previous_plan = @plans.where('tang_plans.order < ?', @subscription.plan.order).last
|
|
67
|
+
@receipts = current_customer.charges.order(created: :desc).limit(5)
|
|
66
68
|
render :show
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -77,6 +79,7 @@ module Tang
|
|
|
77
79
|
|
|
78
80
|
def set_subscription
|
|
79
81
|
@subscription = current_customer.subscription
|
|
82
|
+
puts "set_subscription: #{@subscription}"
|
|
80
83
|
end
|
|
81
84
|
|
|
82
85
|
def subscription_params
|
|
@@ -5,10 +5,10 @@ module Tang
|
|
|
5
5
|
layout Tang.admin_layout
|
|
6
6
|
|
|
7
7
|
def ensure_admin
|
|
8
|
-
authenticate_user! if
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
authenticate_user! if respond_to?(:authenticate_user!)
|
|
9
|
+
return if current_user.present? && current_user.respond_to?(:admin?) && current_user.admin?
|
|
10
|
+
|
|
11
|
+
redirect_to Tang.unauthorized_url, alert: 'You do not have access to that.'
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::CouponsController < Admin::ApplicationController
|
|
@@ -6,14 +6,13 @@ module Tang
|
|
|
6
6
|
|
|
7
7
|
# GET /coupons
|
|
8
8
|
def index
|
|
9
|
-
@coupons = Coupon.all
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
@coupons = Coupon.all
|
|
10
|
+
.paginate(page: params[:page])
|
|
11
|
+
.order(:stripe_id)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
# GET /coupons/1
|
|
15
|
-
def show
|
|
16
|
-
end
|
|
15
|
+
def show; end
|
|
17
16
|
|
|
18
17
|
# GET /coupons/new
|
|
19
18
|
def new
|
|
@@ -38,14 +37,19 @@ module Tang
|
|
|
38
37
|
end
|
|
39
38
|
|
|
40
39
|
private
|
|
41
|
-
# Use callbacks to share common setup or constraints between actions.
|
|
42
|
-
def set_coupon
|
|
43
|
-
@coupon = Coupon.find(params[:id])
|
|
44
|
-
end
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
42
|
+
def set_coupon
|
|
43
|
+
@coupon = Coupon.find(params[:id])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Only allow a trusted parameter "white list" through.
|
|
47
|
+
def coupon_params
|
|
48
|
+
params.require(:coupon)
|
|
49
|
+
.permit(
|
|
50
|
+
:stripe_id, :duration, :amount_off, :currency,
|
|
51
|
+
:duration_in_months, :max_redemptions, :percent_off, :redeem_by
|
|
52
|
+
)
|
|
53
|
+
end
|
|
50
54
|
end
|
|
51
55
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::CustomersController < Admin::ApplicationController
|
|
@@ -6,18 +6,17 @@ module Tang
|
|
|
6
6
|
|
|
7
7
|
# GET /customers
|
|
8
8
|
def index
|
|
9
|
-
@customers = Tang.customer_class
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
@customers = Tang.customer_class
|
|
10
|
+
.where.not(stripe_id: nil)
|
|
11
|
+
.paginate(page: params[:page])
|
|
12
|
+
.order(:email)
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
# GET /customers/1
|
|
15
|
-
def show
|
|
16
|
-
end
|
|
16
|
+
def show; end
|
|
17
17
|
|
|
18
18
|
# GET /customers/1/edit
|
|
19
|
-
def edit
|
|
20
|
-
end
|
|
19
|
+
def edit; end
|
|
21
20
|
|
|
22
21
|
# PATCH/PUT /customers/1
|
|
23
22
|
def update
|
|
@@ -53,14 +52,15 @@ module Tang
|
|
|
53
52
|
end
|
|
54
53
|
|
|
55
54
|
private
|
|
56
|
-
# Use callbacks to share common setup or constraints between actions.
|
|
57
|
-
def set_customer
|
|
58
|
-
@customer = Tang.customer_class.find(params[:id])
|
|
59
|
-
end
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
57
|
+
def set_customer
|
|
58
|
+
@customer = Tang.customer_class.find(params[:id])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Only allow a trusted parameter "white list" through.
|
|
62
|
+
def customer_params
|
|
63
|
+
params.require(Tang.customer_class.to_s.downcase).permit(:email, :account_balance)
|
|
64
|
+
end
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::InvoicesController < Admin::ApplicationController
|
|
5
5
|
before_action :set_invoice, only: [:show]
|
|
6
6
|
|
|
7
|
-
def show
|
|
8
|
-
end
|
|
7
|
+
def show; end
|
|
9
8
|
|
|
10
9
|
private
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
def set_invoice
|
|
12
|
+
@invoice = Invoice.find(params[:id])
|
|
13
|
+
end
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::PaymentsController < Admin::ApplicationController
|
|
5
5
|
before_action :set_payment, only: [:show]
|
|
6
6
|
|
|
7
7
|
def index
|
|
8
|
-
@payments = Tang::Charge.all
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
@payments = Tang::Charge.all
|
|
9
|
+
.paginate(page: params[:page])
|
|
10
|
+
.order(created: :desc)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def show
|
|
14
|
-
end
|
|
13
|
+
def show; end
|
|
15
14
|
|
|
16
15
|
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
|
|
17
|
+
def set_payment
|
|
18
|
+
@payment = Charge.find(params[:id])
|
|
19
|
+
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::PlansController < Admin::ApplicationController
|
|
@@ -6,14 +6,13 @@ module Tang
|
|
|
6
6
|
|
|
7
7
|
# GET /plans
|
|
8
8
|
def index
|
|
9
|
-
@plans = Plan.all
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
@plans = Plan.all
|
|
10
|
+
.paginate(page: params[:page])
|
|
11
|
+
.order(:name)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
# GET /plans/1
|
|
15
|
-
def show
|
|
16
|
-
end
|
|
15
|
+
def show; end
|
|
17
16
|
|
|
18
17
|
# GET /plans/new
|
|
19
18
|
def new
|
|
@@ -21,8 +20,7 @@ module Tang
|
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
# GET /plans/1/edit
|
|
24
|
-
def edit
|
|
25
|
-
end
|
|
23
|
+
def edit; end
|
|
26
24
|
|
|
27
25
|
# POST /plans
|
|
28
26
|
def create
|
|
@@ -51,18 +49,22 @@ module Tang
|
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
private
|
|
54
|
-
# Use callbacks to share common setup or constraints between actions.
|
|
55
|
-
def set_plan
|
|
56
|
-
@plan = Plan.find(params[:id])
|
|
57
|
-
end
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
54
|
+
def set_plan
|
|
55
|
+
@plan = Plan.find(params[:id])
|
|
56
|
+
end
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
# Only allow a trusted parameter "white list" through.
|
|
59
|
+
def plan_create_params
|
|
60
|
+
params.require(:plan).permit(
|
|
61
|
+
:stripe_id, :amount, :currency, :interval, :interval_count, :name,
|
|
62
|
+
:statement_descriptor, :trial_period_days, :order, :highlight, :features, :description, :group
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def plan_update_params
|
|
67
|
+
params.require(:plan).permit(:name, :order, :highlight, :features, :description, :group)
|
|
68
|
+
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::SearchController < Admin::ApplicationController
|
|
@@ -18,41 +18,42 @@ module Tang
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
20
|
def search_charges
|
|
21
|
-
|
|
21
|
+
Charge.search(@query)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def search_customers
|
|
25
|
-
|
|
25
|
+
Customer.search(@query)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def search_plans
|
|
29
29
|
plans = Plan.none
|
|
30
30
|
if @query.present?
|
|
31
31
|
q = "%#{@query.downcase}%"
|
|
32
|
-
plans = Plan.where(
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
plans = Plan.where('lower(tang_plans.stripe_id) like ? or lower(tang_plans.name) like ?',
|
|
33
|
+
q,
|
|
34
|
+
q)
|
|
35
|
+
.distinct
|
|
35
36
|
end
|
|
36
|
-
|
|
37
|
+
plans
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def search_coupons
|
|
40
41
|
coupons = Coupon.none
|
|
41
42
|
if @query.present?
|
|
42
43
|
q = "%#{@query.downcase}%"
|
|
43
|
-
coupons = Coupon.where(
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
coupons = Coupon.where('lower(tang_coupons.stripe_id) like ?',
|
|
45
|
+
q)
|
|
46
|
+
.distinct
|
|
46
47
|
end
|
|
47
|
-
|
|
48
|
+
coupons
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
def search_invoices
|
|
51
|
-
|
|
52
|
+
Invoice.search(@query)
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
def search_invoice_items
|
|
55
|
-
|
|
56
|
+
InvoiceItem.search(@query)
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
|
-
end
|
|
59
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require_dependency
|
|
1
|
+
require_dependency 'tang/application_controller'
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
class Admin::SubscriptionsController < Admin::ApplicationController
|
|
@@ -6,19 +6,17 @@ module Tang
|
|
|
6
6
|
|
|
7
7
|
# GET /subscriptions
|
|
8
8
|
def index
|
|
9
|
-
@subscriptions = Subscription.includes(:customer)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
@subscriptions = Subscription.includes(:customer)
|
|
10
|
+
.where.not(status: :canceled)
|
|
11
|
+
.paginate(page: params[:page])
|
|
12
|
+
.order("#{Customer.table_name}.email")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# GET /subscriptions/1
|
|
16
|
-
def show
|
|
17
|
-
end
|
|
16
|
+
def show; end
|
|
18
17
|
|
|
19
18
|
# GET /subscriptions/1/edit
|
|
20
|
-
def edit
|
|
21
|
-
end
|
|
19
|
+
def edit; end
|
|
22
20
|
|
|
23
21
|
# PATCH/PUT /subscriptions/1
|
|
24
22
|
def update
|
|
@@ -60,14 +58,15 @@ module Tang
|
|
|
60
58
|
end
|
|
61
59
|
|
|
62
60
|
private
|
|
63
|
-
# Use callbacks to share common setup or constraints between actions.
|
|
64
|
-
def set_subscription
|
|
65
|
-
@subscription = Subscription.find(params[:id])
|
|
66
|
-
end
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
63
|
+
def set_subscription
|
|
64
|
+
@subscription = Subscription.find(params[:id])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Only allow a trusted parameter "white list" through.
|
|
68
|
+
def subscription_params
|
|
69
|
+
params.require(:subscription).permit(:plan_id, :quantity, :trial_end)
|
|
70
|
+
end
|
|
72
71
|
end
|
|
73
72
|
end
|
|
@@ -2,11 +2,6 @@ require 'will_paginate/view_helpers/action_view'
|
|
|
2
2
|
|
|
3
3
|
module Tang
|
|
4
4
|
module ApplicationHelper
|
|
5
|
-
|
|
6
|
-
# def created_date(date)
|
|
7
|
-
# date.strftime('%Y/%m/%d')
|
|
8
|
-
# end
|
|
9
|
-
|
|
10
5
|
def created_datetime(date)
|
|
11
6
|
date.strftime('%Y/%m/%d %H:%M')
|
|
12
7
|
end
|
|
@@ -39,28 +34,24 @@ module Tang
|
|
|
39
34
|
end
|
|
40
35
|
|
|
41
36
|
def will_paginate(collection_or_options = nil, options = {})
|
|
42
|
-
if collection_or_options.is_a? Hash
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
unless options[:renderer]
|
|
46
|
-
options = options.merge renderer: BootstrapLinkRenderer
|
|
47
|
-
end
|
|
37
|
+
options, collection_or_options = collection_or_options, nil if collection_or_options.is_a? Hash
|
|
38
|
+
options = options.merge renderer: BootstrapLinkRenderer unless options[:renderer]
|
|
48
39
|
super(*[collection_or_options, options].compact)
|
|
49
40
|
end
|
|
50
41
|
|
|
51
42
|
class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer
|
|
52
|
-
ELLIPSIS =
|
|
43
|
+
ELLIPSIS = '…'.freeze
|
|
53
44
|
|
|
54
45
|
def to_html
|
|
55
46
|
list_items = pagination.map do |item|
|
|
56
47
|
case item
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
when Integer
|
|
49
|
+
page_number(item)
|
|
50
|
+
else
|
|
51
|
+
send(item)
|
|
61
52
|
end
|
|
62
53
|
end.join(@options[:link_separator])
|
|
63
|
-
tag(
|
|
54
|
+
tag('ul', list_items, class: ul_class)
|
|
64
55
|
end
|
|
65
56
|
|
|
66
57
|
def container_attributes
|
|
@@ -73,41 +64,44 @@ module Tang
|
|
|
73
64
|
link_options = @options[:link_options] || {}
|
|
74
65
|
|
|
75
66
|
if page == current_page
|
|
76
|
-
tag(
|
|
67
|
+
tag(
|
|
68
|
+
'li',
|
|
69
|
+
tag('span', "#{page} <span class=\"sr-only\">(current)</span>", class: 'page-link'),
|
|
70
|
+
class: 'page-item active'
|
|
71
|
+
)
|
|
77
72
|
else
|
|
78
|
-
tag(
|
|
73
|
+
tag('li', link(page, page, link_options.merge(rel: rel_value(page), class: 'page-link')), class: 'page-item')
|
|
79
74
|
end
|
|
80
75
|
end
|
|
81
76
|
|
|
82
77
|
def previous_or_next_page(page, text, classname)
|
|
83
78
|
link_options = @options[:link_options] || {}
|
|
84
79
|
if page
|
|
85
|
-
tag(
|
|
80
|
+
tag('li', link(text, page, link_options.merge(class: 'page-link')), class: format('%s page-item', classname))
|
|
86
81
|
else
|
|
87
|
-
tag(
|
|
82
|
+
tag('li', tag('span', text, class: 'page-link'), class: format('%s page-item disabled', classname))
|
|
88
83
|
end
|
|
89
84
|
end
|
|
90
85
|
|
|
91
86
|
def gap
|
|
92
|
-
tag(
|
|
87
|
+
tag('li', tag('span', ELLIPSIS), class: 'page-item disabled')
|
|
93
88
|
end
|
|
94
89
|
|
|
95
90
|
def previous_page
|
|
96
91
|
@options[:previous_label] = '<span aria-hidden="true">«</span><span class="sr-only">Previous</span>'
|
|
97
|
-
num = @collection.current_page > 1 && @collection.current_page - 1
|
|
98
|
-
previous_or_next_page(num, @options[:previous_label],
|
|
92
|
+
num = @collection.current_page > 1 && (@collection.current_page - 1)
|
|
93
|
+
previous_or_next_page(num, @options[:previous_label], 'prev')
|
|
99
94
|
end
|
|
100
95
|
|
|
101
96
|
def next_page
|
|
102
97
|
@options[:next_label] = '<span aria-hidden="true">»</span><span class="sr-only">Next</span>'
|
|
103
|
-
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
|
104
|
-
previous_or_next_page(num, @options[:next_label],
|
|
98
|
+
num = @collection.current_page < @collection.total_pages && (@collection.current_page + 1)
|
|
99
|
+
previous_or_next_page(num, @options[:next_label], 'next')
|
|
105
100
|
end
|
|
106
101
|
|
|
107
102
|
def ul_class
|
|
108
|
-
[@options[:class]].compact.join(
|
|
103
|
+
[@options[:class]].compact.join(' ')
|
|
109
104
|
end
|
|
110
105
|
end
|
|
111
|
-
|
|
112
106
|
end
|
|
113
107
|
end
|