Skip to content

Commit

Permalink
Fix some codeclimate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Szlosarczyk committed Apr 23, 2018
1 parent b578cdc commit 144cef3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
14 changes: 7 additions & 7 deletions app/controllers/registrar/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class PaymentsController < BaseController

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)
Expand Down Expand Up @@ -53,9 +54,8 @@ def callback
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


Expand Down
2 changes: 1 addition & 1 deletion app/models/payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions app/models/payments/bank_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def settled_payment?
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?
Expand Down Expand Up @@ -113,12 +110,12 @@ def sign(data)

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

Expand Down
6 changes: 3 additions & 3 deletions app/models/payments/every_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def form_fields

# 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

Expand All @@ -38,7 +38,7 @@ def complete_transaction
)

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!
Expand Down Expand Up @@ -68,7 +68,7 @@ def valid_hmac?
hmac_hash[field.to_sym] = response[field.to_sym]
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
Expand Down

0 comments on commit 144cef3

Please sign in to comment.