stripe 1.30.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.github/ISSUE_TEMPLATE.md +5 -0
  4. data/.travis.yml +3 -14
  5. data/Gemfile +28 -4
  6. data/History.txt +180 -0
  7. data/README.md +147 -0
  8. data/Rakefile +10 -0
  9. data/VERSION +1 -1
  10. data/bin/stripe-console +12 -5
  11. data/lib/data/ca-certificates.crt +3868 -5114
  12. data/lib/stripe/account.rb +43 -23
  13. data/lib/stripe/alipay_account.rb +20 -0
  14. data/lib/stripe/api_operations/create.rb +2 -2
  15. data/lib/stripe/api_operations/delete.rb +2 -2
  16. data/lib/stripe/api_operations/list.rb +2 -3
  17. data/lib/stripe/api_operations/request.rb +9 -3
  18. data/lib/stripe/api_operations/save.rb +85 -0
  19. data/lib/stripe/api_resource.rb +38 -5
  20. data/lib/stripe/apple_pay_domain.rb +12 -0
  21. data/lib/stripe/application_fee.rb +8 -8
  22. data/lib/stripe/application_fee_refund.rb +7 -3
  23. data/lib/stripe/balance_transaction.rb +1 -1
  24. data/lib/stripe/bank_account.rb +13 -4
  25. data/lib/stripe/bitcoin_receiver.rb +6 -6
  26. data/lib/stripe/bitcoin_transaction.rb +1 -1
  27. data/lib/stripe/card.rb +9 -5
  28. data/lib/stripe/charge.rb +38 -20
  29. data/lib/stripe/country_spec.rb +9 -0
  30. data/lib/stripe/coupon.rb +1 -1
  31. data/lib/stripe/customer.rb +12 -10
  32. data/lib/stripe/dispute.rb +4 -5
  33. data/lib/stripe/errors.rb +92 -0
  34. data/lib/stripe/file_upload.rb +1 -1
  35. data/lib/stripe/invoice.rb +7 -7
  36. data/lib/stripe/invoice_item.rb +1 -1
  37. data/lib/stripe/list_object.rb +8 -7
  38. data/lib/stripe/order.rb +12 -4
  39. data/lib/stripe/order_return.rb +9 -0
  40. data/lib/stripe/plan.rb +1 -1
  41. data/lib/stripe/product.rb +2 -10
  42. data/lib/stripe/recipient.rb +1 -1
  43. data/lib/stripe/refund.rb +1 -1
  44. data/lib/stripe/reversal.rb +7 -3
  45. data/lib/stripe/singleton_api_resource.rb +3 -3
  46. data/lib/stripe/sku.rb +2 -2
  47. data/lib/stripe/source.rb +11 -0
  48. data/lib/stripe/stripe_client.rb +396 -0
  49. data/lib/stripe/stripe_object.rb +167 -91
  50. data/lib/stripe/stripe_response.rb +48 -0
  51. data/lib/stripe/subscription.rb +15 -9
  52. data/lib/stripe/subscription_item.rb +12 -0
  53. data/lib/stripe/three_d_secure.rb +9 -0
  54. data/lib/stripe/transfer.rb +4 -5
  55. data/lib/stripe/util.rb +105 -33
  56. data/lib/stripe/version.rb +1 -1
  57. data/lib/stripe.rb +69 -266
  58. data/spec/fixtures.json +1409 -0
  59. data/spec/fixtures.yaml +1153 -0
  60. data/spec/spec.json +19949 -0
  61. data/spec/spec.yaml +15504 -0
  62. data/stripe.gemspec +5 -18
  63. data/test/api_fixtures.rb +29 -0
  64. data/test/api_stub_helpers.rb +125 -0
  65. data/test/stripe/account_test.rb +163 -211
  66. data/test/stripe/alipay_account_test.rb +19 -0
  67. data/test/stripe/api_operations_test.rb +31 -0
  68. data/test/stripe/api_resource_test.rb +174 -340
  69. data/test/stripe/apple_pay_domain_test.rb +33 -0
  70. data/test/stripe/application_fee_refund_test.rb +22 -31
  71. data/test/stripe/application_fee_test.rb +6 -14
  72. data/test/stripe/balance_test.rb +3 -3
  73. data/test/stripe/bank_account_test.rb +41 -0
  74. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  75. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  76. data/test/stripe/charge_test.rb +39 -98
  77. data/test/stripe/country_spec_test.rb +20 -0
  78. data/test/stripe/coupon_test.rb +35 -11
  79. data/test/stripe/customer_card_test.rb +25 -46
  80. data/test/stripe/customer_test.rb +89 -61
  81. data/test/stripe/dispute_test.rb +28 -31
  82. data/test/stripe/errors_test.rb +18 -0
  83. data/test/stripe/file_upload_test.rb +32 -24
  84. data/test/stripe/invoice_item_test.rb +55 -0
  85. data/test/stripe/invoice_test.rb +50 -24
  86. data/test/stripe/list_object_test.rb +57 -45
  87. data/test/stripe/order_return_test.rb +21 -0
  88. data/test/stripe/order_test.rb +41 -34
  89. data/test/stripe/plan_test.rb +52 -0
  90. data/test/stripe/product_test.rb +31 -25
  91. data/test/stripe/recipient_card_test.rb +23 -40
  92. data/test/stripe/recipient_test.rb +50 -0
  93. data/test/stripe/refund_test.rb +20 -36
  94. data/test/stripe/reversal_test.rb +27 -31
  95. data/test/stripe/sku_test.rb +39 -13
  96. data/test/stripe/source_test.rb +43 -0
  97. data/test/stripe/stripe_client_test.rb +428 -0
  98. data/test/stripe/stripe_object_test.rb +186 -13
  99. data/test/stripe/stripe_response_test.rb +46 -0
  100. data/test/stripe/subscription_item_test.rb +54 -0
  101. data/test/stripe/subscription_test.rb +40 -52
  102. data/test/stripe/three_d_secure_test.rb +23 -0
  103. data/test/stripe/transfer_test.rb +38 -13
  104. data/test/stripe/util_test.rb +48 -16
  105. data/test/stripe_test.rb +25 -0
  106. data/test/test_data.rb +5 -621
  107. data/test/test_helper.rb +24 -24
  108. metadata +60 -139
  109. data/README.rdoc +0 -68
  110. data/gemfiles/default-with-activesupport.gemfile +0 -10
  111. data/gemfiles/json.gemfile +0 -12
  112. data/gemfiles/yajl.gemfile +0 -12
  113. data/lib/stripe/api_operations/update.rb +0 -58
  114. data/lib/stripe/errors/api_connection_error.rb +0 -4
  115. data/lib/stripe/errors/api_error.rb +0 -4
  116. data/lib/stripe/errors/authentication_error.rb +0 -4
  117. data/lib/stripe/errors/card_error.rb +0 -12
  118. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  119. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  120. data/lib/stripe/errors/stripe_error.rb +0 -26
  121. data/test/stripe/charge_refund_test.rb +0 -55
  122. data/test/stripe/metadata_test.rb +0 -129
@@ -8,8 +8,10 @@ module Stripe
8
8
  end
9
9
 
10
10
  should "provide #count via enumerable" do
11
- list = Stripe::ListObject.construct_from(make_charge_array)
12
- assert_equal 3, list.count
11
+ list = Stripe::ListObject.construct_from({
12
+ data: [API_FIXTURES.fetch(:charge)]
13
+ })
14
+ assert_equal 1, list.count
13
15
  end
14
16
 
15
17
  should "provide #each" do
@@ -31,9 +33,14 @@ module Stripe
31
33
  ]
32
34
  expected = Util.convert_to_stripe_object(arr, {})
33
35
 
34
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
35
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
36
- returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
36
+ list = TestListObject.construct_from({
37
+ :data => [{ :id => 1 }],
38
+ :has_more => true,
39
+ :url => "/things",
40
+ })
41
+ stub_request(:get, "#{Stripe.api_base}/things").
42
+ with(query: { starting_after: "1" }).
43
+ to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
37
44
 
38
45
  assert_equal expected, list.auto_paging_each.to_a
39
46
  end
@@ -46,9 +53,14 @@ module Stripe
46
53
  ]
47
54
  expected = Util.convert_to_stripe_object(arr, {})
48
55
 
49
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
50
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
51
- returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
56
+ list = TestListObject.construct_from({
57
+ :data => [{ :id => 1 }],
58
+ :has_more => true,
59
+ :url => "/things",
60
+ })
61
+ stub_request(:get, "#{Stripe.api_base}/things").
62
+ with(query: { starting_after: "1" }).
63
+ to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
52
64
 
53
65
  actual = []
54
66
  list.auto_paging_each do |obj|
@@ -70,33 +82,38 @@ module Stripe
70
82
  #
71
83
 
72
84
  should "fetch a next page through #next_page" do
73
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
74
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
75
- returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
85
+ list = TestListObject.construct_from({
86
+ :data => [{ :id => 1 }],
87
+ :has_more => true,
88
+ :url => "/things",
89
+ })
90
+ stub_request(:get, "#{Stripe.api_base}/things").
91
+ with(query: { starting_after: "1" }).
92
+ to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
76
93
  next_list = list.next_page
77
94
  refute next_list.empty?
78
95
  end
79
96
 
80
97
  should "fetch a next page through #next_page and respect limit" do
81
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
98
+ list = TestListObject.construct_from({
99
+ :data => [{ :id => 1 }],
100
+ :has_more => true,
101
+ :url => "/things",
102
+ })
82
103
  list.filters = { :expand => ['data.source'], :limit => 3 }
83
- @mock.expects(:get).with do |url, _, _|
84
- # apparently URI.parse in 1.8.7 doesn't support query parameters ...
85
- url, query = url.split("?")
86
- u = URI.parse(url)
87
- params = CGI.parse(query)
88
- u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
89
- "expand[]" => ["data.source"],
90
- "limit" => ["3"],
91
- "starting_after" => ["1"],
92
- }
93
- end.returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
104
+ stub_request(:get, "#{Stripe.api_base}/things").
105
+ with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" }).
106
+ to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
94
107
  next_list = list.next_page
95
108
  assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
96
109
  end
97
110
 
98
111
  should "fetch an empty page through #next_page" do
99
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => false })
112
+ list = TestListObject.construct_from({
113
+ :data => [{ :id => 1 }],
114
+ :has_more => false,
115
+ :url => "/things",
116
+ })
100
117
  next_list = list.next_page
101
118
  assert_equal Stripe::ListObject.empty_list, next_list
102
119
  end
@@ -106,27 +123,26 @@ module Stripe
106
123
  #
107
124
 
108
125
  should "fetch a next page through #previous_page" do
109
- list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
110
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
111
- returns(make_response({ :data => [{ :id => 1 }] }))
126
+ list = TestListObject.construct_from({
127
+ :data => [{ :id => 2 }],
128
+ :url => "/things",
129
+ })
130
+ stub_request(:get, "#{Stripe.api_base}/things").
131
+ with(query: { ending_before: "2" }).
132
+ to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
112
133
  next_list = list.previous_page
113
134
  refute next_list.empty?
114
135
  end
115
136
 
116
137
  should "fetch a next page through #previous_page and respect limit" do
117
- list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
138
+ list = TestListObject.construct_from({
139
+ :data => [{ :id => 2 }],
140
+ :url => "/things",
141
+ })
118
142
  list.filters = { :expand => ['data.source'], :limit => 3 }
119
- @mock.expects(:get).with do |url, _, _|
120
- # apparently URI.parse in 1.8.7 doesn't support query parameters ...
121
- url, query = url.split("?")
122
- u = URI.parse(url)
123
- params = CGI.parse(query)
124
- u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
125
- "ending_before" => ["2"],
126
- "expand[]" => ["data.source"],
127
- "limit" => ["3"],
128
- }
129
- end.returns(make_response({ :data => [{ :id => 1 }] }))
143
+ stub_request(:get, "#{Stripe.api_base}/things").
144
+ with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" }).
145
+ to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
130
146
  next_list = list.previous_page
131
147
  assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
132
148
  end
