stripe 1.40.0 → 1.41.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df8595ba1c8112e53a16598f41277d6fe8e0f120
4
- data.tar.gz: c4511690653728df59c9e060ed1e01967fdd8e4e
3
+ metadata.gz: f758a647e45ad29868db9a730a4242bc5c28d28c
4
+ data.tar.gz: 5b9878c4db71d5d4f7690b2acc6e19cc9983b8ab
5
5
  SHA512:
6
- metadata.gz: abab2102477a032ee062eade9b36b4a99a2704c5e831d7e43d9500ca63e7d6bd800dd256ec6ee3525d585cde3b2da3244326a9c134e28125eb879ee65e30cd8a
7
- data.tar.gz: 725cb8e7ac1c6899311a750a90b905451340b41f34ed5a737d420d20108791366beb7f475d384760497c2345a8a6b622b1e23c9472fbc18bc1c7b03a6b91ce96
6
+ metadata.gz: c3626353eec44fecf27536bfc52a311018ec5734669384baafe285fd64adf3e30c0f4b0e1b44efa19cee111d7bd1434fdf30169b5342d3070bea5d5267cf4b87
7
+ data.tar.gz: 433941fb35789f121ab6518dcc3b2bf681ef75da67858bd42a85a649ca1818b8f80c31a91427dea4348ab59a8e1ea831c8208bc4ce16c50abde5d9c01499ab94
@@ -1,3 +1,7 @@
1
+ === 1.41.0 2016-04-13
2
+
3
+ * Add global `stripe_account` option that adds a `Stripe-Account` header to all requests
4
+
1
5
  === 1.40.0 2016-04-06
2
6
 
3
7
  * Fix bug that omitted subresources from serialization
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.40.0
1
+ 1.41.0
@@ -82,7 +82,7 @@ module Stripe
82
82
  @read_timeout = 80
83
83
 
84
84
  class << self
85
- attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base,
85
+ attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base,
86
86
  :open_timeout, :read_timeout
87
87
 
88
88
  attr_reader :max_network_retry_delay, :initial_network_retry_delay
@@ -208,7 +208,7 @@ module Stripe
208
208
  else
209
209
  response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
210
210
  end
211
- rescue RestClient::Exception, Errno::ECONNREFUSED => e
211
+ rescue RestClient::Exception, Errno::ECONNREFUSED, OpenSSL::SSL::SSLError => e
212
212
  response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
213
213
  end
214
214
 
@@ -278,10 +278,11 @@ module Stripe
278
278
  # It is only safe to retry network failures on post and delete
279
279
  # requests if we add an Idempotency-Key header
280
280
  if [:post, :delete].include?(method) && self.max_network_retries > 0
281
- headers[:idempotency_key] ||= SecureRandom.uuid
281
+ headers[:idempotency_key] ||= SecureRandom.uuid
282
282
  end
283
283
 
284
284
  headers[:stripe_version] = api_version if api_version
285
+ headers[:stripe_account] = stripe_account if stripe_account
285
286
 
286
287
  begin
287
288
  headers.update(:x_stripe_client_user_agent => JSON.generate(user_agent))
@@ -384,6 +385,12 @@ module Stripe
384
385
  message = "The connection to the server (#{api_base_url}) broke before the " \
385
386
  "request completed. #{connection_message}"
386
387
 
388
+ when OpenSSL::SSL::SSLError
389
+ message = "Could not establish a secure connection to Stripe, you may " \
390
+ "need to upgrade your OpenSSL version. To check, try running " \
391
+ "'openssl s_client -connect api.stripe.com:443' from the " \
392
+ "command line."
393
+
387
394
  when RestClient::SSLCertificateNotVerified
388
395
  message = "Could not verify Stripe's SSL certificate. " \
389
396
  "Please make sure that your network is not intercepting certificates. " \
@@ -3,7 +3,6 @@ module Stripe
3
3
  module List
4
4
  def list(filters={}, opts={})
5
5
  opts = Util.normalize_opts(opts)
6
- opts = @opts.merge(opts) if @opts
7
6
 
8
7
  response, opts = request(:get, resource_url, filters, opts)
9
8
  obj = ListObject.construct_from(response, opts)
@@ -13,7 +13,7 @@ module Stripe
13
13
  # an `Array` and fall back to the old refund URL if necessary so as to
14
14
  # maintain internal compatibility.
15
15
  unless self.refunds.is_a?(Array)
16
- refund = self.refunds.create(params, opts)
16
+ self.refunds.create(params, opts)
17
17
 
18
18
  # now that a refund has been created, we expect the state of this object
19
19
  # to change as well (i.e. `refunded` will now be `true`) so refresh it
@@ -32,7 +32,7 @@ module Stripe
32
32
  # considered to be equal if they have the same set of values and each one
33
33
  # of those values is the same.
34
34
  def ==(other)
35
- @values == other.instance_variable_get(:@values)
35
+ other.is_a?(StripeObject) && @values == other.instance_variable_get(:@values)
36
36
  end
37
37
 
38
38
  # Indicates whether or not the resource has been deleted on the server.
@@ -12,7 +12,7 @@ module Stripe
12
12
  end
13
13
 
14
14
  def delete_discount
15
- response, opts = request(:delete, discount_url)
15
+ _, opts = request(:delete, discount_url)
16
16
  initialize_from({ :discount => nil }, opts, true)
17
17
  end
18
18
 
@@ -5,7 +5,7 @@ module Stripe
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  def cancel
8
- response, api_key = Stripe.request(:post, cancel_url, @api_key)
8
+ response, api_key = self.request(:post, cancel_url)
9
9
  initialize_from(response, api_key)
10
10
  end
11
11
 
@@ -120,7 +120,7 @@ module Stripe
120
120
 
121
121
  # do not sort the final output because arrays (and arrays of hashes
122
122
  # especially) can be order sensitive, but do sort incoming parameters
123
- params.sort_by { |(k, v)| k.to_s }.each do |key, value|
123
+ params.sort_by { |(k, _)| k.to_s }.each do |key, value|
124
124
  calculated_key = parent_key ? "#{parent_key}[#{key}]" : "#{key}"
125
125
  if value.is_a?(Hash)
126
126
  result += flatten_params(value, calculated_key)
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.40.0'
2
+ VERSION = '1.41.0'
3
3
  end
@@ -445,7 +445,7 @@ module Stripe
445
445
  opts[:url] == "#{Stripe.api_base}/v1/customers/c_test_customer" &&
446
446
  opts[:headers][:stripe_account] == 'acct_abc'
447
447
  end.once.returns(make_response(make_customer))
448
- c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
448
+ Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
449
449
  end
450
450
 
451
451
  should "passing in a stripe_account header should pass it through on save" do
@@ -695,6 +695,19 @@ module Stripe
695
695
  assert_equal "myid", result.id
696
696
  end
697
697
 
698
+ # We retry the request if we receive SSL errors, since these can be caused
699
+ # by transient network issues, in addition to compatibility issues between
700
+ # the client and server.
701
+ should 'retry failed network requests if they fail with OpenSSL::SSL::SSLError' do
702
+ Stripe.expects(:sleep_time).at_least_once.returns(0)
703
+ @mock.expects(:post).times(3).with('https://api.stripe.com/v1/charges', nil, 'amount=50&currency=usd').raises(OpenSSL::SSL::SSLError.new('message'))
704
+
705
+ err = assert_raises Stripe::APIConnectionError do
706
+ Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
707
+ end
708
+ assert_match(/Request was retried 2 times/, err.message)
709
+ end
710
+
698
711
  should 'not retry a SSLCertificateNotVerified error' do
699
712
  @mock.expects(:post).times(1).with('https://api.stripe.com/v1/charges', nil, 'amount=50&currency=usd').raises(RestClient::SSLCertificateNotVerified.new('message'))
700
713
 
@@ -47,14 +47,14 @@ module Stripe
47
47
  should "delete a bitcoin receiver with no customer through top-level API" do
48
48
  @mock.expects(:delete).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
49
49
  receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
50
- response = receiver.delete
50
+ receiver.delete
51
51
  assert(receiver.deleted)
52
52
  end
53
53
 
54
54
  should "delete a bitcoin receiver with a customer through customer's subresource API" do
55
55
  @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/customer_foo/sources/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
56
56
  receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver(:customer => 'customer_foo'))
57
- response = receiver.delete
57
+ receiver.delete
58
58
  assert(receiver.deleted)
59
59
  end
60
60
  end
@@ -72,6 +72,12 @@ module Stripe
72
72
  assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
73
73
  end
74
74
 
75
+ should "charges should have Outcome objects associated with their outcome property" do
76
+ @mock.expects(:get).once.returns(make_response(make_charge))
77
+ c = Stripe::Charge.retrieve("test_charge")
78
+ assert c.outcome.kind_of?(Stripe::StripeObject) && c.outcome.type == 'authorized'
79
+ end
80
+
75
81
  should "execute should return a new, fully executed charge when passed correct `card` parameters" do
76
82
  @mock.expects(:post).with do |url, api_key, params|
77
83
  url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
@@ -283,7 +283,7 @@ module Stripe
283
283
  e = assert_raises ArgumentError do
284
284
  obj.foo = ""
285
285
  end
286
- assert_match /\(object\).foo = nil/, e.message
286
+ assert_match %r{\(object\).foo = nil}, e.message
287
287
  end
288
288
  end
289
289
  end
@@ -33,4 +33,19 @@ class StripeTest < Test::Unit::TestCase
33
33
  Stripe.max_network_retries = old
34
34
  end
35
35
  end
36
+
37
+ should "makes requests with the Stripe-Account header" do
38
+ response = make_account(
39
+ charges_enabled: false,
40
+ details_submitted: false,
41
+ email: "test+bindings@stripe.com"
42
+ )
43
+ Stripe.stripe_account = 'acct_1234'
44
+
45
+ Stripe.expects(:execute_request).with(
46
+ has_entry(:headers, has_entry(:stripe_account, 'acct_1234')),
47
+ ).returns(make_response(response))
48
+
49
+ Stripe.request(:post, '/v1/account', 'sk_live12334566')
50
+ end
36
51
  end
@@ -152,7 +152,13 @@ module Stripe
152
152
  :object => "charge",
153
153
  :created => 1304114826,
154
154
  :refunds => make_refund_array(id),
155
- :metadata => {}
155
+ :metadata => {},
156
+ :outcome => {
157
+ type: 'authorized',
158
+ reason: nil,
159
+ seller_message: 'Payment complete.',
160
+ network_status: 'approved_by_network',
161
+ },
156
162
  }.merge(params)
157
163
  end
158
164
 
@@ -13,6 +13,10 @@ module Stripe
13
13
  @mock_rest_client = mock_client
14
14
  end
15
15
 
16
+ class << self
17
+ remove_method :execute_request
18
+ end
19
+
16
20
  def self.execute_request(opts)
17
21
  get_params = (opts[:headers] || {})[:params]
18
22
  post_params = opts[:payload]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.40.0
4
+ version: 1.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Boucher
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-06 00:00:00.000000000 Z
12
+ date: 2016-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client