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
@@ -7,10 +7,10 @@ module Stripe
7
7
  e = StripeError.new("message")
8
8
  assert_equal "message", e.to_s
9
9
 
10
- e = StripeError.new("message", 200)
10
+ e = StripeError.new("message", http_status: 200)
11
11
  assert_equal "(Status 200) message", e.to_s
12
12
 
13
- e = StripeError.new("message", nil, nil, nil, { :request_id => "request-id" })
13
+ e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :request_id => "request-id" })
14
14
  assert_equal "(Request request-id) message", e.to_s
15
15
  end
16
16
  end
@@ -2,38 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class FileUploadTest < Test::Unit::TestCase
5
- should "create should return a new file" do
6
- params = {
7
- :purpose => "dispute_evidence",
8
- :file => File.new(__FILE__),
9
- }
5
+ # Note that these tests are written different from others because we
6
+ # don't have anything on the uploads service in our OpenAPI spec. This is
7
+ # something that should be looked into at some point. We may need to ship
8
+ # a separate spec for it though, so it's high effort with low reward for
9
+ # the time being.
10
+ FIXTURE = {
11
+ id: "fil_15ABpV2eZvKYlo2C7vu7XS5l",
12
+ object: "file_upload",
13
+ }.freeze
10
14
 
11
- @mock.expects(:post).once.
12
- with("#{Stripe.uploads_base}/v1/files", nil, params).
13
- returns(make_response(make_file))
15
+ should "be listable" do
16
+ stub_request(:get, "#{Stripe.uploads_base}/v1/files").
17
+ to_return(body: JSON.generate({
18
+ data: [FIXTURE],
19
+ object: 'list',
20
+ resource_url: '/v1/files'
21
+ }))
14
22
 
15
- f = Stripe::FileUpload.create(params)
16
- assert_equal "fil_test_file", f.id
23
+ files = Stripe::FileUpload.list
24
+ assert files.data.kind_of?(Array)
25
+ assert files.data[0].kind_of?(Stripe::FileUpload)
17
26
  end
18
27
 
19
- should "files should be retrievable" do
20
- @mock.expects(:get).once.
21
- with("#{Stripe.uploads_base}/v1/files/fil_test_file", nil, nil).
22
- returns(make_response(make_file))
28
+ should "be retrievable" do
29
+ stub_request(:get, "#{Stripe.uploads_base}/v1/files/#{FIXTURE[:id]}").
30
+ to_return(body: JSON.generate(FIXTURE))
23
31
 
24
- c = Stripe::FileUpload.new("fil_test_file")
25
- c.refresh
26
- assert_equal 1403047735, c.created
32
+ file = Stripe::FileUpload.retrieve(FIXTURE[:id])
33
+ assert file.kind_of?(Stripe::FileUpload)
27
34
  end
28
35
 
29
- should "files should be listable" do
30
- @mock.expects(:get).once.
31
- with("#{Stripe.uploads_base}/v1/files", nil, nil).
32
- returns(make_response(make_file_array))
36
+ should "be creatable" do
37
+ stub_request(:post, "#{Stripe.uploads_base}/v1/files").
38
+ to_return(body: JSON.generate(FIXTURE))
33
39
 
34
- c = Stripe::FileUpload.list.data
35
- assert c.kind_of? Array
36
- assert c[0].kind_of? Stripe::FileUpload
40
+ file = Stripe::FileUpload.create(
41
+ purpose: "dispute_evidence",
42
+ file: File.new(__FILE__),
43
+ )
44
+ assert file.kind_of?(Stripe::FileUpload)
37
45
  end
38
46
  end
39
47
  end
