Created
March 3, 2016 21:34
-
-
Save AugustoPedraza/183c4a6663077cb57f95 to your computer and use it in GitHub Desktop.
Yodlee Account Registration Code Sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/institution_controller.rb | |
class InstitutionsController < ApplicationController | |
def create | |
if uses_intuit? | |
#existing code | |
else | |
service_response = Services::YodleeAccount::Register.call(current_user, params, id) | |
redirect to_some_place_after_success_login and return if service_response[:status] == :complete | |
render 'mfa_form', mfa_form: service_response[:mfa_form] and return if service_response[:status] == :missing_mfa | |
render 'fail_registration', error_message: service_response[:error_msg] | |
end | |
def update_mfa_registration | |
begin | |
service_response = Services::YodleeAccount::UpdateMfa.call(current_user.yodlee_user, params, id) | |
rescue | |
render 'fail' | |
end | |
redirect to_some_place_after_success_login | |
end | |
# app/services/yodlee_account/register.rb | |
class Services::YodleeAccount::Register < Services::Base | |
def call(user, provider_id, form_values) | |
form = create_login_form(form_values) | |
yodlee_user = (user.yodlee_user || Services::YodleeUser::Register.call(user.id)) | |
account_id = Yodlee::Api::V1::Provider.new.tap { user_name = yodlee_user.username, user_password = yodlee_user.password }.register_account(form, provider_id) | |
result = Yodlee::Api::V1::Refresher.new.tap { user_name = yodlee_user.username, user_password = yodlee_user.password }.get_status_registration(account_id) | |
return { status: :complete, mfa_form: nil, account_id: account_id } if result.is_registration_completed? | |
return { status: :missing_mfa, mfa_form: result.mfa_form, account_id: account_id } if result.requires_MFA_login? | |
raise RegistrationError #using the values of result | |
end | |
end | |
# app/services/yodlee_account/update_mfa.rb | |
class Services::YodleeAccount::UpdateMfa < Services::Base | |
def call(yodlee_user, provider_id, form_values) | |
form = create_mfa_form(form_values) | |
account_id = Yodlee::Api::V1::Provider.new.tap { user_name = yodlee_user.username, user_password = yodlee_user.password }.update_mfa(form, provider_id) | |
result = Yodlee::Api::V1::Refresher.new.tap { user_name = yodlee_user.username, user_password = yodlee_user.password }.get_status_registration(account_id) | |
#I assume that just one request to get MFA fields is needed. | |
return if result.is_registration_completed? | |
raise RegistrationError #using the values of result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment