Class: Stripe::Customer

Inherits:
APIResource show all
Includes:
APIOperations::Create, APIOperations::Delete, APIOperations::List, APIOperations::Update
Defined in:
lib/stripe/customer.rb

Instance Attribute Summary

Attributes inherited from StripeObject

#api_key

Instance Method Summary collapse

Methods included from APIOperations::List

included

Methods included from APIOperations::Update

#save, #serialize_metadata, #serialize_params

Methods included from APIOperations::Delete

#delete

Methods included from APIOperations::Create

included

Methods inherited from APIResource

class_name, #refresh, retrieve, url, #url

Methods inherited from StripeObject

#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Method Details

#add_invoice_item(params, opts = {}) ⇒ Object



8
9
10
11
# File 'lib/stripe/customer.rb', line 8

def add_invoice_item(params, opts={})
  opts[:api_key] = @api_key
  InvoiceItem.create(params.merge(:customer => id), opts)
end

#cancel_subscription(params = {}, opts = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/stripe/customer.rb', line 34

def cancel_subscription(params={}, opts={})
  api_key, headers = Util.parse_opts(opts)
  response, api_key = Stripe.request(
    :delete, subscription_url, api_key || @api_key, params, headers)
  refresh_from({ :subscription => response }, api_key, true)
  subscription
end

#chargesObject



25
26
27
# File 'lib/stripe/customer.rb', line 25

def charges
  Charge.all({ :customer => id }, @api_key)
end

#create_subscription(params = {}, opts = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/stripe/customer.rb', line 50

def create_subscription(params={}, opts={})
  api_key, headers = Util.parse_opts(opts)
  response, api_key = Stripe.request(
    :post, subscriptions_url, api_key || @api_key, params, headers)
  refresh_from({ :subscription => response }, api_key, true)
  subscription
end

#create_upcoming_invoice(params = {}, opts = {}) ⇒ Object



29
30
31
32
# File 'lib/stripe/customer.rb', line 29

def create_upcoming_invoice(params={}, opts={})
  opts[:api_key] = @api_key
  Invoice.create(params.merge(:customer => id), opts)
end

#delete_discountObject



58
59
60
61
# File 'lib/stripe/customer.rb', line 58

def delete_discount
  Stripe.request(:delete, discount_url, @api_key)
  refresh_from({ :discount => nil }, api_key, true)
end

#invoice_itemsObject



17
18
19
# File 'lib/stripe/customer.rb', line 17

def invoice_items
  InvoiceItem.all({ :customer => id }, @api_key)
end

#invoicesObject



13
14
15
# File 'lib/stripe/customer.rb', line 13

def invoices
  Invoice.all({ :customer => id }, @api_key)
end

#upcoming_invoiceObject



21
22
23
# File 'lib/stripe/customer.rb', line 21

def upcoming_invoice
  Invoice.upcoming({ :customer => id }, @api_key)
end

#update_subscription(params = {}, opts = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/stripe/customer.rb', line 42

def update_subscription(params={}, opts={})
  api_key, headers = Util.parse_opts(opts)
  response, api_key = Stripe.request(
    :post, subscription_url, api_key  || @api_key, params, headers)
  refresh_from({ :subscription => response }, api_key, true)
  subscription
end