Module: K2ConnectRuby::K2Utilities::K2ProcessResult

Extended by:
K2ProcessResult
Included in:
K2ProcessResult
Defined in:
lib/k2-connect-ruby/k2_utilities/k2_process_result.rb

Instance Method Summary collapse

Instance Method Details

#check_type(payload) ⇒ Object

Check the Event Type.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 15

def check_type(payload)
  result_type = payload.dig("data", "type")
  case result_type
    # Incoming Payments
  when "incoming_payment"
    K2ConnectRuby::K2Services::Payloads::Transactions::IncomingPayment.new(payload)
  when "send_money"
    K2ConnectRuby::K2Services::Payloads::Transactions::SendMoneyPayment.new(payload)
  when "reversal"
    K2ConnectRuby::K2Services::Payloads::Transactions::Reversal.new(payload)
  when "payment_link"
    K2ConnectRuby::K2Services::Payloads::Transactions::PaymentLink.new(payload)
  else
    raise ArgumentError, "No Other Specified Payment Type!"
  end
end

#process(payload, secret_key, signature) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 8

def process(payload, secret_key, signature)
  raise ArgumentError, "Empty/Nil Request Body Argument!" if payload.blank?

  check_type(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature)
end

#return_obj_array(obj, instance_array = []) ⇒ Object

Returns an Array Object



41
42
43
44
45
46
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 41

def return_obj_array(obj, instance_array = [])
  obj.instance_variables.each do |value|
    instance_array << obj.instance_variable_get(value)
  end
  instance_array.each(&:freeze).freeze
end

#return_obj_hash(obj, instance_hash = HashWithIndifferentAccess.new) ⇒ Object

Returns a Hash Object



33
34
35
36
37
38
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 33

def return_obj_hash(obj, instance_hash = HashWithIndifferentAccess.new)
  obj.instance_variables.each do |value|
    instance_hash[:"#{value.to_s.tr('@', '')}"] = obj.instance_variable_get(value)
  end
  instance_hash.each(&:freeze).freeze
end