Class: Stripe::Customer

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::NestedResource, APIOperations::Search
Includes:
APIOperations::Delete, APIOperations::Save
Defined in:
lib/stripe/resources/customer.rb

Overview

This object represents a customer of your business. Use it to [create recurring charges](stripe.com/docs/invoicing/customer), [save payment](stripe.com/docs/payments/save-during-payment) and contact information, and track payments that belong to the same customer.

Defined Under Namespace

Classes: Address, InvoiceSettings, Shipping, Tax, TestHelpers

Constant Summary collapse

OBJECT_NAME =
"customer"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::NestedResource

nested_resource_class_methods

Methods included from APIOperations::Search

_search

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

included

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #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 Attribute Details

#addressObject (readonly)

The customer’s address.



54
55
56
# File 'lib/stripe/resources/customer.rb', line 54

def address
  @address
end

#balanceObject (readonly)

The current balance, if any, that’s stored on the customer. If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that’s added to their next invoice. The balance only considers amounts that Stripe hasn’t successfully applied to any invoice. It doesn’t reflect unpaid invoices. This balance is only taken into account after invoices finalize.



56
57
58
# File 'lib/stripe/resources/customer.rb', line 56

def balance
  @balance
end

#cash_balanceObject (readonly)

The current funds being held by Stripe on behalf of the customer. You can apply these funds towards payment intents when the source is “cash_balance”. The ‘settings` field describes if these funds apply to these payment intents manually or automatically.



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

def cash_balance
  @cash_balance
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



60
61
62
# File 'lib/stripe/resources/customer.rb', line 60

def created
  @created
end

#currencyObject (readonly)

Three-letter [ISO code for the currency](stripe.com/docs/currencies) the customer can be charged in for recurring billing purposes.



62
63
64
# File 'lib/stripe/resources/customer.rb', line 62

def currency
  @currency
end

#default_sourceObject (readonly)

ID of the default payment source for the customer.

If you use payment methods created through the PaymentMethods API, see the [invoice_settings.default_payment_method](stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) field instead.



66
67
68
# File 'lib/stripe/resources/customer.rb', line 66

def default_source
  @default_source
end

#deletedObject (readonly)

Always true for a deleted object



116
117
118
# File 'lib/stripe/resources/customer.rb', line 116

def deleted
  @deleted
end

#delinquentObject (readonly)

Tracks the most recent state change on any invoice belonging to the customer. Paying an invoice or marking it uncollectible via the API will set this field to false. An automatic payment failure or passing the ‘invoice.due_date` will set this field to `true`.

If an invoice becomes uncollectible by [dunning](stripe.com/docs/billing/automatic-collection), ‘delinquent` doesn’t reset to ‘false`.

If you care whether the customer has paid their most recent subscription invoice, use ‘subscription.status` instead. Paying or marking uncollectible any customer invoice regardless of whether it is the latest invoice for a subscription will always set this field to `false`.



72
73
74
# File 'lib/stripe/resources/customer.rb', line 72

def delinquent
  @delinquent
end

#descriptionObject (readonly)

An arbitrary string attached to the object. Often useful for displaying to users.



74
75
76
# File 'lib/stripe/resources/customer.rb', line 74

def description
  @description
end

#discountObject (readonly)

Describes the current discount active on the customer, if there is one.



76
77
78
# File 'lib/stripe/resources/customer.rb', line 76

def discount
  @discount
end

#emailObject (readonly)

The customer’s email address.



78
79
80
# File 'lib/stripe/resources/customer.rb', line 78

def email
  @email
end

#idObject (readonly)

Unique identifier for the object.



80
81
82
# File 'lib/stripe/resources/customer.rb', line 80

def id
  @id
end

#invoice_credit_balanceObject (readonly)

The current multi-currency balances, if any, that’s stored on the customer. If positive in a currency, the customer has a credit to apply to their next invoice denominated in that currency. If negative, the customer has an amount owed that’s added to their next invoice denominated in that currency. These balances don’t apply to unpaid invoices. They solely track amounts that Stripe hasn’t successfully applied to any invoice. Stripe only applies a balance in a specific currency to an invoice after that invoice (which is in the same currency) finalizes.



82
83
84
# File 'lib/stripe/resources/customer.rb', line 82

def invoice_credit_balance
  @invoice_credit_balance
end

#invoice_prefixObject (readonly)

The prefix for the customer used to generate unique invoice numbers.



84
85
86
# File 'lib/stripe/resources/customer.rb', line 84

def invoice_prefix
  @invoice_prefix
end

#invoice_settingsObject (readonly)

Attribute for field invoice_settings



86
87
88
# File 'lib/stripe/resources/customer.rb', line 86

def invoice_settings
  @invoice_settings
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



88
89
90
# File 'lib/stripe/resources/customer.rb', line 88

def livemode
  @livemode
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



90
91
92
# File 'lib/stripe/resources/customer.rb', line 90

def 
  @metadata
end

#nameObject (readonly)

The customer’s full name or business name.



92
93
94
# File 'lib/stripe/resources/customer.rb', line 92

def name
  @name
end

#next_invoice_sequenceObject (readonly)

The suffix of the customer’s next invoice number (for example, 0001). When the account uses account level sequencing, this parameter is ignored in API requests and the field omitted in API responses.



94
95
96
# File 'lib/stripe/resources/customer.rb', line 94

def next_invoice_sequence
  @next_invoice_sequence
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



96
97
98
# File 'lib/stripe/resources/customer.rb', line 96

def object
  @object
end

#phoneObject (readonly)

The customer’s phone number.



98
99
100
# File 'lib/stripe/resources/customer.rb', line 98

def phone
  @phone
end

#preferred_localesObject (readonly)

The customer’s preferred locales (languages), ordered by preference.



100
101
102
# File 'lib/stripe/resources/customer.rb', line 100

def preferred_locales
  @preferred_locales
end

#shippingObject (readonly)

Mailing and shipping address for the customer. Appears on invoices emailed to this customer.



102
103
104
# File 'lib/stripe/resources/customer.rb', line 102

def shipping
  @shipping
end

#sourcesObject (readonly)

The customer’s payment sources, if any.



104
105
106
# File 'lib/stripe/resources/customer.rb', line 104

def sources
  @sources
end

#subscriptionsObject (readonly)

The customer’s current subscriptions, if any.



106
107
108
# File 'lib/stripe/resources/customer.rb', line 106

def subscriptions
  @subscriptions
end

#taxObject (readonly)

Attribute for field tax



108
109
110
# File 'lib/stripe/resources/customer.rb', line 108

def tax
  @tax
end

#tax_exemptObject (readonly)

Describes the customer’s tax exemption status, which is ‘none`, `exempt`, or `reverse`. When set to `reverse`, invoice and receipt PDFs include the following text: **“Reverse charge”**.



110
111
112
# File 'lib/stripe/resources/customer.rb', line 110

def tax_exempt
  @tax_exempt
end

#tax_idsObject (readonly)

The customer’s tax IDs.



112
113
114
# File 'lib/stripe/resources/customer.rb', line 112

def tax_ids
  @tax_ids
end

#test_clockObject (readonly)

ID of the test clock that this customer belongs to.



114
115
116
# File 'lib/stripe/resources/customer.rb', line 114

def test_clock
  @test_clock
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

Creates a new customer object.



119
120
121
# File 'lib/stripe/resources/customer.rb', line 119

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/customers", params: params, opts: opts)
end

.create_funding_instructions(customer, params = {}, opts = {}) ⇒ Object

Retrieve funding instructions for a customer cash balance. If funding instructions do not yet exist for the customer, new funding instructions will be created. If funding instructions have already been created for a given customer, the same funding instructions will be retrieved. In other words, we will return the same funding instructions each time.



138
139
140
141
142
143
144
145
# File 'lib/stripe/resources/customer.rb', line 138

def self.create_funding_instructions(customer, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/customers/%<customer>s/funding_instructions", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts
  )
end

.delete(id, params = {}, opts = {}) ⇒ Object

Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.



148
149
150
151
152
153
154
155
# File 'lib/stripe/resources/customer.rb', line 148

