Create domain renew action

This commit is contained in:
Karl Erik Õunapuu 2021-01-21 13:08:54 +02:00
parent 454433cf10
commit dcb55a1af9
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 36 additions and 2 deletions

View file

@ -9,11 +9,12 @@ module Repp
api :POST, 'repp/v1/domains/:domain_name/renew' api :POST, 'repp/v1/domains/:domain_name/renew'
desc 'Renew domain' desc 'Renew domain'
param :renew, Hash, required: true, desc: 'Renew parameters' do param :renew, Hash, required: true, desc: 'Renew parameters' do
param :renew_period, Integer, required: true, desc: 'Renew period. Month (m) or year (y)' param :period, Integer, required: true, desc: 'Renew period. Month (m) or year (y)'
param :period_unit, String, required: true, desc: 'For how many months or years to renew' param :period_unit, String, required: true, desc: 'For how many months or years to renew'
end end
def create def create
action = Actions::DomainUpdate.new(@domain, renew_params[:renew], current_user) authorize!(:renew, @domain)
action = Actions::DomainRenew.new(@domain, renew_params[:renew], current_user.registrar)
unless action.call unless action.call
handle_errors(@domain) handle_errors(@domain)

View file

@ -0,0 +1,33 @@
module Actions
class DomainRenew
attr_reader :domain
attr_reader :params
attr_reader :user
def initialize(domain, params, user)
@domain = domain
@params = params
@user = user
end
def call
renew
end
def renew
period = params[:period]
unit = params[:period_unit]
task = Domains::BulkRenew::SingleDomainRenew.run(domain: domain,
period: params[:period],
unit: params[:period_unit],
registrar: user)
return true if task
puts task.errors
false
end
end
end