Sha256: 130b32334cf645a88b9887917d1b189ae7a04687f94773f0626e826d33cb9113

Contents?: true

Size: 1.36 KB

Versions: 27

Compression:

Stored size: 1.36 KB

Contents

module MangoPay
  module FilterParameters

    def self.request(body)
      begin
        body = JSON.load(body)
      rescue MultiJson::LoadError => e
        return body
      end
      filter_hash(body, req_confidential_params)
      JSON.dump(body)
    end

    def self.response(body)
      return '' if body.to_s.empty?

      begin
        body = JSON.load(body)
      rescue MultiJson::LoadError => e
        return body
      end
      filter_hash(body, res_confidential_params)
      JSON.dump(body)
    end

    private

    def self.filter_hash(hash, to_filter)
      hash.each do |k,v|
        if v.is_a?(Hash)
          filter_hash(v, to_filter)
        else
          hash[k] = '[FILTERED]' if to_filter.include?(k)
        end
      end
    end

    def self.res_confidential_params
      @@res_confidential_params ||= [
        'access_token', 'AccessKey', 'IBAN', 'CardRegistrationURL',
        'PreregistrationData', 'RedirectURL', 'RegistrationData',
        'SecureModeRedirectUrl', 'OwnerName', 'OwnerAddress', 'BIC',
        'FirstName', 'LastName', 'Email', 'AddressLine1',
        'AddressLine2',
      ].freeze
    end

    def self.req_confidential_params
      @@req_confidential_params ||= [
        'File', 'IBAN', 'OwnerName', 'OwnerAddress', 'BIC', 'FirstName',
        'LastName', 'Email', 'AddressLine1', 'AddressLine2',
      ].freeze
    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mangopay-3.28.0 lib/mangopay/filter_parameters.rb
mangopay-3.27.0 lib/mangopay/filter_parameters.rb
mangopay-3.26.1 lib/mangopay/filter_parameters.rb
mangopay-3.26.0 lib/mangopay/filter_parameters.rb
mangopay-3.25.1 lib/mangopay/filter_parameters.rb
mangopay-3.25.0 lib/mangopay/filter_parameters.rb
mangopay-3.24.1 lib/mangopay/filter_parameters.rb
mangopay-3.24.0 lib/mangopay/filter_parameters.rb
mangopay-3.23.0 lib/mangopay/filter_parameters.rb
mangopay-3.22.0 lib/mangopay/filter_parameters.rb
mangopay-3.21.0 lib/mangopay/filter_parameters.rb
mangopay-3.20.0 lib/mangopay/filter_parameters.rb
mangopay-3.19.0 lib/mangopay/filter_parameters.rb
mangopay-3.18.0 lib/mangopay/filter_parameters.rb
mangopay-3.17.0 lib/mangopay/filter_parameters.rb
mangopay-3.16.0 lib/mangopay/filter_parameters.rb
mangopay-3.15.0 lib/mangopay/filter_parameters.rb
mangopay-3.14.0 lib/mangopay/filter_parameters.rb
mangopay-3.13.2 lib/mangopay/filter_parameters.rb
mangopay-3.12.0 lib/mangopay/filter_parameters.rb