mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 06:56:23 +02:00
updated invoices status request
This commit is contained in:
parent
ee1408e49f
commit
223f53161b
8 changed files with 117 additions and 77 deletions
|
@ -1,63 +1,68 @@
|
||||||
module EisBilling
|
# TEMPORARY COMMENT OUT, IF EVERYTHING WILL BE WORK AS EXPECTED, THEN NEED TO REMOVE THIS CODR
|
||||||
class PaymentStatusController < EisBilling::BaseController
|
# DON'T FORGET TO REMOVE HELPERS, ROUTES AND ETC ALSO
|
||||||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# module EisBilling
|
||||||
|
# class PaymentStatusController < EisBilling::BaseController
|
||||||
|
# TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||||
|
|
||||||
def update
|
# def update
|
||||||
invoice_number = params[:order_reference]
|
# invoice_number = params[:order_reference]
|
||||||
paid_at = params[:transaction_time]
|
# paid_at = params[:transaction_time]
|
||||||
sum = params[:standing_amount]
|
# sum = params[:standing_amount]
|
||||||
everypay_response = params
|
# everypay_response = params
|
||||||
|
|
||||||
payment_status = define_payment_status(params[:payment_state])
|
# payment_status = define_payment_status(params[:payment_state])
|
||||||
|
|
||||||
invoice = Invoice.find_by(number: invoice_number)
|
# invoice = Invoice.find_by(number: invoice_number)
|
||||||
|
|
||||||
bank = create_bank_transfer(invoice: invoice, sum: sum, paid_at: paid_at)
|
# 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)
|
# create_payment_order(invoice: invoice, everypay_response: everypay_response, payment_status: payment_status)
|
||||||
|
|
||||||
registrar = invoice.buyer
|
# registrar = invoice.buyer
|
||||||
bank.create_activity(registrar, invoice)
|
# bank.create_activity(registrar, invoice)
|
||||||
|
|
||||||
render status: 200, json: { status: :ok }
|
# render status: 200, json: { status: :ok }
|
||||||
end
|
# end
|
||||||
|
|
||||||
private
|
# private
|
||||||
|
|
||||||
def define_payment_status(status)
|
# def define_payment_status(status)
|
||||||
return :paid if PaymentOrders::EveryPay::SUCCESSFUL_PAYMENT.include? status
|
# return :paid if PaymentOrders::EveryPay::SUCCESSFUL_PAYMENT.include? status
|
||||||
|
|
||||||
:failed
|
# :failed
|
||||||
end
|
# end
|
||||||
|
|
||||||
def create_payment_order(invoice:, everypay_response:, payment_status:)
|
# def create_payment_order(invoice:, everypay_response:, payment_status:)
|
||||||
payment = PaymentOrder.new
|
# payment = PaymentOrder.new
|
||||||
payment.type = TYPE
|
# payment.type = TYPE
|
||||||
payment.invoice = invoice
|
# payment.invoice = invoice
|
||||||
payment.response = everypay_response
|
# payment.response = everypay_response
|
||||||
payment.status = payment_status
|
# payment.status = payment_status
|
||||||
payment.save
|
# payment.save
|
||||||
|
|
||||||
logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
# logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
||||||
logger.info payment.errors
|
# logger.info payment.errors
|
||||||
|
|
||||||
payment
|
# payment
|
||||||
end
|
# end
|
||||||
|
|
||||||
def create_bank_transfer(invoice:, sum:, paid_at:)
|
# def create_bank_transfer(invoice:, sum:, paid_at:)
|
||||||
bank = BankTransaction.new
|
# bank = BankTransaction.new
|
||||||
bank.description = invoice.order
|
# bank.description = invoice.order
|
||||||
bank.reference_no = invoice.reference_no
|
# bank.reference_no = invoice.reference_no
|
||||||
bank.currency = invoice.currency
|
# bank.currency = invoice.currency
|
||||||
bank.iban = invoice.seller_iban
|
# bank.iban = invoice.seller_iban
|
||||||
bank.sum = sum
|
# bank.sum = sum
|
||||||
bank.paid_at = paid_at
|
# bank.paid_at = paid_at
|
||||||
bank.buyer_name = invoice.buyer_name
|
# bank.buyer_name = invoice.buyer_name
|
||||||
bank.save
|
# bank.save
|
||||||
|
|
||||||
logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
# logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
||||||
logger.info bank.errors
|
# logger.info bank.errors
|
||||||
|
|
||||||
bank
|
# bank
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
|
@ -6,6 +6,12 @@ class Registrar
|
||||||
params[:q] ||= {}
|
params[:q] ||= {}
|
||||||
invoices = current_registrar_user.registrar.invoices.includes(:items, :account_activity)
|
invoices = current_registrar_user.registrar.invoices.includes(:items, :account_activity)
|
||||||
|
|
||||||
|
invoices.each do |invoice|
|
||||||
|
next if invoice.paid? || invoice.cancelled?
|
||||||
|
|
||||||
|
EisBilling::SetInvoiceStatus.ping_status(invoice)
|
||||||
|
end
|
||||||
|
|
||||||
normalize_search_parameters do
|
normalize_search_parameters do
|
||||||
@q = invoices.ransack(params[:q])
|
@q = invoices.ransack(params[:q])
|
||||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||||
|
@ -13,7 +19,9 @@ class Registrar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show; end
|
def show
|
||||||
|
EisBilling::SetInvoiceStatus.ping_status(@invoice)
|
||||||
|
end
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
@invoice.cancel
|
@invoice.cancel
|
||||||
|
|
|
@ -40,9 +40,9 @@ class Invoice < ApplicationRecord
|
||||||
|
|
||||||
attribute :vat_rate, ::Type::VatRate.new
|
attribute :vat_rate, ::Type::VatRate.new
|
||||||
|
|
||||||
def get_status_from_billing
|
def get_response_from_billing
|
||||||
response = EisBilling::GetInvoiceStatus.send_invoice(invoice_number: number)
|
response = EisBilling::GetInvoiceStatus.send_invoice(invoice_number: number)
|
||||||
JSON.parse(response.body, symbolize_names: true)[:status]
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_invoice_number
|
def set_invoice_number
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
class Registrar::InvoiceStatusPresenter
|
|
||||||
include ActionView::Helpers::TagHelper
|
|
||||||
|
|
||||||
attr_reader :invoice
|
|
||||||
|
|
||||||
def initialize(invoice:)
|
|
||||||
@invoice = invoice
|
|
||||||
end
|
|
||||||
|
|
||||||
def display
|
|
||||||
case invoice.get_status_from_billing
|
|
||||||
when 'unpaid'
|
|
||||||
content_tag(:span, 'Unpaid', style: 'color: red;')
|
|
||||||
when 'paid'
|
|
||||||
content_tag(:span, 'Unpaid', style: 'color: red;')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
53
app/services/eis_billing/set_invoice_status.rb
Normal file
53
app/services/eis_billing/set_invoice_status.rb
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
module EisBilling
|
||||||
|
class SetInvoiceStatus
|
||||||
|
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||||
|
|
||||||
|
def self.ping_status(invoice)
|
||||||
|
response = invoice.get_response_from_billing
|
||||||
|
change_status_to_pay(response: response, invoice: invoice) if response[:status] == 'paid'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.change_status_to_pay(response:, invoice:)
|
||||||
|
return if response[:everypay_response].nil?
|
||||||
|
|
||||||
|
everypay_response = response[:everypay_response]
|
||||||
|
bank = create_bank_transfer(invoice: invoice, sum: everypay_response['standing_amount'],
|
||||||
|
paid_at: response[:transaction_time])
|
||||||
|
create_payment_order(invoice: invoice, everypay_response: everypay_response, payment_status: response[:status])
|
||||||
|
|
||||||
|
registrar = invoice.buyer
|
||||||
|
bank.create_activity(registrar, invoice)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.create_payment_order(invoice:, everypay_response:, payment_status:)
|
||||||
|
payment = PaymentOrder.new
|
||||||
|
payment.type = TYPE
|
||||||
|
payment.invoice = invoice
|
||||||
|
payment.response = everypay_response
|
||||||
|
payment.status = payment_status
|
||||||
|
payment.save
|
||||||
|
|
||||||
|
Rails.logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
||||||
|
Rails.logger.info payment.errors
|
||||||
|
|
||||||
|
payment
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.create_bank_transfer(invoice:, sum:, paid_at:)
|
||||||
|
bank = BankTransaction.new
|
||||||
|
bank.description = invoice.order
|
||||||
|
bank.reference_no = invoice.reference_no
|
||||||
|
bank.currency = invoice.currency
|
||||||
|
bank.iban = invoice.seller_iban
|
||||||
|
bank.sum = sum
|
||||||
|
bank.paid_at = paid_at
|
||||||
|
bank.buyer_name = invoice.buyer_name
|
||||||
|
bank.save
|
||||||
|
|
||||||
|
Rails.logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
||||||
|
Rails.logger.info bank.errors
|
||||||
|
|
||||||
|
bank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,2 +0,0 @@
|
||||||
<h1>EisBilling::DirectoResponse#update</h1>
|
|
||||||
<p>Find me in app/views/eis_billing/directo_response/update.html.erb</p>
|
|
|
@ -1,2 +0,0 @@
|
||||||
<h1>EisBilling::EInvoiceResponse#update</h1>
|
|
||||||
<p>Find me in app/views/eis_billing/e_invoice_response/update.html.erb</p>
|
|
|
@ -34,7 +34,3 @@
|
||||||
|
|
||||||
%dt= Invoice.human_attribute_name :reference_no
|
%dt= Invoice.human_attribute_name :reference_no
|
||||||
%dd= @invoice.reference_no
|
%dd= @invoice.reference_no
|
||||||
|
|
||||||
- invoice_presenter = Registrar::InvoiceStatusPresenter.new(invoice: @invoice)
|
|
||||||
%dt Billing system
|
|
||||||
%dd= invoice_presenter.display
|
|
Loading…
Add table
Add a link
Reference in a new issue