Class: GoCardless::Bill

Inherits:
Resource show all
Defined in:
lib/gocardless/bill.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #uri

Instance Method Summary collapse

Methods inherited from Resource

creatable, creatable?, date_accessor, date_writer, find, find_with_client, #initialize, #inspect, new_with_client, #persisted?, reference_accessor, reference_reader, reference_writer, #to_hash, #to_json, updatable, updatable?

Constructor Details

This class inherits a constructor from GoCardless::Resource

Instance Attribute Details

#amount ⇒ Object

Returns the value of attribute amount.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def amount
  @amount
end

#description ⇒ Object

Returns the value of attribute description.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def description
  @description
end

#name ⇒ Object

Returns the value of attribute name.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def name
  @name
end

#plan_id ⇒ Object

Returns the value of attribute plan_id.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def plan_id
  @plan_id
end

#source_id ⇒ String

Returns the ID of the bill's source (eg subscription, pre_authorization).

Returns:

  • (String) —

    the ID of the bill's source (eg subscription, pre_authorization)



16
17
18
# File 'lib/gocardless/bill.rb', line 16

def source_id
  @source_id
end

#source_type ⇒ Object

Returns the value of attribute source_type.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def source_type
  @source_type
end

#status ⇒ Object

Returns the value of attribute status.



7
8
9
# File 'lib/gocardless/bill.rb', line 7

def status
  @status
end

Instance Method Details

#save ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gocardless/bill.rb', line 36

def save
  save_data({
    :bill => {
      :pre_authorization_id => self.source_id,
      :amount => self.amount,
      :name => self.name,
      :description => self.description,
    }
  })
  self
end

#source ⇒ Object



21
22
23
24
# File 'lib/gocardless/bill.rb', line 21

def source
  klass = GoCardless.const_get(Utils.camelize(source_type.to_s))
  klass.find_with_client(client, @source_id)
end

#source=(obj) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gocardless/bill.rb', line 26

def source=(obj)
  klass = obj.class.to_s.split(':').last
  if !%w{Subscription PreAuthorization}.include?(klass)
    raise ArgumentError, ("Object must be an instance of Subscription or "
                          "PreAuthorization")
  end
  @source_id = obj.id
  @source_type = Utils.underscore(klass)
end