summaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorclaucece <soficeli0@gmail.com>2015-09-22 23:50:04 -0500
committerclaucece <soficeli0@gmail.com>2015-10-05 22:39:31 -0500
commit5a4f0fa64d36df1d60bdd693580e10ce55949b6a (patch)
treeda89540518cb5224e9b273d834156fff3ffcfc4e /engines
parentc10bbfa44442c86fda82c16524341d5f21b63664 (diff)
changed routes and links
Diffstat (limited to 'engines')
-rw-r--r--engines/billing/app/controllers/subscription_controller.rb7
-rw-r--r--engines/billing/app/controllers/subscriptions_controller.rb40
-rw-r--r--engines/billing/app/helpers/billing_helper.rb2
-rw-r--r--engines/billing/app/views/subscriptions/index.html.erb23
-rw-r--r--engines/billing/app/views/subscriptions/index2.html.haml (renamed from engines/billing/app/views/subscriptions/index.html.haml)0
-rw-r--r--engines/billing/app/views/subscriptions/new.html.erb43
-rw-r--r--engines/billing/app/views/subscriptions/show2.html.haml (renamed from engines/billing/app/views/subscriptions/show.html.haml)0
-rw-r--r--engines/billing/config/routes.rb32
8 files changed, 56 insertions, 91 deletions
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 @@
+<h2 class="mbs">Subscriptions</h2>
+<br>
+<br>
+<p>Choose subcription:</p>
+<br>
+<ul class="nav nav-tabs nav-stacked">
+ <% @subscriptions.each do |subscription| %>
+ <li>
+ <div class="btn-group">
+ <button class="btn"> <%= subscription.name %>
+ <%= subscription.price %> </button>
+ </div>
+ <div>
+ <%=link_to "Checkout", :show_subscription, class: "button" %>
+ </div>
+ </li>
+ <% end %>
+</ul>
+
+
+
+
+
diff --git a/engines/billing/app/views/subscriptions/index.html.haml b/engines/billing/app/views/subscriptions/index2.html.haml
index 1e3fb25..1e3fb25 100644
--- a/engines/billing/app/views/subscriptions/index.html.haml
+++ b/engines/billing/app/views/subscriptions/index2.html.haml
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 @@
-<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
-<h2 class="mbs">Subscriptions</h2>
-<br>
-<%= form_tag subscriptions_path, id: "checkout-form" do %>
- <% if current_user and !current_user.has_payment_info? %>
- <%= render 'customer_form' %>
- <% end %>
-<br>
-<p>Choose subcription:</p>
-<br>
-<ul class="nav nav-tabs nav-stacked">
- <% @subscriptions.each do |subscription| %>
- <li>
- <div class="btn-group">
- <button class="btn"> <%= subscription.name %>
- <%= subscription.price %> </button>
- </div>
- <br>
- <br>
- <%= simple_form_for :subscription, :url => :subscriptions, :id => "checkout-form-#{subscription.id}" do |f| %>
- <input type="hidden" name="plan_id" id="" value="<%= subscription.id%>" />
- <div id="payment-form-<%= subscription.id%>"></div>
- <div class="form-actions">
- <%= f.submit t(:subscribe), :class => 'btn btn-primary' %>
- </div>
- <script type="text/javascript" charset="utf-8">
- var clientToken = "<%= @client_token %>";
- braintree.setup(clientToken, "dropin", {
- container: "payment-form-<%= subscription.id%>",
- coinbase: { container: "coinbase-container-id" }
- });
- </script>
- <% end %>
- </li>
- <% end %>
-</ul>
-<div id="payment-form"></div>
-<div id='coinbase-container-id'></div>
-<% end %>
-
-
-
-
diff --git a/engines/billing/app/views/subscriptions/show.html.haml b/engines/billing/app/views/subscriptions/show2.html.haml
index 246ebf0..246ebf0 100644
--- a/engines/billing/app/views/subscriptions/show.html.haml
+++ b/engines/billing/app/views/subscriptions/show2.html.haml
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