Class: FreeAgent::CreditNotesResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/credit_notes.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from FreeAgent::Resource

Instance Method Details

#create(contact:, dated_on:, payment_terms_in_days: 0, **params) ⇒ Object



29
30
31
32
33
34
# File 'lib/free_agent/resources/credit_notes.rb', line 29

def create(contact:, dated_on:, payment_terms_in_days: 0, **params)
  attributes = { contact: contact, dated_on: dated_on, payment_terms_in_days: payment_terms_in_days }

  response = post_request("credit_notes", body: { credit_note: attributes.merge(params) })
  CreditNote.new(response.body["credit_note"]) if response.success?
end

#delete(id:) ⇒ Object



46
47
48
49
# File 'lib/free_agent/resources/credit_notes.rb', line 46

def delete(id:)
  response = delete_request("credit_notes/#{id}")
  response.success?
end

#email(id:, to:, **params) ⇒ Object



51
52
53
54
55
# File 'lib/free_agent/resources/credit_notes.rb', line 51

def email(id:, to:, **params)
  attributes = { to: to }
  response = post_request("credit_notes/#{id}/send_email", body: { credit_note: { email: attributes.merge(params) } })
  response.success?
end

#list(**params) ⇒ Object



3
4
5
6
# File 'lib/free_agent/resources/credit_notes.rb', line 3

def list(**params)
  response = get_request("credit_notes", params: params)
  Collection.from_response(response, type: CreditNote)
end

#list_for_contact(contact:, **params) ⇒ Object



8
9
10
11
# File 'lib/free_agent/resources/credit_notes.rb', line 8

def list_for_contact(contact:, **params)
  response = get_request("credit_notes?contact=#{contact}", params: params)
  Collection.from_response(response, type: CreditNote)
end

#list_for_project(project:, **params) ⇒ Object



13
14
15
16
# File 'lib/free_agent/resources/credit_notes.rb', line 13

def list_for_project(project:, **params)
  response = get_request("credit_notes?project=#{project}", params: params)
  Collection.from_response(response, type: CreditNote)
end

#mark_as_cancelled(id:) ⇒ Object



67
68
69
70
# File 'lib/free_agent/resources/credit_notes.rb', line 67

def mark_as_cancelled(id:)
  response = put_request("credit_notes/#{id}/transitions/mark_as_cancelled", body: {})
  response.success?
end

#mark_as_draft(id:) ⇒ Object



62
63
64
65
# File 'lib/free_agent/resources/credit_notes.rb', line 62

def mark_as_draft(id:)
  response = put_request("credit_notes/#{id}/transitions/mark_as_draft", body: {})
  response.success?
end

#mark_as_sent(id:) ⇒ Object



57
58
59
60
# File 'lib/free_agent/resources/credit_notes.rb', line 57

def mark_as_sent(id:)
  response = put_request("credit_notes/#{id}/transitions/mark_as_sent", body: {})
  response.success?
end

#retrieve(id:) ⇒ Object



18
19
20
21
# File 'lib/free_agent/resources/credit_notes.rb', line 18

def retrieve(id:)
  response = get_request("credit_notes/#{id}")
  CreditNote.new(response.body["credit_note"])
end

#retrieve_pdf(id:) ⇒ Object

Returns a Base64-encoded PDF



24
25
26
27
# File 'lib/free_agent/resources/credit_notes.rb', line 24

def retrieve_pdf(id:)
  response = get_request("credit_notes/#{id}/pdf")
  response.body["pdf"]["content"] if response.success?
end

#update(id:, **params) ⇒ Object

def duplicate(id:)

response = post_request("invoices/#{id}/duplicate", body: {})
Invoice.new(response.body["invoice"]) if response.success?

end



41
42
43
44
# File 'lib/free_agent/resources/credit_notes.rb', line 41

def update(id:, **params)
  response = put_request("credit_notes/#{id}", body: { credit_note: params })
  CreditNote.new(response.body["credit_note"]) if response.success?
end