stripe 1.58.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.travis.yml +1 -2
  4. data/Gemfile +11 -12
  5. data/History.txt +8 -0
  6. data/README.md +44 -31
  7. data/Rakefile +1 -1
  8. data/VERSION +1 -1
  9. data/lib/stripe.rb +4 -344
  10. data/lib/stripe/account.rb +4 -4
  11. data/lib/stripe/api_operations/create.rb +2 -2
  12. data/lib/stripe/api_operations/delete.rb +2 -2
  13. data/lib/stripe/api_operations/list.rb +2 -2
  14. data/lib/stripe/api_operations/request.rb +9 -3
  15. data/lib/stripe/api_operations/save.rb +4 -6
  16. data/lib/stripe/api_resource.rb +2 -2
  17. data/lib/stripe/bank_account.rb +2 -2
  18. data/lib/stripe/bitcoin_receiver.rb +1 -1
  19. data/lib/stripe/charge.rb +12 -12
  20. data/lib/stripe/customer.rb +6 -6
  21. data/lib/stripe/dispute.rb +2 -3
  22. data/lib/stripe/errors.rb +20 -10
  23. data/lib/stripe/invoice.rb +4 -4
  24. data/lib/stripe/list_object.rb +2 -2
  25. data/lib/stripe/order.rb +4 -4
  26. data/lib/stripe/reversal.rb +1 -1
  27. data/lib/stripe/source.rb +2 -2
  28. data/lib/stripe/stripe_client.rb +396 -0
  29. data/lib/stripe/stripe_response.rb +48 -0
  30. data/lib/stripe/transfer.rb +2 -2
  31. data/lib/stripe/util.rb +6 -6
  32. data/lib/stripe/version.rb +1 -1
  33. data/spec/fixtures.json +0 -0
  34. data/spec/fixtures.yaml +0 -0
  35. data/spec/spec.json +0 -0
  36. data/spec/spec.yaml +0 -0
  37. data/stripe.gemspec +1 -1
  38. data/test/api_fixtures.rb +29 -0
  39. data/test/api_stub_helpers.rb +125 -0
  40. data/test/stripe/account_test.rb +153 -247
  41. data/test/stripe/alipay_account_test.rb +10 -2
  42. data/test/stripe/api_operations_test.rb +3 -3
  43. data/test/stripe/api_resource_test.rb +139 -499
  44. data/test/stripe/apple_pay_domain_test.rb +22 -23
  45. data/test/stripe/application_fee_refund_test.rb +22 -31
  46. data/test/stripe/application_fee_test.rb +6 -17
  47. data/test/stripe/balance_test.rb +3 -3
  48. data/test/stripe/bank_account_test.rb +31 -11
  49. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  50. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  51. data/test/stripe/charge_test.rb +39 -126
  52. data/test/stripe/country_spec_test.rb +7 -30
  53. data/test/stripe/coupon_test.rb +33 -17
  54. data/test/stripe/customer_card_test.rb +25 -46
  55. data/test/stripe/customer_test.rb +86 -81
  56. data/test/stripe/dispute_test.rb +27 -38
  57. data/test/stripe/errors_test.rb +2 -2
  58. data/test/stripe/file_upload_test.rb +32 -24
  59. data/test/stripe/invoice_item_test.rb +46 -10
  60. data/test/stripe/invoice_test.rb +48 -48
  61. data/test/stripe/list_object_test.rb +22 -31
  62. data/test/stripe/order_return_test.rb +11 -15
  63. data/test/stripe/order_test.rb +38 -51
  64. data/test/stripe/plan_test.rb +39 -18
  65. data/test/stripe/product_test.rb +29 -33
  66. data/test/stripe/recipient_card_test.rb +23 -40
  67. data/test/stripe/recipient_test.rb +39 -10
  68. data/test/stripe/refund_test.rb +20 -45
  69. data/test/stripe/reversal_test.rb +27 -31
  70. data/test/stripe/sku_test.rb +36 -19
  71. data/test/stripe/source_test.rb +26 -66
  72. data/test/stripe/stripe_client_test.rb +428 -0
  73. data/test/stripe/stripe_object_test.rb +6 -2
  74. data/test/stripe/stripe_response_test.rb +46 -0
  75. data/test/stripe/subscription_item_test.rb +37 -59
  76. data/test/stripe/subscription_test.rb +40 -176
  77. data/test/stripe/three_d_secure_test.rb +13 -12
  78. data/test/stripe/transfer_test.rb +36 -19
  79. data/test/stripe_test.rb +3 -36
  80. data/test/test_data.rb +5 -931
  81. data/test/test_helper.rb +21 -25
  82. metadata +22 -17
  83. data/test/stripe/charge_refund_test.rb +0 -67
  84. data/test/stripe/metadata_test.rb +0 -129
@@ -116,9 +116,13 @@ module Stripe
116
116
 
117
117
  # customer comes with a `sources` list that makes a convenient object to
118
118
  # perform tests on
119
- customer = Stripe::Customer.construct_from(make_customer, opts)
119
+ obj = Stripe::StripeObject.construct_from({
120
+ sources: [
121
+ {}
122
+ ]
123
+ }, opts)
120
124
 
121
- source = customer.sources.first
125
+ source = obj.sources.first
122
126
  # Pulling `@opts` as an instance variable here is not ideal, but it's
123
127
  # important enough argument that the test here is worth it. we should
124
128
  # consider exposing it publicly on a future pull (and possibly renaming
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class StripeResponseTest < Test::Unit::TestCase
5
+ context ".from_faraday_hash" do
6
+ should "converts to StripeResponse" do
7
+ body = '{"foo": "bar"}'
8
+ headers = { "Request-Id" => "request-id" }
9
+
10
+ http_resp = {
11
+ body: body,
12
+ headers: headers,
13
+ status: 200,
14
+ }
15
+
16
+ resp = StripeResponse.from_faraday_hash(http_resp)
17
+
18
+ assert_equal JSON.parse(body, symbolize_names: true), resp.data
19
+ assert_equal body, resp.http_body
20
+ assert_equal headers, resp.http_headers
21
+ assert_equal 200, resp.http_status
22
+ assert_equal "request-id", resp.request_id
23
+ end
24
+ end
25
+
26
+ context ".from_faraday_response" do
27
+ should "converts to StripeResponse" do
28
+ body = '{"foo": "bar"}'
29
+ headers = { "Request-Id" => "request-id" }
30
+
31
+ env = Faraday::Env.from(
32
+ :status => 200, :body => body,
33
+ :response_headers => headers)
34
+ http_resp = Faraday::Response.new(env)
35
+
36
+ resp = StripeResponse.from_faraday_response(http_resp)
37
+
38
+ assert_equal JSON.parse(body, symbolize_names: true), resp.data
39
+ assert_equal body, resp.http_body
40
+ assert_equal headers, resp.http_headers
41
+ assert_equal 200, resp.http_status
42
+ assert_equal "request-id", resp.request_id
43
+ end
44
+ end
45
+ end
46
+ end
@@ -2,75 +2,53 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class SubscriptionItemTest < Test::Unit::TestCase
5
- should "subscription items should be retrievable" do
6
- @mock.expects(:get).once.with("#{Stripe.api_base}/v1/subscription_items/si_test_subscription_item", nil, nil).
7
- returns(make_response(make_subscription_item))
8
-
9
- sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
10
-
11
- assert sub_item.kind_of?(Stripe::SubscriptionItem)
5
+ FIXTURE = API_FIXTURES.fetch(:subscription_item)
6
+
7
+ should "be listable" do
8
+ items = Stripe::SubscriptionItem.list(
9
+ subscription: API_FIXTURES.fetch(:subscription)[:id]
10
+ )
11
+ assert_requested :get, "#{Stripe.api_base}/v1/subscription_items",
12
+ query: { subscription: API_FIXTURES.fetch(:subscription)[:id] }
13
+ assert items.data.kind_of?(Array)
14
+ assert items.data[0].kind_of?(Stripe::SubscriptionItem)
12
15
  end
13
16
 
14
- should "subscription items should be listable" do
15
- @mock.expects(:get).once.with("#{Stripe.api_base}/v1/subscription_items?subscription=s_test_subscription&limit=3", nil, nil).
16
- returns(make_response(make_subscription_item_array))
17
- sub_items = Stripe::SubscriptionItem.list(:subscription => 's_test_subscription', :limit => 3).data
18
-
19
- assert sub_items.kind_of? Array
20
- assert sub_items[0].kind_of? Stripe::SubscriptionItem
17
+ should "be retrievable" do
18
+ item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
19
+ assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
20
+ assert item.kind_of?(Stripe::SubscriptionItem)
21
21
  end
