Refactor EveryPay / Banklink processing

This commit is contained in:
Karl Erik Õunapuu 2020-01-30 21:01:15 +02:00
parent cb76a9f962
commit 32d4fc3c83
5 changed files with 55 additions and 28 deletions

View file

@ -48,10 +48,17 @@ module PaymentOrders
end
end
def complete_transaction
return unless valid_response_from_intermediary? && settled_payment?
def payment_received?
valid_response_from_intermediary? && settled_payment?
end
self.status = 'paid'
def create_failure_report
notes = "User failed to make valid payment. Bank responded with code #{response['VK_SERVICE']}"
status = 'cancelled'
update!(notes: notes, status: status)
end
def composed_transaction
transaction = BankTransaction.where(description: invoice.order).first_or_initialize(
description: invoice.order,
reference_no: invoice.reference_no,
@ -66,8 +73,7 @@ module PaymentOrders
transaction.buyer_name = response['VK_SND_NAME']
transaction.paid_at = Time.parse(response['VK_T_DATETIME'])
transaction.save!
transaction.autobind_invoice(invoice_no: invoice.number)
transaction
end
def settled_payment?

View file

@ -34,11 +34,12 @@ module PaymentOrders
SUCCESSFUL_PAYMENT.include?(response['payment_state'])
end
def complete_transaction
return unless valid_response_from_intermediary? && settled_payment?
self.status = 'paid'
def payment_received?
valid_response_from_intermediary? && settled_payment?
end
transaction = BankTransaction.where(description: invoice.order).first_or_initialize(
def composed_transaction
transaction = BankTransaction.new(
description: invoice.order,
reference_no: invoice.reference_no,
currency: invoice.currency,
@ -49,8 +50,13 @@ module PaymentOrders
transaction.paid_at = Date.strptime(response['timestamp'], '%s')
transaction.buyer_name = response['cc_holder_name']
transaction.save!
transaction.autobind_invoice(invoice_no: invoice.number)
transaction
end
def create_failure_report
notes = "User failed to make valid payment. Payment state: #{response['payment_state']}"
status = 'cancelled'
update!(notes: notes, status: status)
end
def base_params
@ -80,6 +86,8 @@ module PaymentOrders
end
def valid_amount?
return false unless response.key? 'amount'
invoice.total == BigDecimal(response['amount'])
end