Class: Paggi::Payment

Inherits:
Resource show all
Includes:
Rest::GetAll
Defined in:
lib/paggi/payment.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#created, #errors, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rest::GetAll

#get_all, included

Methods inherited from Resource

build, class_name, opts, request, url, #valid?

Constructor Details

#initialize(attributes = {}) ⇒ Payment

Returns a new instance of Payment.



34
35
36
# File 'lib/paggi/payment.rb', line 34

def initialize(attributes = {})
  super(attributes)
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def amount
  @amount
end

#amount_rawObject

Returns the value of attribute amount_raw.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def amount_raw
  @amount_raw
end

#compensated_atObject

Returns the value of attribute compensated_at.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def compensated_at
  @compensated_at
end

#expected_compensationObject

Returns the value of attribute expected_compensation.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def expected_compensation
  @expected_compensation
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def status
  @status
end

#totalObject

Returns the value of attribute total.



5
6
7
# File 'lib/paggi/payment.rb', line 5

def total
  @total
end

Class Method Details

.all(params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/paggi/payment.rb', line 20

def all(params = {})
  url = params[:customer].nil? ? '' : "#{params[:customer]}/"
  parameters = []
  parameters << "start_date=#{params[:start_date].to_s(:db)}" if params[:start_date]
  parameters << "end_date=#{params[:end_date].to_s(:db)}" if params[:end_date]
  parameters << "page=#{params[:page]}" if params[:page]
  parameters << "page_size=#{params[:page_size]}" if params[:page_size]
  url += "?#{parameters.join('&')}" if parameters.length
  result = request(url, {}, :GET, {})
  raise result if result.kind_of? StandardError
  result
end

.consolidated(customer = nil, start_date = nil, end_date = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/paggi/payment.rb', line 8

def consolidated(customer = nil, start_date = nil, end_date = nil)
  url = customer.nil? ? '' : "#{customer}/"
  url += 'consolidated'
  params = []
  params << "start_date=#{start_date.strftime('%Y-%m-%d %H:%M:%S')}" if start_date
  params << "end_date=#{end_date.strftime('%Y-%m-%d %H:%M:%S')}" if end_date
  url += "?#{params.join('&')}" if params.length
  result = request(url, {}, :GET, {})
  raise result if result.kind_of? StandardError
  result.total
end

Instance Method Details

#to_jsonObject



38
39
40
41
42
43
44
45
46
# File 'lib/paggi/payment.rb', line 38

def to_json
  super.merge!(super([
    :status,
    :expected_compensation,
    :compensated_at,
    :amount,
    :amount_raw,
  ]))
end