mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 22:16:19 +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
|
||||
class PaymentStatusController < EisBilling::BaseController
|
||||
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||
# TEMPORARY COMMENT OUT, IF EVERYTHING WILL BE WORK AS EXPECTED, THEN NEED TO REMOVE THIS CODR
|
||||
# DON'T FORGET TO REMOVE HELPERS, ROUTES AND ETC ALSO
|
||||
#
|
||||
#
|
||||
#
|
||||
# module EisBilling
|
||||
# class PaymentStatusController < EisBilling::BaseController
|
||||
# TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||
|
||||
def update
|
||||
invoice_number = params[:order_reference]
|
||||
paid_at = params[:transaction_time]
|
||||
sum = params[:standing_amount]
|
||||
everypay_response = params
|
||||
# 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])
|
||||
# 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)
|
||||
create_payment_order(invoice: invoice, everypay_response: everypay_response, payment_status: payment_status)
|
||||
# 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)
|
||||
|
||||
registrar = invoice.buyer
|
||||
bank.create_activity(registrar, invoice)
|
||||
# registrar = invoice.buyer
|
||||
# bank.create_activity(registrar, invoice)
|
||||
|
||||
render status: 200, json: { status: :ok }
|
||||
end
|
||||
# render status: 200, json: { status: :ok }
|
||||
# end
|
||||
|
||||
private
|
||||
# private
|
||||
|
||||
def define_payment_status(status)
|
||||
return :paid if PaymentOrders::EveryPay::SUCCESSFUL_PAYMENT.include? status
|
||||
# def define_payment_status(status)
|
||||
# return :paid if PaymentOrders::EveryPay::SUCCESSFUL_PAYMENT.include? status
|
||||
|
||||
:failed
|
||||
end
|
||||
# :failed
|
||||
# end
|
||||
|
||||
def 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
|
||||
# def 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
|
||||
|
||||
logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
||||
logger.info payment.errors
|
||||
# logger.info '++++ PAYMENT ORDER ERRORS ? ++++'
|
||||
# logger.info payment.errors
|
||||
|
||||
payment
|
||||
end
|
||||
# payment
|
||||
# end
|
||||
|
||||
def 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
|
||||
# def 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
|
||||
|
||||
logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
||||
logger.info bank.errors
|
||||
# logger.info '++++ BANK TRANSACTION ERRORS ? ++++'
|
||||
# logger.info bank.errors
|
||||
|
||||
bank
|
||||
end
|
||||
end
|
||||
end
|
||||
# bank
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
@ -6,6 +6,12 @@ class Registrar
|
|||
params[:q] ||= {}
|
||||
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
|
||||
@q = invoices.ransack(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
@ -13,7 +19,9 @@ class Registrar
|
|||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
def show
|
||||
EisBilling::SetInvoiceStatus.ping_status(@invoice)
|
||||
end
|
||||
|
||||
def cancel
|
||||
@invoice.cancel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue