Created
July 9, 2021 12:21
-
-
Save saikumar-everest/f217fc4dcec66d0a17e7d99f7705ed39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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