22
22
 
23
- should "subscription items should be deletable" do
24
- @mock.expects(:get).once.returns(make_response(make_subscription_item))
25
- sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
26
-
27
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/subscription_items/#{sub_item.id}", nil, nil).
28
- returns(make_response(make_subscription_item))
29
- sub_item.delete
23
+ should "be creatable" do
24
+ item = Stripe::SubscriptionItem.create(
25
+ item: 'silver',
26
+ plan: API_FIXTURES.fetch(:plan)[:id],
27
+ quantity: 3,
28
+ subscription: API_FIXTURES.fetch(:subscription)[:id]
29
+ )
30
+ assert_requested :post, "#{Stripe.api_base}/v1/subscription_items"
31
+ assert item.kind_of?(Stripe::SubscriptionItem)
30
32
  end
31
33
 
32
- should "subscription items should be updateable" do
33
- sid = 'si_test_subscription_item'
34
- @mock.expects(:post).once.with do |url, api_key, params|
35
- url == "#{Stripe.api_base}/v1/subscription_items/#{sid}" &&
36
- api_key.nil? &&
37
- CGI.parse(params) == {'plan' => ['silver'], 'quantity' => ['3']}
38
- end.returns(make_response(make_subscription_item(:plan => 'silver', :quantity => 3)))
39
-
40
- sub_item = Stripe::SubscriptionItem.update(sid, {:plan => 'silver', :quantity => 3})
41
-
42
- assert_equal 'silver', sub_item.plan.id
43
- assert_equal 3, sub_item.quantity
34
+ should "be saveable" do
35
+ item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
36
+ item.quantity = 4
37
+ item.save
38
+ assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
44
39
  end
45
40
 
46
- should "subscription items should be saveable" do
47
- @mock.expects(:get).once.returns(make_response(make_subscription_item))
48
- sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
49
-
50
- @mock.expects(:post).once.with do |url, api_key, params|
51
- url == "#{Stripe.api_base}/v1/subscription_items/#{sub_item.id}" &&
52
- api_key.nil? &&
53
- CGI.parse(params) == {'plan' => ['silver'], 'quantity' => ['3']}
54
- end.returns(make_response(make_subscription_item(:plan => 'silver', :quantity => 3)))
55
-
56
- sub_item.plan = 'silver'
57
- sub_item.quantity = 3
58
- sub_item.save
59
-
60
- assert_equal 'silver', sub_item.plan.id
61
- assert_equal 3, sub_item.quantity
41
+ should "be updateable" do
42
+ item = Stripe::SubscriptionItem.update(FIXTURE[:id], metadata: {foo: 'bar'})
43
+ assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
44
+ assert item.kind_of?(Stripe::SubscriptionItem)
62
45
  end
63
46
 
64
- should "create should return a new subscription item" do
65
- @mock.expects(:post).once.with do |url, api_key, params|
66
- url == "#{Stripe.api_base}/v1/subscription_items" && api_key.nil? &&
67
- CGI.parse(params) == {'plan' => ['silver'], 'quantity' => ['3']}
68
- end.returns(make_response(make_subscription_item(:plan => 'silver', :quantity => 3)))
69
-
70
- sub_item = Stripe::SubscriptionItem.create(:plan => 'silver', :quantity => 3)
71
-
72
- assert_equal 'silver', sub_item.plan.id
73
- assert_equal 3, sub_item.quantity
47
+ should "be deletable" do
48
+ item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
49
+ item = item.delete
50
+ assert_requested :delete, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
51
+ assert item.kind_of?(Stripe::SubscriptionItem)
74
52
  end
75
53
  end
76
54
  end
@@ -2,195 +2,59 @@ 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 retrievable by customer" do
6
- @mock.expects(:get).once.returns(make_response(make_customer))
7
- customer = Stripe::Customer.retrieve('c_test_customer')
5
+ FIXTURE = API_FIXTURES.fetch(:subscription)
8
6
 
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
- _ = customer.subscriptions.retrieve('s_test_subscription')
7
+ should "be listable" do
8
+ subscriptions = Stripe::Subscription.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/subscriptions"
10
+ assert subscriptions.data.kind_of?(Array)
11
+ assert subscriptions.data[0].kind_of?(Stripe::Subscription)
11
12
  end
