From c10bbfa44442c86fda82c16524341d5f21b63664 Mon Sep 17 00:00:00 2001 From: claucece Date: Tue, 22 Sep 2015 10:48:14 -0500 Subject: subscriptions, translation --- .../billing/app/controllers/customer_controller.rb | 63 ++++------------------ engines/billing/app/controllers/subscriptors.rb | 9 ++++ 2 files changed, 18 insertions(+), 54 deletions(-) create mode 100644 engines/billing/app/controllers/subscriptors.rb (limited to 'engines/billing/app/controllers') diff --git a/engines/billing/app/controllers/customer_controller.rb b/engines/billing/app/controllers/customer_controller.rb index 6cbcb44..3a82ff7 100644 --- a/engines/billing/app/controllers/customer_controller.rb +++ b/engines/billing/app/controllers/customer_controller.rb @@ -1,64 +1,19 @@ class CustomerController < BillingBaseController - before_filter :require_login, :fetch_customer - - def show - if @customer - @customer.with_braintree_data! - @default_cc = @customer.default_credit_card - @active_subscription = @customer.subscriptions - @transactions = @customer.braintree_customer.transactions - end - end + before_filter :require_login def new - if @customer.has_payment_info? - redirect_to edit_customer_path(@user), :notice => 'Here is your saved customer data' - else - fetch_new_transparent_redirect_data - end - end - - def edit - fetch_edit_transparent_redirect_data - end - - def confirm - @result = Braintree::TransparentRedirect.confirm(request.query_string) - if @result.success? - @customer.braintree_customer = @result.customer - @customer.save - render :action => "confirm" - elsif @customer.has_payment_info? - fetch_edit_transparent_redirect_data - render :action => "edit" + if current_user.braintree_customer_id + Braintree::Customer.find current_user.braintree_customer_id else - fetch_new_transparent_redirect_data - render :action => "new" + customer = Braintree::Customer.create(payment_method_nonce: params[:payment_method_nonce]).customer + current_user.update_attributes braintree_customer_id: customer.id + customer end end - protected - - def fetch_new_transparent_redirect_data - access_denied unless @user == current_user # admins cannot do this for others - @tr_data = Braintree::TransparentRedirect. - create_customer_data(:redirect_url => confirm_customer_url) - end - - def fetch_edit_transparent_redirect_data - access_denied unless @user == current_user # admins cannot do this for others - @customer.with_braintree_data! - @default_cc = @customer.default_credit_card - @tr_data = Braintree::TransparentRedirect. - update_customer_data(:redirect_url => confirm_customer_url, - :customer_id => @customer.braintree_customer_id) ##?? + def show + if current_user.braintree_customer_id + Braintree::Customer.find current_user.braintree_customer_id end - - def fetch_customer - @customer = Customer.find_by_user_id(@user.id) - if @user == current_user - @customer ||= Customer.new(user: @user) - end - access_denied unless (@customer and (@customer.user == current_user)) or admin? end end diff --git a/engines/billing/app/controllers/subscriptors.rb b/engines/billing/app/controllers/subscriptors.rb new file mode 100644 index 0000000..2e80e69 --- /dev/null +++ b/engines/billing/app/controllers/subscriptors.rb @@ -0,0 +1,9 @@ +def braintree_customer + if current_user.braintree_customer_id + Braintree::Customer.find current_user.braintree_customer_id + else + customer = Braintree::Customer.create(payment_method_nonce: params[:payment_method_nonce]).customer + current_user.update_attributes braintree_customer_id: customer.id + customer + end +end -- cgit v1.2.3