Class: Bs2Api::Entities::AsyncRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/entities/async_request.rb

Overview

Used by Bs2Api::Payment::Async. This class stores PIX key, user defined identificador for the key and the value to be transfered. Bs2Api::Payment::Async sends a bucket of AsyncRequest and in the response we get a list of passed payments. The identificador can be used to keep track of the transactino in the response.

Constant Summary collapse

ALLOWED_PIX_KEY_TYPES =
%w[
  CPF
  CNPJ
  EMAIL
  EVP
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ AsyncRequest

Returns a new instance of AsyncRequest.



22
23
24
25
26
27
28
# File 'lib/bs2_api/entities/async_request.rb', line 22

def initialize(args = {})
  @pix_key = args[:pix_key]
  raise Errors::InvalidPixKey unless ALLOWED_PIX_KEY_TYPES.include? @pix_key.type

  @identificator = args.fetch(:identificator)
  @value = args[:value]
end

Instance Attribute Details

#identificatorObject

Returns the value of attribute identificator.



13
14
15
# File 'lib/bs2_api/entities/async_request.rb', line 13

def identificator
  @identificator
end

#pix_keyObject

Returns the value of attribute pix_key.



13
14
15
# File 'lib/bs2_api/entities/async_request.rb', line 13

def pix_key
  @pix_key
end

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/bs2_api/entities/async_request.rb', line 13

def value
  @value
end

Instance Method Details

#to_hashObject



30
31
32
33
34
35
36
37
38
# File 'lib/bs2_api/entities/async_request.rb', line 30

def to_hash
  ActiveSupport::HashWithIndifferentAccess.new(
    {
      identificador: @identificator,
      chave: @pix_key.to_hash,
      valor: @value
    }
  )
end

#to_jsonObject



40
41
42
# File 'lib/bs2_api/entities/async_request.rb', line 40

def to_json(*)
  to_hash.to_json
end