Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/controllers/api/v4/ach_transfers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

module Api
module V4
class AchTransfersController < ApplicationController
include SetEvent

before_action :set_api_event, only: [:create]

def create
permitted_params = [
:routing_number,
:account_number,
:recipient_email,
:bank_name,
:recipient_name,
:amount_money,
:payment_for,
:send_email_notification,
:invoiced_at,
:file,
]

if current_user&.admin?
permitted_params << :scheduled_on
end

ach_transfer_params = params.require(:ach_transfer).permit(*permitted_params)

@ach_transfer = @event.ach_transfers.build(ach_transfer_params.merge(creator: current_user))

authorize @ach_transfer

if @ach_transfer.amount > SudoModeHandler::THRESHOLD_CENTS
# Don't let API submit ACH transfers above sudo mode threshold
return render json: { error: "invalid_operation", messages: ["ACH transfers above the sudo mode threshold of #{ApplicationController.helpers.render_money(SudoModeHandler::THRESHOLD_CENTS)} are not allowed."] }, status: :bad_request
end


begin
@ach_transfer.save!
if ach_transfer_params[:file]
::ReceiptService::Create.new(
uploader: current_user,
attachments: ach_transfer_params[:file],
upload_method: :ach_transfer_api,
receiptable: @ach_transfer.local_hcb_code
).run!
end
rescue ArgumentError => e
render json: { error: "invalid_operation", messages: [e.message] }, status: :bad_request
end

render :show, status: :created
end

end
end
end
3 changes: 3 additions & 0 deletions app/views/api/v4/ach_transfers/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

json.partial! "api/v4/transactions/ach_transfer", ach_transfer: @ach_transfer
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@
end

resources :disbursements, path: "transfers", only: [:create]
resources :ach_transfers, only: [:create]

resources :donations, path: "donations", only: [:create]

Expand Down