summaryrefslogtreecommitdiff
path: root/engines/billing/app
diff options
context:
space:
mode:
Diffstat (limited to 'engines/billing/app')
-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
7 files changed, 41 insertions, 74 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