From 5a4f0fa64d36df1d60bdd693580e10ce55949b6a Mon Sep 17 00:00:00 2001 From: claucece Date: Tue, 22 Sep 2015 23:50:04 -0500 Subject: changed routes and links --- .../app/controllers/subscription_controller.rb | 7 ++++ .../app/controllers/subscriptions_controller.rb | 40 +++++--------------- engines/billing/app/helpers/billing_helper.rb | 2 +- .../billing/app/views/subscriptions/index.html.erb | 23 ++++++++++++ .../app/views/subscriptions/index.html.haml | 8 ---- .../app/views/subscriptions/index2.html.haml | 8 ++++ .../billing/app/views/subscriptions/new.html.erb | 43 ---------------------- .../billing/app/views/subscriptions/show.html.haml | 7 ---- .../app/views/subscriptions/show2.html.haml | 7 ++++ engines/billing/config/routes.rb | 32 ++++++++-------- 10 files changed, 71 insertions(+), 106 deletions(-) create mode 100644 engines/billing/app/controllers/subscription_controller.rb create mode 100644 engines/billing/app/views/subscriptions/index.html.erb delete mode 100644 engines/billing/app/views/subscriptions/index.html.haml create mode 100644 engines/billing/app/views/subscriptions/index2.html.haml delete mode 100644 engines/billing/app/views/subscriptions/new.html.erb delete mode 100644 engines/billing/app/views/subscriptions/show.html.haml create mode 100644 engines/billing/app/views/subscriptions/show2.html.haml (limited to 'engines') diff --git a/engines/billing/app/controllers/subscription_controller.rb b/engines/billing/app/controllers/subscription_controller.rb new file mode 100644 index 0000000..5328c48 --- /dev/null +++ b/engines/billing/app/controllers/subscription_controller.rb @@ -0,0 +1,7 @@ +class SubscriptionsController < BillingBaseController + +before_filter :require_admin +before_filter :require_login +before_filter :confirm_cancel_subscription, :only => [:destroy] +before_filter :confirm_no_pending_active_pastdue_subscription, :only => [:new, :create] +before_filter :confirm_self, :only => [:new, :create] diff --git a/engines/billing/app/controllers/subscriptions_controller.rb b/engines/billing/app/controllers/subscriptions_controller.rb index 0a9b412..dda328a 100644 --- a/engines/billing/app/controllers/subscriptions_controller.rb +++ b/engines/billing/app/controllers/subscriptions_controller.rb @@ -1,16 +1,20 @@ class SubscriptionsController < BillingBaseController before_filter :require_login before_filter :confirm_cancel_subscription, :only => [:destroy] - before_filter :confirm_self_or_admin, :only => [:index] - before_filter :confirm_no_pending_active_pastdue_subscription, :only => [:new, :create] - # for now, admins cannot create or destroy subscriptions for others: - before_filter :confirm_self, :only => [:new, :create] + + def index + @subscriptions = Braintree::Plan.all + end + + def show + @subscription = Braintree::Plan.all.find params[:subscription_id] + end def new if current_user.braintree_customer_id @client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id) else - @client_token = Braintree::ClientToken.generate + @client_token = Braintree::ClientToken.generate end @subscriptions = Braintree::Plan.all end @@ -41,7 +45,7 @@ class SubscriptionsController < BillingBaseController def confirm @result = Braintree::Subscription.sale( payment_method_token: params[:payment_method_nonce], - plans_id: params[:plan_id], + plan_id: params[:plan_id], ) end @@ -94,29 +98,5 @@ private @result = Braintree::Subscription.cancel params[:id] end - def index - customer = Customer.find_by_user_id(@user.id) - @subscriptions = customer.subscriptions(nil, false) - end - - - def confirm_cancel_subscription - access_denied unless view_context.allow_cancel_subscription(@subscription) - end - - def confirm_no_pending_active_pastdue_subscription - #@customer = Customer.find_by_user_id(@user.id) - #if subscription = @customer.subscriptions # will return pending, active or pastdue subscription, if it exists - #redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription' - #end - end - - def confirm_self - @user == current_user - end - - def confirm_self_or_admin - access_denied unless confirm_self or admin? - end end diff --git a/engines/billing/app/helpers/billing_helper.rb b/engines/billing/app/helpers/billing_helper.rb index cb8abd6..650c15d 100644 --- a/engines/billing/app/helpers/billing_helper.rb +++ b/engines/billing/app/helpers/billing_helper.rb @@ -14,7 +14,7 @@ module BillingHelper if (admin? and user == current_user) billing_admin_path else - new_subscription_path + :index_subscription end end diff --git a/engines/billing/app/views/subscriptions/index.html.erb b/engines/billing/app/views/subscriptions/index.html.erb new file mode 100644 index 0000000..b47fae6 --- /dev/null +++ b/engines/billing/app/views/subscriptions/index.html.erb @@ -0,0 +1,23 @@ +

