Class: Quickeebooks::Online::Service::Payment

Inherits:
ServiceBase
  • Object
show all
Defined in:
lib/quickeebooks/online/service/payment.rb

Constant Summary

Constants inherited from ServiceBase

ServiceBase::QB_BASE_URI, ServiceBase::XML_NS

Instance Attribute Summary

Attributes inherited from ServiceBase

#base_uri, #oauth, #realm_id

Instance Method Summary collapse

Methods inherited from ServiceBase

#access_token=, #base_url=, #initialize, #login_name, #url_for_base, #url_for_resource

Constructor Details

This class inherits a constructor from Quickeebooks::Online::Service::ServiceBase

Instance Method Details

#create(payment) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/quickeebooks/online/service/payment.rb', line 16

def create(payment)
  raise InvalidModelException unless payment.valid?
  xml = payment.to_xml_ns
  response = do_http_post(url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular), valid_xml_document(xml))
  if response.code.to_i == 200
    Quickeebooks::Online::Model::Payment.from_xml(response.body)
  else
    nil
  end
end

#delete(payment) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/quickeebooks/online/service/payment.rb', line 53

def delete(payment)
  raise InvalidModelException.new("Missing required parameters for delete") unless payment.valid_for_deletion?
  xml = valid_xml_document(payment.to_xml_ns(:fields => ['Id', 'SyncToken']))
  url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{payment.id}"
  response = do_http_post(url, xml, {:methodx => "delete"})
  response.code.to_i == 200
end

#fetch_by_id(id) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/quickeebooks/online/service/payment.rb', line 27

def fetch_by_id(id)
  url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{id}"
  response = do_http_get(url)
  if response && response.code.to_i == 200
    Quickeebooks::Online::Model::Payment.from_xml(response.body)
  else
    nil
  end
end

#list(filters = [], page = 1, per_page = 20, sort = nil, options = {}) ⇒ Object



49
50
51
# File 'lib/quickeebooks/online/service/payment.rb', line 49

def list(filters = [], page = 1, per_page = 20, sort = nil, options = {})
  fetch_collection(Quickeebooks::Online::Model::Payment, filters, page, per_page, sort, options)
end

#update(payment) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/quickeebooks/online/service/payment.rb', line 37

def update(payment)
  raise InvalidModelException.new("Missing required parameters for update") unless payment.valid_for_update?
  url = "#{url_for_resource(Quickeebooks::Online::Model::Payment.resource_for_singular)}/#{payment.id}"
  xml = payment.to_xml_ns
  response = do_http_post(url, valid_xml_document(xml))
  if response.code.to_i == 200
    Quickeebooks::Online::Model::Payment.from_xml(response.body)
  else
    nil
  end
end