stripe 1.16.1 → 1.17.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
5
6
  gem 'rest-client', '~> 1.6.8'
6
7
  gem 'activesupport', '~> 3.2'
7
8
  end
@@ -1,3 +1,15 @@
1
+ === 1.17.1 2015-01-07
2
+
3
+ * 2 minor enhacements:
4
+ * Fixed dependencies for Ruby versions less than 1.9.3
5
+ * Added deauthorize method to Account object
6
+
7
+ === 1.17.0 2014-12-15
8
+
9
+ * 1 major enhacement:
10
+ * File uploads resource was added (for uploading pdf or image documents for
11
+ disputes)
12
+
1
13
  === 1.16.1 2014-12-19
2
14
 
3
15
  * 2 minor enhancements:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.16.1
1
+ 1.17.1
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
3
 
4
4
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
5
6
  gem 'rest-client', '~> 1.6.8'
6
7
  gem 'activesupport', '~> 3.2'
7
8
  else
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
3
 
4
4
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
5
6
  gem 'rest-client', '~> 1.6.8'
6
7
  gem 'activesupport', '~> 3.2'
7
8
  else
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
3
 
4
4
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
5
6
  gem 'rest-client', '~> 1.6.8'
6
7
  gem 'activesupport', '~> 3.2'
7
8
  else
@@ -30,6 +30,7 @@ require 'stripe/invoice'
30
30
  require 'stripe/invoice_item'
31
31
  require 'stripe/charge'
32
32
  require 'stripe/plan'
33
+ require 'stripe/file_upload'
33
34
  require 'stripe/coupon'
34
35
  require 'stripe/token'
35
36
  require 'stripe/event'
@@ -52,6 +53,7 @@ require 'stripe/errors/authentication_error'
52
53
  module Stripe
53
54
  DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data/ca-certificates.crt'
54
55
  @api_base = 'https://api.stripe.com'
56
+ @connect_base = 'https://connect.stripe.com'
55
57
 
56
58
  @ssl_bundle_path = DEFAULT_CA_BUNDLE_PATH
57
59
  @verify_ssl_certs = true
@@ -59,14 +61,16 @@ module Stripe
59
61
 
60
62
 
61
63
  class << self
62
- attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version
64
+ attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base
63
65
  end
64
66
 
65
- def self.api_url(url='')
66
- @api_base + url
67
+ def self.api_url(url='', api_base_url=nil)
68
+ (api_base_url || @api_base) + url
67
69
  end
68
70
 
69
- def self.request(method, url, api_key, params={}, headers={})
71
+ def self.request(method, url, api_key, params={}, headers={}, api_base_url=nil)
72
+ api_base_url = api_base_url || @api_base
73
+
70
74
  unless api_key ||= @api_key