@@ -138,13 +154,12 @@ module Stripe
138
154
  # note that the name #all is deprecated, as is using it fetch the next page
139
155
  # in a list
140
156
  should "be able to retrieve full lists given a listobject" do
141
- @mock.expects(:get).twice.returns(make_response(make_charge_array))
142
157
  c = Stripe::Charge.all
143
158
  assert c.kind_of?(Stripe::ListObject)
144
- assert_equal('/v1/charges', c.url)
159
+ assert_equal('/v1/charges', c.resource_url)
145
160
  all = c.all
146
161
  assert all.kind_of?(Stripe::ListObject)
147
- assert_equal('/v1/charges', all.url)
162
+ assert_equal('/v1/charges', all.resource_url)
148
163
  assert all.data.kind_of?(Array)
149
164
  end
150
165
  end
@@ -152,7 +167,4 @@ end
152
167
 
153
168
  # A helper class with a URL that allows us to try out pagination.
154
169
  class TestListObject < Stripe::ListObject
155
- def url
156
- "/things"
157
- end
158
170
  end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class OrderReturnTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:order_return)
6
+
7
+ should "be listable" do
8
+ order_returns = Stripe::OrderReturn.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/order_returns"
10
+ assert order_returns.data.kind_of?(Array)
11
+ assert order_returns.data[0].kind_of?(Stripe::OrderReturn)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ order_return = Stripe::OrderReturn.retrieve(FIXTURE[:id])
16
+ assert_requested :get,
17
+ "#{Stripe.api_base}/v1/order_returns/#{FIXTURE[:id]}"
18
+ assert order_return.kind_of?(Stripe::OrderReturn)
19
+ end
20
+ end
21
+ end
@@ -2,51 +2,58 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class OrderTest < Test::Unit::TestCase
5
- should "orders should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_order_array))
5
+ FIXTURE = API_FIXTURES.fetch(:order)
6
+
7
+ should "be listable" do
7
8
  orders = Stripe::Order.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/orders"
8
10
  assert orders.data.kind_of?(Array)
9
- orders.each do |order|
10
- assert order.kind_of?(Stripe::Order)
11
- end
11
+ assert orders.first.kind_of?(Stripe::Order)
12
12
  end
13
13
 
