Module: K2ProcessWebhook
- Defined in:
- lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb
Overview
Processes Webhook
Class 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.
Class Method Details
.check_topic(payload) ⇒ Object
8 9 10 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 38 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 8 def self.check_topic(payload) result_topic = payload.dig('topic') case result_topic # Buygoods Transaction Received when 'buygoods_transaction_received' buygoods_received = BuygoodsTransactionReceived.new(payload) return buygoods_received # Buygoods Transaction Reversed when 'buygoods_transaction_reversed' buygoods_reversed = BuygoodsTransactionReversed.new(payload) return buygoods_reversed # B2b Transaction when 'b2b_transaction_received' b2b_transaction = B2b.new(payload) return b2b_transaction # Merchant to Merchant when 'm2m_transaction_received' m2m_transaction_received = MerchantToMerchant.new(payload) return m2m_transaction_received # Settlement Transfer when 'settlement_transfer_completed' settlement_transfer = SettlementWebhook.new(payload) return settlement_transfer # Customer Created when 'customer_created' customer_created = CustomerCreated.new(payload) return customer_created else raise ArgumentError, 'No Other Specified Event!' end end |
.process(payload, secret_key, signature) ⇒ Object
3 4 5 6 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 3 def self.process(payload, secret_key, signature) raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank? self.check_topic(payload) if K2Authenticator.authenticate(payload, secret_key, signature) end |
.return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object
49 50 51 52 53 54 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 49 def self.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
41 42 43 44 45 46 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb', line 41 def self.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 |