class PagSeguro::SubscriptionSearchPaymentOrders

Attributes

code[R]
errors[R]
options[R]
page[R]
status[R]

Public Class Methods

new(code, status, options={}) click to toggle source
# 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

Public Instance Methods

created_at() click to toggle source

The report’s creation date.

# 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!() click to toggle source

Move the page pointer to the next page.

# File lib/pagseguro/subscription_search_payment_orders.rb, line 59
def next_page!
  return unless next_page?
  @page += 1
  clear!
end
next_page?() click to toggle source

Detect if the report has a next page.

# File lib/pagseguro/subscription_search_payment_orders.rb, line 49
def next_page?
  page.zero? || page < total_pages
end
payment_orders() click to toggle source

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

# 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!() click to toggle source

Move the page pointer to the previous page.

# File lib/pagseguro/subscription_search_payment_orders.rb, line 66
def previous_page!
  return unless previous_page?
  @page -= 1
  clear!
end
previous_page?() click to toggle source

Detect if the report has a previous page.

# File lib/pagseguro/subscription_search_payment_orders.rb, line 54
def previous_page?
  page > 1
end
results() click to toggle source

How many results the report returned on the given page.

# 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_pages() click to toggle source

How many pages the report returned.

# 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?() click to toggle source

Detect if the report request returned errors.

# File lib/pagseguro/subscription_search_payment_orders.rb, line 73
def valid?
  fetch { errors.empty? }
end

Private Instance Methods

api_version() click to toggle source

The default PagSeguro API version

# File lib/pagseguro/subscription_search_payment_orders.rb, line 102
def api_version
  :v2
end
clear!() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 114
def clear!
  @fetched = false
end
fetch(&block) click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 118
def fetch(&block)
  unless fetched?
    perform_request_and_serialize
    fetched!
  end

  instance_eval(&block)
end
fetched!() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 110
def fetched!
  @fetched = true
end
fetched?() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 106
def fetched?
  @fetched
end
header() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 87
def header
  { "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }
end
params() click to toggle source

The params that will be sent

# File lib/pagseguro/subscription_search_payment_orders.rb, line 92
def params
  {}.tap do |param|
    param[:status] = SubscriptionPaymentOrder::STATUSES[status.to_sym]
    param[:page] = page
    param[:maxPageResults] = options[:per_page]
    param[:credentials] = options[:credentials]
  end
end
path() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 83
def path
  PagSeguro.api_url "pre-approvals/#{code}/payment-orders"
end
perform_request_and_serialize() click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 78
def perform_request_and_serialize
  @response = Request.get_without_api_version(path, params, header)
  @errors = Errors.new(@response)
end
xml(&block) click to toggle source
# File lib/pagseguro/subscription_search_payment_orders.rb, line 127
def xml(&block)
  valid? && block.call(@response.data)
end