Class: Bs2Api::Refund::Pix::Detail

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/refund/pix/detail.rb

Constant Summary collapse

STATUSES =
{
  'EM_PROCESSAMENTO' => :processing,
  'DEVOLVIDO' => :refunded,
  'NAO_REALIZADO' => :not_achieved,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, end_to_end_id:, transaction_id:, proxy: nil) ⇒ Detail

Returns a new instance of Detail.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bs2_api/refund/pix/detail.rb', line 11

def initialize(
  client_id:,
  client_secret:,
  end_to_end_id:,
  transaction_id:,
  proxy: nil
)
  @client_id = client_id
  @client_secret = client_secret
  @end_to_end_id = end_to_end_id
  @transaction_id = transaction_id
  @proxy = proxy
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bs2_api/refund/pix/detail.rb', line 26

def call
  url = "#{Bs2Api.endpoint}/pix/direto/forintegration/v1/pix/#{@end_to_end_id}/devolucao/#{@transaction_id}"

  access_token = Bs2Api::Request::Auth.token(
    client_id: @client_id,
    client_secret: @client_secret
  )

  response = HTTParty.get(
    url,
    http_proxyaddr: @proxy&.host,
    http_proxyport: @proxy&.port,
    http_proxyuser: @proxy&.user,
    http_proxypass: @proxy&.password,
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
      'Authorization' => "Bearer #{access_token}",
    }
  )

  raise response.body unless response.success?

  JSON.parse(response.body)
end

#statusObject



52
53
54
# File 'lib/bs2_api/refund/pix/detail.rb', line 52

def status
  @status ||= STATUSES.fetch(call.fetch('status'))
end