stripe 1.18.0 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +11 -1
  4. data/History.txt +98 -0
  5. data/README.rdoc +19 -10
  6. data/VERSION +1 -1
  7. data/lib/stripe/account.rb +46 -4
  8. data/lib/stripe/api_operations/create.rb +3 -10
  9. data/lib/stripe/api_operations/delete.rb +4 -4
  10. data/lib/stripe/api_operations/list.rb +17 -9
  11. data/lib/stripe/api_operations/request.rb +41 -0
  12. data/lib/stripe/api_operations/update.rb +41 -40
  13. data/lib/stripe/api_resource.rb +7 -4
  14. data/lib/stripe/application_fee.rb +3 -4
  15. data/lib/stripe/application_fee_refund.rb +1 -1
  16. data/lib/stripe/balance_transaction.rb +1 -1
  17. data/lib/stripe/bank_account.rb +19 -0
  18. data/lib/stripe/bitcoin_receiver.rb +12 -2
  19. data/lib/stripe/bitcoin_transaction.rb +5 -0
  20. data/lib/stripe/card.rb +6 -4
  21. data/lib/stripe/charge.rb +14 -22
  22. data/lib/stripe/coupon.rb +2 -2
  23. data/lib/stripe/customer.rb +24 -26
  24. data/lib/stripe/dispute.rb +16 -0
  25. data/lib/stripe/errors/card_error.rb +3 -2
  26. data/lib/stripe/errors/invalid_request_error.rb +3 -2
  27. data/lib/stripe/errors/rate_limit_error.rb +4 -0
  28. data/lib/stripe/errors/stripe_error.rb +8 -2
  29. data/lib/stripe/event.rb +1 -1
  30. data/lib/stripe/file_upload.rb +12 -22
  31. data/lib/stripe/invoice.rb +8 -8
  32. data/lib/stripe/invoice_item.rb +2 -2
  33. data/lib/stripe/list_object.rb +77 -13
  34. data/lib/stripe/order.rb +19 -0
  35. data/lib/stripe/plan.rb +2 -2
  36. data/lib/stripe/product.rb +16 -0
  37. data/lib/stripe/recipient.rb +2 -2
  38. data/lib/stripe/refund.rb +2 -9
  39. data/lib/stripe/reversal.rb +14 -0
  40. data/lib/stripe/singleton_api_resource.rb +2 -2
  41. data/lib/stripe/sku.rb +8 -0
  42. data/lib/stripe/stripe_object.rb +232 -46
  43. data/lib/stripe/subscription.rb +3 -3
  44. data/lib/stripe/token.rb +1 -1
  45. data/lib/stripe/transfer.rb +3 -3
  46. data/lib/stripe/util.rb +64 -21
  47. data/lib/stripe/version.rb +1 -1
  48. data/lib/stripe.rb +102 -67
  49. data/stripe.gemspec +0 -2
  50. data/test/stripe/account_test.rb +135 -6
  51. data/test/stripe/api_resource_test.rb +326 -42
  52. data/test/stripe/application_fee_refund_test.rb +6 -6
  53. data/test/stripe/application_fee_test.rb +3 -3
  54. data/test/stripe/balance_test.rb +11 -0
  55. data/test/stripe/bitcoin_receiver_test.rb +30 -7
  56. data/test/stripe/bitcoin_transaction_test.rb +29 -0
  57. data/test/stripe/charge_refund_test.rb +55 -0
  58. data/test/stripe/charge_test.rb +32 -13
  59. data/test/stripe/coupon_test.rb +3 -3
  60. data/test/stripe/customer_card_test.rb +20 -14
  61. data/test/stripe/customer_test.rb +15 -15
  62. data/test/stripe/dispute_test.rb +45 -0
  63. data/test/stripe/file_upload_test.rb +17 -6
  64. data/test/stripe/invoice_test.rb +18 -4
  65. data/test/stripe/list_object_test.rb +126 -2
  66. data/test/stripe/metadata_test.rb +28 -13
  67. data/test/stripe/order_test.rb +52 -0
  68. data/test/stripe/product_test.rb +41 -0
  69. data/test/stripe/recipient_card_test.rb +9 -9
  70. data/test/stripe/refund_test.rb +23 -15
  71. data/test/stripe/reversal_test.rb +47 -0
  72. data/test/stripe/sku_test.rb +24 -0
  73. data/test/stripe/stripe_object_test.rb +67 -6
  74. data/test/stripe/subscription_test.rb +13 -13
  75. data/test/stripe/transfer_test.rb +4 -4
  76. data/test/stripe/util_test.rb +45 -29
  77. data/test/stripe_test.rb +16 -0
  78. data/test/test_data.rb +273 -66
  79. metadata +47 -76
  80. data/lib/stripe/certificate_blacklist.rb +0 -55
  81. data/test/stripe/certificate_blacklist_test.rb +0 -18
