Class: Moip::Invoice

Inherits:
Model
  • Object
show all
Includes:
HTTParty, Header
Defined in:
lib/moip/models/invoice.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Header

#auth, #base_url, #default_header

Methods inherited from Model

build, #set_parameters, #to_json, #validate_response

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def amount
  @amount
end

#creation_dateObject

Returns the value of attribute creation_date.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def creation_date
  @creation_date
end

#customerObject

Returns the value of attribute customer.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def customer
  @customer
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def id
  @id
end

#itemsObject

Returns the value of attribute items.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def items
  @items
end

#occurrenceObject

Returns the value of attribute occurrence.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def occurrence
  @occurrence
end

#planObject

Returns the value of attribute plan.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def plan
  @plan
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def status
  @status
end

#subscription_codeObject

Returns the value of attribute subscription_code.



6
7
8
# File 'lib/moip/models/invoice.rb', line 6

def subscription_code
  @subscription_code
end

Class Method Details

.retry(id) ⇒ Object



66
67
68
# File 'lib/moip/models/invoice.rb', line 66

def self.retry id
	response = self.class.post(base_url(:payments, :code => id, :status => "retry"), default_header).parsed_response
end

Instance Method Details

#attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/moip/models/invoice.rb', line 9

def attributes
	{
		"id" => id,
		"amount" => amount,
		"subscription_code" => subscription_code,
		"occurrence" => occurrence,
		"status" => status,
		"items" => items,
		"plan" => plan,
		"customer" => customer,
		"creation_date" => creation_date
	}
end

#findObject



53
54
55
56
# File 'lib/moip/models/invoice.rb', line 53

def find
	response = self.class.get(base_url(:invoices, :code => self.id), default_header).parsed_response
	self.set_parameters response unless response.nil?
end

#full_statusObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/moip/models/invoice.rb', line 33

def full_status
	status = case self.status['code']
		when 1 then "Em aberto" # A fatura foi gerada mas ainda não foi paga pelo assinante.
		when 2 then "Aguardando Confirmação" # A fatura foi paga pelo assinante, mas o pagamento está em processo de análise de risco.
		when 3 then "Pago" # A fatura foi paga pelo assinante e confirmada.
		when 4 then "Não Pago" # O assinante tentou pagar a fatura, mas o pagamento foi negado pelo banco emissor do cartão de crédito ou a análise de risco detectou algum problema. Veja os motivos possíveis.
		when 5 then "Atrasada" # O pagamento da fatura foi cancelado e serão feitas novas tentativas de cobrança de acordo com a configuração de retentativa automática.
	end
	status
end

#invoicesObject



44
45
46
# File 'lib/moip/models/invoice.rb', line 44

def invoices
	@invoices ||= self.invoices=(self.load)
end

#invoices=(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/moip/models/invoice.rb', line 23

def invoices= hash
	@invoices = []
	hash.each do |e|
		invoice = Moip::Invoice.new
		invoice.set_parameters e
		@invoices << invoice
	end
	@invoices
end

#loadObject



48
49
50
51
# File 'lib/moip/models/invoice.rb', line 48

def load
	list = self.class.get(base_url(:subscriptions, :code => self.subscription_code, :status => "invoices"), default_header).parsed_response
	self.invoices = list["invoices"]
end

#paymentsObject



58
59
60
# File 'lib/moip/models/invoice.rb', line 58

def payments
	@payments ||= Moip::Payment.build(:invoice => self.id).payments
end

#retryObject



62
63
64
# File 'lib/moip/models/invoice.rb', line 62

def retry
	response = self.class.post(base_url(:invoices, :code => self.id, :status => "retry"), default_header).parsed_response
end