summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-06-10 11:24:46 -0700
committerAzul <azul@leap.se>2013-07-17 10:47:14 +0200
commit888baf7539e131a6201dd6f53a152eeaeb8a0f94 (patch)
tree63cff56d488f7c2b1aaa26801b15e82bf41121b5
parent87dc4f9d11af4610f534d57d5e51fabca9bb328a (diff)
Fix issue with transparent redirect if form is first submitted incorrectly. Based on:
https://github.com/bvsatyaram/braintree_ruby_examples/commit/00f4852af60f0b1aae188fb11a9d5d06780d1539
-rw-r--r--billing/app/controllers/customer_controller.rb22
-rw-r--r--billing/app/controllers/payments_controller.rb35
2 files changed, 33 insertions, 24 deletions
diff --git a/billing/app/controllers/customer_controller.rb b/billing/app/controllers/customer_controller.rb
index 505aa6e..1fa19c9 100644
--- a/billing/app/controllers/customer_controller.rb
+++ b/billing/app/controllers/customer_controller.rb
@@ -10,16 +10,12 @@ class CustomerController < BillingBaseController
if customer = Customer.find_by_user_id(current_user.id)
redirect_to edit_customer_path(customer.braintree_customer_id), :notice => 'Here is your saved customer data'
else
- @tr_data = Braintree::TransparentRedirect.
- # create_customer_data(:redirect_url => confirm_customer_url(-1)) # trial
- create_customer_data(:redirect_url => confirm_customer_url)
+ fetch_new_transparent_redirect_data
end
end
def edit
- @tr_data = Braintree::TransparentRedirect.
- update_customer_data(:redirect_url => confirm_customer_url,
- :customer_id => params[:id])
+ fetch_edit_transparent_redirect_data
end
def confirm
@@ -35,8 +31,10 @@ class CustomerController < BillingBaseController
#elsif current_user.has_payment_info?
elsif (customer = Customer.find_by_user_id(current_user.id)) and customer.has_payment_info?
#customer.with_braintree_data!
+ fetch_edit_transparent_redirect_data
render :action => "edit"
else
+ fetch_new_transparent_redirect_data
render :action => "new"
end
end
@@ -54,4 +52,16 @@ class CustomerController < BillingBaseController
end
end
+ def fetch_new_transparent_redirect_data
+ @tr_data = Braintree::TransparentRedirect.
+ create_customer_data(:redirect_url => confirm_customer_url)
+ end
+
+ def fetch_edit_transparent_redirect_data
+ @tr_data = Braintree::TransparentRedirect.
+ update_customer_data(:redirect_url => confirm_customer_url,
+ :customer_id => params[:id]) ##??
+
+ end
+
end
diff --git a/billing/app/controllers/payments_controller.rb b/billing/app/controllers/payments_controller.rb
index 6cce9bf..97e0353 100644
--- a/billing/app/controllers/payments_controller.rb
+++ b/billing/app/controllers/payments_controller.rb
@@ -2,20 +2,7 @@ class PaymentsController < ApplicationController
before_filter :authorize, :only => [:index]
def new
- if current_user
- if @customer = Customer.find_by_user_id(current_user.id)
- @braintree_data = Braintree::Customer.find(@customer.braintree_customer_id)
- @default_cc = @customer.default_credit_card(@braintree_data)
- @tr_data = transparent_redirect(@customer.braintree_customer_id)
- else
- # TODO: this requires user to add self to vault before making payment. Is that desired functionality?
- redirect_to new_customer_path, :notice => 'Before making payment, please add your customer data'
- end
- else
- # anonymous payment not attributed to any user (ie, donation)
- @tr_data = transparent_redirect
- end
-
+ fetch_transparent_redirect
end
def confirm
@@ -23,6 +10,7 @@ class PaymentsController < ApplicationController
if @result.success?
render :action => "confirm"
else
+ fetch_transparent_redirect
render :action => "new"
end
end
@@ -36,10 +24,21 @@ class PaymentsController < ApplicationController
protected
- def transparent_redirect(braintree_customer_id = nil)
- Braintree::TransparentRedirect.transaction_data(:redirect_url => confirm_payment_url,
- :transaction => {:type => "sale", :customer_id => braintree_customer_id, :options => {:submit_for_settlement => true } })
- end
+ def fetch_transparent_redirect
+ if current_user
+ if @customer = Customer.find_by_user_id(current_user.id)
+ @braintree_data = Braintree::Customer.find(@customer.braintree_customer_id)
+ @default_cc = @customer.default_credit_card(@braintree_data)
+ braintree_customer_id = @customer.braintree_customer_id
+ else
+ # TODO: this requires user to add self to vault before making payment. Is that desired functionality?
+ redirect_to new_customer_path, :notice => 'Before making payment, please add your customer data'
+ end
+ end
+
+ @tr_data = Braintree::TransparentRedirect.transaction_data(:redirect_url => confirm_payment_url,
+ :transaction => {:type => "sale", :customer_id => braintree_customer_id, :options => {:submit_for_settlement => true } })
+ end
end