@@ -3,7 +3,7 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  module Stripe
4
4
  class SubscriptionTest < Test::Unit::TestCase
5
5
  should "subscriptions should be listable" do
6
- @mock.expects(:get).once.returns(test_response(test_customer))
6
+ @mock.expects(:get).once.returns(make_response(make_customer))
7
7
 
8
8
  customer = Stripe::Customer.retrieve('test_customer')
9
9
 
@@ -11,7 +11,7 @@ module Stripe
11
11
  end
12
12
 
13
13
  should "subscriptions should be refreshable" do
14
- @mock.expects(:get).twice.returns(test_response(test_customer), test_response(test_subscription(:id => 'refreshed_subscription')))
14
+ @mock.expects(:get).twice.returns(make_response(make_customer), make_response(make_subscription(:id => 'refreshed_subscription')))
15
15
 
16
16
  customer = Stripe::Customer.retrieve('test_customer')
17
17
  subscription = customer.subscriptions.first
@@ -21,20 +21,20 @@ module Stripe
21
21
  end
22
22
 
23
23
  should "subscriptions should be deletable" do
24
- @mock.expects(:get).once.returns(test_response(test_customer))
24
+ @mock.expects(:get).once.returns(make_response(make_customer))
25
25
  customer = Stripe::Customer.retrieve('test_customer')
26
26
  subscription = customer.subscriptions.first
27
27
 
28
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}?at_period_end=true", nil, nil).returns(test_response(test_subscription))
28
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}?at_period_end=true", nil, nil).returns(make_response(make_subscription))
29
29
  subscription.delete :at_period_end => true
30
30
 
31
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}", nil, nil).returns(test_response(test_subscription))
31
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}", nil, nil).returns(make_response(make_subscription))
32
32
  subscription.delete
33
33
  end
34
34
 
35
35
  should "subscriptions should be updateable" do
36
- @mock.expects(:get).once.returns(test_response(test_customer))
37
- @mock.expects(:post).once.returns(test_response(test_subscription({:status => 'active'})))
36
+ @mock.expects(:get).once.returns(make_response(make_customer))
37
+ @mock.expects(:post).once.returns(make_response(make_subscription({:status => 'active'})))
38
38
 
39
39
  customer = Stripe::Customer.retrieve('test_customer')
40
40
  subscription = customer.subscriptions.first
@@ -47,8 +47,8 @@ module Stripe
47
47
  end
48
48
 
49
49
  should "create should return a new subscription" do
50
- @mock.expects(:get).once.returns(test_response(test_customer))
51
- @mock.expects(:post).once.returns(test_response(test_subscription(:id => 'test_new_subscription')))
50
+ @mock.expects(:get).once.returns(make_response(make_customer))
51
+ @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
52
52
 
53
53
  customer = Stripe::Customer.retrieve('test_customer')
54
54
  subscription = customer.subscriptions.create(:plan => 'silver')
@@ -56,15 +56,15 @@ module Stripe
56
56
  end
57
57
 
58
58
  should "be able to delete a subscriptions's discount" do
59
- @mock.expects(:get).once.returns(test_response(test_customer))
60
- @mock.expects(:post).once.returns(test_response(test_subscription(:id => 'test_new_subscription')))
59
+ @mock.expects(:get).once.returns(make_response(make_customer))
60
+ @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
61
61
 
62
62
 
63
- customer = Stripe::Customer.retrieve("test_customer")
63
+ customer = Stripe::Customer.retrieve('test_customer')
64
64
  subscription = customer.subscriptions.create(:plan => 'silver')
65
65
 
66
66
  url = "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/test_new_subscription/discount"
67
- @mock.expects(:delete).once.with(url, nil, nil).returns(test_response(test_delete_discount_response))
67
+ @mock.expects(:delete).once.with(url, nil, nil).returns(make_response(make_delete_discount_response))
68
68
  subscription.delete_discount
69
69
  assert_equal nil, subscription.discount
70
70
  end
@@ -3,22 +3,22 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  module Stripe
4
4
  class TransferTest < Test::Unit::TestCase
5
5
  should "retrieve should retrieve transfer" do
6
- @mock.expects(:get).once.returns(test_response(test_transfer))
6
+ @mock.expects(:get).once.returns(make_response(make_transfer))
7
7
  transfer = Stripe::Transfer.retrieve('tr_test_transfer')
8
8
  assert_equal 'tr_test_transfer', transfer.id
9
9
  end
10
10
 
11
11
  should "create should create a transfer" do
12
- @mock.expects(:post).once.returns(test_response(test_transfer))
12
+ @mock.expects(:post).once.returns(make_response(make_transfer))
13
13
  transfer = Stripe::Transfer.create
14
14
  assert_equal "tr_test_transfer", transfer.id
15
15
  end
16
16
 
17
17
  should "cancel should cancel a transfer" do
