Sha256: 99b54cf5d15b470800ad4423c8a4b83930b30e8863d3404c320a8f1480eb5504

Contents?: true

Size: 802 Bytes

Versions: 3

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true

module Bs2Api
  module Entities
    class PixKey
      attr_accessor :key, :type

      TYPES = {
        cpf: 'CPF',
        cnpj: 'CNPJ',
        phone: 'PHONE',
        email: 'EMAIL',
        random: 'EVP'
      }

      def initialize(args = {})
        @key = args.fetch(:key, nil)
        @type = args.fetch(:type, 'CPF')
      end

      def to_hash
        ActiveSupport::HashWithIndifferentAccess.new(
          {
            "valor": @key,
            "tipo": @type
          }
        )
      end

      def self.from_response(hash_payload)
        hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
        
        Bs2Api::Entities::PixKey.new(
          key: hash["valor"],
          type: hash["tipo"]
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bs2_api-1.2.2 lib/bs2_api/entities/pix_key.rb
bs2_api-1.2.1 lib/bs2_api/entities/pix_key.rb
bs2_api-1.2.0 lib/bs2_api/entities/pix_key.rb