Sha256: c1ac03e51c5bc3ced0a6a6cf3a072659d08d2b052960147577b1384cb3536ef3

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 KB

Contents

module Bs2Api
  module Refund
    module Pix
      class Detail
        STATUSES = {
          'EM_PROCESSAMENTO' => :processing,
          'DEVOLVIDO' => :refunded,
          'NAO_REALIZADO' => :not_achieved,
        }.transform_keys(&:downcase).freeze

        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

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

          response.body
        end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bs2_api-1.6.1 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.6.0 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.5.1 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.5.0 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.4.3 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.4.2 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.4.1 lib/bs2_api/refund/pix/detail.rb
bs2_api-1.4.0 lib/bs2_api/refund/pix/detail.rb