Class: Stripe::Customer
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::Customer
- 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](docs.stripe.com/invoicing/customer), [save payment](docs.stripe.com/payments/save-during-payment) and contact information, and track payments that belong to the same customer.
Defined Under Namespace
Classes: Address, InvoiceSettings, Redaction, Shipping, Tax, TestHelpers
Constant Summary collapse
- OBJECT_NAME =
"customer"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
The customer’s address.
-
#balance ⇒ Object
readonly
The current balance, if any, that’s stored on the customer in their default currency.
-
#business_name ⇒ Object
readonly
The customer’s business name.
-
#cash_balance ⇒ Object
readonly
The current funds being held by Stripe on behalf of the customer.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#currency ⇒ Object
readonly
Three-letter [ISO code for the currency](stripe.com/docs/currencies) the customer can be charged in for recurring billing purposes.
-
#customer_account ⇒ Object
readonly
The ID of an Account representing a customer.
-
#default_source ⇒ Object
readonly
ID of the default payment source for the customer.
-
#deleted ⇒ Object
readonly
Always true for a deleted object.
-
#delinquent ⇒ Object
readonly
Tracks the most recent state change on any invoice belonging to the customer.
-
#description ⇒ Object
readonly
An arbitrary string attached to the object.
-
#discount ⇒ Object
readonly
Describes the current discount active on the customer, if there is one.
-
#email ⇒ Object
readonly
The customer’s email address.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#individual_name ⇒ Object
readonly
The customer’s individual name.
-
#invoice_credit_balance ⇒ Object
readonly
The current multi-currency balances, if any, that’s stored on the customer.
-
#invoice_prefix ⇒ Object
readonly
The prefix for the customer used to generate unique invoice numbers.
-
#invoice_settings ⇒ Object
readonly
Attribute for field invoice_settings.
-
#livemode ⇒ Object
readonly
If the object exists in live mode, the value is ‘true`.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](docs.stripe.com/api/metadata) that you can attach to an object.
-
#name ⇒ Object
readonly
The customer’s full name or business name.
-
#next_invoice_sequence ⇒ Object
readonly
The suffix of the customer’s next invoice number (for example, 0001).
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#phone ⇒ Object
readonly
The customer’s phone number.
-
#preferred_locales ⇒ Object
readonly
The customer’s preferred locales (languages), ordered by preference.
-
#redaction ⇒ Object
readonly
Redaction status of this customer.
-
#shipping ⇒ Object
readonly
Mailing and shipping address for the customer.
-
#sources ⇒ Object
readonly
The customer’s payment sources, if any.
-
#subscriptions ⇒ Object
readonly
The customer’s current subscriptions, if any.
-
#tax ⇒ Object
readonly
Attribute for field tax.
-
#tax_exempt ⇒ Object
readonly
Describes the customer’s tax exemption status, which is ‘none`, `exempt`, or `reverse`.
-
#tax_ids ⇒ Object
readonly
The customer’s tax IDs.
-
#test_clock ⇒ Object
readonly
ID of the test clock that this customer belongs to.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.create(params = {}, opts = {}) ⇒ Object
Creates a new customer object.
-
.create_funding_instructions(customer, params = {}, opts = {}) ⇒ Object
Retrieve funding instructions for a customer cash balance.
-
.delete(customer, params = {}, opts = {}) ⇒ Object
Permanently deletes a customer.
-
.delete_discount(customer, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a customer.
- .field_remappings ⇒ Object
- .inner_class_types ⇒ Object
-
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your customers.
-
.list_payment_methods(customer, params = {}, opts = {}) ⇒ Object
Returns a list of PaymentMethods for a given Customer.
- .object_name ⇒ Object
-
.retrieve_cash_balance(customer, params = {}, opts = {}) ⇒ Object
Retrieves a customer’s cash balance.
-
.retrieve_payment_method(customer, payment_method, params = {}, opts = {}) ⇒ Object
Retrieves a PaymentMethod object for a given Customer.
- .search(params = {}, opts = {}) ⇒ Object
- .search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
-
.update(customer, params = {}, opts = {}) ⇒ Object
Updates the specified customer by setting the values of the parameters passed.
-
.update_cash_balance(customer, params = {}, opts = {}) ⇒ Object
Changes the settings on a customer’s cash balance.
Instance Method Summary collapse
-
#create_funding_instructions(params = {}, opts = {}) ⇒ Object
Retrieve funding instructions for a customer cash balance.
-
#delete(params = {}, opts = {}) ⇒ Object
Permanently deletes a customer.
-
#delete_discount(params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a customer.
-
#list_payment_methods(params = {}, opts = {}) ⇒ Object
Returns a list of PaymentMethods for a given Customer.
-
#retrieve_payment_method(payment_method, params = {}, opts = {}) ⇒ Object
Retrieves a PaymentMethod object for a given Customer.
- #test_helpers ⇒ Object
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::NestedResource
Methods included from APIOperations::Search
Methods included from APIOperations::Save
Methods included from APIOperations::Delete
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
Methods inherited from StripeObject
#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, field_encodings, #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
#address ⇒ Object (readonly)
The customer’s address.
187 188 189 |
# File 'lib/stripe/resources/customer.rb', line 187 def address @address end |
#balance ⇒ Object (readonly)
The current balance, if any, that’s stored on the customer in their default currency. 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. For multi-currency balances, see [invoice_credit_balance](docs.stripe.com/api/customers/object#customer_object-invoice_credit_balance).
189 190 191 |
# File 'lib/stripe/resources/customer.rb', line 189 def balance @balance end |
#business_name ⇒ Object (readonly)
The customer’s business name.
191 192 193 |
# File 'lib/stripe/resources/customer.rb', line 191 def business_name @business_name end |
#cash_balance ⇒ Object (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.
193 194 195 |
# File 'lib/stripe/resources/customer.rb', line 193 def cash_balance @cash_balance end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
195 196 197 |
# File 'lib/stripe/resources/customer.rb', line 195 def created @created end |
#currency ⇒ Object (readonly)
Three-letter [ISO code for the currency](stripe.com/docs/currencies) the customer can be charged in for recurring billing purposes.
197 198 199 |
# File 'lib/stripe/resources/customer.rb', line 197 def currency @currency end |
#customer_account ⇒ Object (readonly)
The ID of an Account representing a customer. You can use this ID with any v1 API that accepts a customer_account parameter.
199 200 201 |
# File 'lib/stripe/resources/customer.rb', line 199 def customer_account @customer_account end |
#default_source ⇒ Object (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](docs.stripe.com/api/customers/object#customer_object-invoice_settings-default_payment_method) field instead.
203 204 205 |
# File 'lib/stripe/resources/customer.rb', line 203 def default_source @default_source end |
#deleted ⇒ Object (readonly)
Always true for a deleted object
205 206 207 |
# File 'lib/stripe/resources/customer.rb', line 205 def deleted @deleted end |
#delinquent ⇒ Object (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](docs.stripe.com/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`.
211 212 213 |
# File 'lib/stripe/resources/customer.rb', line 211 def delinquent @delinquent end |
#description ⇒ Object (readonly)
An arbitrary string attached to the object. Often useful for displaying to users.
213 214 215 |
# File 'lib/stripe/resources/customer.rb', line 213 def description @description end |
#discount ⇒ Object (readonly)
Describes the current discount active on the customer, if there is one.
215 216 217 |
# File 'lib/stripe/resources/customer.rb', line 215 def discount @discount end |
#email ⇒ Object (readonly)
The customer’s email address.
217 218 219 |
# File 'lib/stripe/resources/customer.rb', line 217 def email @email end |
#id ⇒ Object (readonly)
Unique identifier for the object.
219 220 221 |
# File 'lib/stripe/resources/customer.rb', line 219 def id @id end |
#individual_name ⇒ Object (readonly)
The customer’s individual name.
221 222 223 |
# File 'lib/stripe/resources/customer.rb', line 221 def individual_name @individual_name end |
#invoice_credit_balance ⇒ Object (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.
223 224 225 |
# File 'lib/stripe/resources/customer.rb', line 223 def invoice_credit_balance @invoice_credit_balance end |
#invoice_prefix ⇒ Object (readonly)
The prefix for the customer used to generate unique invoice numbers.
225 226 227 |
# File 'lib/stripe/resources/customer.rb', line 225 def invoice_prefix @invoice_prefix end |
#invoice_settings ⇒ Object (readonly)
Attribute for field invoice_settings
227 228 229 |
# File 'lib/stripe/resources/customer.rb', line 227 def invoice_settings @invoice_settings end |
#livemode ⇒ Object (readonly)
If the object exists in live mode, the value is ‘true`. If the object exists in test mode, the value is `false`.
229 230 231 |
# File 'lib/stripe/resources/customer.rb', line 229 def livemode @livemode end |
#metadata ⇒ Object (readonly)
Set of [key-value pairs](docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
231 232 233 |
# File 'lib/stripe/resources/customer.rb', line 231 def @metadata end |
#name ⇒ Object (readonly)
The customer’s full name or business name.
233 234 235 |
# File 'lib/stripe/resources/customer.rb', line 233 def name @name end |
#next_invoice_sequence ⇒ Object (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.
235 236 237 |
# File 'lib/stripe/resources/customer.rb', line 235 def next_invoice_sequence @next_invoice_sequence end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
237 238 239 |
# File 'lib/stripe/resources/customer.rb', line 237 def object @object end |
#phone ⇒ Object (readonly)
The customer’s phone number.
239 240 241 |
# File 'lib/stripe/resources/customer.rb', line 239 def phone @phone end |
#preferred_locales ⇒ Object (readonly)
The customer’s preferred locales (languages), ordered by preference.
241 242 243 |
# File 'lib/stripe/resources/customer.rb', line 241 def preferred_locales @preferred_locales end |
#redaction ⇒ Object (readonly)
Redaction status of this customer. If not null, this customer is associated to a redaction job.
243 244 245 |
# File 'lib/stripe/resources/customer.rb', line 243 def redaction @redaction end |
#shipping ⇒ Object (readonly)
Mailing and shipping address for the customer. Appears on invoices emailed to this customer.
245 246 247 |
# File 'lib/stripe/resources/customer.rb', line 245 def shipping @shipping end |
#sources ⇒ Object (readonly)
The customer’s payment sources, if any.
247 248 249 |
# File 'lib/stripe/resources/customer.rb', line 247 def sources @sources end |
#subscriptions ⇒ Object (readonly)
The customer’s current subscriptions, if any.
249 250 251 |
# File 'lib/stripe/resources/customer.rb', line 249 def subscriptions @subscriptions end |
#tax ⇒ Object (readonly)
Attribute for field tax
251 252 253 |
# File 'lib/stripe/resources/customer.rb', line 251 def tax @tax end |
#tax_exempt ⇒ Object (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”**.
253 254 255 |
# File 'lib/stripe/resources/customer.rb', line 253 def tax_exempt @tax_exempt end |
#tax_ids ⇒ Object (readonly)
The customer’s tax IDs.
255 256 257 |
# File 'lib/stripe/resources/customer.rb', line 255 def tax_ids @tax_ids end |
#test_clock ⇒ Object (readonly)
ID of the test clock that this customer belongs to.
257 258 259 |
# File 'lib/stripe/resources/customer.rb', line 257 def test_clock @test_clock end |
Class Method Details
.create(params = {}, opts = {}) ⇒ Object
Creates a new customer object.
260 261 262 |
# File 'lib/stripe/resources/customer.rb', line 260 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.
279 280 281 282 283 284 285 286 |
# File 'lib/stripe/resources/customer.rb', line 279 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(customer, params = {}, opts = {}) ⇒ Object
Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.
289 290 291 292 293 294 295 296 |
# File 'lib/stripe/resources/customer.rb', line 289 def self.delete(customer, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/customers/%<customer>s", { customer: CGI.escape(customer) }), params: params, opts: opts ) end |
.delete_discount(customer, params = {}, opts = {}) ⇒ Object
Removes the currently applied discount on a customer.
319 320 321 322 323 324 325 326 |
# File 'lib/stripe/resources/customer.rb', line 319 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 |
.field_remappings ⇒ Object
462 463 464 |
# File 'lib/stripe/resources/customer.rb', line 462 def self.field_remappings @field_remappings = {} end |
.inner_class_types ⇒ Object
452 453 454 455 456 457 458 459 460 |
# File 'lib/stripe/resources/customer.rb', line 452 def self.inner_class_types @inner_class_types = { address: Address, invoice_settings: InvoiceSettings, redaction: Redaction, shipping: Shipping, tax: Tax, } end |
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.
329 330 331 |
# File 'lib/stripe/resources/customer.rb', line 329 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/customers", params: params, opts: opts) end |
.list_payment_methods(customer, params = {}, opts = {}) ⇒ Object
Returns a list of PaymentMethods for a given Customer
344 345 346 347 348 349 350 351 |
# File 'lib/stripe/resources/customer.rb', line 344 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_name ⇒ Object
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.
354 355 356 357 358 359 360 361 |
# File 'lib/stripe/resources/customer.rb', line 354 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.
374 375 376 377 378 379 380 381 |
# File 'lib/stripe/resources/customer.rb', line 374 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
383 384 385 |
# File 'lib/stripe/resources/customer.rb', line 383 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
387 388 389 |
# File 'lib/stripe/resources/customer.rb', line 387 def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end |
.update(customer, params = {}, opts = {}) ⇒ Object
Updates the specified customer by setting the values of the parameters passed. Any parameters not provided are left unchanged. For example, if you pass the source parameter, that becomes the customer’s active source (such as 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 is retried. This retry doesn’t count as an automatic retry, and doesn’t affect the next regularly scheduled payment for the invoice. Changing the default_source for a customer doesn’t trigger this behavior.
This request accepts mostly the same arguments as the customer creation call.
394 395 396 397 398 399 400 401 |
# File 'lib/stripe/resources/customer.rb', line 394 def self.update(customer, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/customers/%<customer>s", { customer: CGI.escape(customer) }), params: params, opts: opts ) end |
.update_cash_balance(customer, params = {}, opts = {}) ⇒ Object
Changes the settings on a customer’s cash balance.
404 405 406 407 408 409 410 411 |
# File 'lib/stripe/resources/customer.rb', line 404 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.
267 268 269 270 271 272 273 274 |
# File 'lib/stripe/resources/customer.rb', line 267 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.
299 300 301 302 303 304 305 306 |
# File 'lib/stripe/resources/customer.rb', line 299 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.
309 310 311 312 313 314 315 316 |
# File 'lib/stripe/resources/customer.rb', line 309 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
334 335 336 337 338 339 340 341 |
# File 'lib/stripe/resources/customer.rb', line 334 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.
364 365 366 367 368 369 370 371 |
# File 'lib/stripe/resources/customer.rb', line 364 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_helpers ⇒ Object
421 422 423 |
# File 'lib/stripe/resources/customer.rb', line 421 def test_helpers TestHelpers.new(self) end |