Class: Bs2Api::Entities::AsyncStatus

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

Overview

Used with Bs2Api::Payment::Async. When we call Bs2Api::Payment::Async#call we expect to get data for each item in the bucket via webhook. If we don’t get webhooks in a few seconds (roughly about 10s) we should start polling the status of the payment by calling # Bs2Api::Payment::Async::check_payment_status. The following # class is used to wrap the result of Bs2Api::Payment::Async::check_payment_status

Constant Summary collapse

STATUS =
{
  'Realizado' => :awaiting_validation,
  'Iniciado' => :in_process,
  'Confirmado' => :confirmed,
  'Rejeitado' => :rejected,
  'Erro' => :error
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ AsyncStatus

Returns a new instance of AsyncStatus.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bs2_api/entities/async_status.rb', line 46

def initialize(args = {})
  @request_id = args[:request_id]
  @payment_id = args[:payment_id]
  @end_to_end_id = args[:end_to_end_id]
  @status = args[:status]
  @agency = args[:agency]
  @number = args[:number]
  @pix_key = args[:pix_key]
  @value = args[:value]
  @free_field = args[:free_field]
  @rejection_description = args[:rejection_description]
  @error_description = args[:error_description]
end

Instance Attribute Details

#agencyObject

Returns the value of attribute agency.



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

def agency
  @agency
end

#end_to_end_idObject

Returns the value of attribute end_to_end_id.



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

def end_to_end_id
  @end_to_end_id
end

#error_descriptionObject

Returns the value of attribute error_description.



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

def error_description
  @error_description
end

#free_fieldObject

Returns the value of attribute free_field.



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

def free_field
  @free_field
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#payment_idObject

Returns the value of attribute payment_id.



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

def payment_id
  @payment_id
end

#pix_keyObject

Returns the value of attribute pix_key.



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

def pix_key
  @pix_key
end

#rejection_descriptionObject

Returns the value of attribute rejection_description.



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

def rejection_description
  @rejection_description
end

#request_idObject

Returns the value of attribute request_id.



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

def request_id
  @request_id
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.from_response(hash) ⇒ Object

Parses the has from the response body of Bs2Api::Payment::Async::check_payment_status @param The response body as a hash with string keys



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bs2_api/entities/async_status.rb', line 21

def from_response(hash)
  new(
    request_id: hash['solicitacaoId'],
    payment_id: hash['pagamentoId'],
    end_to_end_id: hash['endToEndId'],
    status: STATUS[hash['status']],
    agency: hash['agencia'],
    number: hash['numero'],
    pix_key: Bs2Api::Entities::PixKey.from_response(hash['chave']),
    value: hash['valor'],
    free_field: hash['campoLivre'],
    rejection_description: hash['rejeitadoDescricao'],
    error_description: hash['erroDescricao']
  )
end

Instance Method Details

#awaiting_validation?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/bs2_api/entities/async_status.rb', line 72

def awaiting_validation?
  @status == :awaiting_validation
end

#confirmed?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bs2_api/entities/async_status.rb', line 64

def confirmed?
  @status == :confirmed
end

#error?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/bs2_api/entities/async_status.rb', line 68

def error?
  @status == :error
end

#in_process?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/bs2_api/entities/async_status.rb', line 76

def in_process?
  @status == :in_process
end

#rejected?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bs2_api/entities/async_status.rb', line 60

def rejected?
  @status == :rejected
end