14
- should "orders should not be deletable" do
15
- assert_raises NoMethodError do
16
- @mock.expects(:get).once.returns(make_response(make_order))
17
- p = Stripe::Order.retrieve("test_order")
18
- p.delete
19
- end
14
+ should "be retrievable" do
15
+ order = Stripe::Order.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
17
+ assert order.kind_of?(Stripe::Order)
18
+ end
19
+
20
+ should "be creatable" do
21
+ order = Stripe::Order.create(
22
+ currency: "USD"
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/orders"
25
+ assert order.kind_of?(Stripe::Order)
20
26
  end
21
27
 
22
- should "orders should be updateable" do
23
- @mock.expects(:get).once.returns(make_response(make_order))
24
- @mock.expects(:post).once.returns(make_response(make_order))
25
- p = Stripe::Order.new("test_order")
26
- p.refresh
27
- p.status = "fulfilled"
28
- p.save
28
+ should "be saveable" do
29
+ order = Stripe::Order.retrieve(FIXTURE[:id])
30
+ order.metadata['key'] = 'value'
31
+ order.save
32
+ assert_requested :post, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
29
33
  end
30
34
 
31
- should "orders should allow metadata updates" do
32
- @mock.expects(:get).once.returns(make_response(make_order))
33
- @mock.expects(:post).once.returns(make_response(make_order))
34
- p = Stripe::Order.new("test_order")
35
- p.refresh
36
- p.metadata['key'] = 'value'
37
- p.save
35
+ should "be updateable" do
36
+ order = Stripe::Order.update(FIXTURE[:id], metadata: { key: 'value' })
37
+ assert_requested :post, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
38
+ assert order.kind_of?(Stripe::Order)
38
39
  end
39
40
 
40
- should "pay should pay an order" do
41
- @mock.expects(:get).once.
42
- returns(make_response(make_order(:id => 'or_test_order')))
43
- order = Stripe::Order.retrieve('or_test_order')
41
+ context "#pay" do
42
+ should "pay an order" do
43
+ order = Stripe::Order.retrieve(FIXTURE[:id])
44
+ order = order.pay(token: API_FIXTURES.fetch(:token)[:id])
45
+ assert order.kind_of?(Stripe::Order)
46
+ end
47
+ end
44
48
 
45
- @mock.expects(:post).once.
46
- with('https://api.stripe.com/v1/orders/or_test_order/pay', nil, 'token=test_token').
47
- returns(make_response(make_paid_order))
48
- order.pay(:token => 'test_token')
49
- assert_equal "paid", order.status
49
+ context "#return_order" do
50
+ should "return an order" do
51
+ order = Stripe::Order.retrieve(FIXTURE[:id])
52
+ order = order.return_order(:orders => [
53
+ { parent: API_FIXTURES.fetch(:sku)[:id] }
54
+ ])
55
+ assert order.kind_of?(Stripe::OrderReturn)
56
+ end
50
57
  end
51
58
  end
52
59
  end
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class PlanTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:plan)
6
+
7
+ should "be listable" do
8
+ plans = Stripe::Plan.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/plans"
10
+ assert plans.data.kind_of?(Array)
11
+ assert plans.data[0].kind_of?(Stripe::Plan)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
17
+ assert plan.kind_of?(Stripe::Plan)
18
+ end
19
+
20
+ should "be creatable" do
21
+ plan = Stripe::Plan.create(
22
+ amount: 5000,
23
+ interval: "month",
24
+ name: "Sapphire elite",
25
+ currency: "usd",
26
+ id: "sapphire-elite"
27
+ )
28
+ assert_requested :post, "#{Stripe.api_base}/v1/plans"
29
+ assert plan.kind_of?(Stripe::Plan)
30
+ end
31
+
32
+ should "be saveable" do
33
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
34
+ plan.metadata['key'] = 'value'
35
+ plan.save
36
+ assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
37
+ end
38
+
39
+ should "be updateable" do
40
+ plan = Stripe::Plan.update(FIXTURE[:id], metadata: {foo: 'bar'})
41
+ assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
42
+ assert plan.kind_of?(Stripe::Plan)
43
+ end
44
+
45
+ should "be deletable" do
46
+ plan = Stripe::Plan.retrieve(FIXTURE[:id])
47
+ plan = plan.delete
48
+ assert_requested :delete, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
49
+ assert plan.kind_of?(Stripe::Plan)
50
+ end
51
+ end
52
+ end
@@ -2,40 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ProductTest < Test::Unit::TestCase
5
- should "products should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_product_array))
5
+ FIXTURE = API_FIXTURES.fetch(:product)
6
+
7
+ should "be listable" do
7
8
  products = Stripe::Product.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/products"
8
10
  assert products.data.kind_of?(Array)
9
- products.each do |product|
10
- assert product.kind_of?(Stripe::Product)
11
- end
11
+ assert products.data[0].kind_of?(Stripe::Product)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ product = Stripe::Product.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
17
+ assert product.kind_of?(Stripe::Product)
12
18
  end
13
19
 
