mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 06:26:15 +02:00
eis_billing-request-to-generate-invoice-28-03-2022
This commit is contained in:
parent
223f53161b
commit
c54c89baf7
8 changed files with 77 additions and 117 deletions
|
@ -1,68 +1,63 @@
|
||||||
# TEMPORARY COMMENT OUT, IF EVERYTHING WILL BE WORK AS EXPECTED, THEN NEED TO REMOVE THIS CODR
|
module EisBilling
|
||||||
# DON'T FORGET TO REMOVE HELPERS, ROUTES AND ETC ALSO
|
class PaymentStatusController < EisBilling::BaseController
|
||||||
#
|
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,12 +6,6 @@ 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?
|
||||||
|
@ -19,9 +13,7 @@ class Registrar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show; end
|
||||||
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_response_from_billing
|
def get_status_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)
|
JSON.parse(response.body, symbolize_names: true)[:status]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_invoice_number
|
def set_invoice_number
|
||||||
|
|
18
app/presenters/registrar/invoice_status_presenter.rb
Normal file
18
app/presenters/registrar/invoice_status_presenter.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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
|
|
@ -1,53 +0,0 @@
|
||||||
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
|
|
2
app/views/eis_billing/directo_response/update.html.erb
Normal file
2
app/views/eis_billing/directo_response/update.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>EisBilling::DirectoResponse#update</h1>
|
||||||
|
<p>Find me in app/views/eis_billing/directo_response/update.html.erb</p>
|
2
app/views/eis_billing/e_invoice_response/update.html.erb
Normal file
2
app/views/eis_billing/e_invoice_response/update.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>EisBilling::EInvoiceResponse#update</h1>
|
||||||
|
<p>Find me in app/views/eis_billing/e_invoice_response/update.html.erb</p>
|
|
@ -34,3 +34,7 @@
|
||||||
|
|
||||||
%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