Class: KillBillClient::Model::Account

Inherits:
AccountAttributes show all
Defined in:
lib/killbill_client/models/account.rb

Constant Summary collapse

KILLBILL_API_ACCOUNTS_PREFIX =
"#{KILLBILL_API_PREFIX}/accounts"

Constants inherited from Resource

Resource::KILLBILL_API_PREFIX

Instance Attribute Summary

Attributes inherited from Resource

#etag, #response, #session_id, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attribute, create_alias, delete, extract_session_id, from_json, from_response, get, has_many, has_one, head, instantiate_record_from_json, post, put, #refresh, #to_hash, #to_json

Class Method Details

.find_by_id(account_id, with_balance = false, with_balance_and_cba = false, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/killbill_client/models/account.rb', line 10

def find_by_id(, with_balance = false, with_balance_and_cba = false, options = {})
  get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}",
      {
          :accountWithBalance => with_balance,
          :accountWithBalanceAndCBA => with_balance_and_cba
      },
      options
end

Instance Method Details

#add_tag(tag_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/killbill_client/models/account.rb', line 64

def add_tag(tag_name, user = nil, reason = nil, comment = nil, options = {})
  tag_definition = TagDefinition.find_by_name(tag_name)
  if tag_definition.nil?
    tag_definition = TagDefinition.new
    tag_definition.name = tag_name
    tag_definition.description = "Tag created for account #{@account_id}"
    tag_definition = TagDefinition.create(user, options)
  end

  created_tag = self.class.post "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/tags",
                                {},
                                {
                                    :tagList => tag_definition.id
                                },
                                {
                                    :user => user,
                                    :reason => reason,
                                    :comment => comment,
                                }.merge(options),
                                Tag
  created_tag.refresh(options)
end

#create(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/killbill_client/models/account.rb', line 20

def create(user = nil, reason = nil, comment = nil, options = {})
   = self.class.post KILLBILL_API_ACCOUNTS_PREFIX,
                                    to_json,
                                    {},
                                    {
                                        :user => user,
                                        :reason => reason,
                                        :comment => comment,
                                    }.merge(options)
  .refresh(options)
end

#invoices(with_items = false, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/killbill_client/models/account.rb', line 32

def invoices(with_items=false, options = {})
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/invoices",
                 {
                     :withItems => with_items
                 },
                 options,
                 Invoice
end

#overdue(options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/killbill_client/models/account.rb', line 48

def overdue(options = {})
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/overdue",
                 {},
                 options,
                 OverdueStateAttributes
end

#payments(options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/killbill_client/models/account.rb', line 41

def payments(options = {})
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
                 {},
                 options,
                 Payment
end

#remove_tag(tag_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/killbill_client/models/account.rb', line 87

def remove_tag(tag_name, user = nil, reason = nil, comment = nil, options = {})
  tag_definition = TagDefinition.find_by_name(tag_name)
  return nil if tag_definition.nil?

  self.class.delete "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/tags",
                    {
                        :tagList => tag_definition.id
                    },
                    {
                        :user => user,
                        :reason => reason,
                        :comment => comment,
                    }.merge(options)
end

#tags(audit = 'NONE', options = {}) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/killbill_client/models/account.rb', line 55

def tags(audit = 'NONE', options = {})
  self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/tags",
                 {
                     :audit => audit
                 },
                 options,
                 Tag
end