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?)
|
||||
|
|
|
@ -33,8 +33,6 @@ module Invoice::Cancellable
|
|||
end
|
||||
|
||||
def cancel_manualy
|
||||
return unless cancellable?
|
||||
|
||||
account_activity = AccountActivity.find_by(invoice_id: id)
|
||||
account_activity_dup = account_activity.dup
|
||||
account_activity_dup.sum = -account_activity.sum.to_i
|
||||
|
|
|
@ -256,7 +256,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
|||
assert_equal invoice.payment_orders.count, 1
|
||||
assert invoice.payment_orders.first.paid?
|
||||
assert invoice.account_activity
|
||||
|
||||
assert invoice.paid?
|
||||
assert_equal account.balance.to_f, 200.0
|
||||
|
||||
decrease_balance_params = {
|
||||
|
@ -265,7 +265,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
|||
initiator: 'registry',
|
||||
payment_reference: '93b29d54ae08f7728e72ee3fe0e88855cd1d266912039d7d23fa2b54b7e1b349',
|
||||
transaction_amount: 120.0,
|
||||
status: 'cancelled',
|
||||
status: 'unpaid',
|
||||
in_directo: false,
|
||||
everypay_response: {
|
||||
'some' => 'some'
|
||||
|
@ -278,6 +278,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
|||
invoice.reload
|
||||
invoice.payment_orders.each(&:reload)
|
||||
account.reload
|
||||
assert invoice.unpaid?
|
||||
|
||||
assert_equal account.balance.to_f, 100.0
|
||||
end
|
||||
|
@ -303,6 +304,4 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
|||
|
||||
assert_equal registry_response[:message], 'Invoice with nonexisted-invoice number not found'
|
||||
end
|
||||
|
||||
test 'it should ignore if you trying to set failed status to canceled'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue