Module: K2ConnectRuby::K2Utilities::K2ProcessWebhook
- Extended by:
- K2ProcessWebhook
- Included in:
- K2ProcessWebhook
- Defined in:
- lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb
Instance Method Summary collapse
- #check_topic(payload) ⇒ Object
- #process(payload, secret_key, signature) ⇒ Object
-
#return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object.
-
#return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) ⇒ Object
Returns a Hash Object.
Instance Method Details
#check_topic(payload) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 11 def check_topic(payload) result_topic = payload.dig('topic') case result_topic # Buygoods Transaction Received when 'buygoods_transaction_received' buygoods_received = K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReceived.new(payload) return buygoods_received # Buygoods Transaction Reversed when 'buygoods_transaction_reversed' buygoods_reversed = K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReversed.new(payload) return buygoods_reversed # B2b Transaction when 'b2b_transaction_received' b2b_transaction = K2ConnectRuby::K2Services::Payloads::Webhooks::B2bTransactionReceived.new(payload) return b2b_transaction # Settlement Transfer when 'settlement_transfer_completed' settlement_transfer = K2ConnectRuby::K2Services::Payloads::Webhooks::SettlementWebhook.new(payload) return settlement_transfer # Customer Created when 'customer_created' customer_created = K2ConnectRuby::K2Services::Payloads::Webhooks::CustomerCreated.new(payload) return customer_created else raise ArgumentError, 'No Other Specified Event!' end end |
#process(payload, secret_key, signature) ⇒ Object
6 7 8 9 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 6 def process(payload, secret_key, signature) raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank? check_topic(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature) end |
#return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object
48 49 50 51 52 53 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 48 def return_obj_array(instance_array = [], obj) obj.instance_variables.each do |value| instance_array << obj.instance_variable_get(value) end instance_array.each(&:freeze).freeze end |
#return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) ⇒ Object
Returns a Hash Object
40 41 42 43 44 45 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 40 def return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) obj.instance_variables.each do |value| instance_hash[:"#{value.to_s.tr('@', '')}"] = obj.instance_variable_get(value) end instance_hash.each(&:freeze).freeze end |