mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Make sure that Payment method is functional prior to paying
This commit is contained in:
parent
03b031abeb
commit
3f5b5962d1
5 changed files with 27 additions and 36 deletions
|
@ -5,21 +5,14 @@ class Registrar
|
||||||
skip_authorization_check # actually anyone can pay, no problems at all
|
skip_authorization_check # actually anyone can pay, no problems at all
|
||||||
skip_before_action :authenticate_registrar_user!, :check_ip_restriction,
|
skip_before_action :authenticate_registrar_user!, :check_ip_restriction,
|
||||||
only: [:back, :callback]
|
only: [:back, :callback]
|
||||||
before_action :check_supported_payment_method
|
|
||||||
|
before_action :check_supported_payment_method, only: [:pay]
|
||||||
|
|
||||||
def pay
|
def pay
|
||||||
invoice = Invoice.find(params[:invoice_id])
|
invoice = Invoice.find(params[:invoice_id])
|
||||||
payment_type = params[:bank]
|
payment_type = params[:bank]
|
||||||
|
|
||||||
channel = if payment_type == 'every_pay'
|
channel = PaymentOrder.type_from_shortname(payment_type)
|
||||||
'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 = PaymentOrder.new(type: channel, invoice: invoice)
|
||||||
@payment_order.save && @payment_order.reload
|
@payment_order.save && @payment_order.reload
|
||||||
|
@ -31,7 +24,7 @@ class Registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
def back
|
def back
|
||||||
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
@payment_order = PaymentOrder.find_by!(id: params[:payment_order])
|
||||||
@payment_order.update!(response: params.to_unsafe_h)
|
@payment_order.update!(response: params.to_unsafe_h)
|
||||||
|
|
||||||
if @payment_order.payment_received?
|
if @payment_order.payment_received?
|
||||||
|
@ -51,7 +44,7 @@ class Registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
def callback
|
def callback
|
||||||
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
@payment_order = PaymentOrder.find_by!(id: params[:payment_order])
|
||||||
@payment_order.update!(response: params.to_unsafe_h)
|
@payment_order.update!(response: params.to_unsafe_h)
|
||||||
|
|
||||||
if @payment_order.payment_received?
|
if @payment_order.payment_received?
|
||||||
|
@ -68,13 +61,11 @@ class Registrar
|
||||||
def check_supported_payment_method
|
def check_supported_payment_method
|
||||||
return if supported_payment_method?
|
return if supported_payment_method?
|
||||||
|
|
||||||
raise StandardError.new('Not supported payment method')
|
raise(StandardError, 'Not supported payment method')
|
||||||
end
|
end
|
||||||
|
|
||||||
def supported_payment_method?
|
def supported_payment_method?
|
||||||
puts "Payment method param is #{params[:bank]}"
|
PaymentOrder.supported_method?(params[:bank])
|
||||||
# PaymentOrder::PAYMENT_METHODS.include?(params[:bank])
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,14 +25,14 @@ class PaymentOrder < ApplicationRecord
|
||||||
errors.add(:invoice, 'is already paid')
|
errors.add(:invoice, 'is already paid')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.supported_method?(some_class)
|
def self.type_from_shortname(shortname)
|
||||||
raise ArgumentError unless some_class < PaymentOrder
|
('PaymentOrders::' + shortname.camelize).constantize
|
||||||
|
end
|
||||||
|
|
||||||
if PAYMENT_METHODS.include?(some_class.name)
|
def self.supported_method?(some_class)
|
||||||
true
|
supported_methods.include? type_from_shortname(some_class)
|
||||||
else
|
rescue NameError
|
||||||
false
|
false
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def complete_transaction(transaction)
|
def complete_transaction(transaction)
|
||||||
|
@ -52,16 +52,16 @@ class PaymentOrder < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.supported_methods
|
def self.supported_methods
|
||||||
enabled = []
|
supported = []
|
||||||
|
|
||||||
ENABLED_METHODS.each do |method|
|
PAYMENT_METHODS.each do |method|
|
||||||
class_name = method.constantize
|
class_name = ('PaymentOrders::' + method.camelize).constantize
|
||||||
raise(Errors::ExpectedPaymentOrder, class_name) unless class_name < PaymentOrder
|
raise(NoMethodError, class_name) unless class_name < PaymentOrder
|
||||||
|
|
||||||
enabled << class_name
|
supported << class_name
|
||||||
end
|
end
|
||||||
|
|
||||||
enabled
|
supported
|
||||||
end
|
end
|
||||||
|
|
||||||
def channel
|
def channel
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module PaymentOrders
|
module PaymentOrders
|
||||||
class LHV < BankLink
|
class Lhv < BankLink
|
||||||
def self.config_namespace_name
|
def self.config_namespace_name
|
||||||
'lhv'
|
'lhv'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module PaymentOrders
|
module PaymentOrders
|
||||||
class SEB < BankLink
|
class Seb < BankLink
|
||||||
def self.config_namespace_name
|
def self.config_namespace_name
|
||||||
'seb'
|
'seb'
|
||||||
end
|
end
|
||||||
|
|
|
@ -127,11 +127,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'pay/return/:bank' => 'payments#back', as: 'return_payment_with'
|
get 'pay/return/:payment_order' => 'payments#back', as: 'return_payment_with'
|
||||||
post 'pay/return/:bank' => 'payments#back'
|
post 'pay/return/:payment_order' => 'payments#back'
|
||||||
put 'pay/return/:bank' => 'payments#back'
|
put 'pay/return/:payment_order' => 'payments#back'
|
||||||
post 'pay/callback/:bank' => 'payments#callback', as: 'response_payment_with'
|
post 'pay/callback/:payment_order' => 'payments#callback', as: 'response_payment_with'
|
||||||
get 'pay/go/:bank' => 'payments#pay', as: 'payment_with'
|
get 'pay/go/:bank' => 'payments#pay', as: 'payment_with'
|
||||||
|
|
||||||
namespace :settings do
|
namespace :settings do
|
||||||
resource :balance_auto_reload, controller: :balance_auto_reload, only: %i[edit update destroy]
|
resource :balance_auto_reload, controller: :balance_auto_reload, only: %i[edit update destroy]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue