Sha256: b4e6b80a1a97af843edd55227a783d219de64090b9f2d36b145de9c39659f272

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

module Bs2Api
  module Payment
    class Confirmation < Base
      attr_reader :success

      def initialize(
        payment,
        value: nil,
        client_id: Bs2Api.configuration.client_id,
        client_secret: Bs2Api.configuration.client_secret,
        proxy: 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
        @client_id = client_id
        @client_secret = client_secret
        @proxy = proxy
      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

6 entries across 6 versions & 1 rubygems

Version Path
bs2_api-1.9.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.8.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.7.0 lib/bs2_api/payment/confirmation.rb
bs2_api-1.6.2 lib/bs2_api/payment/confirmation.rb
bs2_api-1.6.1 lib/bs2_api/payment/confirmation.rb
bs2_api-1.6.0 lib/bs2_api/payment/confirmation.rb