Move payment method fetching logic to Model, rewrite tests for EveryPay component

This commit is contained in:
Karl Erik Õunapuu 2020-02-03 19:57:52 +02:00
parent fa1687baf0
commit b6469f3dfe
10 changed files with 139 additions and 77 deletions

View file

@ -29,6 +29,12 @@ class PaymentOrder < ApplicationRecord
supported
end
def self.create_with_type(type:, invoice:)
channel = PaymentOrder.type_from_shortname(type)
PaymentOrder.new(type: channel, invoice: invoice)
end
# Name of configuration namespace
def self.config_namespace_name; end
@ -67,11 +73,11 @@ class PaymentOrder < ApplicationRecord
end
def complete_transaction
return NoMethodError unless payment_received?
paid!
transaction = composed_transaction
transaction.save!
transaction.bind_invoice(invoice.number)
transaction.save! && transaction.bind_invoice(invoice.number)
return unless transaction.errors.any?
worded_errors = 'Failed to bind. '

View file

@ -76,6 +76,8 @@ module PaymentOrders
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']
rescue NoMethodError
false
end
def valid_amount?