summaryrefslogtreecommitdiff
path: root/engines/billing/app/controllers/payments_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'engines/billing/app/controllers/payments_controller.rb')
-rw-r--r--engines/billing/app/controllers/payments_controller.rb60
1 files changed, 46 insertions, 14 deletions
diff --git a/engines/billing/app/controllers/payments_controller.rb b/engines/billing/app/controllers/payments_controller.rb
index fce6570..871f1b4 100644
--- a/engines/billing/app/controllers/payments_controller.rb
+++ b/engines/billing/app/controllers/payments_controller.rb
@@ -2,19 +2,14 @@ class PaymentsController < BillingBaseController
before_filter :require_login, :only => [:index]
def new
- fetch_transparent_redirect
- end
-
- def confirm
- @result = Braintree::TransparentRedirect.confirm(request.query_string)
- if @result.success?
- render :action => "confirm"
+ if current_user.has_payment_info?
+ @client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
else
- fetch_transparent_redirect
- render :action => "new"
- end
+ @client_token = Braintree::ClientToken.generate
+ end
end
+# not sure if this should be kept
def index
access_denied unless admin? or (@user == current_user)
customer = Customer.find_by_user_id(@user.id)
@@ -23,12 +18,49 @@ class PaymentsController < BillingBaseController
@transactions = braintree_data.transactions
end
- protected
+ def confirm
+ make_transaction
+ if @result.success?
+ flash[:success] = I18n.t(:donation_sucess)
+ else
+ flash[:error] = I18n.t(:donation_not_sucess)
+ end
+ redirect_to action: :new, locale: params[:locale]
+ end
- def fetch_transparent_redirect
- @tr_data = Braintree::TransparentRedirect.transaction_data redirect_url: confirm_payment_url,
- transaction: { type: "sale", options: {submit_for_settlement: true } }
+ private
+ def make_transaction
+ if current_user.has_payment_info?
+ transact_without_user_info
+ elsif current_user.is_anonymous?
+ transact_without_user_info
+ else
+ transact_with_user_info
+ end
end
+ def transact_with_user_info
+ @result = Braintree::Transaction.sale(
+ amount: params[:amount],
+ payment_method_nonce: params[:payment_method_nonce],
+ customer: {
+ first_name: params[:first_name],
+ last_name: params[:last_name],
+ company: params[:company],
+ email: current_user.email,
+ phone: params[:phone]
+ },
+ options: {
+ store_in_vault: true
+ })
+ current_user.update_attributes(braintree_customer_id: @result.transaction.customer_details.id) if @result.success?
+ end
+
+ def transact_without_user_info
+ @result = Braintree::Transaction.sale(
+ amount: params[:amount],
+ payment_method_nonce: params[:payment_method_nonce],
+ )
+ end
end