diff options
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | engines/billing/app/controllers/payments_controller.rb | 11 | ||||
-rw-r--r-- | engines/billing/app/views/payments/_customer_form.html.erb | 13 | ||||
-rw-r--r-- | engines/billing/app/views/payments/new.html.erb | 2 |
4 files changed, 27 insertions, 3 deletions
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 @@ +<p>Please enter your personal info:</p> +<div class="mb1"> + <%= text_field_tag :first_name, "",placeholder: "First Name", class: "radius" %> +</div> +<div class="mb1"> + <%= text_field_tag :last_name, "",placeholder: "Last Name", class: "radius" %> +</div> +<div class="mb1"> + <%= text_field_tag :company, "",placeholder: "Company", class: "radius" %> +</div> +<div class="mb1"> + <%= text_field_tag :phone, "",placeholder: "Phone", class: "radius" %> +</div> 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 @@ <p>Please enter your donation details (this is a donation and will not be applied towards your account):</p> <br> <%= 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? %> <div id="payment-form"></div> <div id='coinbase-container-id'></div> <input type="text" name="amount" placeholder="Enter amount"> |