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

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


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

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

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


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

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, opts_or_unused_nested_id = nil, opts = {}) ⇒ Object


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/stripe/resources/customer.rb', line 111

def self.retrieve_cash_balance(
  customer,
  opts_or_unused_nested_id = nil,
  opts = {}
)
  # Support two call patterns for backwards compatibility.
  # 1. Legacy: (nil unused nested_id, opts)
  # 2. Fixed pattern: (opts)
  if !opts_or_unused_nested_id.nil? && opts_or_unused_nested_id.class == Hash && opts.empty?
    opts = opts_or_unused_nested_id
  end
  request_stripe_object(
    method: :get,
    path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
    params: {},
    opts: opts
  )
end

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


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

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


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

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

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


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

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

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


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/stripe/resources/customer.rb', line 130

def self.update_cash_balance(
  customer,
  unused_nested_id = nil,
  params = {},
  opts = {}
)
  # Do not allow passing in a hash as the second argument, as we require a nil for compatibility reasons. We cannot differentiate from a legacy pattern (nil, params) and a modern pattern (nil for params, opts).
  if !unused_nested_id.nil? && unused_nested_id.class == Hash
    raise ArgumentError, "update_cash_balance requires the second argument always be nil for legacy reasons."
  end

  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


20
21
22
23
24
25
26
27
# File 'lib/stripe/resources/customer.rb', line 20

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_discountObject

Deletes a discount associated with the customer.

Returns the deleted discount. The customer object is not updated, so you must call `refresh` on it to get a new version with the discount removed.


95
96
97
98
99
100
101
# File 'lib/stripe/resources/customer.rb', line 95

def delete_discount
  request_stripe_object(
    method: :delete,
    path: resource_url + "/discount",
    params: {}
  )
end

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


29
30
31
32
33
34
35
36
# File 'lib/stripe/resources/customer.rb', line 29

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


38
39
40
41
42
43
44
45
# File 'lib/stripe/resources/customer.rb', line 38

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


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

def test_helpers
  TestHelpers.new(self)
end