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
@@ -2,62 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CustomerCardTest < Test::Unit::TestCase
5
- CUSTOMER_CARD_URL = '/v1/customers/test_customer/sources/test_card'
5
+ FIXTURE = API_FIXTURES.fetch(:source)
6
6
 
7
- def customer
8
- @mock.expects(:get).once.returns(make_response(make_customer))
9
- Stripe::Customer.retrieve('test_customer')
7
+ setup do
8
+ @customer =
9
+ Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
10
10
  end
11
11
 
12
- should "customer cards should be listable" do
13
- c = customer
14
- @mock.expects(:get).once.returns(make_response(make_customer_card_array(customer.id)))
15
- cards = c.sources.list(:object => "card").data
16
- assert cards.kind_of? Array
17
- assert cards[0].kind_of? Stripe::Card
12
+ should "be listable" do
13
+ sources = @customer.sources.list
14
+ assert sources.data.kind_of?(Array)
15
+ # because of the terrible :wildcard nature of sources, the API stub
16
+ # cannot currently replace this response with anything meaningful so we
17
+ # don't assert on the type of individual items like we do in other tests
18
18
  end
19
19
 
20
- should "customer cards should have the correct url" do
21
- c = customer
22
- @mock.expects(:get).once.returns(make_response(make_card(
23
- :id => 'test_card',
24
- :customer => 'test_customer'
25
- )))
26
- card = c.sources.retrieve('card')
27
- assert_equal CUSTOMER_CARD_URL, card.url
20
+ should "be creatable" do
21
+ card = @customer.sources.create(
22
+ source: API_FIXTURES.fetch(:token)[:id]
23
+ )
24
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
25
+ assert card.kind_of?(Stripe::BankAccount)
28
26
  end
29
27
 
30
- should "customer cards should be deletable" do
31
- c = customer
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.sources.retrieve('card')
35
- card.delete
36
- assert card.deleted
28
+ should "be deletable" do
29
+ card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
30
+ card = card.delete
31
+ assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
32
+ assert card.kind_of?(Stripe::Card)
37
33
  end
38
34
 
39
- should "customer cards should be updateable" do
40
- c = customer
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.sources.retrieve('card')
44
- assert_equal "2000", card.exp_year
45
- card.exp_year = "2100"
35
+ should "be saveable" do
36
+ card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
37
+ card.metadata['key'] = 'value'
46
38
  card.save
47
- assert_equal "2100", card.exp_year
48
- end
49
-
50
- should "create should return a new customer card" do
51
- c = customer
52
- @mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
53
- card = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
54
- assert_equal "test_card", card.id
55
- end
56
-
57
- should "raise if accessing Stripe::Card.retrieve directly" do
58
- assert_raises NotImplementedError do
59
- Stripe::Card.retrieve "card_12345"
60
- end
39
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
61
40
  end
62
41
  end
63
42
  end
@@ -2,87 +2,115 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CustomerTest < Test::Unit::TestCase
5
- should "customers should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_customer_array))
7
- c = Stripe::Customer.list.data
8
- assert c.kind_of? Array
9
- assert c[0].kind_of? Stripe::Customer
10
- end
5
+ FIXTURE = API_FIXTURES.fetch(:customer)
11
6
 
12
- should "customers should be deletable" do
13
- @mock.expects(:delete).once.returns(make_response(make_customer({:deleted => true})))
14
- c = Stripe::Customer.new("test_customer")
15
- c.delete
16
- assert c.deleted
7
+ should "be listable" do
8
+ customers = Stripe::Customer.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/customers"
10
+ assert customers.data.kind_of?(Array)
11
+ assert customers.first.kind_of?(Stripe::Customer)
17
12
  end
18
13
 
19
- should "customers should be updateable" do
20
- @mock.expects(:get).once.returns(make_response(make_customer({:mnemonic => "foo"})))
21
- @mock.expects(:post).once.returns(make_response(make_customer({:mnemonic => "bar"})))
22
- c = Stripe::Customer.new("test_customer").refresh
23
- assert_equal "foo", c.mnemonic
24
- c.mnemonic = "bar"
25
- c.save
26
- assert_equal "bar", c.mnemonic
14
+ should "be retrievable" do
15
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
17
+ assert customer.kind_of?(Stripe::Customer)
27
18
  end
28
19
 
29
- should "create should return a new customer" do
30
- @mock.expects(:post).once.returns(make_response(make_customer))
31
- c = Stripe::Customer.create
32
- assert_equal "c_test_customer", c.id
20
+ should "be creatable" do
21
+ customer = Stripe::Customer.create
22
+ assert_requested :post, "#{Stripe.api_base}/v1/customers"
23
+ assert customer.kind_of?(Stripe::Customer)
33
24
  end
