Sha256: 24d64458f7ca8d8f875281a52356bc194fe5aad22f1c317bdb86fa36b694e033

Contents?: true

Size: 1016 Bytes

Versions: 20

Compression:

Stored size: 1016 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, ::Util::Response.parse_error(response) unless response.accepted?

        @success = true
        self
      end

      def success?
        !!@success
      end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
bs2_api-1.5.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.4.3 lib/bs2_api/payment/confirmation.rb
bs2_api-1.4.2 lib/bs2_api/payment/confirmation.rb
bs2_api-1.4.1 lib/bs2_api/payment/confirmation.rb
bs2_api-1.4.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.2.2 lib/bs2_api/payment/confirmation.rb
bs2_api-1.2.1 lib/bs2_api/payment/confirmation.rb
bs2_api-1.2.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.7 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.6 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.5 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.4 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.3 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.2 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.1 lib/bs2_api/payment/confirmation.rb
bs2_api-1.1.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.0.3 lib/bs2_api/payment/confirmation.rb
bs2_api-1.0.2 lib/bs2_api/payment/confirmation.rb
bs2_api-1.0.1 lib/bs2_api/payment/confirmation.rb
bs2_api-1.0.0 lib/bs2_api/payment/confirmation.rb