mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 01:35:10 +02:00
Add balance checking
This commit is contained in:
parent
3ef6c53a8c
commit
729f39f612
5 changed files with 67 additions and 3 deletions
|
@ -16,8 +16,12 @@ class Registrar
|
|||
|
||||
if domain_ids_for_bulk_renew.present?
|
||||
domains = Epp::Domain.where(id: domain_ids_for_bulk_renew).to_a
|
||||
task = Domains::BulkRenew::Start.run(domains: domains)
|
||||
flash[:notice] = t(:bulk_renew_completed)
|
||||
task = Domains::BulkRenew::Start.run(domains: domains, period_element: @period)
|
||||
if task.valid?
|
||||
flash[:notice] = t(:bulk_renew_completed)
|
||||
else
|
||||
flash[:notice] = task.errors.full_messages.join(' and ')
|
||||
end
|
||||
end
|
||||
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew }
|
||||
end
|
||||
|
|
|
@ -4,9 +4,18 @@ module Domains
|
|||
array :domains do
|
||||
object class: Epp::Domain
|
||||
end
|
||||
string :period_element
|
||||
|
||||
def execute
|
||||
|
||||
period = (period_element.to_i == 0) ? 1 : period_element.to_i
|
||||
unit = period_element[-1] || 'y'
|
||||
task = Domains::CheckBalance::Mass.run(domains: domains,
|
||||
operation: 'renew',
|
||||
period: period,
|
||||
unit: unit)
|
||||
unless task.valid?
|
||||
errors.merge!(task.errors)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
23
app/interactions/domains/check_balance/mass.rb
Normal file
23
app/interactions/domains/check_balance/mass.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Domains
|
||||
module CheckBalance
|
||||
class Mass < ActiveInteraction::Base
|
||||
array :domains do
|
||||
object class: Epp::Domain
|
||||
end
|
||||
|
||||
string :operation
|
||||
integer :period
|
||||
string :unit
|
||||
|
||||
def execute
|
||||
domains.each do |domain|
|
||||
compose(Domains::CheckBalance::SingleDomain,
|
||||
domain: domain,
|
||||
operation: 'renew',
|
||||
period: period,
|
||||
unit: unit)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
app/interactions/domains/check_balance/single_domain.rb
Normal file
26
app/interactions/domains/check_balance/single_domain.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Domains
|
||||
module CheckBalance
|
||||
class SingleDomain < ActiveInteraction::Base
|
||||
object :domain,
|
||||
class: Epp::Domain
|
||||
|
||||
string :operation
|
||||
integer :period
|
||||
string :unit
|
||||
|
||||
def execute
|
||||
domain_pricelist = domain.pricelist(operation, period.try(:to_i), unit)
|
||||
if domain_pricelist.try(:price) # checking if price list is not found
|
||||
if current_user.registrar.balance < domain_pricelist.price.amount
|
||||
errors.add(:domain, I18n.t('billing_failure_credit_balance_low_for_domain', domain: domain.name))
|
||||
return false
|
||||
end
|
||||
else
|
||||
errors.add(:domain, I18n.t(:active_price_missing_for_operation_with_domain, domain: domain.name))
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue