Sha256: 8d5cd7924a2160386a0a69a6e6378e3617e663d4ba6143c8a7849f3d3e288440

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 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 Bs2Api::Errors::RefundError, response.body.to_s unless response.success?

          response.body
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bs2_api-1.9.0 lib/bs2_api/refund/pix/create.rb
bs2_api-1.8.0 lib/bs2_api/refund/pix/create.rb
bs2_api-1.7.0 lib/bs2_api/refund/pix/create.rb
bs2_api-1.6.2 lib/bs2_api/refund/pix/create.rb
bs2_api-1.6.1 lib/bs2_api/refund/pix/create.rb
bs2_api-1.6.0 lib/bs2_api/refund/pix/create.rb
bs2_api-1.5.1 lib/bs2_api/refund/pix/create.rb
bs2_api-1.5.0 lib/bs2_api/refund/pix/create.rb
bs2_api-1.4.3 lib/bs2_api/refund/pix/create.rb