Skip to content

Instantly share code, notes, and snippets.

@saikumar-everest
Created July 9, 2021 12:21
Show Gist options
  • Save saikumar-everest/f217fc4dcec66d0a17e7d99f7705ed39 to your computer and use it in GitHub Desktop.
Save saikumar-everest/f217fc4dcec66d0a17e7d99f7705ed39 to your computer and use it in GitHub Desktop.
class Account::PayoutDetailsController < Account::ProfilesController
skip_before_action :ensure_can_edit_provider_profile
before_action :ensure_can_edit_payout_details
before_action :prepare_payout_detail
def create
update
end
def edit
params[:section] = 'payout_details'
end
def update
if @payout_detail_updater.update(payout_details_params)
notify_user_about_change
redirect_to_edit_payout_detail
else
render :edit
end
end
private
def notify_user_about_change
ProviderMailer.delay.payout_details_changed(current_user.id)
end
def redirect_to_edit_payout_detail
if @payout_detail_updater.using_payoneer?
p "@payout_detail_updater.payoneer_url", @payout_detail_updater.payoneer_url
p URI.parse(@payout_detail_updater.payoneer_url).path
redirect_to @payout_detail_updater.payoneer_url
else
redirect_to edit_account_profile_payout_detail_path, flash: { success: I18n.t(:success, scope: [:flash, :profiles, :update]) }
end
end
def prepare_payout_detail
@payout_detail = current_user.payout_detail || current_user.build_payout_detail
@payout_detail_updater = User::PayoutDetail::Updater.new(@payout_detail)
end
def payout_details_params
fields = [ :payment_service, :payment_identifier, :paypal_email ]
(params.permit(user_payout_detail: fields)[:user_payout_detail] || { }).tap do |params|
params[:callback_url] = edit_account_profile_payout_detail_url
end
end
def ensure_can_edit_payout_details
permission.ensure!(:edit_payout_details)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment