Class: Stripe::Account

Inherits:
APIResource show all
Extended by:
Gem::Deprecate, Stripe::APIOperations::Create, Stripe::APIOperations::List, Stripe::APIOperations::NestedResource
Includes:
Stripe::APIOperations::Delete, Stripe::APIOperations::Save
Defined in:
lib/stripe/resources/account.rb

Constant Summary collapse

OBJECT_NAME =
"account"

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 Stripe::APIOperations::Create

create

Methods included from Stripe::APIOperations::List

list

Methods included from Stripe::APIOperations::NestedResource

nested_resource_class_methods

Methods included from Stripe::APIOperations::Save

included, #save

Methods included from Stripe::APIOperations::Delete

#delete, included

Methods inherited from APIResource

class_name, custom_method, #refresh, resource_url, save_nested_resource

Methods included from Stripe::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, #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

.protected_fieldsObject



115
116
117
# File 'lib/stripe/resources/account.rb', line 115

def self.protected_fields
  [:legal_entity]
end

.retrieve(id = nil, opts = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stripe/resources/account.rb', line 48

def self.retrieve(id = nil, opts = {})
  Util.check_string_argument!(id) if id

  # Account used to be a singleton, where this method's signature was
  # `(opts={})`. For the sake of not breaking folks who pass in an OAuth
  # key in opts, let's lurkily string match for it.
  if opts == {} && id.is_a?(String) && id.start_with?("sk_")
    # `super` properly assumes a String opts is the apiKey and normalizes
    # as expected.
    opts = id
    id = nil
  end
  super(id, opts)
end

Instance Method Details

#deauthorize(client_id = nil, opts = {}) ⇒ Object



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

def deauthorize(client_id = nil, opts = {})
  params = {
    client_id: client_id,
    stripe_user_id: id,
  }
  opts = @opts.merge(Util.normalize_opts(opts))
  OAuth.deauthorize(params, opts)
end


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

def legal_entity
  self["legal_entity"]
end

Raises:

  • (NoMethodError)


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

def legal_entity=(_legal_entity)
  raise NoMethodError,
        "Overriding legal_entity can cause serious issues. Instead, set " \
        "the individual fields of legal_entity like " \
        "`account.legal_entity.first_name = 'Blah'`"
end

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



63
64
65
66
# File 'lib/stripe/resources/account.rb', line 63

def persons(params = {}, opts = {})
  resp, opts = execute_resource_request(:get, resource_url + "/persons", params, opts)
  Util.convert_to_stripe_object(resp.data, opts)
end

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



23
24
25
26
27
28
29
30
# File 'lib/stripe/resources/account.rb', line 23

def reject(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: resource_url + "/reject",
    params: params,
    opts: opts
  )
end

#resource_urlObject



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

def resource_url
  if self["id"]
    super
  else
    "/v1/account"
  end
end

#serialize_params(options = {}) ⇒ Object

Somewhat unfortunately, we attempt to do a special encoding trick when serializing ‘additional_owners` under an account: when updating a value, we actually send the update parameters up as an integer-indexed hash rather than an array. So instead of this:

field[]=item1&field[]=item2&field[]=item3

We send this:

field[0]=item1&field[1]=item2&field[2]=item3

There are two major problems with this technique:

* Entities are addressed by array index, which is not stable and can
  easily result in unexpected results between two different requests.

* A replacement of the array's contents is ambiguous with setting a
  subset of the array. Because of this, the only way to shorten an
  array is to unset it completely by making sure it goes into the
  server as an empty string, then setting its contents again.

We’re trying to get this overturned on the server side, but for now, patch in a special allowance.



95
96
97
# File 'lib/stripe/resources/account.rb', line 95

def serialize_params(options = {})
  (self, super, options)
end

#serialize_params_account(_obj, update_hash, options = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/stripe/resources/account.rb', line 99

def (_obj, update_hash, options = {})
  if (entity = @values[:legal_entity])
    if (owners = entity[:additional_owners])
      entity_update = update_hash[:legal_entity] ||= {}
      entity_update[:additional_owners] =
        serialize_additional_owners(entity, owners)
    end
  end
  if (individual = @values[:individual])
    if individual.is_a?(Person) && !update_hash.key?(:individual)
      update_hash[:individual] = individual.serialize_params(options)
    end
  end
  update_hash
end