@@ -2,18 +2,54 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class InvoiceItemTest < Test::Unit::TestCase
5
- should "retrieve should retrieve invoice items" do
6
- @mock.expects(:get).once.returns(make_response(make_invoice_item))
7
- ii = Stripe::InvoiceItem.retrieve('in_test_invoice_item')
8
- assert_equal 'ii_test_invoice_item', ii.id
5
+ FIXTURE = API_FIXTURES.fetch(:invoice_item)
6
+
7
+ should "be listable" do
8
+ invoiceitems = Stripe::InvoiceItem.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
10
+ assert invoiceitems.data.kind_of?(Array)
11
+ assert invoiceitems.first.kind_of?(Stripe::InvoiceItem)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
16
+ assert_requested :get,
17
+ "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
18
+ assert item.kind_of?(Stripe::InvoiceItem)
19
+ end
20
+
21
+ should "be creatable" do
22
+ item = Stripe::InvoiceItem.create(
23
+ amount: 100,
24
+ currency: "USD",
25
+ customer: API_FIXTURES[:customer][:id]
26
+ )
27
+ assert_requested :post,
28
+ "#{Stripe.api_base}/v1/invoiceitems"
29
+ assert item.kind_of?(Stripe::InvoiceItem)
30
+ end
31
+
32
+ should "be saveable" do
33
+ item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
34
+ item.metadata['key'] = 'value'
35
+ item.save
36
+ assert_requested :post,
37
+ "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
38
+ end
39
+
40
+ should "be updateable" do
41
+ item = Stripe::InvoiceItem.update(FIXTURE[:id], metadata: { key: 'value' })
42
+ assert_requested :post,
43
+ "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
44
+ assert item.kind_of?(Stripe::InvoiceItem)
9
45
  end
10
46
 
11
- should "invoice items should be updateable" do
12
- @mock.expects(:post).once.
13
- with('https://api.stripe.com/v1/invoiceitems/test_invoice_item', nil, 'metadata[foo]=bar').
14
- returns(make_response(make_charge(metadata: {'foo' => 'bar'})))
15
- ii = Stripe::InvoiceItem.update("test_invoice_item", metadata: {foo: 'bar'})
16
- assert_equal('bar', ii.metadata['foo'])
47
+ should "be deletable" do
48
+ item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
49
+ item = item.delete
50
+ assert_requested :delete,
51
+ "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
52
+ assert item.kind_of?(Stripe::InvoiceItem)
17
53
  end
18
54
  end
19
55
  end
@@ -2,65 +2,65 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class InvoiceTest < Test::Unit::TestCase
5
- should "retrieve should retrieve invoices" do
6
- @mock.expects(:get).once.returns(make_response(make_invoice))
7
- i = Stripe::Invoice.retrieve('in_test_invoice')
8
- assert_equal 'in_test_invoice', i.id
9
- end
5
+ FIXTURE = API_FIXTURES.fetch(:invoice)
10
6
 
11
- should "create should create a new invoice" do
12
- @mock.expects(:post).once.returns(make_response(make_invoice))
13
- i = Stripe::Invoice.create
14
- assert_equal "in_test_invoice", i.id
7
+ should "be listable" do
8
+ invoices = Stripe::Invoice.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/invoices"
10
+ assert invoices.data.kind_of?(Array)
11
+ assert invoices.first.kind_of?(Stripe::Invoice)
15
12
  end
16
13
 
17
- should "pay should pay an invoice" do
18
- @mock.expects(:get).once.returns(make_response(make_invoice))
19
- i = Stripe::Invoice.retrieve('in_test_invoice')
20
-
21
- @mock.expects(:post).once.with('https://api.stripe.com/v1/invoices/in_test_invoice/pay', nil, '').returns(make_response(make_paid_invoice))
22
- i.pay
23
- assert_equal nil, i.next_payment_attempt
14
+ should "be retrievable" do
15
+ invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
17
+ assert invoice.kind_of?(Stripe::Invoice)
24
18
  end
25
19
 
