55 lines
1.4 KiB
Ruby
55 lines
1.4 KiB
Ruby
|
class ContributionsController < ApplicationController
|
||
|
before_action :set_member, only: %i[ new create ]
|
||
|
before_action :set_contribution, only: %i[ edit ]
|
||
|
|
||
|
# GET /members/new
|
||
|
def new
|
||
|
@contribution = Contribution.new
|
||
|
end
|
||
|
|
||
|
# GET /members/1/edit
|
||
|
def edit
|
||
|
end
|
||
|
|
||
|
# POST /members
|
||
|
def create
|
||
|
@contribution = @member.contributions.build(contribution_params)
|
||
|
|
||
|
Contribution.transaction do
|
||
|
if @contribution.save
|
||
|
@member.handle_new_contribution(@contribution, params.dig(:contribution, :overriden_expires_on))
|
||
|
@member.reset_status!
|
||
|
|
||
|
redirect_to @member, notice: "Contribution was successfully created."
|
||
|
else
|
||
|
render :new, status: :unprocessable_entity
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
## PATCH/PUT /members/1
|
||
|
#def update
|
||
|
# if @member.update(member_params)
|
||
|
# redirect_to @member, notice: "Member was successfully updated."
|
||
|
# else
|
||
|
# render :edit, status: :unprocessable_entity
|
||
|
# end
|
||
|
#end
|
||
|
|
||
|
private
|
||
|
# Use callbacks to share common setup or constraints between actions.
|
||
|
def set_member
|
||
|
@member = Member.find(params[:member_id])
|
||
|
end
|
||
|
|
||
|
def set_contribution
|
||
|
@contribution = Contribution.find(params[:id])
|
||
|
end
|
||
|
|
||
|
# Only allow a list of trusted parameters through.
|
||
|
def contribution_params
|
||
|
params.fetch(:contribution, {}).permit(:eurocents, :payment_method, :payment_on, :payment_reference)
|
||
|
end
|
||
|
end
|
||
|
|