Subscriptions

+
+
+

Choose subcription:

+
+ + + + + + diff --git a/engines/billing/app/views/subscriptions/index.html.haml b/engines/billing/app/views/subscriptions/index.html.haml deleted file mode 100644 index 1e3fb25..0000000 --- a/engines/billing/app/views/subscriptions/index.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%h2=t :all_subscriptions -- pending_active_pastdue = false -- @subscriptions.each do |s| - - if ['Pending', 'Active','Past Due'].include? s.status - - pending_active_pastdue = true - = render :partial => "subscription_details", :locals => {:subscription => s} -- if !pending_active_pastdue and @user == current_user - = btn 'subscribe to plan', new_subscription_path diff --git a/engines/billing/app/views/subscriptions/index2.html.haml b/engines/billing/app/views/subscriptions/index2.html.haml new file mode 100644 index 0000000..1e3fb25 --- /dev/null +++ b/engines/billing/app/views/subscriptions/index2.html.haml @@ -0,0 +1,8 @@ +%h2=t :all_subscriptions +- pending_active_pastdue = false +- @subscriptions.each do |s| + - if ['Pending', 'Active','Past Due'].include? s.status + - pending_active_pastdue = true + = render :partial => "subscription_details", :locals => {:subscription => s} +- if !pending_active_pastdue and @user == current_user + = btn 'subscribe to plan', new_subscription_path diff --git a/engines/billing/app/views/subscriptions/new.html.erb b/engines/billing/app/views/subscriptions/new.html.erb deleted file mode 100644 index 2336981..0000000 --- a/engines/billing/app/views/subscriptions/new.html.erb +++ /dev/null @@ -1,43 +0,0 @@ - -

Subscriptions

-
-<%= form_tag subscriptions_path, id: "checkout-form" do %> - <% if current_user and !current_user.has_payment_info? %> - <%= render 'customer_form' %> - <% end %> -
-

Choose subcription:

-
- -
-
-<% end %> - - - - diff --git a/engines/billing/app/views/subscriptions/show.html.haml b/engines/billing/app/views/subscriptions/show.html.haml deleted file mode 100644 index 246ebf0..0000000 --- a/engines/billing/app/views/subscriptions/show.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 - - if @subscription.status == 'Active' - Current - Subscription -= render :partial => "subscription_details", :locals => {:subscription => @subscription} -- if allow_cancel_subscription(@subscription) - = destroy_btn :cancel_subscription, user_subscription_path(@user, @subscription.id), type: 'danger' diff --git a/engines/billing/app/views/subscriptions/show2.html.haml b/engines/billing/app/views/subscriptions/show2.html.haml new file mode 100644 index 0000000..246ebf0 --- /dev/null +++ b/engines/billing/app/views/subscriptions/show2.html.haml @@ -0,0 +1,7 @@ +%h1 + - if @subscription.status == 'Active' + Current + Subscription += render :partial => "subscription_details", :locals => {:subscription => @subscription} +- if allow_cancel_subscription(@subscription) + = destroy_btn :cancel_subscription, user_subscription_path(@user, @subscription.id), type: 'danger' diff --git a/engines/billing/config/routes.rb b/engines/billing/config/routes.rb index 6bbe501..444a837 100644 --- a/engines/billing/config/routes.rb +++ b/engines/billing/config/routes.rb @@ -1,25 +1,23 @@ Rails.application.routes.draw do scope "(:locale)", :locale => CommonLanguages.match_available do - match 'payments/new' => 'payments#new', :as => :new_payment - match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment - resources :users do - resources :payments, :only => [:index] - resources :subscriptions, :only => [:index, :show, :destroy] - end + match 'payments/new' => 'payments#new', :as => :new_payment + match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment + #resources :users do + # resources :payments, :only => [:index] + # resources :subscriptions, :only => [:index, :destroy] + #end - resources :customer, :only => [:new, :edit] - resources :credit_card_info, :only => [:edit] + resources :customer, :only => [:new, :edit] + resources :credit_card_info, :only => [:edit] - match 'customer/confirm/' => 'customer#confirm', :as => :confirm_customer - match 'customer/show/:id' => 'customer#show', :as => :show_customer - match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info + match 'customer/confirm/' => 'customer#confirm', :as => :confirm_customer + match 'customer/show/:id' => 'customer#show', :as => :show_customer + match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info - resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path - match 'billing_admin' => 'billing_admin#show', :as => :billing_admin - - #match 'transactions/:product_id/new' => 'transactions#new', :as => :new_transaction - #match 'transactions/confirm/:product_id' => 'transactions#confirm', :as => :confirm_transaction + resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path + match 'billing_admin' => 'billing_admin#show', :as => :billing_admin + match 'subscriptions/index' => 'subscriptions#index', :as => :index_subscription + match 'subscriptions/show' => 'subscriptions#show', :as => :show_subscription end - end -- cgit v1.2.3