Sha256: d16834b95284bbd04019b7e6716c9bf64758e283563d57d36bb25c6824faa797

Contents?: true

Size: 997 Bytes

Versions: 4

Compression:

Stored size: 997 Bytes

Contents

module Bs2Api
  module Payment
    class Confirmation < Base
      attr_reader :success

      def initialize payment, value: nil
        raise Bs2Api::Errors::ConfirmationError, 'invalid payment' unless payment.present? && payment.is_a?(Bs2Api::Entities::Payment)
        raise Bs2Api::Errors::ConfirmationError, 'invalid value' unless value.to_f.positive?
        @payment = payment

        @value = value.to_f
      end

      def call
        response = post_request
        raise Bs2Api::Errors::ConfirmationError, parse_error(response) unless response.accepted?

        @success = true
        self
      end

      private
        def payload
          @payment.to_hash
                  .except!("pagamentoId", "endToEndId")
                  .merge("valor": @value)
        end
        
        def url
          "#{Bs2Api.endpoint}/pix/direto/forintegration/v1/pagamentos/#{@payment.id}/confirmacao"
        end

        def success?
          !!@success
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bs2_api-0.3.3 lib/bs2_api/payment/confirmation.rb
bs2_api-0.3.2 lib/bs2_api/payment/confirmation.rb
bs2_api-0.3.1 lib/bs2_api/payment/confirmation.rb
bs2_api-0.3.0 lib/bs2_api/payment/confirmation.rb