mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
fixed status handlers
This commit is contained in:
parent
1b377dadcd
commit
36d629fe2b
3 changed files with 34 additions and 15 deletions
|
@ -3,21 +3,26 @@ module EisBilling
|
|||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||
PAID = 'paid'.freeze
|
||||
CANCELLED = 'cancelled'.freeze
|
||||
ISSUED = 'issued'.freeze
|
||||
ISSUED = 'unpaid'.freeze
|
||||
FAILED = 'failed'.freeze
|
||||
|
||||
before_action :load_invoice, only: :update
|
||||
|
||||
def update
|
||||
if @invoice.update(modified_params)
|
||||
payment_orders_handler
|
||||
p '=========='
|
||||
p params
|
||||
p '=========='
|
||||
|
||||
if @invoice.update(modified_params) && payment_orders_handler
|
||||
|
||||
render json: {
|
||||
message: 'Invoice data was successfully updated',
|
||||
}, status: :ok
|
||||
else
|
||||
render json: {
|
||||
error: @message.errors.full_messages,
|
||||
error: {
|
||||
message: @invoice.errors.full_messages
|
||||
}
|
||||
}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
@ -25,16 +30,33 @@ module EisBilling
|
|||
private
|
||||
|
||||
def payment_orders_handler
|
||||
p '-----'
|
||||
p @invoice.cancelled?
|
||||
p status.issued?
|
||||
p status
|
||||
p '------'
|
||||
|
||||
if @invoice.payment_orders.present?
|
||||
return if (@invoice.paid? && status.paid?) || (@invoice.unpaid? && status.issued?)
|
||||
if @invoice.cancelled? && status.paid? || @invoice.cancelled? && status.issued?
|
||||
@invoice.errors.add(:base, 'Unable to change status of record')
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
if @invoice.paid? && (status.failed? || status.cancelled?)
|
||||
@invoice.errors.add(:base, 'Unable to change status of record')
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return true if (@invoice.paid? && status.paid?) || (@invoice.unpaid? && status.issued?) || (@invoice.cancelled? && status.cancelled?)
|
||||
|
||||
if status.issued?
|
||||
@invoice.cancel_manualy
|
||||
elsif status.paid?
|
||||
@invoice.autobind_manually
|
||||
else
|
||||
# TODO
|
||||
# CANCELLED
|
||||
@invoice.cancel
|
||||
end
|
||||
else
|
||||
return unless status.paid?
|
||||
|
@ -44,7 +66,7 @@ module EisBilling
|
|||
end
|
||||
|
||||
def status
|
||||
status = case params[:invoice][:status]
|
||||
status = case params[:status][:status]
|
||||
when 'paid'
|
||||
'paid'
|
||||
when 'cancelled'
|
||||
|
@ -52,7 +74,7 @@ module EisBilling
|
|||
when 'failed'
|
||||
'failed'
|
||||
else
|
||||
'issued'
|
||||
'unpaid'
|
||||
end
|
||||
|
||||
Struct.new(:paid?, :cancelled?, :issued?, :failed?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue