Browse Source

Paypal is now working

development
Godwin 10 years ago
parent
commit
534b9303e9
  1. 37
      app/assets/stylesheets/sass/_typography.scss
  2. 112
      app/controllers/conferences_controller.rb
  3. 10
      app/helpers/bike_bike_form_helper.rb
  4. 5
      app/views/conferences/_register_confirm_payment.html.haml
  5. 22
      app/views/conferences/_register_thanks.html.haml
  6. 2
      config/environments/development.rb
  7. 4
      config/routes.rb
  8. 5
      db/migrate/20140725001300_add_registration_fees_paid_to_conference_registration.rb
  9. 3
      db/schema.rb
  10. 2
      features/step_definitions/interface_steps.rb
  11. 8
      features/support/paths.rb

37
app/assets/stylesheets/sass/_typography.scss

@ -28,24 +28,32 @@
padding: 0.5em 1em; padding: 0.5em 1em;
vertical-align: middle; vertical-align: middle;
&.organization, &.secondary { &.organization, &.secondary, &.best {
background-color: $organization-color; background-color: $organization-color;
} }
&.article { &.article, &.good {
background-color: $article-color; background-color: $article-color;
} }
&.better {
background-color: darken($warning-color, 2);
}
&:hover { &:hover {
color: $primary-color; color: $primary-color;
border: 0.15em solid; border: 0.15em solid;
background-color: transparent; background-color: transparent;
&.organization { &.organization, &.secondary, &.best {
color: $organization-color; color: $organization-color;
} }
&.article { &.better {
color: darken($warning-color, 2);
}
&.article, &.good {
color: $article-color; color: $article-color;
} }
} }
@ -625,3 +633,24 @@ article {
p.help { p.help {
font-size: 1.1em; 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;
}
}

112
app/controllers/conferences_controller.rb

@ -354,7 +354,21 @@ class ConferencesController < ApplicationController
when 'already_registered' when 'already_registered'
send_confirmation send_confirmation
next_step = 'thanks' 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' next_step = 'thanks'
end end
session.delete(:registration_step) session.delete(:registration_step)
@ -415,6 +429,8 @@ class ConferencesController < ApplicationController
@actions = [:cancel, :submit] @actions = [:cancel, :submit]
when 'cancel' when 'cancel'
@actions = [:no, :yes] @actions = [:no, :yes]
when 'confirm_payment'
@actions = [:cancel_payment, :confirm_payment]
when 'already_registered' when 'already_registered'
@registration = ConferenceRegistration.find_by(:email => session[:registration][:email]) @registration = ConferenceRegistration.find_by(:email => session[:registration][:email])
if !@registration.complete if !@registration.complete
@ -472,92 +488,50 @@ class ConferencesController < ApplicationController
@conference_registration = ConferenceRegistration.find_by(confirmation_token: params[:confirmation_token]) @conference_registration = ConferenceRegistration.find_by(confirmation_token: params[:confirmation_token])
host = "#{request.protocol}#{request.host_with_port}" host = "#{request.protocol}#{request.host_with_port}"
if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete 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] = YAML.load(@conference_registration.data)
session[:registration][:registration_id] = @conference_registration.id session[:registration][:registration_id] = @conference_registration.id
session[:registration][:path] = Array.new session[:registration][:path] = Array.new
session[:registration_step] = 'pay_now' session[:registration_step] = 'pay_now'
redirect_to action: 'register' 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 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 else
do_404 do_404
end end
end end
def register_confirm_payment def register_paypal_confirm
set_conference set_conference
@conference_registration = ConferenceRegistration.find_by(payment_confirmation_token: params[:confirmation_token]) @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? if !@conference_registration.nil? && @conference_registration.conference_id == @conference.id && @conference_registration.complete && @conference_registration.registration_fees_paid.nil?
@conference_registration.payment_info = "#{params[:PayerID]}:#{params[:token]}" @conference_registration.payment_info = {:payer_id => params[:PayerID], :token => params[:token], :amount => PayPal!.details(params[:token]).amount.total}.to_yaml
@conference_registration.save! @conference_registration.save!
session[:registration] = YAML.load(@conference_registration.data) session[:registration] = YAML.load(@conference_registration.data)
session[:registration][:registration_id] = @conference_registration.id session[:registration][:registration_id] = @conference_registration.id
session[:registration][:path] = Array.new session[:registration][:path] = Array.new
session[:registration_step] = 'payment-confirmed' session[:registration_step] = 'paypal-confirmed'
redirect_to action: 'register' redirect_to action: 'register'
else else
do_404 do_404
end end
end end
def register_cancel_payment def register_paypal_cancel
set_conference set_conference
@conference_registration = ConferenceRegistration.find_by(confirmation_token: params[:confirmation_token]) @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? 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] = YAML.load(@conference_registration.data)
session[:registration][:registration_id] = @conference_registration.id session[:registration][:registration_id] = @conference_registration.id
session[:registration][:path] = Array.new session[:registration][:path] = Array.new
session[:registration_step] = 'payment-cancelled' session[:registration_step] = 'paypal-cancelled'
redirect_to action: 'register' redirect_to action: 'register'
end end
end end
@ -789,4 +763,26 @@ class ConferencesController < ApplicationController
data ||= YAML.load(registration.data) data ||= YAML.load(registration.data)
UserMailer.conference_registration_payment_received(@conference, data, registration).deliver UserMailer.conference_registration_payment_received(@conference, data, registration).deliver
end 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 end