34
25
 
35
- should "create_upcoming_invoice should create a new invoice" do
36
- @mock.expects(:post).once.returns(make_response(make_invoice))
37
- i = Stripe::Customer.new("test_customer").create_upcoming_invoice
38
- assert_equal "c_test_customer", i.customer
26
+ should "be saveable" do
27
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
28
+ customer.metadata['key'] = 'value'
29
+ customer.save
30
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
39
31
  end
40
32
 
41
- should "be able to update a customer's subscription" do
42
- @mock.expects(:get).once.returns(make_response(make_customer))
43
- c = Stripe::Customer.retrieve("test_customer")
44
-
45
- @mock.expects(:post).once.with do |url, api_key, params|
46
- url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
47
- end.returns(make_response(make_subscription(:plan => 'silver')))
48
- s = c.update_subscription({:plan => 'silver'})
49
-
50
- assert_equal 'subscription', s.object
51
- assert_equal 'silver', s.plan.identifier
33
+ should "be updateable" do
34
+ customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
35
+ assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
36
+ assert customer.kind_of?(Stripe::Customer)
52
37
  end
53
38
 
54
- should "be able to cancel a customer's subscription" do
55
- @mock.expects(:get).once.returns(make_response(make_customer))
56
- c = Stripe::Customer.retrieve("test_customer")
39
+ should "be deletable" do
40
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
41
+ customer = customer.delete
42
+ assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
43
+ assert customer.kind_of?(Stripe::Customer)
44
+ end
57
45
 
58
- # Not an accurate response, but whatever
46
+ context "#create_subscription" do
47
+ should "create a new subscription" do
48
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
49
+ subscription = customer.create_subscription({:plan => 'silver'})
50
+ assert subscription.kind_of?(Stripe::Subscription)
51
+ end
52
+ end
59
53
 
60
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
61
- c.cancel_subscription({:at_period_end => 'true'})
54
+ context "#create_upcoming_invoice" do
55
+ should "create a new invoice" do
56
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
57
+ invoice = customer.create_upcoming_invoice
58
+ assert invoice.kind_of?(Stripe::Invoice)
59
+ end
60
+ end
62
61
 
63
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
64
- c.cancel_subscription
62
+ context "#update_subscription" do
63
+ should "update a subscription" do
64
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
65
+
66
+ # deprecated API and not in schema
67
+ stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
68
+ with(body: { plan: "silver" }).
69
+ to_return(body: JSON.generate(API_FIXTURES[:subscription]))
70
+ subscription = customer.update_subscription({:plan => 'silver'})
71
+ assert subscription.kind_of?(Stripe::Subscription)
72
+ end
65
73
  end
66
74
 
67
- should "be able to create a subscription for a customer" do
68
- c = Stripe::Customer.new("test_customer")
75
+ context "#cancel_subscription" do
76
+ should "cancel a subscription" do
77
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
78
+
79
+ # deprecated API and not in schema
80
+ stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
81
+ with(query: { at_period_end: "true" }).
82
+ to_return(body: JSON.generate(API_FIXTURES[:subscription]))
83
+ subscription = customer.cancel_subscription({:at_period_end => 'true'})
84
+ assert subscription.kind_of?(Stripe::Subscription)
85
+ end
86
+ end
69
87
 
70
- @mock.expects(:post).once.with do |url, api_key, params|
71
- url == "#{Stripe.api_base}/v1/customers/test_customer/subscriptions" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
72
- end.returns(make_response(make_subscription(:plan => 'silver')))
73
- s = c.create_subscription({:plan => 'silver'})
88
+ context "#delete_discount" do
89
+ should "delete a discount" do
90
+ customer = Stripe::Customer.retrieve(FIXTURE[:id])
74
91
 
75
- assert_equal 'subscription', s.object
76
- assert_equal 'silver', s.plan.identifier
92
+ stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/discount").
93
+ to_return(body: JSON.generate(API_FIXTURES[:discount]))
94
+ discount = customer.delete_discount
95
+ assert discount.kind_of?(Stripe::Customer)
96
+ end
77
97
  end
78
98
 
79
- should "be able to delete a customer's discount" do
80
- @mock.expects(:get).once.returns(make_response(make_customer))
81
- c = Stripe::Customer.retrieve("test_customer")
82
-
83
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(make_response(make_delete_discount_response))
84
- c.delete_discount
85
- assert_equal nil, c.discount
99
+ context "source field" do
100
+ should "allow setting source with token" do
101
+ c = Stripe::Customer.new("test_customer")
102
+ c.source = "tok_123"
103
+ assert_equal "tok_123", c.source
104
+ end
105
+
106
+ should "allow setting source with hash and set flag" do
107
+ c = Stripe::Customer.new("test_customer")
108
+ c.source = {
109
+ :object => 'card'
110
+ }
111
+ assert_equal true, c.source.save_with_parent
112
+ end
86
113
  end
