mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
EPP Renew: Use action instead
This commit is contained in:
parent
349df32e95
commit
f26dd52fb0
1 changed files with 8 additions and 36 deletions
|
@ -78,42 +78,14 @@ module Epp
|
||||||
def renew
|
def renew
|
||||||
authorize! :renew, @domain
|
authorize! :renew, @domain
|
||||||
|
|
||||||
period_element = params[:parsed_frame].css('period').text
|
registrar_id = current_user.registrar.id
|
||||||
period = (period_element.to_i == 0) ? 1 : period_element.to_i
|
renew_params = ::Deserializers::Xml::Domain.new(params[:parsed_frame],
|
||||||
period_unit = Epp::Domain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
|
registrar_id).call
|
||||||
|
action = Actions::DomainRenew.new(@domain, renew_params, current_user.registrar)
|
||||||
balance_ok?('renew', period, period_unit) # loading pricelist
|
if action.call
|
||||||
|
render_epp_response '/epp/domains/renew'
|
||||||
begin
|
else
|
||||||
ActiveRecord::Base.transaction(isolation: :serializable) do
|
handle_errors(@domain)
|
||||||
@domain.reload
|
|
||||||
|
|
||||||
success = @domain.renew(
|
|
||||||
params[:parsed_frame].css('curExpDate').text,
|
|
||||||
period, period_unit
|
|
||||||
)
|
|
||||||
|
|
||||||
if success
|
|
||||||
unless balance_ok?('renew', period, period_unit)
|
|
||||||
handle_errors
|
|
||||||
fail ActiveRecord::Rollback
|
|
||||||
end
|
|
||||||
|
|
||||||
current_user.registrar.debit!({
|
|
||||||
sum: @domain_pricelist.price.amount,
|
|
||||||
description: "#{I18n.t('renew')} #{@domain.name}",
|
|
||||||
activity_type: AccountActivity::RENEW,
|
|
||||||
price: @domain_pricelist
|
|
||||||
})
|
|
||||||
|
|
||||||
render_epp_response '/epp/domains/renew'
|
|
||||||
else
|
|
||||||
handle_errors(@domain)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::StatementInvalid => e
|
|
||||||
sleep rand / 100
|
|
||||||
retry
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue