mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Process payments: Create new invoice by transaction to allow direct top ups
This commit is contained in:
parent
39a21cb790
commit
be960457e6
4 changed files with 23 additions and 6 deletions
|
@ -31,12 +31,18 @@ class BankTransaction < ApplicationRecord
|
||||||
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
@registrar ||= Invoice.find_by(reference_no: parsed_ref_number)&.buyer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autobindable?
|
||||||
|
return false if binded?
|
||||||
|
return false unless registrar
|
||||||
|
return false unless invoice
|
||||||
|
return false unless invoice.payable?
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||||
def autobind_invoice(manual: false)
|
def autobind_invoice(manual: false)
|
||||||
return if binded?
|
return unless autobindable?
|
||||||
return unless registrar
|
|
||||||
return unless invoice
|
|
||||||
return unless invoice.payable?
|
|
||||||
|
|
||||||
channel = if manual
|
channel = if manual
|
||||||
'admin_payment'
|
'admin_payment'
|
||||||
|
|
|
@ -112,6 +112,15 @@ class Invoice < ApplicationRecord
|
||||||
e_invoice_sent_at.present?
|
e_invoice_sent_at.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.create_from_transaction!(transaction)
|
||||||
|
registrar_user = Registrar.find_by(reference_no: transasction.parsed_ref_number)
|
||||||
|
return unless registrar_user
|
||||||
|
|
||||||
|
registrar_user.issue_prepayment_invoice(amount: transaction.sum,
|
||||||
|
description: 'Direct top-up via bank transfer',
|
||||||
|
paid: true)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def apply_default_buyer_vat_no
|
def apply_default_buyer_vat_no
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Registrar < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_prepayment_invoice(amount, description = nil)
|
def issue_prepayment_invoice(amount, description = nil, paid: false)
|
||||||
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
|
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
|
||||||
|
|
||||||
invoice = invoices.create!(
|
invoice = invoices.create!(
|
||||||
|
@ -99,7 +99,7 @@ class Registrar < ApplicationRecord
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
SendEInvoiceJob.enqueue(invoice.id)
|
SendEInvoiceJob.enqueue(invoice.id) unless paid
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace :invoices do
|
||||||
reference_no: incoming_transaction.payment_reference_number,
|
reference_no: incoming_transaction.payment_reference_number,
|
||||||
description: incoming_transaction.payment_description }
|
description: incoming_transaction.payment_description }
|
||||||
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
||||||
|
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||||
|
|
||||||
transaction.autobind_invoice
|
transaction.autobind_invoice
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue