mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +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
|
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||||
PAID = 'paid'.freeze
|
PAID = 'paid'.freeze
|
||||||
CANCELLED = 'cancelled'.freeze
|
CANCELLED = 'cancelled'.freeze
|
||||||
ISSUED = 'issued'.freeze
|
ISSUED = 'unpaid'.freeze
|
||||||
FAILED = 'failed'.freeze
|
FAILED = 'failed'.freeze
|
||||||
|
|
||||||
before_action :load_invoice, only: :update
|
before_action :load_invoice, only: :update
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @invoice.update(modified_params)
|
p '=========='
|
||||||
payment_orders_handler
|
p params
|
||||||
|
p '=========='
|
||||||
|
|
||||||
|
if @invoice.update(modified_params) && 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: @invoice.errors.full_messages
|
||||||
|
}
|
||||||
}, status: :unprocessable_entity
|
}, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,16 +30,33 @@ module EisBilling
|
||||||
private
|
private
|
||||||
|
|
||||||
def payment_orders_handler
|
def payment_orders_handler
|
||||||
|
p '-----'
|
||||||
|
p @invoice.cancelled?
|
||||||
|
p status.issued?
|
||||||
|
p status
|
||||||
|
p '------'
|
||||||
|
|
||||||
if @invoice.payment_orders.present?
|
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?
|
if status.issued?
|
||||||
@invoice.cancel_manualy
|
@invoice.cancel_manualy
|
||||||
elsif status.paid?
|
elsif status.paid?
|
||||||
@invoice.autobind_manually
|
@invoice.autobind_manually
|
||||||
else
|
else
|
||||||
# TODO
|
@invoice.cancel
|
||||||
# CANCELLED
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return unless status.paid?
|
return unless status.paid?
|
||||||
|
@ -44,7 +66,7 @@ module EisBilling
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
status = case params[:invoice][:status]
|
status = case params[:status][:status]
|
||||||
when 'paid'
|
when 'paid'
|
||||||
'paid'
|
'paid'
|
||||||
when 'cancelled'
|
when 'cancelled'
|
||||||
|
@ -52,7 +74,7 @@ module EisBilling
|
||||||
when 'failed'
|
when 'failed'
|
||||||
'failed'
|
'failed'
|
||||||
else
|
else
|
||||||
'issued'
|
'unpaid'
|
||||||
end
|
end
|
||||||
|
|
||||||
Struct.new(:paid?, :cancelled?, :issued?, :failed?)
|
Struct.new(:paid?, :cancelled?, :issued?, :failed?)
|
||||||
|
|
|
@ -33,8 +33,6 @@ module Invoice::Cancellable
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel_manualy
|
def cancel_manualy
|
||||||
return unless cancellable?
|
|
||||||
|
|
||||||
account_activity = AccountActivity.find_by(invoice_id: id)
|
account_activity = AccountActivity.find_by(invoice_id: id)
|
||||||
account_activity_dup = account_activity.dup
|
account_activity_dup = account_activity.dup
|
||||||
account_activity_dup.sum = -account_activity.sum.to_i
|
account_activity_dup.sum = -account_activity.sum.to_i
|
||||||
|
|
|
@ -256,7 +256,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
||||||
assert_equal invoice.payment_orders.count, 1
|
assert_equal invoice.payment_orders.count, 1
|
||||||
assert invoice.payment_orders.first.paid?
|
assert invoice.payment_orders.first.paid?
|
||||||
assert invoice.account_activity
|
assert invoice.account_activity
|
||||||
|
assert invoice.paid?
|
||||||
assert_equal account.balance.to_f, 200.0
|
assert_equal account.balance.to_f, 200.0
|
||||||
|
|
||||||
decrease_balance_params = {
|
decrease_balance_params = {
|
||||||
|
@ -265,7 +265,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
||||||
initiator: 'registry',
|
initiator: 'registry',
|
||||||
payment_reference: '93b29d54ae08f7728e72ee3fe0e88855cd1d266912039d7d23fa2b54b7e1b349',
|
payment_reference: '93b29d54ae08f7728e72ee3fe0e88855cd1d266912039d7d23fa2b54b7e1b349',
|
||||||
transaction_amount: 120.0,
|
transaction_amount: 120.0,
|
||||||
status: 'cancelled',
|
status: 'unpaid',
|
||||||
in_directo: false,
|
in_directo: false,
|
||||||
everypay_response: {
|
everypay_response: {
|
||||||
'some' => 'some'
|
'some' => 'some'
|
||||||
|
@ -278,6 +278,7 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
||||||
invoice.reload
|
invoice.reload
|
||||||
invoice.payment_orders.each(&:reload)
|
invoice.payment_orders.each(&:reload)
|
||||||
account.reload
|
account.reload
|
||||||
|
assert invoice.unpaid?
|
||||||
|
|
||||||
assert_equal account.balance.to_f, 100.0
|
assert_equal account.balance.to_f, 100.0
|
||||||
end
|
end
|
||||||
|
@ -303,6 +304,4 @@ class EInvoiceResponseTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
assert_equal registry_response[:message], 'Invoice with nonexisted-invoice number not found'
|
assert_equal registry_response[:message], 'Invoice with nonexisted-invoice number not found'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'it should ignore if you trying to set failed status to canceled'
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue