diff options
author | jessib <jessib@leap.se> | 2013-04-23 13:23:01 -0700 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-07-17 10:47:13 +0200 |
commit | 1e557522fafc26829b8e9a873da28b7082d4df42 (patch) | |
tree | a78542bf9cc801d444168e2a88f1957c27a6d8b7 | |
parent | c2330394daf004974656d8240ca6c83567401595 (diff) |
Some improvements to navigation, and pulling out separate show/edit views for customers.
-rw-r--r-- | billing/app/controllers/customer_controller.rb | 54 | ||||
-rw-r--r-- | billing/app/controllers/subscriptions_controller.rb | 4 | ||||
-rw-r--r-- | billing/app/views/credit_card_info/edit.html.haml | 3 | ||||
-rw-r--r-- | billing/app/views/customer/_transaction.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/customer/edit.html.haml | 21 | ||||
-rw-r--r-- | billing/app/views/customer/show.html.haml | 8 | ||||
-rw-r--r-- | billing/app/views/payments/_customer_data.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/payments/new.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/subscriptions/_subscription_details.html.haml | 2 | ||||
-rw-r--r-- | billing/app/views/subscriptions/show.html.haml | 4 | ||||
-rw-r--r-- | billing/config/routes.rb | 2 |
11 files changed, 59 insertions, 45 deletions
diff --git a/billing/app/controllers/customer_controller.rb b/billing/app/controllers/customer_controller.rb index d71a5e4..556b607 100644 --- a/billing/app/controllers/customer_controller.rb +++ b/billing/app/controllers/customer_controller.rb @@ -1,5 +1,18 @@ class CustomerController < BillingBaseController before_filter :authorize + before_filter :fetch_customer_data, :only => [:show, :edit] + + + def show + @subscriptions = @customer.active_subscriptions(@braintree_data) + + # UGLY Braintree::ResourceCollection to array. + # might want method + @transactions = [] + @braintree_data.transactions.each do |transaction| + @transactions << transaction + end + end def new if customer = Customer.find_by_user_id(current_user.id) @@ -8,30 +21,12 @@ class CustomerController < BillingBaseController @tr_data = Braintree::TransparentRedirect. create_customer_data(:redirect_url => confirm_customer_url) end - end + end def edit - if ((customer = Customer.find_by_user_id(current_user.id)) and - (params[:id] == customer.braintree_customer_id)) - #current_customer.with_braintree_data! - @braintree_data = Braintree::Customer.find(params[:id]) #used in editing form - @default_cc = customer.default_credit_card(@braintree_data) - @tr_data = Braintree::TransparentRedirect. - update_customer_data(:redirect_url => confirm_customer_url, - :customer_id => params[:id]) - - @subscriptions = customer.active_subscriptions(@braintree_data) - - # UGLY Braintree::ResourceCollection to array. - # might want method - @transactions = [] - @braintree_data.transactions.each do |transaction| - @transactions << transaction - end - else - # TODO: will want to have case for admins, presumably - access_denied - end + @tr_data = Braintree::TransparentRedirect. + update_customer_data(:redirect_url => confirm_customer_url, + :customer_id => params[:id]) end def confirm @@ -52,4 +47,19 @@ class CustomerController < BillingBaseController render :action => "new" end end + + private + + def fetch_customer_data + if ((@customer = Customer.find_by_user_id(current_user.id)) and + (params[:id] == @customer.braintree_customer_id)) + #current_customer.with_braintree_data! + @braintree_data = Braintree::Customer.find(params[:id]) #used in editing form + @default_cc = @customer.default_credit_card(@braintree_data) + else + # TODO will want case for admins, presumably + access_denied + end + end + end diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb index 1f15954..9735527 100644 --- a/billing/app/controllers/subscriptions_controller.rb +++ b/billing/app/controllers/subscriptions_controller.rb @@ -29,9 +29,9 @@ 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 + @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 + 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 diff --git a/billing/app/views/credit_card_info/edit.html.haml b/billing/app/views/credit_card_info/edit.html.haml index 95f450f..57322de 100644 --- a/billing/app/views/credit_card_info/edit.html.haml +++ b/billing/app/views/credit_card_info/edit.html.haml @@ -13,4 +13,5 @@ %dt= f.label :cvv, 'CVV' %dd= f.text_field :cvv = hidden_field_tag :tr_data, @tr_data - = f.submit 'Save Payment Info'
\ No newline at end of file + = f.submit 'Save Payment Info', :class => :btn + = link_to t(:cancel), edit_customer_path(@credit_card.customer_id), :class => :btn
\ No newline at end of file diff --git a/billing/app/views/customer/_transaction.html.haml b/billing/app/views/customer/_transaction.html.haml index 97842dc..53483d9 100644 --- a/billing/app/views/customer/_transaction.html.haml +++ b/billing/app/views/customer/_transaction.html.haml @@ -2,7 +2,7 @@ = transaction.id Type: = transaction.type - Transaction Amount: + Amount: = number_to_currency(transaction.amount) Status: = transaction.status diff --git a/billing/app/views/customer/edit.html.haml b/billing/app/views/customer/edit.html.haml index 2104b09..bea3211 100644 --- a/billing/app/views/customer/edit.html.haml +++ b/billing/app/views/customer/edit.html.haml @@ -11,19 +11,12 @@ %dd= f.text_field :last_name %dt= f.label :phone, 'Phone' %dd= f.text_field :phone - - if @default_cc - %ul - %li - Stored Credit Card + - if @default_cc + = # todo, as they will need a credit card, so not sure about conditional? + %dt Stored Credit Card + %dd = @default_cc.masked_number - = link_to 'Change credit card', edit_credit_card_info_path(:id => @default_cc.token) - %li - Transaction History - = render(:partial => "transaction", :collection => @transactions) - - if @subscriptions.any? - %li - Active Subscriptions - = # todo: won't really have multiple subscriptions - = render(:partial => "subscription", :collection => @subscriptions) + = 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'
\ No newline at end of file + = f.submit 'Save Customer Info', :class => :btn += link_to 'Cancel', 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 new file mode 100644 index 0000000..7416682 --- /dev/null +++ b/billing/app/views/customer/show.html.haml @@ -0,0 +1,8 @@ += render :partial => 'payments/customer_data' += link_to 'Make Payment', new_payment_path, :class => :btn +%h3 Transaction History += render(:partial => "transaction", :collection => @transactions) # show subset with link to see more +- if @subscriptions.any? + %h3 Active Subscriptions + = # todo: won't really have multiple subscriptions + = render(:partial => "subscription", :collection => @subscriptions)
\ No newline at end of file diff --git a/billing/app/views/payments/_customer_data.html.haml b/billing/app/views/payments/_customer_data.html.haml index 900fbd8..d46065c 100644 --- a/billing/app/views/payments/_customer_data.html.haml +++ b/billing/app/views/payments/_customer_data.html.haml @@ -12,4 +12,4 @@ %dd= @default_cc.masked_number %dt Expiration Date %dd= @default_cc.expiration_date -= link_to 'edit saved data', edit_customer_path(@customer.braintree_customer_id), :class => :btn += link_to 'Edit Saved Data', edit_customer_path(@customer.braintree_customer_id), :class => :btn diff --git a/billing/app/views/payments/new.html.haml b/billing/app/views/payments/new.html.haml index 1d958b9..d1d0aa9 100644 --- a/billing/app/views/payments/new.html.haml +++ b/billing/app/views/payments/new.html.haml @@ -12,4 +12,4 @@ - else = render :partial => 'customer_data' = hidden_field_tag :tr_data, @tr_data - = f.submit "Submit"
\ No newline at end of file + = f.submit "Submit Payment", :class => :btn
\ No newline at end of file diff --git a/billing/app/views/subscriptions/_subscription_details.html.haml b/billing/app/views/subscriptions/_subscription_details.html.haml index db07204..db9d75b 100644 --- a/billing/app/views/subscriptions/_subscription_details.html.haml +++ b/billing/app/views/subscriptions/_subscription_details.html.haml @@ -1,5 +1,5 @@ %p - = subscription.id + = link_to subscription.id, subscription_path(subscription.id) Balance: = number_to_currency(subscription.balance) Bill on: diff --git a/billing/app/views/subscriptions/show.html.haml b/billing/app/views/subscriptions/show.html.haml index bc85fd9..b630a05 100644 --- a/billing/app/views/subscriptions/show.html.haml +++ b/billing/app/views/subscriptions/show.html.haml @@ -1,2 +1,4 @@ +%h1 Current Subscription = render :partial => "subscription_details", :locals => {:subscription => @subscription} -= link_to t(:Cancel), subscription_path, :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger' if @subscription.status == 'Active' # permission check or should that just be on show?
\ No newline at end of file += 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', customer_path(@subscription_customer_id), :class => :btn
\ No newline at end of file diff --git a/billing/config/routes.rb b/billing/config/routes.rb index b5ccf6e..4f31fb7 100644 --- a/billing/config/routes.rb +++ b/billing/config/routes.rb @@ -3,7 +3,7 @@ Rails.application.routes.draw do match 'payments/new' => 'payments#new', :as => :new_payment match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment - resources :customer, :only => [:new, :edit] + resources :customer, :only => [:new, :edit, :show] resources :credit_card_info, :only => [:edit] match 'customer/confirm' => 'customer#confirm', :as => :confirm_customer |