Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of vendor validator abstraction #1803

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .reek
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ NilCheck:
LongParameterList:
exclude:
- IdentityLinker#optional_attributes
- VendorValidatorJob#perform
- Idv::ProoferJob#perform
- Idv::VendorResult#initialize
RepeatedConditional:
exclude:
Expand All @@ -66,6 +66,7 @@ TooManyInstanceVariables:
- OpenidConnectAuthorizeForm
- OpenidConnectRedirector
- Idv::VendorResult
- Idv::ProoferJob
TooManyStatements:
max_statements: 6
exclude:
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/verify/finance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ def show
private

def submit_idv_job
SubmitIdvJob.new(
vendor_validator_class: Idv::FinancialsValidator,
Idv::SubmitIdvJob.new(
idv_session: idv_session,
vendor_params: vendor_params
).call
).submit_finance_job
end

def step_name
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/verify/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def phone_confirmation_required?
end

def submit_idv_job
SubmitIdvJob.new(
vendor_validator_class: Idv::PhoneValidator,
Idv::SubmitIdvJob.new(
idv_session: idv_session,
vendor_params: idv_session.params[:phone]
).call
).submit_phone_job
end

def step_name
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/verify/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ def destroy
private

def submit_idv_job
SubmitIdvJob.new(
vendor_validator_class: Idv::ProfileValidator,
Idv::SubmitIdvJob.new(
idv_session: idv_session,
vendor_params: idv_session.vendor_params
).call
).submit_profile_job
end

def step_name
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/idv/finance_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Idv
class FinanceJob < ProoferJob
def verify_identity_with_vendor
confirmation = agent.submit_financials(vendor_params, vendor_session_id)
result = extract_result(confirmation)
store_result(result)
end
end
end
9 changes: 9 additions & 0 deletions app/jobs/idv/phone_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Idv
class PhoneJob < ProoferJob
def verify_identity_with_vendor
confirmation = agent.submit_phone(vendor_params, vendor_session_id)
result = extract_result(confirmation)
store_result(result)
end
end
end
23 changes: 23 additions & 0 deletions app/jobs/idv/profile_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Idv
class ProfileJob < ProoferJob
def verify_identity_with_vendor
resolution = agent.start(vendor_params)
result = extract_result(resolution)
store_result(result)
end

private

def extract_result(resolution)
vendor_resp = resolution.vendor_resp

Idv::VendorResult.new(
success: resolution.success?,
errors: resolution.errors,
reasons: vendor_resp.reasons,
normalized_applicant: vendor_resp.normalized_applicant,
session_id: resolution.session_id
)
end
end
end
57 changes: 57 additions & 0 deletions app/jobs/idv/proofer_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Idv
class ProoferJob < ApplicationJob
queue_as :idv

attr_reader :result_id, :vendor, :vendor_params, :applicant, :vendor_session_id

def perform(result_id:, vendor:, vendor_params:, applicant_json:, vendor_session_id: nil)
@result_id = result_id
@vendor = vendor.to_sym
@vendor_params = vendor_params
@applicant = applicant_from_json(applicant_json)
@vendor_session_id = vendor_session_id
perform_identity_proofing
end

def verify_identity_with_vendor
raise NotImplementedError, "subclass must implement #{__method__}"
end

private

def agent
Idv::Agent.new(applicant: applicant, vendor: vendor)
end

def applicant_from_json(applicant_json)
applicant_attributes = JSON.parse(applicant_json, symbolize_names: true)
Proofer::Applicant.new(applicant_attributes)
end

def perform_identity_proofing
verify_identity_with_vendor
rescue StandardError
store_failed_job_result
raise
end

def extract_result(confirmation)
vendor_resp = confirmation.vendor_resp

Idv::VendorResult.new(
success: confirmation.success?,
errors: confirmation.errors,
reasons: vendor_resp.reasons
)
end

def store_failed_job_result
job_failed_result = Idv::VendorResult.new(errors: { job_failed: true })
VendorValidatorResultStorage.new.store(result_id: result_id, result: job_failed_result)
end

def store_result(vendor_result)
VendorValidatorResultStorage.new.store(result_id: result_id, result: vendor_result)
end
end
end
49 changes: 0 additions & 49 deletions app/jobs/vendor_validator_job.rb

This file was deleted.

11 changes: 0 additions & 11 deletions app/services/idv/financials_validator.rb

This file was deleted.

11 changes: 0 additions & 11 deletions app/services/idv/phone_validator.rb

This file was deleted.

15 changes: 0 additions & 15 deletions app/services/idv/profile_validator.rb

This file was deleted.

50 changes: 50 additions & 0 deletions app/services/idv/submit_idv_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Idv
class SubmitIdvJob
def initialize(idv_session:, vendor_params:)
@idv_session = idv_session
@vendor_params = vendor_params
end

def submit_profile_job
update_idv_session
ProfileJob.perform_later(proofer_job_params)
end

def submit_finance_job
update_idv_session
FinanceJob.perform_later(proofer_job_params)
end

def submit_phone_job
update_idv_session
PhoneJob.perform_later(proofer_job_params)
end

private

attr_reader :idv_session, :vendor_params

def proofer_job_params
{
result_id: result_id,
vendor: vendor.to_s,
vendor_params: vendor_params,
vendor_session_id: idv_session.vendor_session_id,
applicant_json: idv_session.applicant.to_json,
}
end

def result_id
@_result_id ||= SecureRandom.uuid
end

def update_idv_session
idv_session.async_result_id = result_id
idv_session.async_result_started_at = Time.zone.now.to_i
end

def vendor
idv_session.vendor || Idv::Vendor.new.pick
end
end
end
4 changes: 2 additions & 2 deletions app/services/idv/vendor_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def initialize(success: nil, errors: {}, reasons: [], session_id: nil,
end

def success?
success
success == true
end

def timed_out?
timed_out
timed_out == true
end

def job_failed?
Expand Down
42 changes: 0 additions & 42 deletions app/services/idv/vendor_validator.rb

This file was deleted.

37 changes: 0 additions & 37 deletions app/services/submit_idv_job.rb

This file was deleted.

Loading