12
13
 
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
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')
38
-
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')
53
-
54
- assert subs.kind_of?(Stripe::ListObject)
55
- assert subs.data.kind_of?(Array)
56
- assert subs.data[0].kind_of? Stripe::Subscription
57
- end
58
-
59
- should "subscriptions should be refreshable" do
60
- @mock.expects(:get).twice.returns(make_response(make_subscription(:id => 'refreshed_subscription')))
61
-
62
- sub = Stripe::Subscription.retrieve('s_test_subscription')
63
- sub.refresh
64
-
65
- assert_equal 'refreshed_subscription', sub.id
66
- end
67
-
68
- should "subscriptions should be deletable" do
69
- @mock.expects(:get).once.returns(make_response(make_subscription))
70
- sub = Stripe::Subscription.retrieve('s_test_subscription')
71
-
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
74
-
75
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/subscriptions/#{sub.id}", nil, nil).returns(make_response(make_subscription))
76
- sub.delete
77
- end
78
-
79
- should "subscriptions should be updateable" do
80
- sid = 's_test_subscription'
81
- @mock.expects(:post).once.with do |url, api_key, params|
82
- url == "#{Stripe.api_base}/v1/subscriptions/#{sid}" && api_key.nil? && CGI.parse(params) == {'status' => ['active']}
83
- end.returns(make_response(make_subscription(:status => 'active')))
84
-
85
- sub = Stripe::Subscription.update(sid, :status => 'active')
86
-
87
- assert_equal 'active', sub.status
14
+ should "be retrievable" do
15
+ subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
16
+ assert_requested :get,
17
+ "#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
18
+ assert subscription.kind_of?(Stripe::Subscription)
88
19
  end
89
20
 
90
- should "subscription items should be updateable" do
91
- sid = 's_test_subscription'
92
- items = {:data => [{:plan => {:id =>'gold'}, :quantity => 1}, {:plan => {:id =>'silver'}, :quantity => 2}]}
93
-
94
- @mock.expects(:post).once.with do |url, api_key, params|
95
- url == "#{Stripe.api_base}/v1/subscriptions/#{sid}" &&
96
- api_key.nil? &&
97
- CGI.parse(params) == {
98
- 'items[0][plan]' => ['gold'],
99
- 'items[0][quantity]' => ['1'],
100
- 'items[1][plan]' => ['silver'],
101
- 'items[1][quantity]' => ['2'],
102
- }
103
- end.returns(make_response(make_subscription(:items => items)))
104
-
105
- sub = Stripe::Subscription.update(sid, :items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}])
106
-
107
- assert_equal 'gold', sub.items.data[0].plan.id
108
- assert_equal 1, sub.items.data[0].quantity
109
- assert_equal 'silver', sub.items.data[1].plan.id
110
- assert_equal 2, sub.items.data[1].quantity
111
- end
112
-
113
- should "subscription items should be updateable with hash" do
114
- sid = 's_test_subscription'
115
- items = {:data => [{:plan => {:id =>'gold'}, :quantity => 1}, {:plan => {:id =>'silver'}, :quantity => 2}]}
116
-
117
- @mock.expects(:post).once.with do |url, api_key, params|
118
- url == "#{Stripe.api_base}/v1/subscriptions/#{sid}" &&
119
- api_key.nil? &&
120
- CGI.parse(params) == {
121
- 'items[0][plan]' => ['gold'],
122
- 'items[0][quantity]' => ['1'],
123
- 'items[1][plan]' => ['silver'],
124
- 'items[1][quantity]' => ['2'],
125
- }
126
- end.returns(make_response(make_subscription(:items => items)))
127
-
128
- sub = Stripe::Subscription.update(sid, :items => {'0' => {:plan => 'gold', :quantity =>1}, '1' => {:plan => 'silver', :quantity =>2}})
129
-
130
- assert_equal 'gold', sub.items.data[0].plan.id
131
- assert_equal 1, sub.items.data[0].quantity
132
- assert_equal 'silver', sub.items.data[1].plan.id
133
- assert_equal 2, sub.items.data[1].quantity
21
+ should "be creatable" do
22
+ subscription = Stripe::Subscription.create(
23
+ customer: API_FIXTURES.fetch(:customer)[:id]
24
+ )
25
+ assert_requested :post, "#{Stripe.api_base}/v1/subscriptions"
26
+ assert subscription.kind_of?(Stripe::Subscription)
134
27
  end
