mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 21:54:48 +02:00
- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is changed to `rake 'invoices:cancel_overdue'`. - `invoices.payment_term` database column is removed and its value is hardcoded in UI. - `invoices.paid_at` is removed as unused - `invoices.due_date` column's type is now `date`. - `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice` interface to get a list of items is unified. - Default date format in UI. - Default translations are used. - Tests improved. - Specs converted to tests and removed along with factories. - Database structure improved.
67 lines
2 KiB
Ruby
67 lines
2 KiB
Ruby
class Registrar
|
|
class PaymentsController < BaseController
|
|
protect_from_forgery except: [:back, :callback]
|
|
|
|
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
|
|
|
|
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
|
|
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?
|
|
@payment.complete_transaction
|
|
|
|
if invoice.paid?
|
|
flash[:notice] = t(:pending_applied)
|
|
else
|
|
flash[:alert] = t(:something_wrong)
|
|
end
|
|
else
|
|
flash[:alert] = t(:something_wrong)
|
|
end
|
|
redirect_to registrar_invoice_path(invoice)
|
|
end
|
|
|
|
def callback
|
|
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?
|
|
@payment.complete_transaction
|
|
end
|
|
|
|
render status: 200, json: { status: 'ok' }
|
|
end
|
|
|
|
private
|
|
|
|
def check_supported_payment_method
|
|
return if supported_payment_method?
|
|
raise StandardError.new("Not supported payment method")
|
|
end
|
|
|
|
|
|
def supported_payment_method?
|
|
PaymentOrders::PAYMENT_METHODS.include?(params[:bank])
|
|
end
|
|
end
|
|
end
|