Class: Akatus::Services::PaymentOptions
- Inherits:
-
Akatus::Service
- Object
- Akatus::Service
- Akatus::Services::PaymentOptions
- Defined in:
- lib/akatus/services/payment_options.rb
Constant Summary collapse
- PATH =
'meios-de-pagamento'
- METHOD =
:post
Class Method Summary collapse
Instance Method Summary collapse
- #available ⇒ Object
- #available_with_installments(transaction) ⇒ Object
- #payment_description_to_type(group) ⇒ Object
- #payment_type_to_class(type) ⇒ Object
- #to_payload ⇒ Object
Methods inherited from Akatus::Service
Class Method Details
.available ⇒ Object
12 13 14 |
# File 'lib/akatus/services/payment_options.rb', line 12 def self.available self.new.available end |
.available_with_installments(*args) ⇒ Object
16 17 18 |
# File 'lib/akatus/services/payment_options.rb', line 16 def self.available_with_installments(*args) self.new.available_with_installments(*args) end |
Instance Method Details
#available ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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']) = 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 => } end result end |
#available_with_installments(transaction) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
61 62 63 64 65 66 67 68 |
# 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) ⇒ Object
70 71 72 73 74 75 76 77 |
# 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 |