mirror of
https://github.com/internetee/registry.git
synced 2025-06-15 17:14:46 +02:00
33 lines
863 B
Ruby
33 lines
863 B
Ruby
module Domains
|
|
module CheckBalance
|
|
class Mass < ActiveInteraction::Base
|
|
array :domains do
|
|
object class: Epp::Domain
|
|
end
|
|
string :operation
|
|
integer :period
|
|
string :unit
|
|
float :balance
|
|
|
|
attr_accessor :total_price
|
|
|
|
def execute
|
|
calculate_total_price
|
|
|
|
balance >= @total_price
|
|
end
|
|
|
|
def calculate_total_price
|
|
@total_price = 0
|
|
domains.each do |domain|
|
|
task = Domains::CheckBalance::SingleDomain.run(domain: domain,
|
|
operation: 'renew',
|
|
period: period,
|
|
unit: unit)
|
|
|
|
task.valid? ? @total_price += task.result : errors.merge!(task.errors)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|