class Akatus::Services::Installments

Constants

METHOD
PATH

Public Class Methods

calculate(payment) click to toggle source
# File lib/akatus/services/installments.rb, line 10
def self.calculate(payment)
  self.new.calculate(payment)
end

Public Instance Methods

calculate(payment) click to toggle source
# File lib/akatus/services/installments.rb, line 14
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
to_payload() click to toggle source
# File lib/akatus/services/installments.rb, line 41
def to_payload
  {
    :email          => @payment.receiver.email,
    :amount         => @payment.total_amount,
    :payment_method => @payment.payment_method.brand,
    :api_key        => @payment.receiver.api_key
  }
end