71
75
  raise AuthenticationError.new('No API key provided. ' +
72
76
  'Set your API key using "Stripe.api_key = <API-KEY>". ' +
@@ -90,11 +94,11 @@ module Stripe
90
94
  end
91
95
 
92
96
  if @verify_ssl_certs and !@CERTIFICATE_VERIFIED
93
- @CERTIFICATE_VERIFIED = CertificateBlacklist.check_ssl_cert(@api_base, @ssl_bundle_path)
97
+ @CERTIFICATE_VERIFIED = CertificateBlacklist.check_ssl_cert(api_base_url, @ssl_bundle_path)
94
98
  end
95
99
 
96
100
  params = Util.objects_to_ids(params)
97
- url = api_url(url)
101
+ url = api_url(url, api_base_url)
98
102
 
99
103
  case method.to_s.downcase.to_sym
100
104
  when :get, :head, :delete
@@ -102,7 +106,11 @@ module Stripe
102
106
  url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
103
107
  payload = nil
104
108
  else
105
- payload = uri_encode(params)
109
+ if headers[:content_type] && headers[:content_type] == "multipart/form-data"
110
+ payload = params
111
+ else
112
+ payload = uri_encode(params)
113
+ end
106
114
  end
107
115
 
108
116
  request_opts.update(:headers => request_headers(api_key).update(headers),
@@ -112,12 +120,12 @@ module Stripe
112
120
  begin
113
121
  response = execute_request(request_opts)
114
122
  rescue SocketError => e
115
- handle_restclient_error(e)
123
+ handle_restclient_error(e, api_base_url)
116
124
  rescue NoMethodError => e
117
125
  # Work around RestClient bug
118
126
  if e.message =~ /\WRequestFailed\W/
119
127
  e = APIConnectionError.new('Unexpected HTTP response code')
120
- handle_restclient_error(e)
128
+ handle_restclient_error(e, api_base_url)
121
129
  else
122
130
  raise
123
131
  end
@@ -125,10 +133,10 @@ module Stripe
125
133
  if rcode = e.http_code and rbody = e.http_body
126
134
  handle_api_error(rcode, rbody)
127
135
  else
128
- handle_restclient_error(e)
136
+ handle_restclient_error(e, api_base_url)
129
137
  end
130
138
  rescue RestClient::Exception, Errno::ECONNREFUSED => e
131
- handle_restclient_error(e)
139
+ handle_restclient_error(e, api_base_url)
132
140
  end
133
141
 
134
142
  [parse(response), api_key]
@@ -258,17 +266,18 @@ module Stripe
258
266
  APIError.new(error[:message], rcode, rbody, error_obj)
259
267
  end
260
268
 
261
- def self.handle_restclient_error(e)
269
+ def self.handle_restclient_error(e, api_base_url=nil)
270
+ api_base_url = @api_base unless api_base_url
262
271
  connection_message = "Please check your internet connection and try again. " \
263
272
  "If this problem persists, you should check Stripe's service status at " \
264
273
  "https://twitter.com/stripestatus, or let us know at support@stripe.com."
265
274
 
266
275
  case e
267
276
  when RestClient::RequestTimeout
268
- message = "Could not connect to Stripe (#{@api_base}). #{connection_message}"
277
+ message = "Could not connect to Stripe (#{api_base_url}). #{connection_message}"
269
278
 
270
279
  when RestClient::ServerBrokeConnection
271
- message = "The connection to the server (#{@api_base}) broke before the " \
280
+ message = "The connection to the server (#{api_base_url}) broke before the " \
272
281
  "request completed. #{connection_message}"
273
282
 
274
283
  when RestClient::SSLCertificateNotVerified
@@ -1,4 +1,9 @@
1
1
  module Stripe
2
2
  class Account < SingletonAPIResource
3
+ def deauthorize(client_id, opts={})
4
+ api_key, headers = Util.parse_opts(opts)
5
+ response, api_key = Stripe.request(:post, '/oauth/deauthorize', api_key, { 'client_id' => client_id, 'stripe_user_id' => self.id }, headers, Stripe.connect_base)
6
+ Util.convert_to_stripe_object(response, api_key)
7
+ end
3
8
  end
4
9
  end
@@ -0,0 +1,27 @@
1
+ module Stripe
2
+ class FileUpload < APIResource
3
+ UPLOADS_API_BASE = "https://uploads.stripe.com"
4
+
5
+ def self.url
6
+ "/v1/files"
7
+ end
8
+
9
+ def self.request_headers
10
+ {
11
+ :content_type => 'multipart/form-data',
12
+ }
13
+ end
14
+
15
+ def self.create(params={}, api_key=nil)
16
+ response, api_key = Stripe.request(
17
+ :post, self.url, api_key, params, self.request_headers, UPLOADS_API_BASE)
18
+ Util.convert_to_stripe_object(response, api_key)
19
+ end
20
+
21
+ def refresh
22
+ response, api_key = Stripe.request(
23
+ :get, url, @api_key, @retrieve_options, self.class.request_headers, UPLOADS_API_BASE)
24
+ refresh_from(response, api_key)
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.16.1'
2
+ VERSION = '1.17.1'
3
3
  end
@@ -10,5 +10,17 @@ module Stripe
10
10
  assert !a.charge_enabled
11
11
  assert !a.details_submitted
12
12
  end
13
+
14
+ should "be able to deauthorize an account" do
15
+ resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
16
+ @mock.expects(:get).once.returns(test_response(resp))
17
+ a = Stripe::Account.retrieve
18
+
19
+
20
+ @mock.expects(:post).once.with do |url, api_key, params|
21
+ url == "#{Stripe.connect_base}/oauth/deauthorize" && api_key.nil? && CGI.parse(params) == { 'client_id' => [ 'ca_1234' ], 'stripe_user_id' => [ a.id ]}
22
+ end.returns(test_response({ 'stripe_user_id' => a.id }))
23
+ a.deauthorize('ca_1234', 'sk_test_1234')
24
+ end
13
25
  end
14
- end
26
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class FileUploadTest < Test::Unit::TestCase
5
+ should "create should return a new file" do
6
+ @mock.expects(:post).once.returns(test_response(test_file))
7
+ f = Stripe::FileUpload.create({
8
+ :purpose => "dispute_evidence",
9
+ :file => File.new(__FILE__),
10
+ })
11
+ assert_equal "fil_test_file", f.id
12
+ end
13
+
14
+ should "files should be retrievable" do
15
+ @mock.expects(:get).once.returns(test_response(test_file))
16
+ c = Stripe::FileUpload.new("fil_test_file")
17
+ c.refresh
18
+ assert_equal 1403047735, c.created
19
+ end
20
+ end
21
+ end
@@ -183,6 +183,17 @@ module Stripe
183
183
  }.merge(params)
184
184
  end
185
185
 
186
+ def test_file(params={})
187
+ {
188
+ :id => "fil_test_file",
189
+ :created => 1403047735,
190
+ :size => 4908,
191
+ :purpose => params[:purpose] || "dispute_evidence",
192
+ :url => nil,
193
+ :mimetype => nil,
194
+ }
195
+ end
196
+
186
197
  #FIXME nested overrides would be better than hardcoding plan_id
187
198
  def test_subscription(params = {})
188
199
  plan = params.delete(:plan) || 'gold'
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.16.1
4
+ version: 1.17.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-12-20 00:00:00.000000000 Z
13
+ date: 2015-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -177,6 +177,7 @@ files:
177
177
  - lib/stripe/errors/invalid_request_error.rb
178
178
  - lib/stripe/errors/stripe_error.rb
179
179
  - lib/stripe/event.rb
180
+ - lib/stripe/file_upload.rb
180
181
  - lib/stripe/invoice.rb
181
182
  - lib/stripe/invoice_item.rb
182
183
  - lib/stripe/list_object.rb
@@ -200,6 +201,7 @@ files:
200
201
  - test/stripe/coupon_test.rb
201
202
  - test/stripe/customer_card_test.rb
202
203
  - test/stripe/customer_test.rb
204
+ - test/stripe/file_upload_test.rb
203
205
  - test/stripe/invoice_test.rb
204
206
  - test/stripe/list_object_test.rb
205
207
  - test/stripe/metadata_test.rb
@@ -246,6 +248,7 @@ test_files:
246
248
  - test/stripe/coupon_test.rb
247
249
  - test/stripe/customer_card_test.rb
248
250
  - test/stripe/customer_test.rb
251
+ - test/stripe/file_upload_test.rb
249
252
  - test/stripe/invoice_test.rb
250
253
  - test/stripe/list_object_test.rb
251
254
  - test/stripe/metadata_test.rb