2014-09-09 19:06:38 -07:00
|
|
|
class DonationsController < ApplicationController
|
|
|
|
def create
|
2014-09-11 15:40:37 -07:00
|
|
|
@campaign = Campaign.current
|
2017-01-07 19:19:44 -08:00
|
|
|
begin
|
|
|
|
@donation = Donation.create_from_charge(
|
|
|
|
@campaign, current_user, params[:donation])
|
|
|
|
rescue Stripe::CardError => e
|
|
|
|
flash[:alert] = "We couldn't process your donation: #{e.message}"
|
|
|
|
redirect_to :donate
|
|
|
|
rescue => e
|
|
|
|
flash[:alert] =
|
|
|
|
"We couldn't process your donation: #{e.message} " +
|
|
|
|
"Please try again later!"
|
|
|
|
redirect_to :donate
|
|
|
|
else
|
|
|
|
redirect_to @donation
|
|
|
|
end
|
2014-09-09 20:04:17 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@donation = Donation.from_param(params[:id])
|
2014-09-09 21:16:02 -07:00
|
|
|
@features = @donation.features
|
|
|
|
@outfits = current_user.outfits.wardrobe_order if user_signed_in?
|
2014-09-09 20:04:17 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@donation = Donation.from_param(params[:id])
|
|
|
|
@donation.update_attributes params[:donation]
|
|
|
|
|
2014-09-09 21:16:02 -07:00
|
|
|
feature_params = params[:feature] || {}
|
|
|
|
@features = @donation.features.find(feature_params.keys)
|
|
|
|
@features.each do |feature|
|
|
|
|
feature.outfit_url = feature_params[feature.id.to_s][:outfit_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
Donation.transaction do
|
|
|
|
@donation.save!
|
|
|
|
@features.each(&:save!)
|
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
2014-09-13 12:16:50 -07:00
|
|
|
flash[:alert] = "Couldn't save donation details. Do those outfits exist?"
|
2014-09-09 21:16:02 -07:00
|
|
|
redirect_to @donation
|
|
|
|
else
|
|
|
|
flash[:success] = 'Donation details saved! ' +
|
|
|
|
'Also, have we thanked you yet today? Thank you!'
|
|
|
|
redirect_to @donation
|
|
|
|
end
|
2014-09-09 19:06:38 -07:00
|
|
|
end
|
|
|
|
end
|