Class: Bs2Api::Entities::AsyncResponse

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

Overview

After we send async payment request via calling Bs2Api::Payment::Async#call the API is expected to return array of JSON objects describing each payment this class is used to wrap those JSON objects identificator is optional and is for internal purposes it won’t be sent via the webhook when the payment confirmation is done. request_id is the id of the payment which the bank will send via webhook

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ AsyncResponse

Returns a new instance of AsyncResponse.



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

def initialize(args = {})
  @identificator = args.fetch(:identificator, '')
  @pix_key = args[:pix_key]
  @value = args[:value]
  @error = args[:error]
  @request_id = args[:request_id]
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



12
13
14
# File 'lib/bs2_api/entities/async_response.rb', line 12

def error
  @error
end

#identificatorObject

Returns the value of attribute identificator.



12
13
14
# File 'lib/bs2_api/entities/async_response.rb', line 12

def identificator
  @identificator
end

#pix_keyObject

Returns the value of attribute pix_key.



12
13
14
# File 'lib/bs2_api/entities/async_response.rb', line 12

def pix_key
  @pix_key
end

#request_idObject

Returns the value of attribute request_id.



12
13
14
# File 'lib/bs2_api/entities/async_response.rb', line 12

def request_id
  @request_id
end

#valueObject

Returns the value of attribute value.



12
13
14
# File 'lib/bs2_api/entities/async_response.rb', line 12

def value
  @value
end

Class Method Details

.from_response(input_hash) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bs2_api/entities/async_response.rb', line 15

def from_response(input_hash)
  pix_key = PixKey.new(
    key: input_hash['chave']['valor'],
    type: input_hash['chave']['tipo']
  )
  AsyncResponse.new(
    identificator: input_hash['identificador'],
    pix_key: pix_key,
    value: input_hash['valor'],
    error: input_hash['erros'],
    request_id: input_hash['solicitacaoId']
  )
end