87
114
  end
88
115
  end
116
+
@@ -2,44 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class DisputeTest < Test::Unit::TestCase
5
- should "disputes should be retrievable" do
6
- @mock.expects(:get).once.returns(make_response(make_dispute))
7
- d = Stripe::Dispute.retrieve('dp_test_dispute')
8
- assert d.kind_of?(Stripe::Dispute)
5
+ FIXTURE = API_FIXTURES.fetch(:dispute)
6
+
7
+ should "be listable" do
8
+ disputes = Stripe::Dispute.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/disputes"
10
+ assert disputes.data.kind_of?(Array)
11
+ assert disputes.first.kind_of?(Stripe::Dispute)
9
12
  end
10
13
 
11
- should "disputes should be listable" do
12
- @mock.expects(:get).once.returns(make_response(make_dispute_array))
13
- d = Stripe::Dispute.list
14
- assert d.data.kind_of? Array
15
- d.each do |dispute|
16
- assert dispute.kind_of?(Stripe::Dispute)
17
- end
14
+ should "be retrievable" do
15
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
17
+ assert dispute.kind_of?(Stripe::Dispute)
18
18
  end
19
19
 
20
- should "disputes should be closeable" do
21
- @mock.expects(:get).never
22
- @mock.expects(:post).with(
23
- "#{Stripe.api_base}/v1/disputes/test_dispute/close",
24
- nil,
25
- ''
26
- ).once.returns(make_response({:id => 'dp_test_dispute', :status => 'lost'}))
27
- d = Stripe::Dispute.new('test_dispute')
28
- d.close
20
+ should "be saveable" do
21
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
22
+ dispute.metadata['key'] = 'value'
23
+ dispute.save
24
+ assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
29
25
  end
30
26
 
31
- should "disputes should be updateable" do
32
- @mock.expects(:get).once.returns(make_response(make_dispute))
33
- @mock.expects(:post).with(
34
- "#{Stripe.api_base}/v1/disputes/dp_test_dispute",
35
- nil,
36
- 'evidence[customer_name]=customer'
37
- ).once.returns(make_response(make_dispute))
27
+ should "be updateable" do
28
+ dispute = Stripe::Dispute.update(FIXTURE[:id], metadata: { key: 'value' })
29
+ assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
30
+ assert dispute.kind_of?(Stripe::Dispute)
31
+ end
38
32
 
39
- d = Stripe::Dispute.new('test_dispute')
40
- d.refresh
41
- d.evidence['customer_name'] = 'customer'
42
- d.save
33
+ context "#close" do
34
+ should "be closeable" do
35
+ dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
36
+ dispute.close
37
+ assert_requested :post,
38
+ "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}/close"
39
+ end
43
40
  end
44
41
  end
45
42
  end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class StripeErrorTest < Test::Unit::TestCase
5
+ context "#to_s" do
6
+ should "convert to string" do
7
+ e = StripeError.new("message")
8
+ assert_equal "message", e.to_s
9
+
10
+ e = StripeError.new("message", http_status: 200)
11
+ assert_equal "(Status 200) message", e.to_s
12
+
13
+ e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :request_id => "request-id" })
14
+ assert_equal "(Request request-id) message", e.to_s
15
+ end
16
+ end
17
+ end
18
+ 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
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class InvoiceItemTest < Test::Unit::TestCase
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)
45
+ end
46
+
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)
53
+ end
54
+ end
55
+ end
@@ -2,39 +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
5
+ FIXTURE = API_FIXTURES.fetch(:invoice)
6
+
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)
9
12
  end
10
13
 
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
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)
15
18
  end
16
19
 
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
+ 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)
26
+ end
20
27
 
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
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]}"
24
33
  end
25
34
 
26
- should "pay with extra opts should pay an invoice" do
27
- @mock.expects(:get).once.returns(make_response(make_invoice))
28
- i = Stripe::Invoice.retrieve('in_test_invoice', {:api_key => 'foobar'})
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
29
40
 
30
- Stripe.expects(:execute_request).with do |opts|
31
- opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" &&
32
- opts[:method] == :post &&
33
- opts[:headers][:authorization] == 'Bearer foobar'
34
- end.returns(make_response(make_paid_invoice))
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
35
50
 
36
- i.pay
37
- assert_equal nil, i.next_payment_attempt
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
38
64
  end
39
65
  end
40
66
  end