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
|
|
|
module Nonprofits
|
2019-07-30 21:29:24 +00:00
|
|
|
class CardsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Nonprofit::Current
|
|
|
|
include Controllers::Nonprofit::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_nonprofit_user!
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def edit
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /nonprofits/:nonprofit_id/card
|
|
|
|
def create
|
|
|
|
render(
|
2019-07-30 21:29:24 +00:00
|
|
|
JsonResp.new(params) do |_d|
|
2018-03-25 17:30:42 +00:00
|
|
|
requires(:nonprofit_id).as_int
|
|
|
|
requires(:card).nested do
|
|
|
|
requires(:name, :stripe_card_token, :stripe_card_id).as_string
|
|
|
|
requires(:holder_id).as_int
|
|
|
|
requires(:holder_type).one_of('Supporter', 'Nonprofit')
|
|
|
|
end
|
|
|
|
end.when_valid do |d|
|
|
|
|
InsertCard.with_stripe(d[:card])
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
2019-10-29 21:57:52 +00:00
|
|
|
|
2021-02-12 00:34:39 +00:00
|
|
|
private
|
2019-10-29 21:57:52 +00:00
|
|
|
def required_params
|
2019-10-29 22:00:11 +00:00
|
|
|
params.require(:nonprofit_id, card: [:name, :stripe_card_token, :stripe_card_id, :holder_id, :holder_type])
|
2019-10-29 21:57:52 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|