18
- @mock.expects(:get).once.returns(test_response(test_transfer))
18
+ @mock.expects(:get).once.returns(make_response(make_transfer))
19
19
  transfer = Stripe::Transfer.retrieve('tr_test_transfer')
20
20
 
21
- @mock.expects(:post).once.with('https://api.stripe.com/v1/transfers/tr_test_transfer/cancel', nil, '').returns(test_response(test_canceled_transfer))
21
+ @mock.expects(:post).once.with('https://api.stripe.com/v1/transfers/tr_test_transfer/cancel', nil, '').returns(make_response(make_canceled_transfer))
22
22
  transfer.cancel
23
23
  end
24
24
  end
@@ -2,7 +2,48 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class UtilTest < Test::Unit::TestCase
5
- should "symbolize_names should convert names to symbols" do
5
+ should "#encode_parameters should prepare parameters for an HTTP request" do
6
+ params = {
7
+ :a => 3,
8
+ :b => "+foo?",
9
+ :c => "bar&baz",
10
+ :d => { :a => "a", :b => "b" },
11
+ :e => [0, 1],
12
+ }
13
+ assert_equal(
14
+ "a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1",
15
+ Stripe::Util.encode_parameters(params)
16
+ )
17
+ end
18
+
19
+ should "#url_encode should prepare strings for HTTP" do
20
+ assert_equal "foo", Stripe::Util.url_encode("foo")
21
+ assert_equal "foo", Stripe::Util.url_encode(:foo)
22
+ assert_equal "foo%2B", Stripe::Util.url_encode("foo+")
23
+ assert_equal "foo%26", Stripe::Util.url_encode("foo&")
24
+ assert_equal "foo[bar]", Stripe::Util.url_encode("foo[bar]")
25
+ end
26
+
27
+ should "#flatten_params should encode parameters according to Rails convention" do
28
+ params = {
29
+ :a => 3,
30
+ :b => "foo?",
31
+ :c => "bar&baz",
32
+ :d => { :a => "a", :b => "b" },
33
+ :e => [0, 1],
34
+ }
35
+ assert_equal([
36
+ ["a", 3],
37
+ ["b", "foo?"],
38
+ ["c", "bar&baz"],
39
+ ["d[a]", "a"],
40
+ ["d[b]", "b"],
41
+ ["e[]", 0],
42
+ ["e[]", 1],
43
+ ], Stripe::Util.flatten_params(params))
44
+ end
45
+
46
+ should "#symbolize_names should convert names to symbols" do
6
47
  start = {
7
48
  'foo' => 'bar',
8
49
  'array' => [{ 'foo' => 'bar' }],
@@ -26,34 +67,9 @@ module Stripe
26
67
  assert_equal(finish, symbolized)
27
68
  end
28
69
 
29
- should "parse a nil opts argument" do
30
- api_key, headers = Stripe::Util.parse_opts(nil)
31
- assert_equal({}, headers)
32
- assert_equal(nil, api_key)
33
- end
34
-
35
- should "parse a string opts argument" do
36
- api_key, headers = Stripe::Util.parse_opts('foo')
37
- assert_equal({}, headers)
38
- assert_equal('foo', api_key)
39
- end
40
-
41
- should "parse a hash opts argument with just api_key" do
42
- api_key, headers = Stripe::Util.parse_opts({:api_key => 'foo'})
43
- assert_equal({}, headers)
44
- assert_equal('foo', api_key)
45
- end
46
-
47
- should "parse a hash opts argument with just idempotency_key" do
48
- api_key, headers = Stripe::Util.parse_opts({:idempotency_key => 'foo'})
49
- assert_equal({:idempotency_key => 'foo'}, headers)
50
- assert_equal(nil, api_key)
51
- end
52
-
53
- should "parse a hash opts argument both idempotency_key and api_key" do
54
- api_key, headers = Stripe::Util.parse_opts({:api_key => 'bar', :idempotency_key => 'foo'})
55
- assert_equal({:idempotency_key => 'foo'}, headers)
56
- assert_equal('bar', api_key)
70
+ should "#normalize_opts should reject nil keys" do
71
+ assert_raise { Stripe::Util.normalize_opts(nil) }
72
+ assert_raise { Stripe::Util.normalize_opts(:api_key => nil) }
57
73
  end
58
74
  end
59
75
  end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class StripeTest < Test::Unit::TestCase
4
+ should "warn that #refresh_from is deprecated" do
5
+ old_stderr = $stderr
6
+ $stderr = StringIO.new
7
+ begin
8
+ Stripe.uri_encode({})
9
+ message = "NOTE: Stripe.uri_encode is deprecated; use " +
10
+ "Stripe::Util#encode_parameters instead"
11
+ assert_match Regexp.new(message), $stderr.string
12
+ ensure
13
+ $stderr = old_stderr
14
+ end
15
+ end
16
+ end