14
- should "products should not be deletable" do
15
- assert_raises NoMethodError do
16
- @mock.expects(:get).once.returns(make_response(make_product))
17
- p = Stripe::Product.retrieve("test_product")
18
- p.delete
19
- end
20
+ should "be creatable" do
21
+ _ = Stripe::Product.create(
22
+ name: "My Product"
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/products"
20
25
  end
21
26
 
22
- should "products should be updateable" do
23
- @mock.expects(:get).once.returns(make_response(make_product))
24
- @mock.expects(:post).once.returns(make_response(make_product))
25
- p = Stripe::Product.new("test_product")
26
- p.refresh
27
- p.description = "New product description"
28
- p.save
27
+ should "be saveable" do
28
+ product = Stripe::Product.retrieve(FIXTURE[:id])
29
+ product.metadata['key'] = 'value'
30
+ product.save
31
+ assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
29
32
  end
30
33
 
31
- should "products should allow metadata updates" do
32
- @mock.expects(:get).once.returns(make_response(make_product))
33
- @mock.expects(:post).once.returns(make_response(make_product))
34
- p = Stripe::Product.new("test_product")
35
- p.refresh
36
- p.metadata['key'] = 'value'
37
- p.save
34
+ should "be updateable" do
35
+ product = Stripe::Product.update(FIXTURE[:id], metadata: {foo: 'bar'})
36
+ assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
37
+ assert product.kind_of?(Stripe::Product)
38
38
  end
39
39
 
40
+ should "be deletable" do
41
+ product = Stripe::Product.retrieve(FIXTURE[:id])
42
+ product = product.delete
43
+ assert_requested :delete, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
44
+ assert product.kind_of?(Stripe::Product)
45
+ end
40
46
  end
41
47
  end
@@ -2,56 +2,39 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class RecipientCardTest < Test::Unit::TestCase
5
- RECIPIENT_CARD_URL = '/v1/recipients/test_recipient/cards/test_card'
5
+ FIXTURE = API_FIXTURES.fetch(:source)
6
6
 
7
- def recipient
8
- @mock.expects(:get).once.returns(make_response(make_recipient))
9
- Stripe::Recipient.retrieve('test_recipient')
7
+ setup do
8
+ @recipient =
9
+ Stripe::Recipient.retrieve(API_FIXTURES.fetch(:transfer_recipient)[:id])
10
10
  end
11
11
 
12
- should "recipient cards should be listable" do
13
- c = recipient
14
- @mock.expects(:get).once.returns(make_response(make_recipient_card_array(recipient.id)))
15
- cards = c.cards.list.data
16
- assert cards.kind_of? Array
17
- assert cards[0].kind_of? Stripe::Card
12
+ should "be listable" do
13
+ cards = @recipient.cards.list
14
+ assert cards.data.kind_of?(Array)
15
+ assert cards.data[0].kind_of?(Stripe::Token)
18
16
  end
19
17
 
20
- should "recipient cards should have the correct url" do
21
- c = recipient
22
- @mock.expects(:get).once.returns(make_response(make_card(
23
- :id => 'test_card',
24
- :recipient => 'test_recipient'
25
- )))
26
- card = c.cards.retrieve('card')
27
- assert_equal RECIPIENT_CARD_URL, card.url
18
+ should "be creatable" do
19
+ card = @recipient.cards.create(
20
+ card: API_FIXTURES.fetch(:token)[:id]
21
+ )
22
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards"
23
+ assert card.kind_of?(Stripe::Token)
28
24
  end
29
25
 
30
- should "recipient cards should be deletable" do
31
- c = recipient
32
- @mock.expects(:get).once.returns(make_response(make_card))
33
- @mock.expects(:delete).once.returns(make_response(make_card(:deleted => true)))
34
- card = c.cards.retrieve('card')
35
- card.delete
36
- assert card.deleted
26
+ should "be deletable" do
27
+ card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
28
+ card = card.delete
29
+ assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
30
+ assert card.kind_of?(Stripe::Card)
37
31
  end
38
32
 
39
- should "recipient cards should be updateable" do
40
- c = recipient
41
- @mock.expects(:get).once.returns(make_response(make_card(:exp_year => "2000")))
42
- @mock.expects(:post).once.returns(make_response(make_card(:exp_year => "2100")))
43
- card = c.cards.retrieve('card')
44
- assert_equal "2000", card.exp_year
45
- card.exp_year = "2100"
33
+ should "be saveable" do
34
+ card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
35
+ card.metadata['key'] = 'value'
46
36
  card.save
47
- assert_equal "2100", card.exp_year
48
- end
49
-
50
- should "create should return a new recipient card" do
51
- c = recipient
52
- @mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
53
- card = c.cards.create(:card => "tok_41YJ05ijAaWaFS")
54
- assert_equal "test_card", card.id
37
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
55
38
  end
56
39
  end
57
40
  end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class RecipientTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:transfer_recipient)
