mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44: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_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])
|
||||
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
|
||||
channel = PaymentOrder.type_from_shortname(payment_type)
|
||||
|
||||
@payment_order = PaymentOrder.new(type: channel, invoice: invoice)
|
||||
@payment_order.save && @payment_order.reload
|
||||
|
@ -31,7 +24,7 @@ class Registrar
|
|||
end
|
||||
|
||||
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)
|
||||
|
||||
if @payment_order.payment_received?
|
||||
|
@ -51,7 +44,7 @@ class Registrar
|
|||
end
|
||||
|
||||
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)
|
||||
|
||||
if @payment_order.payment_received?
|
||||
|
@ -68,13 +61,11 @@ class Registrar
|
|||
def check_supported_payment_method
|
||||
return if supported_payment_method?
|
||||
|
||||
raise StandardError.new('Not supported payment method')
|
||||
raise(StandardError, 'Not supported payment method')
|
||||
end
|
||||
|
||||
def supported_payment_method?
|
||||
puts "Payment method param is #{params[:bank]}"
|
||||
# PaymentOrder::PAYMENT_METHODS.include?(params[:bank])
|
||||
true
|
||||
PaymentOrder.supported_method?(params[:bank])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,14 +25,14 @@ class PaymentOrder < ApplicationRecord
|
|||
errors.add(:invoice, 'is already paid')
|
||||
end
|
||||
|
||||
def self.supported_method?(some_class)
|
||||
raise ArgumentError unless some_class < PaymentOrder
|
||||
def self.type_from_shortname(shortname)
|
||||
('PaymentOrders::' + shortname.camelize).constantize
|
||||
end
|
||||
|
||||
if PAYMENT_METHODS.include?(some_class.name)
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
def self.supported_method?(some_class)
|
||||
supported_methods.include? type_from_shortname(some_class)
|
||||
rescue NameError
|
||||
false
|
||||
end
|
||||
|
||||
def complete_transaction(transaction)
|
||||
|
@ -52,16 +52,16 @@ class PaymentOrder < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.supported_methods
|
||||
enabled = []
|
||||
supported = []
|
||||
|
||||
ENABLED_METHODS.each do |method|
|
||||
class_name = method.constantize
|
||||
raise(Errors::ExpectedPaymentOrder, class_name) unless class_name < PaymentOrder
|
||||
PAYMENT_METHODS.each do |method|
|
||||
class_name = ('PaymentOrders::' + method.camelize).constantize
|
||||
raise(NoMethodError, class_name) unless class_name < PaymentOrder
|
||||
|
||||
enabled << class_name
|
||||
supported << class_name
|
||||
end
|
||||
|
||||
enabled
|
||||
supported
|
||||
end
|
||||
|
||||
def channel
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module PaymentOrders
|
||||
class LHV < BankLink
|
||||
class Lhv < BankLink
|
||||
def self.config_namespace_name
|
||||
'lhv'
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module PaymentOrders
|
||||
class SEB < BankLink
|
||||
class Seb < BankLink
|
||||
def self.config_namespace_name
|
||||
'seb'
|
||||
end
|
||||
|
|
|
@ -127,11 +127,11 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
get 'pay/return/:bank' => 'payments#back', as: 'return_payment_with'
|
||||
post 'pay/return/:bank' => 'payments#back'
|
||||
put 'pay/return/:bank' => 'payments#back'
|
||||
post 'pay/callback/:bank' => 'payments#callback', as: 'response_payment_with'
|
||||
get 'pay/go/:bank' => 'payments#pay', as: 'payment_with'
|
||||
get 'pay/return/:payment_order' => 'payments#back', as: 'return_payment_with'
|
||||
post 'pay/return/:payment_order' => 'payments#back'
|
||||
put 'pay/return/:payment_order' => 'payments#back'
|
||||
post 'pay/callback/:payment_order' => 'payments#callback', as: 'response_payment_with'
|
||||
get 'pay/go/:bank' => 'payments#pay', as: 'payment_with'
|
||||
|
||||
namespace :settings do
|
||||
resource :balance_auto_reload, controller: :balance_auto_reload, only: %i[edit update destroy]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue