class Akatus::Services::PaymentOptions
Constants
- METHOD
- PATH
Public Class Methods
available()
click to toggle source
# File lib/akatus/services/payment_options.rb, line 12 def self.available self.new.available end
available_with_installments(*args)
click to toggle source
# File lib/akatus/services/payment_options.rb, line 16 def self.available_with_installments(*args) self.new.available_with_installments(*args) end
Public Instance Methods
available()
click to toggle source
# File lib/akatus/services/payment_options.rb, line 20 def available data = send_request result = {} data['meios_de_pagamento'].each do |payment_type| key = payment_description_to_type(payment_type['descricao']) options = payment_type['bandeiras'].map do |payment_option| PaymentOption.new({ :code => payment_option['codigo'], :description => payment_option['descricao'], :installments => payment_option['parcelas'] }) end result[key] = { :name => payment_type['descricao'], :options => options } end result end
available_with_installments(transaction)
click to toggle source
# File lib/akatus/services/payment_options.rb, line 46 def available_with_installments(transaction) result = available() result.each do |type, group| group[:options].each do |option| transaction.payment_method = payment_type_to_class(type).new({ :brand => option.code }) option.installments = Installments.calculate(transaction) end end result end
payment_description_to_type(group)
click to toggle source
# File lib/akatus/services/payment_options.rb, line 61 def payment_description_to_type(group) case group when 'Boleto Bancário' then :boleto when 'Cartão de Crédito' then :credit_card when 'TEF' then :eft else raise "Unknown payment group: #{group}" end end
payment_type_to_class(type)
click to toggle source
# File lib/akatus/services/payment_options.rb, line 70 def payment_type_to_class(type) case type when :boleto then Akatus::BoletoBancario when :credit_card then Akatus::CreditCard when :eft then Akatus::ElectronicFundsTransfer else raise "Unknown payment group: #{group}" end end
to_payload()
click to toggle source
# File lib/akatus/services/payment_options.rb, line 80 def to_payload { :meios_de_pagamento => { :correntista => { :email => Akatus.config.email, :api_key => Akatus.config.api_key } } } end