stripe 1.31.0 → 1.58.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +5 -0
  3. data/.travis.yml +2 -12
  4. data/Gemfile +29 -4
  5. data/History.txt +168 -0
  6. data/README.md +134 -0
  7. data/Rakefile +10 -0
  8. data/VERSION +1 -1
  9. data/bin/stripe-console +12 -5
  10. data/lib/data/ca-certificates.crt +3868 -5114
  11. data/lib/stripe/account.rb +41 -21
  12. data/lib/stripe/alipay_account.rb +20 -0
  13. data/lib/stripe/api_operations/create.rb +1 -1
  14. data/lib/stripe/api_operations/delete.rb +1 -1
  15. data/lib/stripe/api_operations/list.rb +1 -2
  16. data/lib/stripe/api_operations/save.rb +87 -0
  17. data/lib/stripe/api_resource.rb +37 -4
  18. data/lib/stripe/apple_pay_domain.rb +12 -0
  19. data/lib/stripe/application_fee.rb +8 -8
  20. data/lib/stripe/application_fee_refund.rb +7 -3
  21. data/lib/stripe/balance_transaction.rb +1 -1
  22. data/lib/stripe/bank_account.rb +9 -5
  23. data/lib/stripe/bitcoin_receiver.rb +6 -6
  24. data/lib/stripe/bitcoin_transaction.rb +1 -1
  25. data/lib/stripe/card.rb +9 -5
  26. data/lib/stripe/charge.rb +30 -12
  27. data/lib/stripe/country_spec.rb +9 -0
  28. data/lib/stripe/coupon.rb +1 -1
  29. data/lib/stripe/customer.rb +6 -4
  30. data/lib/stripe/dispute.rb +2 -2
  31. data/lib/stripe/errors.rb +82 -0
  32. data/lib/stripe/file_upload.rb +1 -1
  33. data/lib/stripe/invoice.rb +3 -3
  34. data/lib/stripe/invoice_item.rb +1 -1
  35. data/lib/stripe/list_object.rb +7 -6
  36. data/lib/stripe/order.rb +10 -2
  37. data/lib/stripe/order_return.rb +9 -0
  38. data/lib/stripe/plan.rb +1 -1
  39. data/lib/stripe/product.rb +2 -10
  40. data/lib/stripe/recipient.rb +1 -1
  41. data/lib/stripe/refund.rb +1 -1
  42. data/lib/stripe/reversal.rb +7 -3
  43. data/lib/stripe/singleton_api_resource.rb +3 -3
  44. data/lib/stripe/sku.rb +2 -2
  45. data/lib/stripe/source.rb +11 -0
  46. data/lib/stripe/stripe_object.rb +167 -91
  47. data/lib/stripe/subscription.rb +15 -9
  48. data/lib/stripe/subscription_item.rb +12 -0
  49. data/lib/stripe/three_d_secure.rb +9 -0
  50. data/lib/stripe/transfer.rb +3 -4
  51. data/lib/stripe/util.rb +100 -28
  52. data/lib/stripe/version.rb +1 -1
  53. data/lib/stripe.rb +283 -140
  54. data/stripe.gemspec +5 -18
  55. data/test/stripe/account_test.rb +55 -9
  56. data/test/stripe/alipay_account_test.rb +11 -0
  57. data/test/stripe/api_operations_test.rb +31 -0
  58. data/test/stripe/api_resource_test.rb +204 -10
  59. data/test/stripe/apple_pay_domain_test.rb +34 -0
  60. data/test/stripe/application_fee_test.rb +8 -5
  61. data/test/stripe/bitcoin_receiver_test.rb +2 -2
  62. data/test/stripe/charge_refund_test.rb +12 -0
  63. data/test/stripe/charge_test.rb +32 -4
  64. data/test/stripe/country_spec_test.rb +43 -0
  65. data/test/stripe/coupon_test.rb +9 -1
  66. data/test/stripe/customer_card_test.rb +2 -2
  67. data/test/stripe/customer_test.rb +24 -1
  68. data/test/stripe/dispute_test.rb +8 -0
  69. data/test/stripe/errors_test.rb +18 -0
  70. data/test/stripe/invoice_item_test.rb +19 -0
  71. data/test/stripe/invoice_test.rb +27 -1
  72. data/test/stripe/list_object_test.rb +36 -15
  73. data/test/stripe/order_return_test.rb +25 -0
  74. data/test/stripe/order_test.rb +21 -1
  75. data/test/stripe/plan_test.rb +31 -0
  76. data/test/stripe/product_test.rb +17 -7
  77. data/test/stripe/recipient_card_test.rb +2 -2
  78. data/test/stripe/recipient_test.rb +21 -0
  79. data/test/stripe/refund_test.rb +10 -1
  80. data/test/stripe/sku_test.rb +15 -6
  81. data/test/stripe/source_test.rb +83 -0
  82. data/test/stripe/stripe_object_test.rb +180 -11
  83. data/test/stripe/subscription_item_test.rb +76 -0
  84. data/test/stripe/subscription_test.rb +161 -37
  85. data/test/stripe/three_d_secure_test.rb +22 -0
  86. data/test/stripe/transfer_test.rb +8 -0
  87. data/test/stripe/util_test.rb +48 -16
  88. data/test/stripe_test.rb +58 -0
  89. data/test/test_data.rb +337 -27
  90. data/test/test_helper.rb +7 -3
  91. metadata +47 -133
  92. data/README.rdoc +0 -68
  93. data/gemfiles/default-with-activesupport.gemfile +0 -10
  94. data/gemfiles/json.gemfile +0 -12
  95. data/gemfiles/yajl.gemfile +0 -12
  96. data/lib/stripe/api_operations/update.rb +0 -58
  97. data/lib/stripe/errors/api_connection_error.rb +0 -4
  98. data/lib/stripe/errors/api_error.rb +0 -4
  99. data/lib/stripe/errors/authentication_error.rb +0 -4
  100. data/lib/stripe/errors/card_error.rb +0 -12
  101. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  102. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  103. data/lib/stripe/errors/stripe_error.rb +0 -26
@@ -3,23 +3,51 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  module Stripe
4
4
  class UtilTest < Test::Unit::TestCase
5
5
  should "#encode_parameters should prepare parameters for an HTTP request" do
6
- # use array instead of hash for 1.8.7 ordering
7
- params = [
8
- [:a, 3],
9
- [:b, "+foo?"],
10
- [:c, "bar&baz"],
11
- [:d, { :a => "a", :b => "b" }],
12
- [:e, [0, 1]],
6
+ params = {
7
+ :a => 3,
8
+ :b => "+foo?",
9
+ :c => "bar&baz",
10
+ :d => { :a => "a", :b => "b" },
11
+ :e => [0, 1],
12
+ :f => "",
13
13
 
14
14
  # note the empty hash won't even show up in the request
15
- [:f, []]
16
- ]
15
+ :g => [],
16
+ }
17
17
  assert_equal(
18
- "a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1",
18
+ "a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1&f=",
19
19
  Stripe::Util.encode_parameters(params)
20
20
  )
21
21
  end
22
22
 
23
+ should "#encode_params should throw an error on an array of maps that cannot be encoded" do
24
+ params = {
25
+ :a => [
26
+ { :a => 1, :b => 2 },
27
+ { :c => 3, :a => 4 },
28
+ ]
29
+ }
30
+ e = assert_raises(ArgumentError) do
31
+ Stripe::Util.encode_parameters(params)
32
+ end
33
+ expected = "All maps nested in an array should start with the same key " +
34
+ "(expected starting key 'a', got 'c')"
35
+ assert_equal expected, e.message
36
+
37
+ # Make sure the check is recursive by taking our original params and
38
+ # nesting it into yet another map and array. Should throw exactly the
39
+ # same error because it's still the in inner array of maps that's wrong.
40
+ params = {
41
+ :x => [
42
+ params
43
+ ]
44
+ }
45
+ e = assert_raises(ArgumentError) do
46
+ Stripe::Util.encode_parameters(params)
47
+ end
48
+ assert_equal expected, e.message
49
+ end
50
+
23
51
  should "#url_encode should prepare strings for HTTP" do
24
52
  assert_equal "foo", Stripe::Util.url_encode("foo")
25
53
  assert_equal "foo", Stripe::Util.url_encode(:foo)
@@ -36,8 +64,8 @@ module Stripe
36
64
  [:d, { :a => "a", :b => "b" }],
37
65
  [:e, [0, 1]],
38
66
  [:f, [
39
- { :bar => "1", :foo => "2" },
40
- { :baz => "3", :foo => "4" },
67
+ { :foo => "1", :ghi => "2" },
68
+ { :foo => "3", :bar => "4" },
41
69
  ]],
42
70
  ]
43
71
  assert_equal([
@@ -52,10 +80,10 @@ module Stripe
52
80
  # *The key here is the order*. In order to be properly interpreted as
53
81
  # an array of hashes on the server, everything from a single hash must
54
82
  # come in at once. A duplicate key in an array triggers a new element.
55
- ["f[][bar]", "1"],
56
- ["f[][foo]", "2"],
57
- ["f[][baz]", "3"],
58
- ["f[][foo]", "4"],
83
+ ["f[][foo]", "1"],
84
+ ["f[][ghi]", "2"],
85
+ ["f[][foo]", "3"],
86
+ ["f[][bar]", "4"],
59
87
  ], Stripe::Util.flatten_params(params))
60
88
  end
61
89
 
@@ -113,5 +141,9 @@ module Stripe
113
141
  obj = Util.convert_to_stripe_object([1, 2, 3], {})
114
142
  assert_equal [1, 2, 3], obj
115
143
  end
144
+
145
+ should "#array_to_hash should convert an array into a hash with integer keys" do
146
+ assert_equal({"0" => 1, "1" => 2, "2" => 3}, Util.array_to_hash([1, 2, 3]))
147
+ end
116
148
  end
117
149
  end
data/test/stripe_test.rb CHANGED
@@ -13,4 +13,62 @@ class StripeTest < Test::Unit::TestCase
13
13
  $stderr = old_stderr
14
14
  end
15
15
  end
16
+
17
+ should "allow ca_bundle_path to be configured" do
18
+ begin
19
+ old = Stripe.ca_bundle_path
20
+ Stripe.ca_bundle_path = "path/to/ca/bundle"
21
+ assert_equal "path/to/ca/bundle", Stripe.ca_bundle_path
22
+ ensure
23
+ Stripe.ca_bundle_path = old
24
+ end
25
+ end
26
+
27
+ should "allow max_network_retries to be configured" do
28
+ begin
29
+ old = Stripe.max_network_retries
30
+ Stripe.max_network_retries = 99
31
+ assert_equal 99, Stripe.max_network_retries
32
+ ensure
33
+ Stripe.max_network_retries = old
34
+ end
35
+ end
36
+
37
+ should "makes requests with the Stripe-Account header" do
38
+ response = make_account(
39
+ charges_enabled: false,
40
+ details_submitted: false,
41
+ email: "test+bindings@stripe.com"
42
+ )
43
+ Stripe.stripe_account = 'acct_1234'
44
+
45
+ Stripe.expects(:execute_request).with(
46
+ has_entry(:headers, has_entry('Stripe-Account', 'acct_1234')),
47
+ ).returns(make_response(response))
48
+
49
+ Stripe.request(:post, '/v1/account', 'sk_live12334566')
50
+ end
51
+
52
+ context "#get_uname" do
53
+ should "run without failure" do
54
+ # Don't actually check the result because we try a variety of different
55
+ # strategies that will have different results depending on where this
56
+ # test and running. We're mostly making sure that no exception is thrown.
57
+ _ = Stripe.get_uname
58
+ end
59
+ end
60
+
61
+ context "#get_uname_from_system" do
62
+ should "run without failure" do
63
+ # as above, just verify that an exception is not thrown
64
+ _ = Stripe.get_uname_from_system
65
+ end
66
+ end
67
+
68
+ context "#get_uname_from_system_ver" do
69
+ should "run without failure" do
70
+ # as above, just verify that an exception is not thrown
71
+ _ = Stripe.get_uname_from_system_ver
72
+ end
73
+ end
16
74
  end