Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

user is redirected to the return page first. modified create_by_brick…

…_and_justgiving method to correctly read the params, so brick can be marked as purchased if the donation was successful
  • Loading branch information...
commit 44fc2a28e7b9a0fa5d336e5e26b4ec00348f4aba 1 parent 95cce06
Natalia Buckley authored
View
2  app/controllers/application_controller.rb
@@ -2,7 +2,7 @@
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
- include ExceptionNotifiable
+ include ExceptionNotification
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
View
9 app/controllers/payment_notifications_controller.rb
@@ -9,9 +9,12 @@ def create
def return
if params[:donationId]
- brick = Brick.find_by_url_key!(params[:id])
- donation = JustGiving::Donation.new(params[:donationId])
- notification = PaymentNotification.create_by_brick_and_justgiving(brick, donation.details)
+ @brick = Brick.find_by_url_key!(params[:id])
+ # save the donation id in case you need to further probe any details
+ @brick.donation_id = params[:donationId]
+ @brick.save
+ @donation = JustGiving::Donation.new(params[:donationId])
+ @notification = PaymentNotification.create_by_brick_and_justgiving(@brick, @donation.details)
# TODO what if the payment failed or was cancelled?
redirect_to thanks_brick_path(@notification.brick)
else
View
2  app/helpers/bricks_helper.rb
@@ -6,7 +6,7 @@ def justgiving_link(brick)
justgiving_path = "http://v3-sandbox.justgiving.com/donation/direct/charity/185222"
end
amount = brick.value/100.0
- exit_url = thanks_brick_url(brick) + "?donationId=JUSTGIVING-DONATION-ID"
+ exit_url = return_payment_notification_url(brick) + "?donationId=JUSTGIVING-DONATION-ID"
return "#{justgiving_path}?amount=#{amount}&frequency=Single&exitUrl=#{CGI.escape(exit_url)}"
end
end
View
10 app/models/payment_notification.rb
@@ -4,7 +4,7 @@ class PaymentNotification < ActiveRecord::Base
after_create :mark_brick_as_purchased
def self.create_by_brick_and_justgiving(brick, params)
- status = (params[:status] == 'Accepted' or params[:status] == 'Pending') ? 'OK' : params[:status]
+ status = (params['status'] == 'Accepted' or params['status'] == 'Pending') ? 'OK' : params['status']
PaymentNotification.create(:brick => brick, :status => status, :params => params)
end
@@ -24,16 +24,16 @@ def aborted?
def mark_brick_as_purchased
if status == 'OK'
- logger.info("Brick #{brick.url_key} purchased successfully")
- brick.update_attribute(:purchased_at, Time.now)
+ logger.info("Brick #{@brick.url_key} purchased successfully")
+ @brick.update_attribute(:purchased_at, Time.now)
begin
FuKing::Twitter.update(twitter_message)
rescue => e
- logger.warn("Error tweeting brick #{brick.url_key}: #{e.message}")
+ logger.warn("Error tweeting brick #{@brick.url_key}: #{e.message}")
end
else
- logger.info("Brick #{brick.url_key} purchase unsuccessful: #{status}")
+ logger.info("Brick #{@brick.url_key} purchase unsuccessful: #{status}")
end
end
View
2  app/views/bricks/confirm.html.erb
@@ -17,7 +17,7 @@
<div id="content" class="col col_copy">
<%= render(:partial => 'brick' ) %>
- <% if admin? %>
+ <% unless admin? %>
<div id="personal_details">
<% form_for(@payment_notification) do |f| %>
<%= f.hidden_field :status %>
View
9 db/migrate/20120213161201_add_donation_id_to_bricks.rb
@@ -0,0 +1,9 @@
+class AddDonationIdToBricks < ActiveRecord::Migration
+ def self.up
+ add_column :bricks, :donation_id, :string
+ end
+
+ def self.down
+ remove_column :bricks, :donation_id
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.