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

#amountObject

Returns the value of attribute amount


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

def amount
  @amount
end

#amount_minus_feesObject

Returns the value of attribute amount_minus_fees


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

def amount_minus_fees
  @amount_minus_fees
end

#can_be_cancelledObject Also known as: can_be_cancelled?

Returns the value of attribute can_be_cancelled


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

def can_be_cancelled
  @can_be_cancelled
end

#can_be_retriedObject Also known as: can_be_retried?

Returns the value of attribute can_be_retried


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

def can_be_retried
  @can_be_retried
end

#currencyObject

Returns the value of attribute currency


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

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description


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

def description
  @description
end

#gocardless_feesObject

Returns the value of attribute gocardless_fees


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

def gocardless_fees
  @gocardless_fees
end

#is_setup_feeObject Also known as: is_setup_fee?

Returns the value of attribute is_setup_fee


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

def is_setup_fee
  @is_setup_fee
end

#nameObject

Returns the value of attribute name


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

def name
  @name
end

#partner_feesObject

Returns the value of attribute partner_fees


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

def partner_fees
  @partner_fees
end

#source_idString


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

def source_id
  @source_id
end

#source_typeObject

Returns the value of attribute source_type


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

def source_type
  @source_type
end

#statusObject

Returns the value of attribute status


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

def status
  @status
end

Instance Method Details

#cancel!Object


52
53
54
55
# File 'lib/gocardless/bill.rb', line 52

def cancel!
  path = self.class.endpoint.gsub(':id', id.to_s) + '/cancel'
  client.api_put(path)
end

#failed?Boolean


89
90
91
# File 'lib/gocardless/bill.rb', line 89

def failed?
  status == 'failed'
end

#paid?Boolean


85
86
87
# File 'lib/gocardless/bill.rb', line 85

def paid?
  status == 'paid'
end

#pending?Boolean


81
82
83
# File 'lib/gocardless/bill.rb', line 81

def pending?
  status == 'pending'
end

#refund!Object

The ability to refund a payment is disabled by default.

Please contact [email protected] if you require access to the refunds API endpoint.


61
62
63
64
# File 'lib/gocardless/bill.rb', line 61

def refund!
  path = self.class.endpoint.gsub(':id', id.to_s) + '/refund'
  client.api_post(path)
end

#refunded?Boolean


97
98
99
# File 'lib/gocardless/bill.rb', line 97

def refunded?
  status == 'refunded'
end

#retry!Object


47
48
49
50
# File 'lib/gocardless/bill.rb', line 47

def retry!
  path = self.class.endpoint.gsub(':id', id.to_s) + '/retry'
  client.api_post(path)
end

#saveObject


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gocardless/bill.rb', line 66

def save
  bill_params = {
    :pre_authorization_id => self.source_id,
    :amount => self.amount,
    :name => self.name,
    :description => self.description,
    :charge_customer_at => self.charge_customer_at,
  }

  bill_params.delete_if { |_,v| v.nil? }

  save_data({ :bill => bill_params })
  self
end

#sourceObject


32
33
34
35
# File 'lib/gocardless/bill.rb', line 32

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

#source=(obj) ⇒ Object


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

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

#withdrawn?Boolean


93
94
95
# File 'lib/gocardless/bill.rb', line 93

def withdrawn?
  status == 'withdrawn'
end