Class: Bs2Api::Refund::Pix::Create

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Create.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bs2_api/refund/pix/create.rb', line 7

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

Instance Method Details

#callObject



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
49
50
51
# File 'lib/bs2_api/refund/pix/create.rb', line 24

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.put(
    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}",
    },
    body: {
      valor: @value
    }.to_json
  )

  raise Bs2Api::Errors::RefundError, response.body.to_s unless response.success?

  response.body
end