10
app/helpers/bike_bike_form_helper.rb

@ -41,6 +41,7 @@ module BikeBikeFormHelper
end end
def number_field_tag(name, value = nil, options = {}) 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) render_field(name, options = get_options(name, options), super(name, value, options), value)
end end
@ -77,6 +78,10 @@ module BikeBikeFormHelper
end end
def text_field_tag(name, value = nil, options = {}) 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) render_field(name, options = get_options(name, options), super(name, value, options), value)
end end
@ -148,6 +153,7 @@ module BikeBikeFormHelper
end end
def number_field(object_name, method, options = {}) 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)) render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
end end
@ -180,6 +186,10 @@ module BikeBikeFormHelper
end end
def text_field(object_name, method, options = {}) 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)) render_field(method, options = get_options(method, options), super(object_name, method, options), get_value(method, options))
end end

5
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 => '$')}

22
app/views/conferences/_register_thanks.html.haml

@ -4,14 +4,24 @@
.columns .columns
- if !@registration.is_participant - if !@registration.is_participant
%p=_'registration.thanks.all_done.volunteer','Thanks for submitting your volunteer infomation. We\'ll see you at Bike!Bike!' %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." %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 = hidden_field_tag :confirmation_token, @registration.confirmation_token
.columns.small-4.small-offset-2 .row
= number_field_tag :payment_amount, 25.00, :step => 0.01, :min => 0.01 .columns.small-12.centered
.columns.small-4.end %p=_'registration.thanks.all_done.please_pay.currency','(amounts are in $USD)'
= form_actions :submit_payment %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 - else
%p=_'registration.thanks.all_done.paid',"You're all done and paid up! We'll see you in #{city}.", vars: {:city => city} %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." %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."

2
config/environments/development.rb

@ -54,6 +54,6 @@ BikeBike::Application.configure do
#PerfTools::CpuProfiler.start('/tmp/dev_prof') #PerfTools::CpuProfiler.start('/tmp/dev_prof')
config.serve_static_assets = true config.serve_static_assets = true
#config.assets.precompile = false #config.assets.precompile = false
#Paypal.sandbox! Paypal.sandbox!
#Paypal.sandbox = false #Paypal.sandbox = false
end end

4
config/routes.rb

@ -17,8 +17,8 @@ BikeBike::Application.routes.draw do
match 'register(/:step)' => 'conferences#register', via: [:get, :post] match 'register(/:step)' => 'conferences#register', via: [:get, :post]
get 'register/confirm/:confirmation_token' => 'conferences#register_confirm' get 'register/confirm/:confirmation_token' => 'conferences#register_confirm'
match 'register/pay-registration/:confirmation_token' => 'conferences#register_pay_registration', via: [:get, :post] 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/paypal-confirm/:confirmation_token' => 'conferences#register_paypal_confirm'
get 'register/cancel-payment/:confirmation_token' => 'conferences#register_cancel_payment' get 'register/paypal-cancel/:confirmation_token' => 'conferences#register_paypal_cancel'
#patch 'register/step/:step' => 'conferences#register_step' #patch 'register/step/:step' => 'conferences#register_step'
#resources :registrations, :path => 'registration' do #resources :registrations, :path => 'registration' do
# get :form, on: :collection # get :form, on: :collection

5
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

3
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -71,6 +71,7 @@ ActiveRecord::Schema.define(version: 20140723183557) do
t.boolean "completed" t.boolean "completed"
t.string "payment_confirmation_token" t.string "payment_confirmation_token"
t.string "payment_info" t.string "payment_info"
t.integer "registration_fees_paid"
end end
create_table "conference_types", force: true do |t| create_table "conference_types", force: true do |t|

2
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| Then (/^my registration (should( not)? be|is( not)?) (confirmed|completed?|paid)$/) do |state, x, y, field|
ConferenceRegistration.find_by!(:email => @last_email_entered). 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) send(state =~ / not/ ? 'should_not' : 'should', be)
end end

8
features/support/paths.rb

@ -8,10 +8,10 @@ module NavigationHelpers
path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm/#{@last_registration.confirmation_token}" path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm/#{@last_registration.confirmation_token}"
when /^pay registration$/i when /^pay registration$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/pay-registration/#{@last_registration.confirmation_token}" path = "/conferences/bikebike/#{@last_conference.slug}/register/pay-registration/#{@last_registration.confirmation_token}"
when /^confirm payment$/i when /^paypal confirm$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/confirm-payment/#{@last_registration.payment_confirmation_token}" path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-confirm/#{@last_registration.payment_confirmation_token}"
when /^cancel payment$/i when /^paypal cancel$/i
path = "/conferences/bikebike/#{@last_conference.slug}/register/cancel-payment/#{@last_registration.confirmation_token}" path = "/conferences/bikebike/#{@last_conference.slug}/register/paypal-cancel/#{@last_registration.confirmation_token}"
when /^translation list$/i when /^translation list$/i
path = '/translations/' path = '/translations/'
when /^(.+) translations?$/i when /^(.+) translations?$/i

Loading…
Cancel
Save