mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 10:45:58 +02:00
Merge pull request #1502 from internetee/1422-record-payment-method-and-failed-payments
Record every payment attempt
This commit is contained in:
commit
444a07c62a
35 changed files with 798 additions and 342 deletions
|
@ -60,7 +60,7 @@ module Admin
|
|||
end
|
||||
|
||||
def bind_invoices
|
||||
@bank_statement.bind_invoices
|
||||
@bank_statement.bind_invoices(manual: true)
|
||||
|
||||
flash[:notice] = t('invoices_were_fully_binded') if @bank_statement.fully_binded?
|
||||
flash[:warning] = t('invoices_were_partially_binded') if @bank_statement.partially_binded?
|
||||
|
|
|
@ -34,7 +34,7 @@ module Admin
|
|||
end
|
||||
|
||||
def bind
|
||||
if @bank_transaction.bind_invoice(params[:invoice_no])
|
||||
if @bank_transaction.bind_invoice(params[:invoice_no], manual: true)
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
|
|
|
@ -5,50 +5,51 @@ class Registrar
|
|||
skip_authorization_check # actually anyone can pay, no problems at all
|
||||
skip_before_action :authenticate_registrar_user!, :check_ip_restriction,
|
||||
only: [:back, :callback]
|
||||
before_action :check_supported_payment_method
|
||||
|
||||
before_action :check_supported_payment_method, only: [:pay]
|
||||
|
||||
def pay
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
bank = params[:bank]
|
||||
opts = {
|
||||
return_url: registrar_return_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
),
|
||||
response_url: registrar_response_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
)
|
||||
}
|
||||
@payment = ::PaymentOrders.create_with_type(bank, invoice, opts)
|
||||
@payment.create_transaction
|
||||
channel = params[:bank]
|
||||
|
||||
@payment_order = PaymentOrder.new_with_type(type: channel, invoice: invoice)
|
||||
@payment_order.save
|
||||
@payment_order.reload
|
||||
|
||||
@payment_order.return_url = registrar_return_payment_with_url(@payment_order)
|
||||
@payment_order.response_url = registrar_response_payment_with_url(@payment_order)
|
||||
|
||||
@payment_order.save
|
||||
@payment_order.reload
|
||||
end
|
||||
|
||||
def back
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
opts = { response: params }
|
||||
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
|
||||
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
|
||||
Rails.logger.info("User paid invoice ##{invoice.number} successfully")
|
||||
@payment_order = PaymentOrder.find_by!(id: params[:payment_order])
|
||||
@payment_order.update!(response: params.to_unsafe_h)
|
||||
|
||||
@payment.complete_transaction
|
||||
if @payment_order.payment_received?
|
||||
@payment_order.complete_transaction
|
||||
|
||||
if invoice.paid?
|
||||
flash[:notice] = t(:pending_applied)
|
||||
if @payment_order.invoice.paid?
|
||||
flash[:notice] = t('.payment_successful')
|
||||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
flash[:alert] = t('.successful_payment_backend_error')
|
||||
end
|
||||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
@payment_order.create_failure_report
|
||||
flash[:alert] = t('.payment_not_received')
|
||||
end
|
||||
redirect_to registrar_invoice_path(invoice)
|
||||
redirect_to registrar_invoice_path(@payment_order.invoice)
|
||||
end
|
||||
|
||||
def callback
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
opts = { response: params }
|
||||
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
|
||||
@payment_order = PaymentOrder.find_by!(id: params[:payment_order])
|
||||
@payment_order.update!(response: params.to_unsafe_h)
|
||||
|
||||
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
|
||||
@payment.complete_transaction
|
||||
if @payment_order.payment_received?
|
||||
@payment_order.complete_transaction
|
||||
else
|
||||
@payment_order.create_failure_report
|
||||
end
|
||||
|
||||
render status: 200, json: { status: 'ok' }
|
||||
|
@ -57,13 +58,9 @@ class Registrar
|
|||
private
|
||||
|
||||
def check_supported_payment_method
|
||||
return if supported_payment_method?
|
||||
raise StandardError.new("Not supported payment method")
|
||||
end
|
||||
return if PaymentOrder.supported_method?(params[:bank], shortname: true)
|
||||
|
||||
|
||||
def supported_payment_method?
|
||||
PaymentOrders::PAYMENT_METHODS.include?(params[:bank])
|
||||
raise(StandardError, 'Not supported payment method')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue