2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
class CardsController < ApplicationController
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_user!, except: [:create]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# post /cards
|
|
|
|
def create
|
2019-08-06 12:39:48 +00:00
|
|
|
acct = Supporter.find(card_params[:holder_id]).nonprofit.stripe_account_id
|
2018-03-25 17:30:42 +00:00
|
|
|
render(
|
2019-07-30 21:29:24 +00:00
|
|
|
JsonResp.new(params) do |_d|
|
2018-03-25 17:30:42 +00:00
|
|
|
requires(:card).nested do
|
|
|
|
requires(:name, :stripe_card_token).as_string
|
|
|
|
requires(:holder_id).as_int
|
|
|
|
requires(:holder_type).one_of('Supporter')
|
|
|
|
end
|
|
|
|
end.when_valid do |d|
|
2019-07-30 21:29:24 +00:00
|
|
|
InsertCard.with_stripe(d[:card], acct, params[:event_id], current_user)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2019-08-06 12:39:48 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def card_params
|
|
|
|
params.require(:card).permit(:cardholders_name, :email, :name, :failure_message, :status, :stripe_card_token, :stripe_card_id, :stripe_customer_id, :holder, :inactive)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|