summaryrefslogtreecommitdiff
path: root/billing/app/controllers
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-03-19 15:54:24 -0700
committerAzul <azul@leap.se>2013-07-17 10:46:25 +0200
commita1837914b8f989e2c45fb7b78fc648f0d3f957d6 (patch)
tree0f43e54764acaad1ba8af6265432fe5606e6fbec /billing/app/controllers
parent925534524317d0b6e7786d5a891e2b462b897d0a (diff)
Start to adding customers to braintree vault.
Diffstat (limited to 'billing/app/controllers')
-rw-r--r--billing/app/controllers/customer_controller.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/billing/app/controllers/customer_controller.rb b/billing/app/controllers/customer_controller.rb
new file mode 100644
index 0000000..dcb94eb
--- /dev/null
+++ b/billing/app/controllers/customer_controller.rb
@@ -0,0 +1,36 @@
+class CustomerController < ApplicationController
+ before_filter :authorize
+
+ def new
+ @tr_data = Braintree::TransparentRedirect.
+ create_customer_data(:redirect_url => confirm_customer_url)
+ end
+
+ def edit
+ current_customer = Customer.find_by_user_id(current_user.id)
+ #current_customer.with_braintree_data!
+ #@credit_card = current_customer.default_credit_card
+ @tr_data = Braintree::TransparentRedirect.
+ update_customer_data(:redirect_url => confirm_customer_url,
+ :customer_id => current_customer.braintree_customer_id)
+ end
+
+ def confirm
+ @result = Braintree::TransparentRedirect.confirm(request.query_string)
+
+ if @result.success?
+ # customer = Customer.new(:user_id => current_user.id, :braintree_customer_id => @result.customer.id)
+ customer = Customer.new(:braintree_customer_id => @result.customer.id)
+ customer.user = current_user
+ customer.save
+ #current_user.save!
+ render :action => "confirm"
+ #elsif current_user.has_payment_info?
+ elsif (current_customer = Customer.find_by_user_id(current_user.id)) and current_customer.has_payment_info?
+ current_customer.with_braintree_data! #todo
+ render :action => "edit"
+ else
+ render :action => "new"
+ end
+ end
+end