135
28
 
136
- should "subscriptions should be saveable" do
137
- @mock.expects(:get).once.returns(make_response(make_subscription))
138
- sub = Stripe::Subscription.retrieve('s_test_subscription')
139
- assert_equal 'trialing', sub.status
140
-
141
- @mock.expects(:post).once.with do |url, api_key, params|
142
- url == "#{Stripe.api_base}/v1/subscriptions/#{sub.id}" && api_key.nil? && CGI.parse(params) == {'status' => ['active']}
143
- end.returns(make_response(make_subscription(:status => 'active')))
144
-
145
- sub.status = 'active'
146
- sub.save
147
-
148
- assert_equal 'active', sub.status
29
+ should "be saveable" do
30
+ subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
31
+ subscription.metadata['key'] = 'value'
32
+ subscription.save
33
+ assert_requested :post,
34
+ "#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
149
35
  end
150
36
 
151
- should "create should return a new subscription" do
152
- @mock.expects(:post).once.with do |url, api_key, params|
153
- url == "#{Stripe.api_base}/v1/subscriptions" && api_key.nil? && CGI.parse(params) == {'customer' => ['c_test_customer'], 'plan' => ['gold']}
154
- end.returns(make_response(make_subscription(:plan => 'gold', :id => 'test_new_subscription')))
155
-
156
- sub = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer')
157
-
158
- assert_equal 'test_new_subscription', sub.id
159
- assert_equal 'gold', sub.plan.identifier
37
+ should "be updateable" do
38
+ subscription = Stripe::Subscription.update(FIXTURE[:id], metadata: {foo: 'bar'})
39
+ assert_requested :post,
40
+ "#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
41
+ assert subscription.kind_of?(Stripe::Subscription)
160
42
  end
161
43
 
162
- should "create with items should return a new subscription" do
163
- items = {:data => [{:plan => {:id =>'gold'}, :quantity => 1}, {:plan => {:id =>'silver'}, :quantity => 2}]}
164
-
165
- @mock.expects(:post).once.with do |url, api_key, params|
166
- url == "#{Stripe.api_base}/v1/subscriptions" &&
167
- api_key.nil? &&
168
- CGI.parse(params) == {
169
- 'customer' => ['c_test_customer'],
170
- 'items[0][plan]' => ['gold'],
171
- 'items[0][quantity]' => ['1'],
172
- 'items[1][plan]' => ['silver'],
173
- 'items[1][quantity]' => ['2'],
174
- }
175
- end.returns(make_response(make_subscription(:items => items, :id => 'test_new_subscription')))
176
-
177
- sub = Stripe::Subscription.create(:customer => 'c_test_customer', :items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}])
178
-
179
- assert_equal 'test_new_subscription', sub.id
180
- assert_equal 'gold', sub.items.data[0].plan.id
181
- assert_equal 1, sub.items.data[0].quantity
182
- assert_equal 'silver', sub.items.data[1].plan.id
183
- assert_equal 2, sub.items.data[1].quantity
44
+ should "be deletable" do
45
+ subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
46
+ subscription = subscription.delete
47
+ assert_requested :delete,
48
+ "#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
49
+ assert subscription.kind_of?(Stripe::Subscription)
184
50
  end
185
51
 
186
- should "be able to delete a subscriptions's discount" do
187
- @mock.expects(:post).once.returns(make_response(make_subscription))
188
- sub = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer', coupon: 'forever')
189
-
190
- url = "#{Stripe.api_base}/v1/subscriptions/#{sub.id}/discount"
191
- @mock.expects(:delete).once.with(url, nil, nil).returns(make_response(make_delete_discount_response))
192
- sub.delete_discount
193
- assert_equal nil, sub.discount
52
+ context "#delete_discount" do
53
+ should "be able to delete a subscriptions's discount" do
54
+ subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
55
+ subscription = subscription.delete_discount
56
+ assert subscription.kind_of?(Stripe::Subscription)
57
+ end
194
58
  end
195
59
  end
196
60
  end
