Class: Bs2Api::Pix::Detail

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Detail.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bs2_api/pix/detail.rb', line 4

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

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bs2_api/pix/detail.rb', line 20

def call
  url = "#{Bs2Api.endpoint}/pix/direto/forintegration/v1/recebimentos/#{@end_to_end_id}/recebimento"
  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}",
    },
    query: {
      Inicio: @time_range.begin.iso8601,
      Fim: @time_range.end.iso8601,
      TxId: @transaction_id,
    }
  )

  raise response.body unless response.success?

  response.body
end