26
- should "invoices should be updateable" do
27
- @mock.expects(:post).once.
28
- with("https://api.stripe.com/v1/invoices/test_invoice", nil, "metadata[foo]=bar").
29
- returns(make_response(make_invoice(metadata: {foo: 'bar'})))
30
- i = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
31
- assert_equal('bar', i.metadata['foo'])
20
+ should "be creatable" do
21
+ invoice = Stripe::Invoice.create(
22
+ :customer => API_FIXTURES[:customer][:id]
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/invoices"
25
+ assert invoice.kind_of?(Stripe::Invoice)
32
26
  end
33
27
 
34
- should "pay with extra opts should pay an invoice" do
35
- @mock.expects(:get).once.returns(make_response(make_invoice))
36
- i = Stripe::Invoice.retrieve('in_test_invoice', {:api_key => 'foobar'})
37
-
38
- Stripe.expects(:execute_request).with do |opts|
39
- opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" &&
40
- opts[:method] == :post &&
41
- opts[:headers]['Authorization'] == 'Bearer foobar'
42
- end.returns(make_response(make_paid_invoice))
43
-
44
- i.pay
45
- assert_equal nil, i.next_payment_attempt
28
+ should "be saveable" do
29
+ invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
30
+ invoice.metadata['key'] = 'value'
31
+ invoice.save
32
+ assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
46
33
  end
47
34
 
48
- should "be able to retrieve upcoming invoices" do
49
- base = "#{Stripe.api_base}/v1/invoices/upcoming?"
50
- cus_sub = "customer=c_test_customer&subscription=s_test_subscription&"
51
- item0 = "subscription_items[][plan]=gold&subscription_items[][quantity]=1&"
52
- item1 = "subscription_items[][plan]=silver&subscription_items[][quantity]=2"
53
- @mock.expects(:get).once.with(base + cus_sub + item0 + item1, nil, nil).
54
- returns(make_response(make_invoice(:customer => 'c_test_customer', :subscription => 's_test_subscription')))
35
+ should "be updateable" do
36
+ invoice = Stripe::Invoice.update(FIXTURE[:id], metadata: { key: 'value' })
37
+ assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
38
+ assert invoice.kind_of?(Stripe::Invoice)
39
+ end
55
40
 
56
- i = Stripe::Invoice.upcoming(
57
- :customer => 'c_test_customer',
58
- :subscription => 's_test_subscription',
59
- :subscription_items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}]
60
- )
41
+ context "#pay" do
42
+ should "pay invoice" do
43
+ invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
44
+ invoice = invoice.pay
45
+ assert_requested :post,
46
+ "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}/pay"
47
+ assert invoice.kind_of?(Stripe::Invoice)
48
+ end
49
+ end
61
50
 
62
- assert_equal 'c_test_customer', i.customer
63
- assert_equal 's_test_subscription', i.subscription
51
+ context "#upcoming" do
52
+ should "retrieve upcoming invoices" do
53
+ invoice = Stripe::Invoice.upcoming(
54
+ customer: API_FIXTURES[:customer][:id],
55
+ subscription: API_FIXTURES[:subscription][:id]
56
+ )
57
+ assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
58
+ query: {
59
+ customer: API_FIXTURES[:customer][:id],
60
+ subscription: API_FIXTURES[:subscription][:id]
61
+ }
62
+ assert invoice.kind_of?(Stripe::Invoice)
63
+ end
64
64
  end
65
65
  end
66
66
  end
@@ -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
@@ -36,8 +38,9 @@ module Stripe
36
38
  :has_more => true,
37
39
  :url => "/things",
38
40
  })
39
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
40
- returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
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 }))
41
44
 
42
45
  assert_equal expected, list.auto_paging_each.to_a
43
46
  end
@@ -55,8 +58,9 @@ module Stripe
55
58
  :has_more => true,
56
59
  :url => "/things",
57
60
  })
58
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
59
- returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
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 }))
60
64
 
61
65
  actual = []
62
66
  list.auto_paging_each do |obj|
@@ -83,8 +87,9 @@ module Stripe
83
87
  :has_more => true,
84
88
  :url => "/things",
85
89
  })
86
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
87
- returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
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 }))
88
93
  next_list = list.next_page
89
94
  refute next_list.empty?
90
95
  end
@@ -96,15 +101,9 @@ module Stripe
96
101
  :url => "/things",
97
102
  })
98
103
  list.filters = { :expand => ['data.source'], :limit => 3 }
99
- @mock.expects(:get).with do |url, _, _|
100
- u = URI.parse(url)
101
- params = CGI.parse(u.query)
102
- u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
103
- "expand[]" => ["data.source"],
104
- "limit" => ["3"],
105
- "starting_after" => ["1"],
106
- }
107
- 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 }))
108
107
  next_list = list.next_page
109
108
  assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
110
109
  end
@@ -128,8 +127,9 @@ module Stripe
128
127
  :data => [{ :id => 2 }],
129
128
  :url => "/things",
130
129
  })
131
- @mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
132
- returns(make_response({ :data => [{ :id => 1 }] }))
130
+ stub_request(:get, "#{Stripe.api_base}/things").
131
+ with(query: { ending_before: "2" }).
132
+ to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
133
133
  next_list = list.previous_page
