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::Search

_search

Methods included from APIOperations::NestedResource

nested_resource_class_methods

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

#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_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.



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

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_discount(customer, params = {}, opts = {}) ⇒ Object

Removes the currently applied discount on a customer.



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

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_payment_methods(customer, params = {}, opts = {}) ⇒ Object

Returns a list of PaymentMethods for a given Customer



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

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

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

Retrieves a customer’s cash balance.



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

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.



97
98
99
100
101
102
103
104
# File 'lib/stripe/resources/customer.rb', line 97

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



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

def self.search(params = {}, opts = {})
  _search("/v1/customers/search", params, opts)
end

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



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

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

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

Changes the settings on a customer’s cash balance.



135
136
137
138
139
140
141
142
# File 'lib/stripe/resources/customer.rb', line 135

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.



25
26
27
28
29
30
31
32
# File 'lib/stripe/resources/customer.rb', line 25

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_discount(params = {}, opts = {}) ⇒ Object

Removes the currently applied discount on a customer.



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

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



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

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.



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

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



144
145
146
# File 'lib/stripe/resources/customer.rb', line 144

def test_helpers
  TestHelpers.new(self)
end