Class: PagSeguro::Installment

Inherits:
Object
  • Object
show all
Includes:
Extensions::MassAssignment
Defined in:
lib/pagseguro/installment.rb,
lib/pagseguro/installment/response.rb,
lib/pagseguro/installment/serializer.rb

Defined Under Namespace

Classes: Response, Serializer

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Extensions::MassAssignment

#initialize

Instance Attribute Details

#amountObject

Set the amount. Must fit the patern: \d+.\d2 (e.g. “12.00”)



13
14
15
# File 'lib/pagseguro/installment.rb', line 13

def amount
  @amount
end

#card_brandObject

Set the credit card brand.



6
7
8
# File 'lib/pagseguro/installment.rb', line 6

def card_brand
  @card_brand
end

#interest_freeObject

Set interest free.



19
20
21
# File 'lib/pagseguro/installment.rb', line 19

def interest_free
  @interest_free
end

#quantityObject

Set the installments quantity.



9
10
11
# File 'lib/pagseguro/installment.rb', line 9

def quantity
  @quantity
end

#total_amountObject

Set total amount.



16
17
18
# File 'lib/pagseguro/installment.rb', line 16

def total_amount
  @total_amount
end

Class Method Details

.find(amount, card_brand = nil) ⇒ Object

Find installment options by a given amount Optional. Credit card brand Return an Array of PagSeguro::Installment instances



24
25
26
27
28
# File 'lib/pagseguro/installment.rb', line 24

def self.find(amount, card_brand = nil)
  string = "installments?amount=#{amount}"
  string += "&cardBrand=#{card_brand}" if card_brand
  load_from_response Request.get(string, 'v2')
end

.load_from_response(response) ⇒ Object

Serialize the HTTP response into data.



31
32
33
34
35
36
37
38
39
# File 'lib/pagseguro/installment.rb', line 31

def self.load_from_response(response) # :nodoc:
  if response.success? and response.xml?
    Nokogiri::XML(response.body).css("installments > installment").map do |node|
      load_from_xml(node)
    end
  else
    Response.new Errors.new(response)
  end
end

.load_from_xml(xml) ⇒ Object

Serialize the XML object.



42
43
44
# File 'lib/pagseguro/installment.rb', line 42

def self.load_from_xml(xml) # :nodoc:
  new Serializer.new(xml).serialize
end