diff --git a/app/controllers/admin/paid_deposit/deposit_statuses_controller.rb b/app/controllers/admin/paid_deposit/deposit_statuses_controller.rb index 47cea3ce7..76be9c2c1 100644 --- a/app/controllers/admin/paid_deposit/deposit_statuses_controller.rb +++ b/app/controllers/admin/paid_deposit/deposit_statuses_controller.rb @@ -1,12 +1,25 @@ +# rubocop:disable Metrics module Admin class PaidDeposit::DepositStatusesController < BaseController def update @deposit = DomainParticipateAuction.find(params[:id]) + deposits = DomainParticipateAuction.includes(:user).includes(:auction).search(params) + @pagy, @deposits = pagy(deposits, items: params[:per_page] ||= 15) + if @deposit.update(status: params[:status]) - redirect_to admin_paid_deposits_path, status: :see_other, flash: { notice: 'Invoice status updated successfully' } + res = @deposit.send_deposit_status_to_billing_system + + if res.result? + redirect_to admin_paid_deposits_path, status: :see_other, + flash: { notice: 'Invoice status updated successfully' } + else + flash[:alert] = "Deposit status is updated in auction side, but got error from billing side: #{res.errors}" + redirect_to admin_paid_deposits_path, status: :see_other + end else - render 'admin/paid_deposits/index', status: :unprocessable_entity + flash[:alert] = @deposit.errors.full_messages.join(', ') + redirect_to admin_paid_deposits_path, status: :see_other end end end diff --git a/app/models/domain_participate_auction.rb b/app/models/domain_participate_auction.rb index 315516159..f6eff6936 100644 --- a/app/models/domain_participate_auction.rb +++ b/app/models/domain_participate_auction.rb @@ -6,11 +6,15 @@ class DomainParticipateAuction < ApplicationRecord scope :search_by_auction_name_and_user_email, ->(origin) { if origin.present? - self.joins(:user).joins(:auction).where('users.email ILIKE ? OR auctions.domain_name ILIKE ?', "%#{origin}%", "%#{origin}%") + joins(:user).joins(:auction).where('users.email ILIKE ? OR auctions.domain_name ILIKE ?', "%#{origin}%", "%#{origin}%") end } def self.search(params = {}) - self.search_by_auction_name_and_user_email(params[:search_string]) + search_by_auction_name_and_user_email(params[:search_string]) + end + + def send_deposit_status_to_billing_system + EisBilling::DepositStatusService.call(domain_name: auction.domain_name, user_uuid: user.uuid, status: status) end end diff --git a/app/services/eis_billing/deposit_status_service.rb b/app/services/eis_billing/deposit_status_service.rb new file mode 100644 index 000000000..a69691b84 --- /dev/null +++ b/app/services/eis_billing/deposit_status_service.rb @@ -0,0 +1,38 @@ +module EisBilling + class DepositStatusService + include EisBilling::Request + include EisBilling::BaseService + + attr_reader :user_uuid, :status, :domain_name + + def initialize(user_uuid:, status:, domain_name:) + @user_uuid = user_uuid + @status = status + @domain_name = domain_name + end + + def self.call(user_uuid:, status:, domain_name:) + new(user_uuid: user_uuid, status: status, domain_name:).call + end + + def call + struct_response(fetch) + end + + private + + def fetch + post deposit_status_url, params + end + + def params + { user_uuid: user_uuid, + domain_name: domain_name, + status: status } + end + + def deposit_status_url + '/api/v1/invoice_generator/deposit_status' + end + end +end diff --git a/app/views/admin/paid_deposits/index.html.erb b/app/views/admin/paid_deposits/index.html.erb index ba263e077..5c8b90529 100644 --- a/app/views/admin/paid_deposits/index.html.erb +++ b/app/views/admin/paid_deposits/index.html.erb @@ -67,11 +67,11 @@