mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 07:26:22 +02:00
refactoring
This commit is contained in:
parent
0a4444b556
commit
7b05e1e28a
2 changed files with 31 additions and 25 deletions
|
@ -1,6 +1,10 @@
|
||||||
module EisBilling
|
module EisBilling
|
||||||
class InvoicesController < BaseController
|
class InvoicesController < BaseController
|
||||||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||||
|
PAID = 'paid'.freeze
|
||||||
|
CANCELLED = 'cancelled'.freeze
|
||||||
|
ISSUED = 'issued'.freeze
|
||||||
|
FAILED = 'failed'.freeze
|
||||||
|
|
||||||
before_action :load_invoice, only: :update
|
before_action :load_invoice, only: :update
|
||||||
|
|
||||||
|
@ -9,11 +13,11 @@ module EisBilling
|
||||||
payment_orders_handler
|
payment_orders_handler
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
message: 'Invoice data was successfully updated'
|
message: 'Invoice data was successfully updated',
|
||||||
}, status: :ok
|
}, status: :ok
|
||||||
else
|
else
|
||||||
render json: {
|
render json: {
|
||||||
error: @message.errors.full_messages
|
error: @message.errors.full_messages,
|
||||||
}, status: :unprocessable_entity
|
}, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,22 +26,22 @@ module EisBilling
|
||||||
|
|
||||||
def payment_orders_handler
|
def payment_orders_handler
|
||||||
if @invoice.payment_orders.present?
|
if @invoice.payment_orders.present?
|
||||||
return if (@invoice.paid? && status == 'paid') || (@invoice.cancelled? && status == 'cancelled')
|
return if (@invoice.paid? && status.paid?) || (@invoice.cancelled? && status.cancelled?)
|
||||||
|
|
||||||
if status == 'cancelled' || status == 'failed'
|
if status.cancelled? || status.failed?
|
||||||
@invoice.cancel_manualy
|
@invoice.cancel_manualy
|
||||||
elsif status == 'paid'
|
elsif status.paid?
|
||||||
@invoice.autobind_manually
|
@invoice.autobind_manually
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return unless status == 'paid'
|
return unless status.paid?
|
||||||
|
|
||||||
@invoice.autobind_manually
|
@invoice.autobind_manually
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
case params[:invoice][:status]
|
status = case params[:invoice][:status]
|
||||||
when 'paid'
|
when 'paid'
|
||||||
'paid'
|
'paid'
|
||||||
when 'cancelled'
|
when 'cancelled'
|
||||||
|
@ -47,24 +51,26 @@ module EisBilling
|
||||||
else
|
else
|
||||||
'issued'
|
'issued'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Struct.new(:paid?, :cancelled?, :issued?, :failed?)
|
||||||
|
.new(status == PAID, status == CANCELLED, status == ISSUED, status == FAILED)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_invoice
|
def load_invoice
|
||||||
@invoice = Invoice.find_by(number: params[:invoice][:invoice_number])
|
@invoice = Invoice.find_by(number: params[:invoice][:invoice_number])
|
||||||
|
return if @invoice.present?
|
||||||
|
|
||||||
if @invoice.nil?
|
|
||||||
render json: {
|
render json: {
|
||||||
error: {
|
error: {
|
||||||
message: "Invoice with #{params[:invoice][:invoice_number]} number not found"
|
message: "Invoice with #{params[:invoice][:invoice_number]} number not found",
|
||||||
}
|
}
|
||||||
}, status: :not_found and return
|
}, status: :not_found and return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def modified_params
|
def modified_params
|
||||||
{
|
{
|
||||||
in_directo: params[:invoice][:in_directo],
|
in_directo: params[:invoice][:in_directo],
|
||||||
e_invoice_sent_at: params[:invoice][:sent_at_omniva]
|
e_invoice_sent_at: params[:invoice][:sent_at_omniva],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue