mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
80 lines
2.5 KiB
Ruby
80 lines
2.5 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])
|
|
payment_type = params[:bank]
|
|
|
|
channel = if payment_type == 'every_pay'
|
|
'PaymentOrders::EveryPay'
|
|
elsif payment_type == 'seb'
|
|
'PaymentOrders::SEB'
|
|
elsif payment_type == 'swed'
|
|
'PaymentOrders::Swed'
|
|
elsif payment_type == 'lhv'
|
|
'PaymentOrders::LHV'
|
|
end
|
|
|
|
@payment_order = PaymentOrder.new(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
|
|
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
|
@payment_order.update!(response: params.to_unsafe_h)
|
|
|
|
if @payment_order.payment_received?
|
|
@payment_order.complete_transaction(@payment_order.composed_transaction)
|
|
|
|
if @payment_order.invoice.paid?
|
|
flash[:notice] = t(:pending_applied)
|
|
else
|
|
# flash[:alert] = t(:something_wrong)
|
|
flash[:alert] = 'We fucked up'
|
|
end
|
|
else
|
|
@payment_order.create_failure_report
|
|
flash[:alert] = t(:something_wrong)
|
|
end
|
|
redirect_to registrar_invoice_path(@payment_order.invoice)
|
|
end
|
|
|
|
def callback
|
|
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
|
@payment_order.update!(response: params.to_unsafe_h)
|
|
|
|
if @payment_order.payment_received?
|
|
@payment_order.complete_transaction
|
|
else
|
|
@payment_order.create_failure_report
|
|
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?
|
|
puts "Payment method param is #{params[:bank]}"
|
|
# PaymentOrder::PAYMENT_METHODS.include?(params[:bank])
|
|
true
|
|
end
|
|
end
|
|
end
|