mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 07:52:04 +02:00
change logic, added tests
This commit is contained in:
parent
e00e87a15c
commit
d28afca00f
5 changed files with 115 additions and 52 deletions
|
@ -1,15 +1,8 @@
|
|||
module EisBilling
|
||||
class InvoicesController < BaseController
|
||||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||
PAID = 'paid'.freeze
|
||||
CANCELLED = 'cancelled'.freeze
|
||||
ISSUED = 'unpaid'.freeze
|
||||
FAILED = 'failed'.freeze
|
||||
|
||||
before_action :load_invoice, only: :update
|
||||
|
||||
def update
|
||||
# if @invoice.update(modified_params) && payment_orders_handler
|
||||
state = InvoiceStateMachine.new(invoice: @invoice, status: params[:status])
|
||||
if @invoice.update(modified_params) && state.call
|
||||
render json: {
|
||||
|
@ -26,42 +19,6 @@ module EisBilling
|
|||
|
||||
private
|
||||
|
||||
# def payment_orders_handler
|
||||
# return false if @invoice.cancelled? && status.paid? || @invoice.cancelled? && status.issued?
|
||||
# return false if @invoice.paid? && (status.failed? || status.cancelled?)
|
||||
|
||||
# case
|
||||
# when @invoice.paid? && status.paid?
|
||||
# true
|
||||
# when @invoice.unpaid? && status.issued?
|
||||
# true
|
||||
# when @invoice.cancelled? && (status.cancelled? || status.failed?)
|
||||
# true
|
||||
# when status.issued?
|
||||
# @invoice.cancel_manualy
|
||||
# when status.paid?
|
||||
# @invoice.autobind_manually
|
||||
# else
|
||||
# @invoice.cancel
|
||||
# end
|
||||
# end
|
||||
|
||||
# def status
|
||||
# status = case params[:status]
|
||||
# when 'paid'
|
||||
# 'paid'
|
||||
# when 'cancelled'
|
||||
# 'cancelled'
|
||||
# when 'failed'
|
||||
# 'failed'
|
||||
# else
|
||||
# 'unpaid'
|
||||
# end
|
||||
|
||||
# Struct.new(:paid?, :cancelled?, :issued?, :failed?)
|
||||
# .new(status == PAID, status == CANCELLED, status == ISSUED, status == FAILED)
|
||||
# end
|
||||
|
||||
def load_invoice
|
||||
@invoice = Invoice.find_by(number: params[:invoice][:invoice_number])
|
||||
return if @invoice.present?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue