mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Fix some codeclimate issues
This commit is contained in:
parent
b578cdcfa8
commit
33a6971c37
4 changed files with 17 additions and 19 deletions
|
@ -8,15 +8,16 @@ class Registrar
|
|||
|
||||
def pay
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
bank = params[:bank]
|
||||
opts = {
|
||||
return_url: self.registrar_return_payment_with_url(
|
||||
params[:bank], invoice_id: invoice.id
|
||||
return_url: registrar_return_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
),
|
||||
response_url: self.registrar_response_payment_with_url(
|
||||
params[:bank], invoice_id: invoice.id
|
||||
response_url: registrar_response_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
)
|
||||
}
|
||||
@payment = ::Payments.create_with_type(params[:bank], invoice, opts)
|
||||
@payment = ::Payments.create_with_type(bank, invoice, opts)
|
||||
@payment.create_transaction
|
||||
end
|
||||
|
||||
|
@ -53,9 +54,8 @@ class Registrar
|
|||
private
|
||||
|
||||
def check_supported_payment_method
|
||||
unless supported_payment_method?
|
||||
raise StandardError.new("Not supported payment method")
|
||||
end
|
||||
return if supported_payment_method?
|
||||
raise StandardError.new("Not supported payment method")
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ module Payments
|
|||
PAYMENT_METHODS = [PAYMENT_INTERMEDIARIES, PAYMENT_BANKLINK_BANKS].flatten.freeze
|
||||
|
||||
def self.create_with_type(type, invoice, opts = {})
|
||||
fail ArgumentError unless PAYMENT_METHODS.include?(type)
|
||||
raise ArgumentError unless PAYMENT_METHODS.include?(type)
|
||||
|
||||
if PAYMENT_BANKLINK_BANKS.include?(type)
|
||||
BankLink.new(type, invoice, opts)
|
||||
|
|
|
@ -75,10 +75,7 @@ module Payments
|
|||
private
|
||||
|
||||
def valid_successful_transaction?
|
||||
return false unless valid_success_notice?
|
||||
return false unless valid_amount?
|
||||
return false unless valid_currency?
|
||||
true
|
||||
valid_success_notice? && valid_amount? && valid_currency?
|
||||
end
|
||||
|
||||
def valid_cancel_notice?
|
||||
|
@ -113,12 +110,12 @@ module Payments
|
|||
|
||||
def calc_mac(fields)
|
||||
pars = NEW_MESSAGE_KEYS
|
||||
data = pars.map { |e| prepend_size(fields[e]) }.join
|
||||
data = pars.map { |element| prepend_size(fields[element]) }.join
|
||||
sign(data)
|
||||
end
|
||||
|
||||
def valid_mac?(hash, keys)
|
||||
data = keys.map { |e| prepend_size(hash[e]) }.join
|
||||
data = keys.map { |element| prepend_size(hash[element]) }.join
|
||||
verify_mac(data, hash["VK_MAC"])
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Payments
|
|||
|
||||
# Not all requests require use of hmac_fields, add only when needed
|
||||
base_json[:hmac_fields] = hmac_fields.join(',')
|
||||
hmac_string = hmac_fields.map { |k, _v| "#{k}=#{base_json[k]}" }.join('&')
|
||||
hmac_string = hmac_fields.map { |key, _v| "#{key}=#{base_json[key]}" }.join('&')
|
||||
hmac = OpenSSL::HMAC.hexdigest('sha1', KEY, hmac_string)
|
||||
base_json[:hmac] = hmac
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Payments
|
|||
)
|
||||
|
||||
transaction.sum = response[:amount]
|
||||
transaction.paid_at = DateTime.strptime(response[:timestamp], '%s')
|
||||
transaction.paid_at = Date.strptime(response[:timestamp], '%s')
|
||||
transaction.buyer_name = response[:cc_holder_name]
|
||||
|
||||
transaction.save!
|
||||
|
@ -65,10 +65,11 @@ module Payments
|
|||
hmac_fields = response[:hmac_fields].split(',')
|
||||
hmac_hash = {}
|
||||
hmac_fields.map do |field|
|
||||
hmac_hash[field.to_sym] = response[field.to_sym]
|
||||
symbol = field.to_sym
|
||||
hmac_hash[symbol] = response[symbol]
|
||||
end
|
||||
|
||||
hmac_string = hmac_hash.map { |k, _v| "#{k}=#{hmac_hash[k]}" }.join('&')
|
||||
hmac_string = hmac_hash.map { |key, _v| "#{key}=#{hmac_hash[key]}" }.join('&')
|
||||
expected_hmac = OpenSSL::HMAC.hexdigest('sha1', KEY, hmac_string)
|
||||
expected_hmac == response[:hmac]
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue