Skip to content

Commit

Permalink
Add direct deposit controller (#16234)
Browse files Browse the repository at this point in the history
* Add direct deposit controller

* Remove tests from disability_compensations_controller_spec

* Update direct deposit policy name
  • Loading branch information
tpharrison authored Apr 9, 2024
1 parent 5a0835c commit ddc4184
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 24 deletions.
84 changes: 84 additions & 0 deletions app/controllers/v0/profile/direct_deposits_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true

require 'lighthouse/service_exception'
require 'lighthouse/direct_deposit/client'
require 'lighthouse/direct_deposit/error_parser'
require 'lighthouse/direct_deposit/payment_account'
require 'lighthouse/direct_deposit/control_information'

module V0
module Profile
class DirectDepositsController < ApplicationController
service_tag 'direct-deposit'
before_action { authorize :lighthouse, :direct_deposit_access? }
before_action :payment_account, only: :update
before_action :control_information, only: :update
after_action :log_sso_info, only: :update

rescue_from(*Lighthouse::ServiceException::ERROR_MAP.values) do |exception|
error = { status: exception.status_code, body: exception.errors.first }
response = Lighthouse::DirectDeposit::ErrorParser.parse(error)

render status: response.status, json: response.body
end

def show
response = client.get_payment_info

render status: response.status,
json: response.body,
serializer: DisabilityCompensationsSerializer
end

def update
response = client.update_payment_info(@payment_account)
send_confirmation_email

render status: response.status,
json: response.body,
serializer: DisabilityCompensationsSerializer
end

private

def client
@client ||= DirectDeposit::Client.new(@current_user.icn)
end

def payment_account
@payment_account ||= Lighthouse::DirectDeposit::PaymentAccount.new(payment_account_params)
end

def control_information
@control_information ||= Lighthouse::DirectDeposit::ControlInformation.new(control_info_params)
end

def payment_account_params
params.require(:payment_account)
.permit(:account_type,
:account_number,
:routing_number)
end

def control_info_params
params.require(:control_information)
.permit(:can_update_direct_deposit,
:is_corp_available,
:is_edu_claim_available,
:is_corp_rec_found,
:has_no_bdn_payments,
:has_index,
:is_competent,
:has_mailing_address,
:has_no_fiduciary_assigned,
:is_not_deceased,
:has_payment_address,
:has_indentity)
end

def send_confirmation_email
VANotifyDdEmailJob.send_to_emails(current_user.all_emails, 'comp_and_pen')
end
end
end
end
3 changes: 2 additions & 1 deletion app/policies/lighthouse_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def access?
user.icn.present? && user.participant_id.present?
end

def access_disability_compensations?
def direct_deposit_access?
user.loa3? &&
allowed_providers.include?(user.identity.sign_in[:service_name]) &&
user.icn.present? && user.participant_id.present?
Expand All @@ -17,6 +17,7 @@ def access_update?
user.icn.present? && user.participant_id.present?
end

alias_method :access_disability_compensations?, :direct_deposit_access?
alias_method :mobile_access?, :access_update?
alias_method :rating_info_access?, :access?

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
resource :military_occupations, only: :show

# Lighthouse
resource :direct_deposits, only: %i[show update], controller: 'direct_deposits/disability_compensations'
resource :direct_deposits, only: %i[show update]
namespace :direct_deposits do
resource :disability_compensations, only: %i[show update]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,4 @@
end
end
end

describe 'alternate routes for direct deposit', type: :routing do
it 'routes GET v0/profile/direct_deposits to disability_compensations_controller#show' do
expect(get('v0/profile/direct_deposits')).to route_to(
{
'format' => 'json',
'controller' => 'v0/profile/direct_deposits/disability_compensations',
'action' => 'show'
}
)
end

it 'routes PUT v0/profile/direct_deposits to disability_compensations_controller#update' do
expect(put('v0/profile/direct_deposits')).to route_to(
{
'format' => 'json',
'controller' => 'v0/profile/direct_deposits/disability_compensations',
'action' => 'update'
}
)
end
end
end
Loading

0 comments on commit ddc4184

Please sign in to comment.