def self.delete(id, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/customers/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end

.delete_discount(customer, params = {}, opts = {}) ⇒ Object

Removes the currently applied discount on a customer.



178
179
180
181
182
183
184
185
# File 'lib/stripe/resources/customer.rb', line 178

def self.delete_discount(customer, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/customers/%<customer>s/discount", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts
  )
end

.list(filters = {}, opts = {}) ⇒ Object

Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.



188
189
190
# File 'lib/stripe/resources/customer.rb', line 188

def self.list(filters = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/customers", params: filters, opts: opts)
end

.list_payment_methods(customer, params = {}, opts = {}) ⇒ Object

Returns a list of PaymentMethods for a given Customer



203
204
205
206
207
208
209
210
# File 'lib/stripe/resources/customer.rb', line 203

def self.list_payment_methods(customer, params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/payment_methods", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts
  )
end

.object_nameObject



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

def self.object_name
  "customer"
end

.retrieve_cash_balance(customer, params = {}, opts = {}) ⇒ Object

Retrieves a customer’s cash balance.



213
214
215
216
217
218
219
220
# File 'lib/stripe/resources/customer.rb', line 213

def self.retrieve_cash_balance(customer, params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts
  )
end

.retrieve_payment_method(customer, payment_method, params = {}, opts = {}) ⇒ Object

Retrieves a PaymentMethod object for a given Customer.



233
234
235
236
237
238
239
240
# File 'lib/stripe/resources/customer.rb', line 233

def self.retrieve_payment_method(customer, payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/payment_methods/%<payment_method>s", { customer: CGI.escape(customer), payment_method: CGI.escape(payment_method) }),
    params: params,
    opts: opts
  )
end

.search(params = {}, opts = {}) ⇒ Object



242
243
244
# File 'lib/stripe/resources/customer.rb', line 242

def self.search(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/customers/search", params: params, opts: opts)
end

.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object



246
247
248
# File 'lib/stripe/resources/customer.rb', line 246

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
  search(params, opts).auto_paging_each(&blk)
end

.update(id, params = {}, opts = {}) ⇒ Object

Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged. For example, if you pass the source parameter, that becomes the customer’s active source (e.g., a card) to be used for all charges in the future. When you update a customer to a new valid card source by passing the source parameter: for each of the customer’s current subscriptions, if the subscription bills automatically and is in the past_due state, then the latest open invoice for the subscription with automatic collection enabled will be retried. This retry will not count as an automatic retry, and will not affect the next regularly scheduled payment for the invoice. Changing the default_source for a customer will not trigger this behavior.

This request accepts mostly the same arguments as the customer creation call.



253
254
255
256
257
258
259
260
# File 'lib/stripe/resources/customer.rb', line 253

def self.update(id, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/customers/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end

.update_cash_balance(customer, params = {}, opts = {}) ⇒ Object

Changes the settings on a customer’s cash balance.



263
264
265
266
267
268
269
270
# File 'lib/stripe/resources/customer.rb', line 263

def self.update_cash_balance(customer, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

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

Retrieve funding instructions for a customer cash balance. If funding instructions do not yet exist for the customer, new funding instructions will be created. If funding instructions have already been created for a given customer, the same funding instructions will be retrieved. In other words, we will return the same funding instructions each time.



126
127
128
129
130
131
132
133
# File 'lib/stripe/resources/customer.rb', line 126

def create_funding_instructions(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/customers/%<customer>s/funding_instructions", { customer: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

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

Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.



158
159
160
161
162
163
164
165
# File 'lib/stripe/resources/customer.rb', line 158

def delete(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/customers/%<customer>s", { customer: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

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

Removes the currently applied discount on a customer.



168
169
170
171
172
173
174
175
# File 'lib/stripe/resources/customer.rb', line 168

def delete_discount(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/customers/%<customer>s/discount", { customer: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

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

Returns a list of PaymentMethods for a given Customer



193
194
195
196
197
198
199
200
# File 'lib/stripe/resources/customer.rb', line 193

def list_payment_methods(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/payment_methods", { customer: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

#retrieve_payment_method(payment_method, params = {}, opts = {}) ⇒ Object

Retrieves a PaymentMethod object for a given Customer.



223
224
225
226
227
228
229
230
# File 'lib/stripe/resources/customer.rb', line 223

def retrieve_payment_method(payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/payment_methods/%<payment_method>s", { customer: CGI.escape(self["id"]), payment_method: CGI.escape(payment_method) }),
    params: params,
    opts: opts
  )
end

#test_helpersObject



280
281
282
# File 'lib/stripe/resources/customer.rb', line 280

def test_helpers
  TestHelpers.new(self)
end