mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +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?
|
if domain_ids_for_bulk_renew.present?
|
||||||
domains = Epp::Domain.where(id: domain_ids_for_bulk_renew).to_a
|
domains = Epp::Domain.where(id: domain_ids_for_bulk_renew).to_a
|
||||||
task = Domains::BulkRenew::Start.run(domains: domains)
|
task = Domains::BulkRenew::Start.run(domains: domains, period_element: @period)
|
||||||
flash[:notice] = t(:bulk_renew_completed)
|
if task.valid?
|
||||||
|
flash[:notice] = t(:bulk_renew_completed)
|
||||||
|
else
|
||||||
|
flash[:notice] = task.errors.full_messages.join(' and ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew }
|
render file: 'registrar/bulk_change/new', locals: { active_tab: :bulk_renew }
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,18 @@ module Domains
|
||||||
array :domains do
|
array :domains do
|
||||||
object class: Epp::Domain
|
object class: Epp::Domain
|
||||||
end
|
end
|
||||||
|
string :period_element
|
||||||
|
|
||||||
def execute
|
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
|
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
|
|
@ -588,6 +588,7 @@ en:
|
||||||
create_bank_transaction: 'Create bank transaction'
|
create_bank_transaction: 'Create bank transaction'
|
||||||
create_new_invoice: 'Create new invoice'
|
create_new_invoice: 'Create new invoice'
|
||||||
billing_failure_credit_balance_low: 'Billing failure - credit balance low'
|
billing_failure_credit_balance_low: 'Billing failure - credit balance low'
|
||||||
|
billing_failure_credit_balance_low_for_domain: 'Billing failure - credit balance low for %{domain}'
|
||||||
create: 'Create'
|
create: 'Create'
|
||||||
activity_type: 'Activity type'
|
activity_type: 'Activity type'
|
||||||
receipt_date_from: 'Receipt date from'
|
receipt_date_from: 'Receipt date from'
|
||||||
|
@ -602,6 +603,7 @@ en:
|
||||||
notes: Notes
|
notes: Notes
|
||||||
active_price_for_this_operation_is: 'Active price for this operation is %{price}'
|
active_price_for_this_operation_is: 'Active price for this operation is %{price}'
|
||||||
active_price_missing_for_this_operation: 'Active price missing for this operation!'
|
active_price_missing_for_this_operation: 'Active price missing for this operation!'
|
||||||
|
active_price_missing_for_operation_with_domain: 'Active price missing for operation with %{domain}'
|
||||||
valid_to_from: 'Valid to from'
|
valid_to_from: 'Valid to from'
|
||||||
valid_to_until: 'Valid to until'
|
valid_to_until: 'Valid to until'
|
||||||
registrant_ident: 'Registrant ident'
|
registrant_ident: 'Registrant ident'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue