1
0
Fork 0
forked from OpenNeo/impress
impress/app/controllers/fundraising/donations_controller.rb
Emi Matchu 82be7fe301 Move most fundraising files into a Fundraising module
Mostly this is just me testing out what it would look like to
modularize the app more… I've noticed that some concerns, like
fundraising, are just not relevant to most of the app, and being able
to lock them away inside subfolders feels like it'll help tidy up
long folder lists.

Notably, I haven't touched the models case yet, because I worry that
might be a bit more complex, whereas everything else seems pretty
well-isolated? We'll try it out!
2024-02-18 20:12:14 -08:00

58 lines
1.6 KiB
Ruby

module Fundraising
class DonationsController < ApplicationController
def create
@campaign = Campaign.current
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
end
def show
@donation = Donation.from_param(params[:id])
@features = @donation.features
@outfits = current_user.outfits.wardrobe_order if user_signed_in?
end
def update
@donation = Donation.from_param(params[:id])
@donation.attributes = donation_params
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
flash[:alert] = "Couldn't save donation details. Do those outfits exist?"
redirect_to @donation
else
flash[:notice] = 'Donation details saved! ' +
'Also, have we thanked you yet today? Thank you!'
redirect_to @donation
end
end
private
def donation_params
params.require(:donation).permit(:donor_name)
end
end
end