diff --git a/app/assets/stylesheets/sass/_typography.scss b/app/assets/stylesheets/sass/_typography.scss index b07b8d5..c5ff002 100644 --- a/app/assets/stylesheets/sass/_typography.scss +++ b/app/assets/stylesheets/sass/_typography.scss @@ -28,24 +28,32 @@ padding: 0.5em 1em; vertical-align: middle; - &.organization, &.secondary { + &.organization, &.secondary, &.best { background-color: $organization-color; } - &.article { + &.article, &.good { background-color: $article-color; } + &.better { + background-color: darken($warning-color, 2); + } + &:hover { color: $primary-color; border: 0.15em solid; background-color: transparent; - &.organization { + &.organization, &.secondary, &.best { color: $organization-color; } - &.article { + &.better { + color: darken($warning-color, 2); + } + + &.article, &.good { color: $article-color; } } @@ -625,3 +633,24 @@ article { p.help { font-size: 1.1em; } + +.small-form { + > .field { + display: inline-block; + vertical-align: baseline; + width: 10em; + + input { + text-align: right; + } + + label { + display: none; + } + } + + .actions { + display: inline-block; + vertical-align: middle; + } +} diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 648126d..3032921 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -354,7 +354,21 @@ class ConferencesController < ApplicationController when 'already_registered' send_confirmation next_step = 'thanks' - when 'pay_now', 'payment-confirmed', 'payment-cancelled' + when 'paypal-confirmed' + @registration = ConferenceRegistration.find(session[:registration][:registration_id]) + next_step = 'confirm_payment' + when 'confirm_payment' + @registration = ConferenceRegistration.find(session[:registration][:registration_id]) + if params[:confirm_payment] + info = YAML.load(@registration.payment_info) + paypal = PayPal!.checkout!(info[:token], info[:payer_id], PayPalRequest(info[:amount])) + if paypal.payment_info.first.payment_status == 'Completed' + @registration.registration_fees_paid = paypal.payment_info.first.amount.total + @registration.save! + end + end + next_step = 'thanks' + when 'pay_now', 'payment-confirmed', 'paypal-cancelled' next_step = 'thanks' end session.delete(:registration_step) @@ -415,6 +429,8 @@ class ConferencesController < ApplicationController @actions = [:cancel, :submit] when 'cancel' @actions = [:no, :yes] + when 'confirm_payment' + @actions = [:cancel_payment, :confirm_payment] when 'already_registered' @registration = ConferenceRegistration.find_by(:email => session[:registration][:email]) if !@registration.complete @@ -472,92 +488,50 @@ class ConferencesController < ApplicationController @conference_registration = ConferenceRegistration.find_by(confirmation_token: params[:confirmation_token]) host = "#{request.protocol}#{request.host_with_port}" if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete - if params[:payment_amount].nil? + amount = (params[:auto_payment_amount] || params[:payment_amount]).to_f + if amount > 0 + response = PayPal!.setup( + PayPalRequest(amount), + host + (@conference.url + "/register/paypal-confirm/#{@conference_registration.payment_confirmation_token}/").gsub(/\/\/+/, '/'), + host + (@conference.url + "/register/paypal-cancel/#{@conference_registration.confirmation_token}/").gsub(/\/\/+/, '/') + ) + redirect_to response.redirect_uri + else session[:registration] = YAML.load(@conference_registration.data) session[:registration][:registration_id] = @conference_registration.id session[:registration][:path] = Array.new session[:registration_step] = 'pay_now' redirect_to action: 'register' - else - begin - paypal_info = get_secure_info(:paypal) - request = Paypal::Express::Request.new( - :username => paypal_info[:username], - :password => paypal_info[:password], - :signature => paypal_info[:signature] - ) - payment_request = Paypal::Payment::Request.new( - :currency_code => 'USD', # if nil, PayPal use USD as default - :description => 'Conference Registration', # item description - :quantity => 1, # item quantity - :amount => params[:payment_amount].to_f, # item value - :custom_fields => { - CARTBORDERCOLOR: "00ADEF", - LOGOIMG: "https://cdn.bikebike.org/assets/bblogo-paypal.png" - } - ) - response = request.setup( - payment_request, - host + (@conference.url + "/register/confirm-payment/#{@conference_registration.payment_confirmation_token}/").gsub(/\/\/+/, '/'), - host + (@conference.url + "/register/cancel-payment/#{@conference_registration.confirmation_token}/").gsub(/\/\/+/, '/') - ) - redirect_to response.redirect_uri - rescue Exception => e - ddd - end end - elsif params[:test] - paypal_info = get_secure_info(:paypal) - request = Paypal::Express::Request.new( - :username => paypal_info[:username], - :password => paypal_info[:password], - :signature => paypal_info[:signature] - ) - payment_request = Paypal::Payment::Request.new( - :currency_code => 'USD', # if nil, PayPal use USD as default - :description => 'Conference Registration Test', # item description - :quantity => 1, # item quantity - :amount => 25.0, # item value - :custom_fields => { - CARTBORDERCOLOR: "00ADEF", - LOGOIMG: "https://cdn.bikebike.org/assets/bblogo-paypal.png" - } - ) - response = request.setup( - payment_request, - host + @conference.url, - host + @conference.url - ) - redirect_to response.redirect_uri else do_404 end end - def register_confirm_payment + def register_paypal_confirm set_conference @conference_registration = ConferenceRegistration.find_by(payment_confirmation_token: params[:confirmation_token]) - if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete && @conference_registration.payment_info.nil? - @conference_registration.payment_info = "#{params[:PayerID]}:#{params[:token]}" + if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete && @conference_registration.registration_fees_paid.nil? + @conference_registration.payment_info = {:payer_id => params[:PayerID], :token => params[:token], :amount => PayPal!.details(params[:token]).amount.total}.to_yaml @conference_registration.save! session[:registration] = YAML.load(@conference_registration.data) session[:registration][:registration_id] = @conference_registration.id session[:registration][:path] = Array.new - session[:registration_step] = 'payment-confirmed' + session[:registration_step] = 'paypal-confirmed' redirect_to action: 'register' else do_404 end end - def register_cancel_payment + def register_paypal_cancel set_conference @conference_registration = ConferenceRegistration.find_by(confirmation_token: params[:confirmation_token]) if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete && @conference_registration.payment_info.nil? session[:registration] = YAML.load(@conference_registration.data) session[:registration][:registration_id] = @conference_registration.id session[:registration][:path] = Array.new - session[:registration_step] = 'payment-cancelled' + session[:registration_step] = 'paypal-cancelled' redirect_to action: 'register' end end @@ -789,4 +763,26 @@ class ConferencesController < ApplicationController data ||= YAML.load(registration.data) UserMailer.conference_registration_payment_received(@conference, data, registration).deliver end + + def PayPal! + paypal_info = get_secure_info(:paypal) + Paypal::Express::Request.new( + :username => paypal_info[:username], + :password => paypal_info[:password], + :signature => paypal_info[:signature] + ) + end + + def PayPalRequest(amount) + Paypal::Payment::Request.new( + :currency_code => 'USD', # if nil, PayPal use USD as default + :description => 'Conference Registration', # item description + :quantity => 1, # item quantity + :amount => amount.to_f, # item value + :custom_fields => { + CARTBORDERCOLOR: "00ADEF", + LOGOIMG: "https://cdn.bikebike.org/assets/bblogo-paypal.png" + } + ) + end end diff --git a/app/helpers/bike_bike_form_helper.rb b/app/helpers/bike_bike_form_helper.rb index 4c627e4..818c048 100644 --- a/app/helpers/bike_bike_form_helper.rb +++ b/app/helpers/bike_bike_form_helper.rb @@ -41,6 +41,7 @@ module BikeBikeFormHelper end def number_field_tag(name, value = nil, options = {}) + options[:_no_wrapper] = true render_field(name, options = get_options(name, options), super(name, value, options), value) end @@ -77,6 +78,10 @@ module BikeBikeFormHelper end def text_field_tag(name, value = nil, options = {}) + if options[:_no_wrapper] + options.delete(:_no_wrapper) + options[:no_wrapper] = true + end render_field(name, options = get_options(name, options), super(name, value, options), value) end @@ -148,6 +153,7 @@ module BikeBikeFormHelper end def number_field(object_name, method, options = {}) + options[:_no_wrapper] = true render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options)) end @@ -180,6 +186,10 @@ module BikeBikeFormHelper end def text_field(object_name, method, options = {}) + if options[:_no_wrapper] + options.delete(:_no_wrapper) + options[:no_wrapper] = true + end render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options)) end diff --git a/app/views/conferences/_register_confirm_payment.html.haml b/app/views/conferences/_register_confirm_payment.html.haml new file mode 100644 index 0000000..d6e1845 --- /dev/null +++ b/app/views/conferences/_register_confirm_payment.html.haml @@ -0,0 +1,5 @@ +- if @registration && @registration.is_participant && @registration.complete && @registration.payment_info.present? + - info = YAML.load(@registration.payment_info) + %h3=_'registration.payment_confirm.title','Please confirm your payment' + .columns + %p=_'registration.payment_confirm.help',"You are about to confirm your payment of #{number_to_currency(info[:amount], :unit => '$')} USD for registration.", vars: {:amount => number_to_currency(info[:amount], :unit => '$')} diff --git a/app/views/conferences/_register_thanks.html.haml b/app/views/conferences/_register_thanks.html.haml index fa066a7..f4341f2 100644 --- a/app/views/conferences/_register_thanks.html.haml +++ b/app/views/conferences/_register_thanks.html.haml @@ -4,14 +4,24 @@ .columns - if !@registration.is_participant %p=_'registration.thanks.all_done.volunteer','Thanks for submitting your volunteer infomation. We\'ll see you at Bike!Bike!' - - elsif @registration.payment_info.nil? + - elsif @registration.registration_fees_paid.nil? %p=_'registration.thanks.all_done.please_pay',"Thank you for completing your registration. We'll see you at Bike!Bike! If you have not already done so, we ask that you pay the registration donation as soon as you can." - = form_tag ("#{@conference.url}/register/pay-registration/#{@registration.confirmation_token}/").gsub(/\/\/+/, '/'), :method => :post, :class => 'row' do + = form_tag ("#{@conference.url}/register/pay-registration/#{@registration.confirmation_token}/").gsub(/\/\/+/, '/'), :method => :post do = hidden_field_tag :confirmation_token, @registration.confirmation_token - .columns.small-4.small-offset-2 - = number_field_tag :payment_amount, 25.00, :step => 0.01, :min => 0.01 - .columns.small-4.end - = form_actions :submit_payment + .row + .columns.small-12.centered + %p=_'registration.thanks.all_done.please_pay.currency','(amounts are in $USD)' + %button{name: 'auto_payment_amount', type: 'submit', value: '25.0', :class => 'good'} + = number_to_currency(25, :unit => '$') + %button{name: 'auto_payment_amount', type: 'submit', value: '50.0', :class => 'better'} + = number_to_currency(50, :unit => '$') + %button{name: 'auto_payment_amount', type: 'submit', value: '100.0', :class => 'best'} + = number_to_currency(100, :unit => '$') + .row + .columns.small-12.centered + .small-form + = number_field_tag :payment_amount, :step => 0.01, :min => 0.01, :label => false + = form_actions :custom_amount - else %p=_'registration.thanks.all_done.paid',"You're all done and paid up! We'll see you in #{city}.", vars: {:city => city} %p=_'register.email.registration_confirmed.info',"We'll have housing, loaner bikes, and food arranged for your arrival. If you have any other questions or concerns, please email bikebike2014columbus@gmail.com." diff --git a/config/environments/development.rb b/config/environments/development.rb index 07d09a4..471e16b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -54,6 +54,6 @@ BikeBike::Application.configure do #PerfTools::CpuProfiler.start('/tmp/dev_prof') config.serve_static_assets = true #config.assets.precompile = false - #Paypal.sandbox! + Paypal.sandbox! #Paypal.sandbox = false end diff --git a/config/routes.rb b/config/routes.rb index 29add61..ef1adb5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,8 +17,8 @@ BikeBike::Application.routes.draw do match 'register(/:step)' => 'conferences#register', via: [:get, :post] get 'register/confirm/:confirmation_token' => 'conferences#register_confirm' match 'register/pay-registration/:confirmation_token' => 'conferences#register_pay_registration', via: [:get, :post] - get 'register/confirm-payment/:confirmation_token' => 'conferences#register_confirm_payment' - get 'register/cancel-payment/:confirmation_token' => 'conferences#register_cancel_payment' + get 'register/paypal-confirm/:confirmation_token' => 'conferences#register_paypal_confirm' + get 'register/paypal-cancel/:confirmation_token' => 'conferences#register_paypal_cancel' #patch 'register/step/:step' => 'conferences#register_step' #resources :registrations, :path => 'registration' do # get :form, on: :collection diff --git a/db/migrate/20140725001300_add_registration_fees_paid_to_conference_registration.rb b/db/migrate/20140725001300_add_registration_fees_paid_to_conference_registration.rb new file mode 100644 index 0000000..e120357 --- /dev/null +++ b/db/migrate/20140725001300_add_registration_fees_paid_to_conference_registration.rb @@ -0,0 +1,5 @@ +class AddRegistrationFeesPaidToConferenceRegistration < ActiveRecord::Migration + def change + add_column :conference_registrations, :registration_fees_paid, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index cc812bc..3e479d8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140723183557) do +ActiveRecord::Schema.define(version: 20140725001300) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -71,6 +71,7 @@ ActiveRecord::Schema.define(version: 20140723183557) do t.boolean "completed" t.string "payment_confirmation_token" t.string "payment_info" + t.integer "registration_fees_paid" end create_table "conference_types", force: true do |t| diff --git a/features/step_definitions/interface_steps.rb b/features/step_definitions/interface_steps.rb index 072c24b..123bedd 100644 --- a/features/step_definitions/interface_steps.rb +++ b/features/step_definitions/interface_steps.rb @@ -181,7 +181,7 @@ end Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)$/) do |state, x, y, field| ConferenceRegistration.find_by!(:email => @last_email_entered). - send(field == 'confirmed' ? 'is_confirmed' : (field == 'paid' ? 'payment_info' : field)). + send(field == 'confirmed' ? 'is_confirmed' : (field == 'paid' ? 'registration_fees_paid' : field)). send(state =~ / not/ ? 'should_not' : 'should', be) end diff --git a/features/support/paths.rb b/features/support/paths.rb index f0591f1..3797ac0 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -8,10 +8,10 @@ module NavigationHelpers path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm/#{@last_registration.confirmation_token}" when /^pay registration$/i path = "/conferences/bikebike/#{@last_conference.slug}/register/pay-registration/#{@last_registration.confirmation_token}" - when /^confirm payment$/i - path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm-payment/#{@last_registration.payment_confirmation_token}" - when /^cancel payment$/i - path = "/conferences/bikebike/#{@last_conference.slug}/register/cancel-payment/#{@last_registration.confirmation_token}" + when /^paypal confirm$/i + path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-confirm/#{@last_registration.payment_confirmation_token}" + when /^paypal cancel$/i + path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-cancel/#{@last_registration.confirmation_token}" when /^translation list$/i path = '/translations/' when /^(.+) translations?$/i