stripe 1.41.0 → 1.42.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f758a647e45ad29868db9a730a4242bc5c28d28c
4
- data.tar.gz: 5b9878c4db71d5d4f7690b2acc6e19cc9983b8ab
3
+ metadata.gz: d527e690f11344fa8621791ef6d1081060615be4
4
+ data.tar.gz: 4eb5cc04a3066b3b0fd41676c73e4dfc4d01d4db
5
5
  SHA512:
6
- metadata.gz: c3626353eec44fecf27536bfc52a311018ec5734669384baafe285fd64adf3e30c0f4b0e1b44efa19cee111d7bd1434fdf30169b5342d3070bea5d5267cf4b87
7
- data.tar.gz: 433941fb35789f121ab6518dcc3b2bf681ef75da67858bd42a85a649ca1818b8f80c31a91427dea4348ab59a8e1ea831c8208bc4ce16c50abde5d9c01499ab94
6
+ metadata.gz: 6c221fc569da0fa801dd6881aa782c907d20eff284539ca3851d30201d7d3b38704f64a038b65f0376391ed4fb53b651f8bfd707adf5ca92897e0e924de145e6
7
+ data.tar.gz: 865fa052fb613f85a6a3544c99579ee6a8b01146314ba794a7af1f486aff2f9e4713806b6d3a069bc102398ee63813b3e01edde6676e2975837a70b02ec5b962
@@ -1,3 +1,12 @@
1
+ === 1.42.0 2016-05-04
2
+
3
+ * Add support for the new /v1/subscriptions endpoint
4
+ * Stripe::Subscription.retrieve
5
+ * Stripe::Subscription.list
6
+ * Stripe::Subscription.create
7
+ * Stripe::Subscription.update
8
+ * Stripe::Subscription.delete
9
+
1
10
  === 1.41.0 2016-04-13
2
11
 
3
12
  * Add global `stripe_account` option that adds a `Stripe-Account` header to all requests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.41.0
1
+ 1.42.0
@@ -1,15 +1,9 @@
1
1
  module Stripe
2
2
  class Subscription < APIResource
3
+ extend Stripe::APIOperations::Create
3
4
  include Stripe::APIOperations::Update
4
5
  include Stripe::APIOperations::Delete
5
-
6
- def resource_url
7
- "#{Customer.resource_url}/#{CGI.escape(customer)}/subscriptions/#{CGI.escape(id)}"
8
- end
9
-
10
- def self.retrieve(id, opts=nil)
11
- raise NotImplementedError.new("Subscriptions cannot be retrieved without a customer ID. Retrieve a subscription using customer.subscriptions.retrieve('subscription_id')")
12
- end
6
+ extend Stripe::APIOperations::List
13
7
 
14
8
  def delete_discount
15
9
  _, opts = request(:delete, discount_url)
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.41.0'
2
+ VERSION = '1.42.0'
3
3
  end
@@ -2,71 +2,114 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class SubscriptionTest < Test::Unit::TestCase
5
- should "subscriptions should be listable" do
5
+ should "subscriptions should be retrievable by customer" do
6
+ @mock.expects(:get).once.returns(make_response(make_customer))
7
+ customer = Stripe::Customer.retrieve('c_test_customer')
8
+
9
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/s_test_subscription", nil, nil).returns(make_response(make_subscription(:id => 's_test_subscription')))
10
+ subscription = customer.subscriptions.retrieve('s_test_subscription')
11
+ end
12
+
13
+ should "subscriptions should be listable by customer" do
14
+ @mock.expects(:get).once.returns(make_response(make_customer))
15
+ customer = Stripe::Customer.retrieve('c_test_customer')
16
+
17
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions", nil, nil).returns(make_response(make_customer_subscription_array('c_test_customer')))
18
+ subs = customer.subscriptions.all()
19
+
20
+ assert subs.kind_of? (Stripe::ListObject)
21
+ assert subs.data.kind_of?(Array)
22
+ assert subs.data[0].kind_of? Stripe::Subscription
23
+ end
24
+
25
+ should "subscriptions should be creatable by customer" do
6
26
  @mock.expects(:get).once.returns(make_response(make_customer))
27
+ customer = Stripe::Customer.retrieve('c_test_customer')
28
+
29
+ @mock.expects(:post).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions", nil, 'plan=silver').returns(make_response(make_subscription(:id => 'test_new_subscription')))
30
+ subscription = customer.subscriptions.create(:plan => 'silver')
31
+
32
+ assert_equal 'test_new_subscription', subscription.id
33
+ end
34
+
35
+ should "subscriptions should be retrievable" do
36
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/subscriptions/s_test_subscription", nil, nil).returns(make_response(make_subscription))
37
+ sub = Stripe::Subscription.retrieve('s_test_subscription')
7
38
 
8
- customer = Stripe::Customer.retrieve('test_customer')
39
+ assert sub.kind_of?(Stripe::Subscription)
40
+ end
41
+
42
+ should "subscriptions should be listable" do
43
+ @mock.expects(:get).once.returns(make_response(make_subscription_array))
44
+ subs = Stripe::Subscription.list.data
45
+
46
+ assert subs.kind_of? Array
47
+ assert subs[0].kind_of? Stripe::Subscription
48
+ end
49
+
50
+ should "subscriptions should be listable with filters" do
51
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/subscriptions?customer=c_test_customer&limit=3&plan=gold", nil, nil).returns(make_response(make_subscription_array))
52
+ subs = Stripe::Subscription.all(:customer => 'c_test_customer', :limit => 3, :plan => 'gold')
9
53
 
10
- assert customer.subscriptions.first.kind_of?(Stripe::Subscription)
54
+ assert subs.kind_of? (Stripe::ListObject)
55
+ assert subs.data.kind_of?(Array)
56
+ assert subs.data[0].kind_of? Stripe::Subscription
11
57
  end
