Sha256: 7e4efd481a12cda5b2b170fe1d5ce04e7c7c664cd6be2dcb780aaff8c8024d88

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

class SettlementWebhook < K2CommonEvents
  attr_reader :disbursements,
              :destination_type,
              :destination_network,
              :destination_reference,
              :destination_last_name,
              :destination_first_name,
              :destination_account_name,
              :destination_phone_number,
              :destination_account_number,
              :destination_bank_branch_ref,
              :destination_settlement_method

  def initialize(payload)
    super
    # Destination
    @disbursements = payload.dig('event', 'resource', 'disbursements')
    @destination_type = payload.dig('event', 'resource', 'destination', 'type')
    @destination_reference = payload.dig('event', 'resource', 'destination', 'resource', 'reference')
    destination_assets(payload)
  end

  def destination_assets(payload)
    if @destination_type.eql?('Mobile Wallet')
      @destination_network = payload.dig('event', 'resource', 'destination', 'resource', 'network')
      @destination_last_name = payload.dig('event', 'resource', 'destination', 'resource', 'last_name')
      @destination_first_name = payload.dig('event', 'resource', 'destination', 'resource', 'first_name')
      @destination_phone_number = payload.dig('event', 'resource', 'destination', 'resource', 'phone_number')
    elsif @destination_type.eql?('Bank Account')
      @destination_account_name = payload.dig('event', 'resource', 'destination', 'resource', 'account_name')
      @destination_account_number = payload.dig('event', 'resource', 'destination', 'resource', 'account_number')
      @destination_bank_branch_ref = payload.dig('event', 'resource', 'destination', 'resource', 'bank_branch_ref')
      @destination_settlement_method = payload.dig('event', 'resource', 'destination', 'resource', 'settlement_method')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
k2-connect-ruby-2.0.0 lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb
k2-connect-ruby-1.0.0 lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb
k2-connect-ruby-0.0.3 lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb
k2-connect-ruby-0.0.2 lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb
k2-connect-ruby-0.0.1 lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb