@ -545,6 +545,44 @@ class ConferencesController < ApplicationController
if form_step
if form_step
if form_step . to_s =~ / ^prev_(.+)$ /
if form_step . to_s =~ / ^prev_(.+)$ /
@register_template = steps [ steps . find_index ( $1 . to_sym ) - 1 ]
@register_template = steps [ steps . find_index ( $1 . to_sym ) - 1 ]
elsif form_step == :paypal_confirm
if @registration . present? && @registration . payment_confirmation_token == params [ :confirmation_token ]
# if ENV['RAILS_ENV'] == 'test'
# @amount = YAML.load(@registration.payment_info)[:amount]
# else
@amount = PayPal ! . details ( params [ :token ] ) . amount . total
# testing this does't work in test but it works in devo and prod
@registration . payment_info = { :payer_id = > params [ :PayerID ] , :token = > params [ :token ] , :amount = > @amount } . to_yaml
# end
@amount = ( @amount * 100 ) . to_i . to_s . gsub ( / ^(.*)( \ d \ d)$ / , '\1.\2' )
@registration . save!
@register_template = :paypal_confirm
end
@register_template = :paypal_confirm
elsif form_step == :paypal_confirmed
#@register_template = :paypal_confirm
info = YAML . load ( @registration . payment_info )
@amount = nil
status = nil
if ENV [ 'RAILS_ENV' ] == 'test'
status = info [ :status ]
@amount = info [ :amount ]
else
paypal = PayPal ! . checkout! ( info [ :token ] , info [ :payer_id ] , PayPalRequest ( info [ :amount ] ) )
status = paypal . payment_info . first . payment_status
@amount = paypal . payment_info . first . amount . total
end
if status == 'Completed'
@registration . registration_fees_paid || = 0
@registration . registration_fees_paid += @amount
@registration . save!
else
@errors = :incomplete
@register_template = :payment
end
else
else
case form_step
case form_step
@ -607,13 +645,15 @@ class ConferencesController < ApplicationController
if amount > 0
if amount > 0
@registration . payment_confirmation_token = ENV [ 'RAILS_ENV' ] == 'test' ? 'token' : Digest :: SHA256 . hexdigest ( rand ( Time . now . to_f * 1000000 ) . to_i . to_s )
@registration . payment_confirmation_token = ENV [ 'RAILS_ENV' ] == 'test' ? 'token' : Digest :: SHA256 . hexdigest ( rand ( Time . now . to_f * 1000000 ) . to_i . to_s )
# @registration. save
@registration . save
host = " #{ request . protocol } #{ request . host_with_port } "
host = " #{ request . protocol } #{ request . host_with_port } "
response = PayPal ! . setup (
response = PayPal ! . setup (
PayPalRequest ( amount ) ,
PayPalRequest ( amount ) ,
register_paypal_confirm_url ( @this_conference . slug , :paypal_confirm , @registration . payment_confirmation_token ) ,
register_paypal_confirm_url ( @this_conference . slug , :paypal_confirm , @registration . payment_confirmation_token ) ,
register_paypal_confirm_url ( @this_conference . slug , :paypal_cancel , @registration . payment_confirmation_token )
register_paypal_confirm_url ( @this_conference . slug , :paypal_cancel , @registration . payment_confirmation_token ) ,
noshipping : true ,
version : 204
)
)
if ENV [ 'RAILS_ENV' ] != 'test'
if ENV [ 'RAILS_ENV' ] != 'test'
redirect_to response . redirect_uri
redirect_to response . redirect_uri
@ -651,7 +691,7 @@ class ConferencesController < ApplicationController
@register_template || = ( params [ :step ] || current_step ) . to_sym
@register_template || = ( params [ :step ] || current_step ) . to_sym
if logged_in?
if logged_in? && @register_template != :paypal_confirm
# if we're logged in
# if we're logged in
if ! steps . include? ( @register_template )
if ! steps . include? ( @register_template )
# and we are not viewing a valid step
# and we are not viewing a valid step