Class: KillBillClient::Model::Account

Inherits:
AccountAttributesWithBalance 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



7
8
9
10
11
12
13
14
# File 'lib/killbill_client/models/account.rb', line 7

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/killbill_client/models/account.rb', line 45

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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/killbill_client/models/account.rb', line 17

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

#payments(options = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/killbill_client/models/account.rb', line 29

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/killbill_client/models/account.rb', line 68

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



36
37
38
39
40
41
42
43
# File 'lib/killbill_client/models/account.rb', line 36

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