12
58
 
13
59
  should "subscriptions should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_customer), make_response(make_subscription(:id => 'refreshed_subscription')))
60
+ @mock.expects(:get).twice.returns(make_response(make_subscription(:id => 'refreshed_subscription')))
15
61
 
16
- customer = Stripe::Customer.retrieve('test_customer')
17
- subscription = customer.subscriptions.first
18
- subscription.refresh
62
+ sub = Stripe::Subscription.retrieve('s_test_subscription')
63
+ sub.refresh
19
64
 
20
- assert_equal 'refreshed_subscription', subscription.id
65
+ assert_equal 'refreshed_subscription', sub.id
21
66
  end
22
67
 
23
68
  should "subscriptions should be deletable" do
24
- @mock.expects(:get).once.returns(make_response(make_customer))
25
- customer = Stripe::Customer.retrieve('test_customer')
26
- subscription = customer.subscriptions.first
69
+ @mock.expects(:get).once.returns(make_response(make_subscription))
70
+ sub = Stripe::Subscription.retrieve('s_test_subscription')
27
71
 
28
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}?at_period_end=true", nil, nil).returns(make_response(make_subscription))
29
- subscription.delete :at_period_end => true
72
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/subscriptions/#{sub.id}?at_period_end=true", nil, nil).returns(make_response(make_subscription))
73
+ sub.delete :at_period_end => true
30
74
 
31
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}", nil, nil).returns(make_response(make_subscription))
32
- subscription.delete
75
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/subscriptions/#{sub.id}", nil, nil).returns(make_response(make_subscription))
76
+ sub.delete
33
77
  end
34
78
 
35
79
  should "subscriptions should be updateable" do
36
- @mock.expects(:get).once.returns(make_response(make_customer))
37
- @mock.expects(:post).once.returns(make_response(make_subscription({:status => 'active'})))
80
+ @mock.expects(:get).once.returns(make_response(make_subscription))
81
+ sub = Stripe::Subscription.retrieve('s_test_subscription')
82
+ assert_equal 'trialing', sub.status
38
83
 
39
- customer = Stripe::Customer.retrieve('test_customer')
40
- subscription = customer.subscriptions.first
41
- assert_equal 'trialing', subscription.status
84
+ @mock.expects(:post).once.with do |url, api_key, params|
85
+ url == "#{Stripe.api_base}/v1/subscriptions/#{sub.id}" && api_key.nil? && CGI.parse(params) == {'status' => ['active']}
86
+ end.returns(make_response(make_subscription(:status => 'active')))
42
87
 
43
- subscription.status = 'active'
44
- subscription.save
88
+ sub.status = 'active'
89
+ sub.save
45
90
 
46
- assert_equal 'active', subscription.status
91
+ assert_equal 'active', sub.status
47
92
  end
48
93
 
49
94
  should "create should return a new subscription" do
50
- @mock.expects(:get).once.returns(make_response(make_customer))
51
- @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
95
+ @mock.expects(:post).once.with do |url, api_key, params|
96
+ url == "#{Stripe.api_base}/v1/subscriptions" && api_key.nil? && CGI.parse(params) == {'customer' => ['c_test_customer'], 'plan' => ['gold']}
97
+ end.returns(make_response(make_subscription(:plan => 'gold', :id => 'test_new_subscription')))
52
98
 
53
- customer = Stripe::Customer.retrieve('test_customer')
54
- subscription = customer.subscriptions.create(:plan => 'silver')
55
- assert_equal 'test_new_subscription', subscription.id
99
+ sub = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer')
100
+
101
+ assert_equal 'test_new_subscription', sub.id
102
+ assert_equal 'gold', sub.plan.identifier
56
103
  end
57
104
 
58
105
  should "be able to delete a subscriptions's discount" do
59
- @mock.expects(:get).once.returns(make_response(make_customer))
60
- @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
61
-
62
-
63
- customer = Stripe::Customer.retrieve('test_customer')
64
- subscription = customer.subscriptions.create(:plan => 'silver')
106
+ @mock.expects(:post).once.returns(make_response(make_subscription))
107
+ sub = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer', coupon: 'forever')
65
108
 
66
- url = "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/test_new_subscription/discount"
109
+ url = "#{Stripe.api_base}/v1/subscriptions/#{sub.id}/discount"
67
110
  @mock.expects(:delete).once.with(url, nil, nil).returns(make_response(make_delete_discount_response))
68
- subscription.delete_discount
69
- assert_equal nil, subscription.discount
111
+ sub.delete_discount
112
+ assert_equal nil, sub.discount
70
113
  end
71
114
  end
72
115
  end
@@ -118,7 +118,7 @@ module Stripe
118
118
  :created => 1304114758,
119
119
  :sources => make_customer_card_array(id),
120
120
  :metadata => {},
121
- :subscriptions => make_subscription_array(id)
121
+ :subscriptions => make_customer_subscription_array(id)
122
122
  }.merge(params)
123
123
  end
124
124
 
@@ -289,7 +289,15 @@ module Stripe
289
289
  }.merge(params)
290
290
  end
291
291
 
292
- def make_subscription_array(customer_id)
292
+ def make_subscription_array
293
+ {
294
+ :data => [make_subscription, make_subscription, make_subscription],
295
+ :object => 'list',
296
+ :resource_url => '/v1/subscriptions'
297
+ }
298
+ end
299
+
300
+ def make_customer_subscription_array(customer_id)
293
301
  {
294
302
  :data => [make_subscription, make_subscription, make_subscription],
295
303
  :object => 'list',
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.41.0
4
+ version: 1.42.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-13 00:00:00.000000000 Z
12
+ date: 2016-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client