Class: PagSeguro::SubscriptionSearchPaymentOrders

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/subscription_search_payment_orders.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, status, options = {}) ⇒ SubscriptionSearchPaymentOrders

Returns a new instance of SubscriptionSearchPaymentOrders.



9
10
11
12
13
14
15
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 9

def initialize(code, status, options={})
  @code = code
  @status = status
  @options = options
  @page = options.delete(:page) || 0
  @errors = Errors.new
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 3

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 4

def options
  @options
end

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 7

def page
  @page
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 5

def status
  @status
end

Instance Method Details

#created_atObject

The report’s creation date.



28
29
30
31
32
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 28

def created_at
  xml do |xml|
    @created_at ||= Time.parse xml.css("paymentOrdersResult > date").text
  end
end

#next_page!Object

Move the page pointer to the next page.



59
60
61
62
63
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 59

def next_page!
  return unless next_page?
  @page += 1
  clear!
end

#next_page?Boolean

Detect if the report has a next page.

Returns:

  • (Boolean)


49
50
51
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 49

def next_page?
  page.zero? || page < total_pages
end

#payment_ordersObject

Return the list of subscription payment orders. Each item will be wrapped in a PagSeguro::SubscriptionPaymentOrder instance.



19
20
21
22
23
24
25
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 19

def payment_orders
  xml do |xml|
    xml.css("paymentOrdersResult > paymentOrders > paymentOrder").map do |node|
      SubscriptionPaymentOrder.load_from_xml(node)
    end
  end
end

#previous_page!Object

Move the page pointer to the previous page.



66
67
68
69
70
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 66

def previous_page!
  return unless previous_page?
  @page -= 1
  clear!
end

#previous_page?Boolean

Detect if the report has a previous page.

Returns:

  • (Boolean)


54
55
56
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 54

def previous_page?
  page > 1
end

#resultsObject

How many results the report returned on the given page.



35
36
37
38
39
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 35

def results
  xml do |xml|
    @results = xml.css("paymentOrdersResult > resultsInThisPage").text.to_i
  end
end

#total_pagesObject

How many pages the report returned.



42
43
44
45
46
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 42

def total_pages
  xml do |xml|
    @total_pages ||= xml.css("paymentOrdersResult > totalPages").text.to_i
  end
end

#valid?Boolean

Detect if the report request returned errors.

Returns:

  • (Boolean)


73
74
75
# File 'lib/pagseguro/subscription_search_payment_orders.rb', line 73

def valid?
  fetch { errors.empty? }
end