stripe 1.58.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitattributes +4 -0
- data/.travis.yml +1 -2
- data/Gemfile +11 -12
- data/History.txt +8 -0
- data/README.md +44 -31
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/stripe.rb +4 -344
- data/lib/stripe/account.rb +4 -4
- data/lib/stripe/api_operations/create.rb +2 -2
- data/lib/stripe/api_operations/delete.rb +2 -2
- data/lib/stripe/api_operations/list.rb +2 -2
- data/lib/stripe/api_operations/request.rb +9 -3
- data/lib/stripe/api_operations/save.rb +4 -6
- data/lib/stripe/api_resource.rb +2 -2
- data/lib/stripe/bank_account.rb +2 -2
- data/lib/stripe/bitcoin_receiver.rb +1 -1
- data/lib/stripe/charge.rb +12 -12
- data/lib/stripe/customer.rb +6 -6
- data/lib/stripe/dispute.rb +2 -3
- data/lib/stripe/errors.rb +20 -10
- data/lib/stripe/invoice.rb +4 -4
- data/lib/stripe/list_object.rb +2 -2
- data/lib/stripe/order.rb +4 -4
- data/lib/stripe/reversal.rb +1 -1
- data/lib/stripe/source.rb +2 -2
- data/lib/stripe/stripe_client.rb +396 -0
- data/lib/stripe/stripe_response.rb +48 -0
- data/lib/stripe/transfer.rb +2 -2
- data/lib/stripe/util.rb +6 -6
- data/lib/stripe/version.rb +1 -1
- data/spec/fixtures.json +0 -0
- data/spec/fixtures.yaml +0 -0
- data/spec/spec.json +0 -0
- data/spec/spec.yaml +0 -0
- data/stripe.gemspec +1 -1
- data/test/api_fixtures.rb +29 -0
- data/test/api_stub_helpers.rb +125 -0
- data/test/stripe/account_test.rb +153 -247
- data/test/stripe/alipay_account_test.rb +10 -2
- data/test/stripe/api_operations_test.rb +3 -3
- data/test/stripe/api_resource_test.rb +139 -499
- data/test/stripe/apple_pay_domain_test.rb +22 -23
- data/test/stripe/application_fee_refund_test.rb +22 -31
- data/test/stripe/application_fee_test.rb +6 -17
- data/test/stripe/balance_test.rb +3 -3
- data/test/stripe/bank_account_test.rb +31 -11
- data/test/stripe/bitcoin_receiver_test.rb +51 -42
- data/test/stripe/bitcoin_transaction_test.rb +11 -19
- data/test/stripe/charge_test.rb +39 -126
- data/test/stripe/country_spec_test.rb +7 -30
- data/test/stripe/coupon_test.rb +33 -17
- data/test/stripe/customer_card_test.rb +25 -46
- data/test/stripe/customer_test.rb +86 -81
- data/test/stripe/dispute_test.rb +27 -38
- data/test/stripe/errors_test.rb +2 -2
- data/test/stripe/file_upload_test.rb +32 -24
- data/test/stripe/invoice_item_test.rb +46 -10
- data/test/stripe/invoice_test.rb +48 -48
- data/test/stripe/list_object_test.rb +22 -31
- data/test/stripe/order_return_test.rb +11 -15
- data/test/stripe/order_test.rb +38 -51
- data/test/stripe/plan_test.rb +39 -18
- data/test/stripe/product_test.rb +29 -33
- data/test/stripe/recipient_card_test.rb +23 -40
- data/test/stripe/recipient_test.rb +39 -10
- data/test/stripe/refund_test.rb +20 -45
- data/test/stripe/reversal_test.rb +27 -31
- data/test/stripe/sku_test.rb +36 -19
- data/test/stripe/source_test.rb +26 -66
- data/test/stripe/stripe_client_test.rb +428 -0
- data/test/stripe/stripe_object_test.rb +6 -2
- data/test/stripe/stripe_response_test.rb +46 -0
- data/test/stripe/subscription_item_test.rb +37 -59
- data/test/stripe/subscription_test.rb +40 -176
- data/test/stripe/three_d_secure_test.rb +13 -12
- data/test/stripe/transfer_test.rb +36 -19
- data/test/stripe_test.rb +3 -36
- data/test/test_data.rb +5 -931
- data/test/test_helper.rb +21 -25
- metadata +22 -17
- data/test/stripe/charge_refund_test.rb +0 -67
- data/test/stripe/metadata_test.rb +0 -129
@@ -0,0 +1,48 @@
|
|
1
|
+
module Stripe
|
2
|
+
# StripeResponse encapsulates some vitals of a response that came back from
|
3
|
+
# the Stripe API.
|
4
|
+
class StripeResponse
|
5
|
+
# The data contained by the HTTP body of the response deserialized from
|
6
|
+
# JSON.
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
# The raw HTTP body of the response.
|
10
|
+
attr_accessor :http_body
|
11
|
+
|
12
|
+
# A Hash of the HTTP headers of the response.
|
13
|
+
attr_accessor :http_headers
|
14
|
+
|
15
|
+
# The integer HTTP status code of the response.
|
16
|
+
attr_accessor :http_status
|
17
|
+
|
18
|
+
# The Stripe request ID of the response.
|
19
|
+
attr_accessor :request_id
|
20
|
+
|
21
|
+
# Initializes a StripeResponse object from a Hash like the kind returned as
|
22
|
+
# part of a Faraday exception.
|
23
|
+
#
|
24
|
+
# This may throw JSON::ParserError if the response body is not valid JSON.
|
25
|
+
def self.from_faraday_hash(http_resp)
|
26
|
+
resp = StripeResponse.new
|
27
|
+
resp.data = JSON.parse(http_resp[:body], symbolize_names: true)
|
28
|
+
resp.http_body = http_resp[:body]
|
29
|
+
resp.http_headers = http_resp[:headers]
|
30
|
+
resp.http_status = http_resp[:status]
|
31
|
+
resp.request_id = http_resp[:headers]["Request-Id"]
|
32
|
+
resp
|
33
|
+
end
|
34
|
+
|
35
|
+
# Initializes a StripeResponse object from a Faraday HTTP response object.
|
36
|
+
#
|
37
|
+
# This may throw JSON::ParserError if the response body is not valid JSON.
|
38
|
+
def self.from_faraday_response(http_resp)
|
39
|
+
resp = StripeResponse.new
|
40
|
+
resp.data = JSON.parse(http_resp.body, symbolize_names: true)
|
41
|
+
resp.http_body = http_resp.body
|
42
|
+
resp.http_headers = http_resp.headers
|
43
|
+
resp.http_status = http_resp.status
|
44
|
+
resp.request_id = http_resp.headers["Request-Id"]
|
45
|
+
resp
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/stripe/transfer.rb
CHANGED
@@ -5,8 +5,8 @@ module Stripe
|
|
5
5
|
include Stripe::APIOperations::Save
|
6
6
|
|
7
7
|
def cancel
|
8
|
-
|
9
|
-
initialize_from(
|
8
|
+
resp, api_key = self.request(:post, cancel_url)
|
9
|
+
initialize_from(resp.data, api_key)
|
10
10
|
end
|
11
11
|
|
12
12
|
def cancel_url
|
data/lib/stripe/util.rb
CHANGED
@@ -68,18 +68,18 @@ module Stripe
|
|
68
68
|
#
|
69
69
|
# ==== Attributes
|
70
70
|
#
|
71
|
-
# * +
|
71
|
+
# * +data+ - Hash of fields and values to be converted into a StripeObject.
|
72
72
|
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
73
73
|
# on subsequent API calls.
|
74
|
-
def self.convert_to_stripe_object(
|
75
|
-
case
|
74
|
+
def self.convert_to_stripe_object(data, opts)
|
75
|
+
case data
|
76
76
|
when Array
|
77
|
-
|
77
|
+
data.map { |i| convert_to_stripe_object(i, opts) }
|
78
78
|
when Hash
|
79
79
|
# Try converting to a known object class. If none available, fall back to generic StripeObject
|
80
|
-
object_classes.fetch(
|
80
|
+
object_classes.fetch(data[:object], StripeObject).construct_from(data, opts)
|
81
81
|
else
|
82
|
-
|
82
|
+
data
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
data/lib/stripe/version.rb
CHANGED
data/spec/fixtures.json
ADDED
Binary file
|
data/spec/fixtures.yaml
ADDED
Binary file
|
data/spec/spec.json
ADDED
Binary file
|
data/spec/spec.yaml
ADDED
Binary file
|
data/stripe.gemspec
CHANGED
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
|
|
13
13
|
s.homepage = 'https://stripe.com/docs/api/ruby'
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
|
-
s.add_dependency('
|
16
|
+
s.add_dependency('faraday', '~> 0')
|
17
17
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
19
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# APIFixtures loads fixture data generated by the core Stripe API so that we
|
2
|
+
# can have slightly more accurate and up-to-date resource information in our
|
3
|
+
# tests.
|
4
|
+
class APIFixtures
|
5
|
+
def initialize
|
6
|
+
@fixtures = ::JSON.parse(File.read("#{PROJECT_ROOT}/spec/fixtures.json"),
|
7
|
+
symbolize_names: true)
|
8
|
+
freeze_recursively(@fixtures)
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](name)
|
12
|
+
@fixtures[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch(*args)
|
16
|
+
@fixtures.fetch(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def freeze_recursively(data)
|
22
|
+
data.each do |k, v|
|
23
|
+
if v.is_a?(Hash)
|
24
|
+
freeze_recursively(v)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
data.freeze
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
# Provides a set of helpers for a test suite that help to mock out the Stripe
|
4
|
+
# API.
|
5
|
+
module APIStubHelpers
|
6
|
+
protected
|
7
|
+
|
8
|
+
# Uses Webmock to stub out the Stripe API for testing purposes. The stub will
|
9
|
+
# by default respond on any routes that are defined in the bundled OpenAPI
|
10
|
+
# spec with generated response data.
|
11
|
+
#
|
12
|
+
# An `override_app` can be specified to get finer grain control over how a
|
13
|
+
# stubbed endpoint responds. It can be used to modify generated responses,
|
14
|
+
# mock expectations, or even to override the default stub completely.
|
15
|
+
def stub_api
|
16
|
+
stub_request(:any, /^#{Stripe.api_base}/).to_rack(new_api_stub)
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_connect
|
20
|
+
stub_request(:any, /^#{Stripe.connect_base}/).to_return(:body => "{}")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# APIStubMiddleware intercepts a response generated by Committee's stubbing
|
26
|
+
# middleware, and tries to replace it with a better version from a set of
|
27
|
+
# sample fixtures data generated from Stripe's core API service.
|
28
|
+
class APIStubMiddleware
|
29
|
+
API_FIXTURES = APIFixtures.new
|
30
|
+
|
31
|
+
def initialize(app)
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
# We use a vendor specific prefix (`x-resourceId`) embedded in the schema
|
37
|
+
# of any resource in our spec to identify it (e.g. "charge"). This allows
|
38
|
+
# us to cross-reference that response with some data that we might find
|
39
|
+
# in our fixtures file so that we can respond with a higher fidelity
|
40
|
+
# response.
|
41
|
+
schema = env["committee.response_schema"]
|
42
|
+
resource_id = schema.data["x-resourceId"] || ""
|
43
|
+
|
44
|
+
if data = API_FIXTURES[resource_id.to_sym]
|
45
|
+
# standard top-level API resource
|
46
|
+
data = fixturize_lists_recursively(schema, data)
|
47
|
+
env["committee.response"] = data
|
48
|
+
elsif schema.properties["object"].enum == ["list"]
|
49
|
+
# top level list (like from a list endpoint)
|
50
|
+
data = fixturize_list(schema, env["committee.response"])
|
51
|
+
env["committee.response"] = data
|
52
|
+
else
|
53
|
+
raise "no fixture for: #{resource_id}"
|
54
|
+
end
|
55
|
+
@app.call(env)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# If schema looks like a Stripe list object, then we look up the resource
|
61
|
+
# that the list is supposed to include and inject it into `data` as a
|
62
|
+
# fixture. Also calls into that other schema recursively so that sublists
|
63
|
+
# within it will also be assigned a fixture.
|
64
|
+
def fixturize_list(schema, data)
|
65
|
+
object_schema = schema.properties["object"]
|
66
|
+
if object_schema && object_schema.enum == ["list"]
|
67
|
+
subschema = schema.properties["data"].items
|
68
|
+
resource_id = subschema.data["x-resourceId"] || ""
|
69
|
+
if subdata = API_FIXTURES[resource_id.to_sym]
|
70
|
+
subdata = fixturize_lists_recursively(subschema, subdata)
|
71
|
+
|
72
|
+
data = data ? data.dup : {}
|
73
|
+
data[:data] = [subdata]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
data
|
77
|
+
end
|
78
|
+
|
79
|
+
# Examines each of the given schema's properties and calls #fixturize_list
|
80
|
+
# on them so that any sublists will be populated with sample fixture data.
|
81
|
+
def fixturize_lists_recursively(schema, data)
|
82
|
+
data = data.dup
|
83
|
+
schema.properties.each do |key, subschema|
|
84
|
+
data[key.to_sym] = fixturize_list(subschema, data[key.to_sym])
|
85
|
+
end
|
86
|
+
data
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# A descendant of the standard `Sinatra::Base` that we can use to enrich
|
91
|
+
# certain types of responses.
|
92
|
+
class APIStubApp < Sinatra::Base
|
93
|
+
not_found do
|
94
|
+
"endpoint not found in API stub: #{request.request_method} #{request.path_info}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Finds the latest OpenAPI specification in ROOT/spec/ and parses it for
|
99
|
+
# use with Committee.
|
100
|
+
def self.initialize_spec
|
101
|
+
schema_data = ::JSON.parse(File.read("#{PROJECT_ROOT}/spec/spec.json"))
|
102
|
+
|
103
|
+
driver = Committee::Drivers::OpenAPI2.new
|
104
|
+
driver.parse(schema_data)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Creates a new Rack app with Committee middleware it.
|
108
|
+
def new_api_stub
|
109
|
+
Rack::Builder.new {
|
110
|
+
use Committee::Middleware::RequestValidation, schema: @@spec,
|
111
|
+
params_response: true, strict: true
|
112
|
+
use Committee::Middleware::Stub, schema: @@spec,
|
113
|
+
call: true
|
114
|
+
use APIStubMiddleware
|
115
|
+
run APIStubApp.new
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
# Parse and initialize the OpenAPI spec only once for the entire test suite.
|
120
|
+
@@spec = initialize_spec
|
121
|
+
|
122
|
+
# The default override app. Doesn't respond on any route so generated
|
123
|
+
# responses will always take precedence.
|
124
|
+
@@default_override_app = Sinatra.new
|
125
|
+
end
|
data/test/stripe/account_test.rb
CHANGED
@@ -2,296 +2,202 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class AccountTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
resp = make_account({
|
7
|
-
:charges_enabled => false,
|
8
|
-
:details_submitted => false,
|
9
|
-
:email => "test+bindings@stripe.com",
|
10
|
-
})
|
11
|
-
@mock.expects(:get).
|
12
|
-
once.
|
13
|
-
with('https://api.stripe.com/v1/account', nil, nil).
|
14
|
-
returns(make_response(resp))
|
15
|
-
a = Stripe::Account.retrieve
|
16
|
-
assert_equal "test+bindings@stripe.com", a.email
|
17
|
-
assert !a.charges_enabled
|
18
|
-
assert !a.details_submitted
|
19
|
-
end
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:account)
|
20
6
|
|
21
|
-
should "be
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
})
|
27
|
-
@mock.expects(:get).
|
28
|
-
once.
|
29
|
-
with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
|
30
|
-
returns(make_response(resp))
|
31
|
-
a = Stripe::Account.retrieve('acct_foo')
|
32
|
-
assert_equal "test+bindings@stripe.com", a.email
|
33
|
-
assert !a.charges_enabled
|
34
|
-
assert !a.details_submitted
|
7
|
+
should "be listable" do
|
8
|
+
accounts = Stripe::Account.list
|
9
|
+
assert_requested :get, "#{Stripe.api_base}/v1/accounts"
|
10
|
+
assert accounts.data.kind_of?(Array)
|
11
|
+
assert accounts.data[0].kind_of?(Stripe::Account)
|
35
12
|
end
|
36
13
|
|
37
|
-
should "be retrievable using
|
38
|
-
account =
|
39
|
-
|
40
|
-
account.
|
41
|
-
Stripe::Account.retrieve('sk_foobar')
|
14
|
+
should "be retrievable using singular endpoint" do
|
15
|
+
account = Stripe::Account.retrieve
|
16
|
+
assert_requested :get, "#{Stripe.api_base}/v1/account"
|
17
|
+
assert account.kind_of?(Stripe::Account)
|
42
18
|
end
|
43
19
|
|
44
|
-
should "
|
45
|
-
account = Stripe::Account.
|
46
|
-
|
47
|
-
|
48
|
-
:secret => 'secret-key',
|
49
|
-
}
|
50
|
-
}))
|
51
|
-
assert_equal 'publishable-key', account.keys.publishable
|
52
|
-
assert_equal 'secret-key', account.keys.secret
|
20
|
+
should "be retrievable using plural endpoint" do
|
21
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
22
|
+
assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
23
|
+
assert account.kind_of?(Stripe::Account)
|
53
24
|
end
|
54
25
|
|
55
26
|
should "be rejectable" do
|
56
27
|
account_data = {:id => 'acct_foo'}
|
57
|
-
|
58
|
-
|
59
|
-
with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
|
60
|
-
returns(make_response(account_data))
|
28
|
+
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
|
29
|
+
to_return(body: JSON.generate(account_data))
|
61
30
|
|
62
|
-
|
63
|
-
|
64
|
-
with("https://api.stripe.com/v1/accounts/acct_foo/reject", nil, 'reason=fraud').
|
65
|
-
returns(make_response(account_data))
|
31
|
+
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject").
|
32
|
+
to_return(body: JSON.generate(account_data))
|
66
33
|
|
67
34
|
account = Stripe::Account.retrieve('acct_foo')
|
68
35
|
account.reject(:reason => 'fraud')
|
69
36
|
end
|
70
37
|
|
71
|
-
should "be
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
:address => {
|
76
|
-
:line1 => '1 Two Three'
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
@mock.expects(:get).
|
81
|
-
once.
|
82
|
-
with('https://api.stripe.com/v1/accounts/acct_foo', nil, nil).
|
83
|
-
returns(make_response(resp))
|
84
|
-
|
85
|
-
@mock.expects(:post).
|
86
|
-
once.
|
87
|
-
with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[address][line1]=2+Three+Four&legal_entity[first_name]=Bob').
|
88
|
-
returns(make_response(resp))
|
89
|
-
|
90
|
-
a = Stripe::Account.retrieve('acct_foo')
|
91
|
-
a.legal_entity.first_name = 'Bob'
|
92
|
-
a.legal_entity.address.line1 = '2 Three Four'
|
93
|
-
a.save
|
38
|
+
should "be creatable" do
|
39
|
+
account = Stripe::Account.create(:metadata => {})
|
40
|
+
assert_requested :post, "#{Stripe.api_base}/v1/accounts"
|
41
|
+
assert account.kind_of?(Stripe::Account)
|
94
42
|
end
|
95
43
|
|
96
|
-
should "be
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
101
|
-
@mock.expects(:post).
|
102
|
-
once.
|
103
|
-
with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'business_name=ACME+Corp').
|
104
|
-
returns(make_response(resp))
|
105
|
-
|
106
|
-
a = Stripe::Account.update('acct_foo', :business_name => "ACME Corp")
|
107
|
-
assert_equal('ACME Corp', a.business_name)
|
44
|
+
should "be saveable" do
|
45
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
46
|
+
account.metadata['key'] = 'value'
|
47
|
+
account.save
|
48
|
+
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
108
49
|
end
|
109
50
|
|
110
|
-
should
|
111
|
-
account = Stripe::Account.
|
112
|
-
|
113
|
-
|
114
|
-
:secret => 'secret-key',
|
115
|
-
},
|
116
|
-
:legal_entity => {
|
117
|
-
:first_name => 'Bling'
|
118
|
-
}
|
119
|
-
}))
|
120
|
-
|
121
|
-
assert_raise NoMethodError do
|
122
|
-
account.legal_entity = {:first_name => 'Blah'}
|
123
|
-
end
|
124
|
-
|
125
|
-
account.legal_entity.first_name = 'Blah'
|
51
|
+
should "be updateable" do
|
52
|
+
account = Stripe::Account.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
53
|
+
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
54
|
+
assert account.kind_of?(Stripe::Account)
|
126
55
|
end
|
127
56
|
|
128
|
-
should "be
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
@mock.expects(:post).once.with do |url, api_key, params|
|
135
|
-
url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]}
|
136
|
-
end.returns(make_response({ 'stripe_user_id' => a.id }))
|
137
|
-
a.deauthorize('ca_1234', 'sk_test_1234')
|
57
|
+
should "be deletable" do
|
58
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
59
|
+
account = account.delete
|
60
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
61
|
+
assert account.kind_of?(Stripe::Account)
|
138
62
|
end
|
139
63
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
64
|
+
context "#bank_account=" do
|
65
|
+
should "warn that #bank_account= is deprecated" do
|
66
|
+
old_stderr = $stderr
|
67
|
+
$stderr = StringIO.new
|
68
|
+
begin
|
69
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
70
|
+
account.bank_account = "tok_123"
|
71
|
+
message = "NOTE: Stripe::Account#bank_account= is " +
|
72
|
+
"deprecated; use #external_account= instead"
|
73
|
+
assert_match Regexp.new(message), $stderr.string
|
74
|
+
ensure
|
75
|
+
$stderr = old_stderr
|
76
|
+
end
|
146
77
|
end
|
147
78
|
end
|
148
79
|
|
149
|
-
|
150
|
-
|
151
|
-
:id
|
152
|
-
:external_accounts => {
|
153
|
-
:object => "list",
|
154
|
-
:resource_url => "/v1/accounts/acct_1234/external_accounts",
|
155
|
-
:data => [],
|
156
|
-
}
|
157
|
-
}
|
158
|
-
@mock.expects(:get).once.returns(make_response(resp))
|
159
|
-
a = Stripe::Account.retrieve
|
80
|
+
context "#deauthorize" do
|
81
|
+
should "deauthorize an account" do
|
82
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
160
83
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
84
|
+
# Unfortunately, the OpenAPI spec doesn't yet cover anything under the
|
85
|
+
# Connect endpoints, so for just stub this out with Webmock.
|
86
|
+
stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
|
87
|
+
with(body: { 'client_id' => 'ca_1234', 'stripe_user_id' => account.id}).
|
88
|
+
to_return(body: JSON.generate({ 'stripe_user_id' => account.id }))
|
89
|
+
account.deauthorize('ca_1234', 'sk_test_1234')
|
90
|
+
end
|
166
91
|
end
|
167
92
|
|
168
|
-
|
169
|
-
|
170
|
-
:id
|
171
|
-
:external_accounts => {
|
172
|
-
:object => "list",
|
173
|
-
:resource_url => "/v1/accounts/acct_1234/external_accounts",
|
174
|
-
:data => [{
|
175
|
-
:id => "ba_1234",
|
176
|
-
:object => "bank_account",
|
177
|
-
}],
|
178
|
-
}
|
179
|
-
}
|
180
|
-
@mock.expects(:get).once.returns(make_response(resp))
|
181
|
-
a = Stripe::Account.retrieve
|
182
|
-
assert_equal(BankAccount, a.external_accounts.data[0].class)
|
183
|
-
end
|
93
|
+
context "#legal_entity=" do
|
94
|
+
should 'disallow direct overrides' do
|
95
|
+
account = Stripe::Account.retrieve(FIXTURE[:id])
|
184
96
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
:legal_entity => Stripe::StripeObject.construct_from({
|
189
|
-
}),
|
190
|
-
}, {})
|
191
|
-
obj.legal_entity.additional_owners = [
|
192
|
-
{ :first_name => "Joe" },
|
193
|
-
{ :first_name => "Jane" },
|
194
|
-
]
|
97
|
+
assert_raise NoMethodError do
|
98
|
+
account.legal_entity = {:first_name => 'Blah'}
|
99
|
+
end
|
195
100
|
|
196
|
-
|
197
|
-
|
198
|
-
:additional_owners => {
|
199
|
-
"0" => { :first_name => "Joe" },
|
200
|
-
"1" => { :first_name => "Jane" },
|
201
|
-
}
|
202
|
-
}
|
203
|
-
}
|
204
|
-
assert_equal(expected, obj.serialize_params)
|
101
|
+
account.legal_entity.first_name = 'Blah'
|
102
|
+
end
|
205
103
|
end
|
206
104
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
:
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
105
|
+
context "#serialize_params" do
|
106
|
+
should "serialize an a new additional_owners" do
|
107
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
108
|
+
:object => "account",
|
109
|
+
:legal_entity => Stripe::StripeObject.construct_from({
|
110
|
+
}),
|
111
|
+
}, {})
|
112
|
+
obj.legal_entity.additional_owners = [
|
113
|
+
{ :first_name => "Joe" },
|
114
|
+
{ :first_name => "Jane" },
|
115
|
+
]
|
116
|
+
|
117
|
+
expected = {
|
118
|
+
:legal_entity => {
|
119
|
+
:additional_owners => {
|
120
|
+
"0" => { :first_name => "Joe" },
|
121
|
+
"1" => { :first_name => "Jane" },
|
122
|
+
}
|
123
|
+
}
|
219
124
|
}
|
220
|
-
|
221
|
-
|
125
|
+
assert_equal(expected, obj.serialize_params)
|
126
|
+
end
|
222
127
|
|
223
|
-
|
224
|
-
|
225
|
-
:
|
226
|
-
|
128
|
+
should "serialize on an partially changed additional_owners" do
|
129
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
130
|
+
:object => "account",
|
131
|
+
:legal_entity => {
|
132
|
+
:additional_owners => [
|
133
|
+
Stripe::StripeObject.construct_from({
|
134
|
+
:first_name => "Joe"
|
135
|
+
}),
|
136
|
+
Stripe::StripeObject.construct_from({
|
137
|
+
:first_name => "Jane"
|
138
|
+
}),
|
139
|
+
]
|
140
|
+
}
|
141
|
+
}, {})
|
142
|
+
obj.legal_entity.additional_owners[1].first_name = "Stripe"
|
143
|
+
|
144
|
+
expected = {
|
145
|
+
:legal_entity => {
|
146
|
+
:additional_owners => {
|
147
|
+
"1" => { :first_name => "Stripe" }
|
148
|
+
}
|
227
149
|
}
|
228
150
|
}
|
229
|
-
|
230
|
-
|
231
|
-
end
|
151
|
+
assert_equal(expected, obj.serialize_params)
|
152
|
+
end
|
232
153
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
154
|
+
should "serialize on an unchanged additional_owners" do
|
155
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
156
|
+
:object => "account",
|
157
|
+
:legal_entity => {
|
158
|
+
:additional_owners => [
|
159
|
+
Stripe::StripeObject.construct_from({
|
160
|
+
:first_name => "Joe"
|
161
|
+
}),
|
162
|
+
Stripe::StripeObject.construct_from({
|
163
|
+
:first_name => "Jane"
|
164
|
+
}),
|
165
|
+
]
|
166
|
+
}
|
167
|
+
}, {})
|
247
168
|
|
248
|
-
|
249
|
-
|
250
|
-
|
169
|
+
expected = {
|
170
|
+
:legal_entity => {
|
171
|
+
:additional_owners => {}
|
172
|
+
}
|
251
173
|
}
|
252
|
-
|
253
|
-
|
254
|
-
end
|
174
|
+
assert_equal(expected, obj.serialize_params)
|
175
|
+
end
|
255
176
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
177
|
+
# Note that the empty string that we send for this one has a special
|
178
|
+
# meaning for the server, which interprets it as an array unset.
|
179
|
+
should "serialize on an unset additional_owners" do
|
180
|
+
obj = Stripe::Util.convert_to_stripe_object({
|
181
|
+
:object => "account",
|
182
|
+
:legal_entity => {
|
183
|
+
:additional_owners => [
|
184
|
+
Stripe::StripeObject.construct_from({
|
185
|
+
:first_name => "Joe"
|
186
|
+
}),
|
187
|
+
Stripe::StripeObject.construct_from({
|
188
|
+
:first_name => "Jane"
|
189
|
+
}),
|
190
|
+
]
|
191
|
+
}
|
192
|
+
}, {})
|
193
|
+
obj.legal_entity.additional_owners = nil
|
273
194
|
|
274
|
-
|
275
|
-
|
276
|
-
|
195
|
+
expected = {
|
196
|
+
:legal_entity => {
|
197
|
+
:additional_owners => ""
|
198
|
+
}
|
277
199
|
}
|
278
|
-
|
279
|
-
assert_equal(expected, obj.serialize_params)
|
280
|
-
end
|
281
|
-
|
282
|
-
context "#bank_account=" do
|
283
|
-
should "warn that #bank_account= is deprecated" do
|
284
|
-
old_stderr = $stderr
|
285
|
-
$stderr = StringIO.new
|
286
|
-
begin
|
287
|
-
a = Stripe::Account.new("test_account")
|
288
|
-
a.bank_account = "tok_123"
|
289
|
-
message = "NOTE: Stripe::Account#bank_account= is " +
|
290
|
-
"deprecated; use #external_account= instead"
|
291
|
-
assert_match Regexp.new(message), $stderr.string
|
292
|
-
ensure
|
293
|
-
$stderr = old_stderr
|
294
|
-
end
|
200
|
+
assert_equal(expected, obj.serialize_params)
|
295
201
|
end
|
296
202
|
end
|
297
203
|
end
|