Browse Source

Paypal working and a few minor fixes

development
Godwin 8 years ago
parent
commit
1eaba5f6c5
  1. 8
      Gemfile
  2. 2
      app/controllers/application_controller.rb
  3. 46
      app/controllers/conferences_controller.rb
  4. 2
      app/views/conferences/_header.html.haml
  5. 7
      app/views/conferences/_payment.html.haml
  6. 5
      config/locales/en.yml
  7. 3
      config/locales/es.yml

8
Gemfile

@ -25,6 +25,12 @@ else
gem 'bumbleberry', :git => 'git://github.com/bumbleberry/bumbleberry.git'
end
if Dir.exists?('../paypal-express')
gem 'paypal-express', :path => "../paypal-express"
else
gem 'paypal-express', :git => 'git://github.com/bikebike/paypal-express.git'
end
gem 'uglifier', '>= 1.3.0'
gem 'sorcery', '>= 0.8.1'
gem 'oauth2', '~> 0.8.0'
@ -35,7 +41,7 @@ gem 'geocoder'
gem 'paper_trail', '~> 3.0.5'
gem 'sitemap_generator'
gem 'activerecord-session_store'
gem 'paypal-express', '0.7.1'
# gem 'paypal-express', '0.7.1'
gem 'sass-json-vars'
gem 'premailer-rails'
gem 'redcarpet'

2
app/controllers/application_controller.rb

@ -237,7 +237,7 @@ class ApplicationController < LinguaFrancaApplicationController
session[:confirm_uid] = user.id
# send the confirmation email and make sure it get sent as quickly as possible
UserMailer.send_mail! :email_confirmation do
UserMailer.send_mail :email_confirmation do
EmailConfirmation.create(user_id: user.id, expiry: expiry, url: url)
end
end

46
app/controllers/conferences_controller.rb

@ -545,6 +545,44 @@ class ConferencesController < ApplicationController
if form_step
if form_step.to_s =~ /^prev_(.+)$/
@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
case form_step
@ -607,13 +645,15 @@ class ConferencesController < ApplicationController
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.save
@registration.save
host = "#{request.protocol}#{request.host_with_port}"
response = PayPal!.setup(
PayPalRequest(amount),
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'
redirect_to response.redirect_uri
@ -651,7 +691,7 @@ class ConferencesController < ApplicationController
@register_template ||= (params[:step] || current_step).to_sym
if logged_in?
if logged_in? && @register_template != :paypal_confirm
# if we're logged in
if !steps.include?(@register_template)
# and we are not viewing a valid step

2
app/views/conferences/_header.html.haml

@ -5,6 +5,6 @@
%h2.primary=location(@conference.organizations.first.locations.first)
.secondary
= date_span(@conference.start_date.to_date, @conference.end_date.to_date)
%img{src: @conference.poster.full.url || image_path('default_poster.jpg'), role: :presentation, alt: ''}
%img{src: @conference.poster.full.url || image_path('default_poster.jpg'), role: :presentation, alt: (_'images.conference.poster', vars: { conference_title: @conference.title })}
- content_for :og_image do
= @conference.poster.full.url || image_path('default_poster.jpg')

7
app/views/conferences/_payment.html.haml

@ -1,6 +1,11 @@
= columns(medium: 12) do
%h2=_'articles.conference_registration.headings.Payment'
%p=_'articles.conference_registration.paragraphs.Payment', 'Thank you for completing your registration. We\'ll see you at Bike!Bike! Payment is by donation and can be done now or upon arrival but to help us fund the conference, we ask that you pay the registration donation as soon as you can.'
- if @registration.registration_fees_paid.present?
%p
%strong=_'articles.conference_registration.paragraphs.Payment_Made', :p, vars: { fees_paid: @registration.registration_fees_paid }
= _'articles.conference_registration.paragraphs.Payment_Add'
- else
%p=_'articles.conference_registration.paragraphs.Payment', :p
= columns(large: 9, push: 1) do
= form_tag register_path(@this_conference.slug), :class => :payment do
= hidden_field_tag :button, :payment

5
config/locales/en.yml

@ -5417,6 +5417,8 @@ en:
Payment is by donation and can be done now or upon arrival but to help us
fund the conference, we ask that you pay the registration donation as soon
as you can.
Payment_Made: You have already made a payment of $%{fees_paid}.
Payment_Add: Thank you! You may add to this amount if you wish by making another payment below.
currency: "(amounts are in USD)"
email_confirm: Go to your inbox! You should see an email from Bike!Bike! in
just a few moments. There will be a link in the email for you to click on.
@ -5622,6 +5624,9 @@ en:
and for community bicycle projects. The conference is a space for participants
from shops and related advocacy groups to converge in a different city each
year over a 4 day period to have workshops and strengthen our social network.
images:
conference:
poster: '%{conference_title} poster'
forms:
labels:
generic:

3
config/locales/es.yml

@ -941,6 +941,9 @@ es:
headings:
contact: Envíenos una pregunta o un complemento
reason: ¿Qué está en contacto con nosotros acerca?
images:
conference:
poster: '%{conference_title} póster'
forms:
labels:
generic:

Loading…
Cancel
Save