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 and track payments that belong to the same customer.

Related guide: [Save a card during payment](stripe.com/docs/payments/save-during-payment)

Defined Under Namespace

Classes: TestHelpers

Constant Summary collapse

OBJECT_NAME =
"customer"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

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

Class Method Details

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

Creates a new customer object.



27
28
29
# File 'lib/stripe/resources/customer.rb', line 27

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.



46
47
48
49
50
51
52
53
# File 'lib/stripe/resources/customer.rb', line 46

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.



56
57
58
59
60
61
62
63
# File 'lib/stripe/resources/customer.rb', line 56

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.



86
87
88
89
90
91
92
93
# File 'lib/stripe/resources/customer.rb', line 86

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.



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

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



111
112
113
114
115
116
117
118
# File 'lib/stripe/resources/customer.rb', line 111

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



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

def self.object_name
  "customer"
end

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

Retrieves a customer’s cash balance.



121
122
123
124
125
126
127
128
# File 'lib/stripe/resources/customer.rb', line 121

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.



141
142
143
144
145
146
147
148
# File 'lib/stripe/resources/customer.rb', line 141

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



150
151
152
# File 'lib/stripe/resources/customer.rb', line 150

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



154
155
156
# File 'lib/stripe/resources/customer.rb', line 154

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.



161
162
163
164
165
166
167
168
# File 'lib/stripe/resources/customer.rb', line 161

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.



171
172
173
174
175
176
177
178
# File 'lib/stripe/resources/customer.rb', line 171

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.



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

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.



66
67
68
69
70
71
72
73
# File 'lib/stripe/resources/customer.rb', line 66

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.



76
77
78
79
80
81
82
83
# File 'lib/stripe/resources/customer.rb', line 76

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



101
102
103
104
105
106
107
108
# File 'lib/stripe/resources/customer.rb', line 101

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.



131
132
133
134
135
136
137
138
# File 'lib/stripe/resources/customer.rb', line 131

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



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

def test_helpers
  TestHelpers.new(self)
end