internetee-registry/app/interactions/domains/check_balance/single_domain.rb
Karl Erik Õunapuu 115cefc0cf
Fix some CC issues
2021-02-08 12:41:10 +02:00

41 lines
1.1 KiB
Ruby

module Domains
module CheckBalance
class SingleDomain < ActiveInteraction::Base
object :domain,
class: Epp::Domain
string :operation
integer :period
string :unit
def execute
if domain_pricelist.try(:price)
price = domain_pricelist.price.amount
return price if balance_ok?(price)
else
domain.add_epp_error(2104, nil, nil, I18n.t(:active_price_missing_for_this_operation))
errors.add(:domain, I18n.t(:active_price_missing_for_operation_with_domain,
domain: domain.name))
end
false
end
private
def balance_ok?(price)
if domain.registrar.cash_account.balance >= price
true
else
domain.add_epp_error(2104, nil, nil, I18n.t(:not_enough_funds))
errors.add(:domain, I18n.t(:billing_failure_credit_balance_low, domain: domain.name))
false
end
end
def domain_pricelist
domain.pricelist(operation, period.try(:to_i), unit)
end
end
end
end