Sha256: 2d8ed2fdb846297228b12d8b7da889822949032edc982440b63d515345a3f49b

Contents?: true

Size: 809 Bytes

Versions: 12

Compression:

Stored size: 809 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'
      }.freeze

      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

12 entries across 12 versions & 1 rubygems

Version Path
bs2_api-1.9.0 lib/bs2_api/entities/pix_key.rb
bs2_api-1.8.0 lib/bs2_api/entities/pix_key.rb
bs2_api-1.7.0 lib/bs2_api/entities/pix_key.rb
bs2_api-1.6.2 lib/bs2_api/entities/pix_key.rb
bs2_api-1.6.1 lib/bs2_api/entities/pix_key.rb
bs2_api-1.6.0 lib/bs2_api/entities/pix_key.rb
bs2_api-1.5.1 lib/bs2_api/entities/pix_key.rb
bs2_api-1.5.0 lib/bs2_api/entities/pix_key.rb
bs2_api-1.4.3 lib/bs2_api/entities/pix_key.rb
bs2_api-1.4.2 lib/bs2_api/entities/pix_key.rb
bs2_api-1.4.1 lib/bs2_api/entities/pix_key.rb
bs2_api-1.4.0 lib/bs2_api/entities/pix_key.rb