Sha256: 181911e00a90d6b53342afccb8420326a6e2ea09ee5e277dd4a61a584e3da467

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Bs2Api
  module Refund
    module Pix
      class Create
        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

        # https://devs.bs2.com/manual/pix-clientes/#tag/Devolucoes-Cliente/paths/~1pix~1direto~1forintegration~1v1~1pix~1{e2eid}~1devolucao~1{idExterno}/put
        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 response.body unless response.success?

          response.body
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bs2_api-1.4.2 lib/bs2_api/refund/pix/create.rb