diff options
Diffstat (limited to 'billing/app')
-rw-r--r-- | billing/app/controllers/subscriptions_controller.rb | 24 | ||||
-rw-r--r-- | billing/app/views/customer/edit.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/customer/show.html.haml | 10 | ||||
-rw-r--r-- | billing/app/views/payments/_transaction_details.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/payments/new.html.haml | 5 | ||||
-rw-r--r-- | billing/app/views/subscriptions/_subscription_details.html.haml | 12 | ||||
-rw-r--r-- | billing/app/views/subscriptions/create.html.haml | 1 | ||||
-rw-r--r-- | billing/app/views/subscriptions/destroy.html.haml | 4 | ||||
-rw-r--r-- | billing/app/views/subscriptions/index.html.haml | 7 | ||||
-rw-r--r-- | billing/app/views/subscriptions/show.html.haml | 5 |
10 files changed, 49 insertions, 23 deletions
diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb index 9217979..366a457 100644 --- a/billing/app/controllers/subscriptions_controller.rb +++ b/billing/app/controllers/subscriptions_controller.rb @@ -1,18 +1,13 @@ class SubscriptionsController < ApplicationController before_filter :authorize before_filter :fetch_subscription, :only => [:show, :destroy] + before_filter :confirm_no_active_subscription, :only => [:new, :create] def new # don't show link to subscribe if they are already subscribed? - customer = Customer.find_by_user_id(current_user.id) - - if subscription = customer.subscriptions # will return active subscription, if it exists - redirect_to subscription_path(subscription.id), :notice => 'You already have an active subscription' - else - credit_card = customer.default_credit_card #safe to assume default? - @payment_method_token = credit_card.token - @plans = Braintree::Plan.all - end + credit_card = @customer.default_credit_card #safe to assume default? + @payment_method_token = credit_card.token + @plans = Braintree::Plan.all end # show has no content, so not needed at this point. @@ -35,9 +30,16 @@ class SubscriptionsController < ApplicationController def fetch_subscription @subscription = Braintree::Subscription.find params[:id] @subscription_customer_id = @subscription.transactions.first.customer_details.id #all of subscriptions transactions should have same customer - customer = Customer.find_by_user_id(current_user.id) - access_denied unless customer and customer.braintree_customer_id == @subscription_customer_id + @customer = Customer.find_by_user_id(current_user.id) + access_denied unless @customer and @customer.braintree_customer_id == @subscription_customer_id # TODO: will presumably want to allow admins to view/cancel subscriptions for all users end + def confirm_no_active_subscription + @customer = Customer.find_by_user_id(current_user.id) + if subscription = @customer.subscriptions # will return active subscription, if it exists + redirect_to subscription_path(subscription.id), :notice => 'You already have an active subscription' + end + end + end diff --git a/billing/app/views/customer/edit.html.haml b/billing/app/views/customer/edit.html.haml index c2e5cb3..f9c1383 100644 --- a/billing/app/views/customer/edit.html.haml +++ b/billing/app/views/customer/edit.html.haml @@ -19,4 +19,4 @@ = link_to 'Change credit card', edit_credit_card_info_path(:id => @default_cc.token), :class => :btn = hidden_field_tag :tr_data, @tr_data = f.submit 'Save Customer Info', :class => :btn -= link_to 'Cancel', show_customer_path(@braintree_data.id), :class=> :btn
\ No newline at end of file += link_to 'Show Customer Information', show_customer_path(@braintree_data.id), :class=> :btn
\ No newline at end of file diff --git a/billing/app/views/customer/show.html.haml b/billing/app/views/customer/show.html.haml index d385d98..8ef5517 100644 --- a/billing/app/views/customer/show.html.haml +++ b/billing/app/views/customer/show.html.haml @@ -8,7 +8,13 @@ = render :partial => "payments/transaction_details", :locals => {:transaction => t} - counter += 1 = link_to 'Transaction History', payments_path +%h3 Subscriptions - if @active_subscription - %h3 Active Subscription = render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription} - = link_to 'All subscriptions', subscriptions_path
\ No newline at end of file +- else + %p + No active subscription + %p + = link_to 'subscribe to plan', new_subscription_path, :class => :btn +%p + = link_to 'All subscriptions', subscriptions_path diff --git a/billing/app/views/payments/_transaction_details.html.haml b/billing/app/views/payments/_transaction_details.html.haml index 53483d9..030639e 100644 --- a/billing/app/views/payments/_transaction_details.html.haml +++ b/billing/app/views/payments/_transaction_details.html.haml @@ -7,7 +7,7 @@ Status: = transaction.status Date - = transaction.created_at + = transaction.created_at.strftime("%Y-%m-%d") - if sub_start = transaction.subscription_details.billing_period_start_date From subscription which started = sub_start diff --git a/billing/app/views/payments/new.html.haml b/billing/app/views/payments/new.html.haml index d1d0aa9..14f6697 100644 --- a/billing/app/views/payments/new.html.haml +++ b/billing/app/views/payments/new.html.haml @@ -1,9 +1,12 @@ %h1 Payment -- if @result +- if @result and @result.errors.size > 0 %div{:style => "color: red;"} = h @result.errors.size error(s) +- if @result and @result.transaction.status == 'processor_declined' + %div{:style => "color: red;"} + Processor Declined = form_for :transaction, :params => @result && @result.params[:transaction], :errors => @result && @result.errors.for(:transaction), :builder => BraintreeFormHelper::BraintreeFormBuilder, :url => Braintree::TransparentRedirect.url, :html => {:autocomplete => "off"} do |f| #TODO: add helper = f.label :amount, "Amount" = f.text_field :amount diff --git a/billing/app/views/subscriptions/_subscription_details.html.haml b/billing/app/views/subscriptions/_subscription_details.html.haml index db9d75b..fb18210 100644 --- a/billing/app/views/subscriptions/_subscription_details.html.haml +++ b/billing/app/views/subscriptions/_subscription_details.html.haml @@ -6,10 +6,14 @@ = subscription.billing_day_of_month Start date: = subscription.first_billing_date - Paid through + Paid through: = subscription.paid_through_date - Price + Plan: + = subscription.plan_id + Price: = subscription.price - Status - = subscription.status + - color = (subscription.status == 'Active') ? "green" : "red" + Status: + %font{:color => color} + = subscription.status - # would be good to get plan name but not sure if that is possible?
\ No newline at end of file diff --git a/billing/app/views/subscriptions/create.html.haml b/billing/app/views/subscriptions/create.html.haml index e0585ab..2b6c5e9 100644 --- a/billing/app/views/subscriptions/create.html.haml +++ b/billing/app/views/subscriptions/create.html.haml @@ -2,6 +2,7 @@ %h1 Subscription Status = @result.subscription.status + = render :partial => "subscription_details", :locals => {:subscription => @result.subscription} - else %h1 Error: diff --git a/billing/app/views/subscriptions/destroy.html.haml b/billing/app/views/subscriptions/destroy.html.haml index f888e6d..e7ed6e8 100644 --- a/billing/app/views/subscriptions/destroy.html.haml +++ b/billing/app/views/subscriptions/destroy.html.haml @@ -2,4 +2,6 @@ Subscription destroyed - else Error: - = @result.message
\ No newline at end of file + = @result.message +%p + = link_to 'Customer Information', show_customer_path(@customer.braintree_customer_id), :class=> :btn
\ No newline at end of file diff --git a/billing/app/views/subscriptions/index.html.haml b/billing/app/views/subscriptions/index.html.haml index c885f90..0e84619 100644 --- a/billing/app/views/subscriptions/index.html.haml +++ b/billing/app/views/subscriptions/index.html.haml @@ -1,2 +1,7 @@ +- active = false - @subscriptions.each do |s| - = render :partial => "subscription_details", :locals => {:subscription => s}
\ No newline at end of file + - if s.status == 'Active' + - active = true + = render :partial => "subscription_details", :locals => {:subscription => s} +- if !active + = link_to 'subscribe to plan', new_subscription_path, :class => :btn
\ No newline at end of file diff --git a/billing/app/views/subscriptions/show.html.haml b/billing/app/views/subscriptions/show.html.haml index a3d57f9..6f108be 100644 --- a/billing/app/views/subscriptions/show.html.haml +++ b/billing/app/views/subscriptions/show.html.haml @@ -1,4 +1,7 @@ -%h1 Current Subscription +%h1 + - if @subscription.status == 'Active' + Current + Subscription = render :partial => "subscription_details", :locals => {:subscription => @subscription} = link_to 'Cancel Subscription', subscription_path, :confirm => 'Are you sure you want to cancel this subscription?', :method => :delete, :class => 'btn btn-danger' if @subscription.status == 'Active' # permission check or should that just be on show? = link_to 'Show Customer Data', show_customer_path(@subscription_customer_id), :class => :btn
\ No newline at end of file |