@@ -2,21 +2,22 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ThreeDSecureTest < Test::Unit::TestCase
5
- should "retrieve an existing 3D Secure object" do
6
- @mock.expects(:get).once.returns(make_response(make_three_d_secure))
7
- tds = Stripe::ThreeDSecure.retrieve("tdsrc_test")
8
- assert_equal "tdsrc_test", tds.id
5
+ FIXTURE = API_FIXTURES.fetch(:three_d_secure)
6
+
7
+ should "be retrievable" do
8
+ secure = Stripe::ThreeDSecure.retrieve(FIXTURE[:id])
9
+ assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/#{FIXTURE[:id]}"
10
+ assert secure.kind_of?(Stripe::ThreeDSecure)
9
11
  end
10
12
 
11
- should "create should return a new 3D Secure object" do
12
- @mock.expects(:post).once.returns(make_response(make_three_d_secure))
13
- tds = Stripe::ThreeDSecure.create(
14
- :card => "tok_test",
15
- :amount => 1500,
16
- :currency => "usd",
17
- :return_url => "https://example.org/3d-secure-result"
13
+ should "be creatable" do
14
+ _ = Stripe::ThreeDSecure.create(
15
+ card: API_FIXTURES.fetch(:token)[:id],
16
+ amount: 1500,
17
+ currency: "usd",
18
+ return_url: "https://example.org/3d-secure-result"
18
19
  )
19
- assert_equal "tdsrc_test", tds.id
20
+ assert_requested :post, "#{Stripe.api_base}/v1/3d_secure"
20
21
  end
21
22
  end
22
23
  end
@@ -2,32 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class TransferTest < Test::Unit::TestCase
5
- should "retrieve should retrieve transfer" do
6
- @mock.expects(:get).once.returns(make_response(make_transfer))
7
- transfer = Stripe::Transfer.retrieve('tr_test_transfer')
8
- assert_equal 'tr_test_transfer', transfer.id
5
+ FIXTURE = API_FIXTURES.fetch(:transfer)
6
+
7
+ should "be listable" do
8
+ transfers = Stripe::Transfer.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/transfers"
10
+ assert transfers.data.kind_of?(Array)
11
+ assert transfers.data[0].kind_of?(Stripe::Transfer)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
17
+ assert transfer.kind_of?(Stripe::Transfer)
9
18
  end
10
19
 
11
- should "create should create a transfer" do
12
- @mock.expects(:post).once.returns(make_response(make_transfer))
13
- transfer = Stripe::Transfer.create
14
- assert_equal "tr_test_transfer", transfer.id
20
+ should "be creatable" do
21
+ transfer = Stripe::Transfer.create(
22
+ amount: 100,
23
+ currency: "USD"
24
+ )
25
+ assert_requested :post, "#{Stripe.api_base}/v1/transfers"
26
+ assert transfer.kind_of?(Stripe::Transfer)
15
27
  end
16
28
 
17
- should "create should update a transfer" do
18
- @mock.expects(:post).once.
19
- with("#{Stripe.api_base}/v1/transfers/test_transfer", nil, "metadata[foo]=bar").
20
- returns(make_response(make_transfer(metadata: {foo: 'bar'})))
21
- transfer = Stripe::Transfer.update("test_transfer", metadata: {foo: 'bar'})
22
- assert_equal "bar", transfer.metadata['foo']
29
+ should "be saveable" do
30
+ transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
31
+ transfer.metadata['key'] = 'value'
32
+ transfer.save
33
+ assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
23
34
  end
24
35
 
25
- should "cancel should cancel a transfer" do
26
- @mock.expects(:get).once.returns(make_response(make_transfer))
27
- transfer = Stripe::Transfer.retrieve('tr_test_transfer')
36
+ should "be updateable" do
37
+ transfer = Stripe::Transfer.update(FIXTURE[:id], metadata: {foo: 'bar'})
38
+ assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
39
+ assert transfer.kind_of?(Stripe::Transfer)
40
+ end
28
41
 
29
- @mock.expects(:post).once.with('https://api.stripe.com/v1/transfers/tr_test_transfer/cancel', nil, '').returns(make_response(make_canceled_transfer))
30
- transfer.cancel
42
+ context "#cancel" do
43
+ should "cancel a transfer" do
44
+ transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
45
+ transfer = transfer.cancel
46
+ assert transfer.kind_of?(Stripe::Transfer)
47
+ end
31
48
  end
32
49
  end
33
50
  end