Sha256: 5392d2f77a76b855e684a6192deb68fd2000bab7b4c8bccf18b69cce23dc5d12

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Akatus

  module Services

    class Installments < Akatus::Service

      PATH   = 'parcelamento/simulacao'
      METHOD = :get

      def self.calculate(payment)
        self.new.calculate(payment)
      end

      def calculate(payment)

        @payment = payment

        unless payment.payment_method.is_a?(CreditCard)
          return InstallmentOptions.blank(payment)
        end

        data = send_request

        options = InstallmentOptions.new

        options.description        = data['descricao']
        options.taken_installments = data['parcelas_assumidas']

        options.installments = data['parcelas'].map do |parcela|
          Installment.new({
            :quantity       => parcela['quantidade'],
            :unitary_amount => BigDecimal.new(parcela['valor']),
            :total_amount   => BigDecimal.new(parcela['total'])
          })
        end

        options

      end

      def to_payload
        {
          :email          => @payment.receiver.email,
          :amount         => @payment.total_amount,
          :payment_method => @payment.payment_method.brand,
          :api_key        => @payment.receiver.api_key
        }
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
akatus-1.0.2 lib/akatus/services/installments.rb
akatus-1.0.1 lib/akatus/services/installments.rb
akatus-1.0.0 lib/akatus/services/installments.rb