134
134
  refute next_list.empty?
135
135
  end
@@ -140,17 +140,9 @@ module Stripe
140
140
  :url => "/things",
141
141
  })
142
142
  list.filters = { :expand => ['data.source'], :limit => 3 }
143
- @mock.expects(:get).with do |url, _, _|
144
- # apparently URI.parse in 1.8.7 doesn't support query parameters ...
145
- url, query = url.split("?")
146
- u = URI.parse(url)
147
- params = CGI.parse(query)
148
- u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
149
- "ending_before" => ["2"],
150
- "expand[]" => ["data.source"],
151
- "limit" => ["3"],
152
- }
153
- 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 }] }))
154
146
  next_list = list.previous_page
155
147
  assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
156
148
  end
@@ -162,7 +154,6 @@ module Stripe
162
154
  # note that the name #all is deprecated, as is using it fetch the next page
163
155
  # in a list
164
156
  should "be able to retrieve full lists given a listobject" do
165
- @mock.expects(:get).twice.returns(make_response(make_charge_array))
166
157
  c = Stripe::Charge.all
167
158
  assert c.kind_of?(Stripe::ListObject)
168
159
  assert_equal('/v1/charges', c.resource_url)
@@ -2,24 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class OrderReturnTest < Test::Unit::TestCase
5
- should "returns should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_order_return_array))
7
- returns = Stripe::OrderReturn.list
8
- assert returns.data.kind_of?(Array)
9
- returns.each do |ret|
10
- assert ret.kind_of?(Stripe::OrderReturn)
11
- end
12
- end
5
+ FIXTURE = API_FIXTURES.fetch(:order_return)
13
6
 
14
- should "returns should not be deletable" do
15
- p = Stripe::OrderReturn.new("test_order")
16
- assert_raises(NoMethodError) { p.delete }
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)
17
12
  end
18
13
 
19
- should "returns should be immutable" do
20
- p = Stripe::OrderReturn.new("test_order")
21
- p.items = []
22
- assert_raises(NoMethodError) { p.save }
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)
23
19
  end
24
20
  end
25
21
  end
@@ -2,71 +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)
20
18
  end
21
19
 
22
- should "orders should be saveable" 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
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)
29
26
  end
30
27
 
31
- should "orders should be updateable" do
32
- @mock.expects(:post).once.
33
- with('https://api.stripe.com/v1/orders/test_order', nil, 'status=fulfilled').
34
- returns(make_response(make_order(status: 'fulfilled')))
35
- ii = Stripe::Order.update("test_order", status: 'fulfilled')
36
- assert_equal('fulfilled', ii.status)
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]}"
37
33
  end
38
34
 
39
- should "orders should allow metadata updates" do
40
- @mock.expects(:get).once.returns(make_response(make_order))
41
- @mock.expects(:post).once.returns(make_response(make_order))
42
- p = Stripe::Order.new("test_order")
43
- p.refresh
44
- p.metadata['key'] = 'value'
45
- 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)
46
39
  end
47
40
 
48
- should "pay should pay an order" do
49
- @mock.expects(:get).once.
50
- returns(make_response(make_order(:id => 'or_test_order')))
51
- order = Stripe::Order.retrieve('or_test_order')
52
-
53
- @mock.expects(:post).once.
54
- with('https://api.stripe.com/v1/orders/or_test_order/pay', nil, 'token=test_token').
55
- returns(make_response(make_paid_order))
56
- order.pay(:token => 'test_token')
57
- assert_equal "paid", order.status
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
58
47
  end
59
48
 
60
- should "return an order" do
61
- @mock.expects(:get).once.
62
- returns(make_response(make_order(:id => 'or_test_order')))
63
- order = Stripe::Order.retrieve('or_test_order')
64
-
65
- @mock.expects(:post).once.
66
- with('https://api.stripe.com/v1/orders/or_test_order/returns', nil, 'items[][parent]=sku_foo').
67
- returns(make_response(make_order_return({:order => order.id})))
68
- order_return = order.return_order(:items => [{:parent => 'sku_foo'}])
69
- assert_equal order.id, order_return.order
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
70
57
  end
71
58
  end
72
59
  end