6
+
7
+ should "be listable" do
8
+ recipients = Stripe::Recipient.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/recipients"
10
+ assert recipients.data.kind_of?(Array)
11
+ assert recipients.data[0].kind_of?(Stripe::Recipient)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
17
+ assert recipient.kind_of?(Stripe::Recipient)
18
+ end
19
+
20
+ should "be creatable" do
21
+ recipient = Stripe::Recipient.create(
22
+ name: "Noah Jackson",
23
+ type: "individual"
24
+ )
25
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients"
26
+ assert recipient.kind_of?(Stripe::Recipient)
27
+ end
28
+
29
+ should "be saveable" do
30
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
31
+ recipient.metadata['key'] = 'value'
32
+ recipient.save
33
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
34
+ end
35
+
36
+ should "be updateable" do
37
+ recipient = Stripe::Recipient.update(FIXTURE[:id], metadata: {foo: 'bar'})
38
+ assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
39
+ assert recipient.kind_of?(Stripe::Recipient)
40
+ end
41
+
42
+ should "be deletable" do
43
+ recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
44
+ recipient = recipient.delete
45
+ assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
46
+ assert recipient.kind_of?(Stripe::Recipient)
47
+ end
48
+ end
49
+ end
50
+
@@ -2,54 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class RefundTest < Test::Unit::TestCase
5
- should "refunds should be listable" do
6
- @mock.expects(:get).
7
- with("#{Stripe.api_base}/v1/refunds", nil, nil).
8
- once.returns(make_response(make_refund_array))
5
+ FIXTURE = API_FIXTURES.fetch(:refund)
9
6
 
7
+ should "be listable" do
10
8
  refunds = Stripe::Refund.list
11
-
9
+ assert_requested :get, "#{Stripe.api_base}/v1/refunds"
10
+ assert refunds.data.kind_of?(Array)
12
11
  assert refunds.first.kind_of?(Stripe::Refund)
13
12
  end
14
13
 
15
- should "refunds should be refreshable" do
16
- @mock.expects(:get).
17
- with("#{Stripe.api_base}/v1/refunds/test_refund", nil, nil).
18
- twice.returns(make_response(make_refund(:id => 'test_refund')),
19
- make_response(make_refund(:id => 'refreshed_refund')))
20
-
21
- refund = Stripe::Refund.retrieve('test_refund')
22
- refund.refresh
23
-
24
- assert_equal 'refreshed_refund', refund.id
14
+ should "be retrievable" do
15
+ refund = Stripe::Refund.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
17
+ assert refund.kind_of?(Stripe::Refund)
25
18
  end
26
19
 
27
- should "refunds should be updateable" do
28
- @mock.expects(:get).
29
- with("#{Stripe.api_base}/v1/refunds/get_refund", nil, nil).
30
- once.returns(make_response(make_refund(:id => 'save_refund')))
31
-
32
- @mock.expects(:post).
33
- with("#{Stripe.api_base}/v1/refunds/save_refund", nil, 'metadata[key]=value').
34
- once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
35
-
36
- refund = Stripe::Refund.retrieve('get_refund')
37
-
38
- assert_equal nil, refund.metadata['key']
20
+ should "be creatable" do
21
+ refund = Stripe::Refund.create(:charge => API_FIXTURES[:charge][:id])
22
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds"
23
+ assert refund.kind_of?(Stripe::Refund)
24
+ end
39
25
 
26
+ should "be saveable" do
27
+ refund = Stripe::Refund.retrieve(FIXTURE[:id])
40
28
  refund.metadata['key'] = 'value'
41
29
  refund.save
42
-
43
- assert_equal 'value', refund.metadata['key']
30
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
44
31
  end
45
32
 
46
- should "create should return a new refund" do
47
- @mock.expects(:post).
48
- with("#{Stripe.api_base}/v1/refunds", nil, 'charge=test_charge').
49
- once.returns(make_response(make_refund(:id => 'test_new_refund')))
50
-
51
- refund = Stripe::Refund.create(:charge => 'test_charge')
52
- assert_equal 'test_new_refund', refund.id
33
+ should "be updateable" do
34
+ refund = Stripe::Refund.update(FIXTURE[:id], metadata: { key: 'value' })
35
+ assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
36
+ assert refund.kind_of?(Stripe::Refund)
53
37
  end
54
38
  end
55
39
  end