mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 07:26:22 +02:00
refactoring
This commit is contained in:
parent
9856a2a5c0
commit
fdf70359d1
6 changed files with 72 additions and 65 deletions
|
@ -5,7 +5,7 @@ class EisBilling::DirectoResponseController < EisBilling::BaseController
|
|||
@month = params.fetch(:month, false)
|
||||
|
||||
process_directo_response(xml_data, response)
|
||||
render status: 200, json: { messege: 'Should return new directo number', status: :ok }
|
||||
render status: :ok, json: { messege: 'Should return new directo number' }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,13 +2,13 @@ class EisBilling::EInvoiceResponseController < EisBilling::BaseController
|
|||
def update
|
||||
invoice_number = params[:invoice_number]
|
||||
|
||||
set_e_invoice_sent_at(invoice_number)
|
||||
render status: :ok, json: { messege: 'Response received' }
|
||||
mark_e_invoice_sent_at(invoice_number)
|
||||
render status: :ok, json: { message: 'Response received' }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_e_invoice_sent_at(invoice_number)
|
||||
def mark_e_invoice_sent_at(invoice_number)
|
||||
invoice = Invoice.find_by(number: invoice_number)
|
||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||
end
|
||||
|
|
|
@ -19,21 +19,27 @@ module EisBilling
|
|||
|
||||
ActiveRecord::Base.transaction do
|
||||
bank_statement.save!
|
||||
transaction = create_transaction(incoming_transaction: incoming_transaction, bank_statement: bank_statement)
|
||||
|
||||
next if transaction.registrar.blank?
|
||||
|
||||
create_invoice_if_missing(transaction) unless transaction.non_canceled?
|
||||
end
|
||||
end
|
||||
|
||||
def create_invoice_if_missing(transaction)
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
|
||||
def create_transaction(incoming_transaction:, bank_statement:)
|
||||
transaction_attributes = { sum: incoming_transaction['amount'],
|
||||
currency: incoming_transaction['currency'],
|
||||
paid_at: incoming_transaction['date'],
|
||||
reference_no: incoming_transaction['payment_reference_number'],
|
||||
description: incoming_transaction['payment_description'] }
|
||||
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
||||
|
||||
next if transaction.registrar.blank?
|
||||
|
||||
unless transaction.non_canceled?
|
||||
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
end
|
||||
bank_statement.bank_transactions.create!(transaction_attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,17 +3,10 @@ module EisBilling
|
|||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||
|
||||
def update
|
||||
invoice_number = params[:order_reference]
|
||||
paid_at = params[:transaction_time]
|
||||
sum = params[:standing_amount]
|
||||
everypay_response = params
|
||||
|
||||
payment_status = define_payment_status(params[:payment_state])
|
||||
|
||||
invoice = Invoice.find_by(number: invoice_number)
|
||||
|
||||
bank = create_bank_transfer(invoice: invoice, sum: sum, paid_at: paid_at)
|
||||
create_payment_order(invoice: invoice, everypay_response: everypay_response, payment_status: payment_status)
|
||||
invoice = Invoice.find_by(number: params[:order_reference])
|
||||
bank = create_bank_transfer(invoice: invoice, sum: params[:standing_amount], paid_at: params[:transaction_time])
|
||||
create_payment_order(invoice: invoice, everypay_response: params, payment_status: payment_status)
|
||||
|
||||
registrar = invoice.buyer
|
||||
bank.create_activity(registrar, invoice)
|
||||
|
@ -37,9 +30,6 @@ module EisBilling
|
|||
payment.status = payment_status
|
||||
payment.save
|
||||
|
||||
logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
||||
logger.info payment.errors
|
||||
|
||||
payment
|
||||
end
|
||||
|
||||
|
@ -54,9 +44,6 @@ module EisBilling
|
|||
bank.buyer_name = invoice.buyer_name
|
||||
bank.save
|
||||
|
||||
logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
||||
logger.info bank.errors
|
||||
|
||||
bank
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,24 +40,33 @@ class Invoice < ApplicationRecord
|
|||
|
||||
attribute :vat_rate, ::Type::VatRate.new
|
||||
|
||||
def set_invoice_number
|
||||
if Feature.billing_system_integrated?
|
||||
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||
def validate_invoice_number(result)
|
||||
response = JSON.parse(result.body)
|
||||
|
||||
if JSON.parse(result.body)['code'] == '403'
|
||||
billing_restrictions_issue if response['code'] == '403'
|
||||
billing_out_of_range_issue if response['error'] == 'out of range'
|
||||
end
|
||||
|
||||
def billing_restrictions_issue
|
||||
errors.add(:base, I18n.t('cannot get access'))
|
||||
logger.error('PROBLEM WITH TOKEN')
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
if JSON.parse(result.body)['error'] == 'out of range'
|
||||
def billing_out_of_range_issue
|
||||
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
def invoice_number_from_billing
|
||||
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||
validate_invoice_number(result)
|
||||
|
||||
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
||||
else
|
||||
end
|
||||
|
||||
def generate_invoice_number_legacy
|
||||
last_no = Invoice.all
|
||||
.where(number: Setting.invoice_number_min.to_i...Setting.invoice_number_max.to_i)
|
||||
.order(number: :desc)
|
||||
|
@ -72,9 +81,14 @@ class Invoice < ApplicationRecord
|
|||
|
||||
return if number <= Setting.invoice_number_max.to_i
|
||||
|
||||
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||
throw(:abort)
|
||||
billing_out_of_range_issue
|
||||
end
|
||||
|
||||
def set_invoice_number
|
||||
if Feature.billing_system_integrated?
|
||||
invoice_number_from_billing
|
||||
else
|
||||
generate_invoice_number_legacy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ module EisBilling
|
|||
data[:order_reference] = invoice.number
|
||||
data[:customer_name] = invoice.buyer_name
|
||||
data[:customer_email] = invoice.buyer_email
|
||||
data[:custom_field_1] = invoice.description
|
||||
data[:custom_field_2] = INITIATOR
|
||||
data[:custom_field1] = invoice.description
|
||||
data[:custom_field2] = INITIATOR
|
||||
data[:invoice_number] = invoice.number
|
||||
|
||||
data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue