From 234cb9af5f11953f93910e79143fcb842e924248 Mon Sep 17 00:00:00 2001 From: claucece Date: Wed, 16 Sep 2015 00:13:01 -0500 Subject: added payment_info, _customer_form, sucess instances --- app/models/user.rb | 4 ++++ engines/billing/app/controllers/payments_controller.rb | 11 ++++++++--- engines/billing/app/views/payments/_customer_form.html.erb | 13 +++++++++++++ engines/billing/app/views/payments/new.html.erb | 2 ++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 engines/billing/app/views/payments/_customer_form.html.erb diff --git a/app/models/user.rb b/app/models/user.rb index 3daee0f..b5bbadf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -177,6 +177,10 @@ class User < CouchRest::Model::Base end + def has_payment_info? + braintree_customer_id + end + protected ## diff --git a/engines/billing/app/controllers/payments_controller.rb b/engines/billing/app/controllers/payments_controller.rb index ece967b..7c2b2d3 100644 --- a/engines/billing/app/controllers/payments_controller.rb +++ b/engines/billing/app/controllers/payments_controller.rb @@ -6,11 +6,16 @@ class PaymentsController < BillingBaseController end def confirm - result = Braintree::Transaction.sale( + @result = Braintree::Transaction.sale( amount: params[:amount], - payment_method_nonce: params[:payment_method_nonce] + payment_method_nonce: params[:payment_method_nonce], ) - redirect_to action: :new, flash: { success: "done" } + if @result.success? == true + redirect_to action: :new, notice: "Congraulations! Your transaction has been successfully!" + else + flash[:alert] = "Something went wrong while processing your donation. Please try again!" + redirect_to action: :new + end end def index diff --git a/engines/billing/app/views/payments/_customer_form.html.erb b/engines/billing/app/views/payments/_customer_form.html.erb new file mode 100644 index 0000000..2e8a3b1 --- /dev/null +++ b/engines/billing/app/views/payments/_customer_form.html.erb @@ -0,0 +1,13 @@ +

Please enter your personal info:

+
+ <%= text_field_tag :first_name, "",placeholder: "First Name", class: "radius" %> +
+
+ <%= text_field_tag :last_name, "",placeholder: "Last Name", class: "radius" %> +
+
+ <%= text_field_tag :company, "",placeholder: "Company", class: "radius" %> +
+
+ <%= text_field_tag :phone, "",placeholder: "Phone", class: "radius" %> +
diff --git a/engines/billing/app/views/payments/new.html.erb b/engines/billing/app/views/payments/new.html.erb index 86a1d64..3cdda01 100644 --- a/engines/billing/app/views/payments/new.html.erb +++ b/engines/billing/app/views/payments/new.html.erb @@ -2,6 +2,8 @@

Please enter your donation details (this is a donation and will not be applied towards your account):


<%= form_tag confirm_payment_path, id: "checkout-form" do %> + # add migration to user first. Not sure about the anonymous part. + # <%= render 'customer_form' unless current_user.has_payment_info? && current_user.where.not.is_anonymous? %>
-- cgit v1.2.3