stripe 4.20.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -4
  3. data/.rubocop_todo.yml +10 -9
  4. data/.travis.yml +2 -6
  5. data/CHANGELOG.md +52 -1
  6. data/Gemfile +2 -12
  7. data/README.md +10 -10
  8. data/Rakefile +8 -7
  9. data/VERSION +1 -1
  10. data/lib/stripe/api_operations/list.rb +0 -6
  11. data/lib/stripe/api_resource.rb +16 -0
  12. data/lib/stripe/connection_manager.rb +131 -0
  13. data/lib/stripe/error_object.rb +94 -0
  14. data/lib/stripe/errors.rb +15 -2
  15. data/lib/stripe/list_object.rb +2 -1
  16. data/lib/stripe/multipart_encoder.rb +131 -0
  17. data/lib/stripe/object_types.rb +1 -4
  18. data/lib/stripe/resources/account.rb +7 -7
  19. data/lib/stripe/resources/account_link.rb +1 -1
  20. data/lib/stripe/resources/alipay_account.rb +1 -1
  21. data/lib/stripe/resources/apple_pay_domain.rb +1 -1
  22. data/lib/stripe/resources/application_fee.rb +1 -12
  23. data/lib/stripe/resources/application_fee_refund.rb +1 -1
  24. data/lib/stripe/resources/balance.rb +1 -1
  25. data/lib/stripe/resources/balance_transaction.rb +1 -5
  26. data/lib/stripe/resources/bank_account.rb +1 -1
  27. data/lib/stripe/resources/bitcoin_receiver.rb +1 -1
  28. data/lib/stripe/resources/bitcoin_transaction.rb +1 -1
  29. data/lib/stripe/resources/capability.rb +1 -1
  30. data/lib/stripe/resources/card.rb +1 -1
  31. data/lib/stripe/resources/charge.rb +7 -69
  32. data/lib/stripe/resources/checkout/session.rb +1 -1
  33. data/lib/stripe/resources/country_spec.rb +1 -1
  34. data/lib/stripe/resources/coupon.rb +1 -1
  35. data/lib/stripe/resources/credit_note.rb +7 -3
  36. data/lib/stripe/resources/customer.rb +5 -66
  37. data/lib/stripe/resources/customer_balance_transaction.rb +1 -1
  38. data/lib/stripe/resources/discount.rb +1 -1
  39. data/lib/stripe/resources/dispute.rb +7 -9
  40. data/lib/stripe/resources/ephemeral_key.rb +1 -1
  41. data/lib/stripe/resources/event.rb +1 -1
  42. data/lib/stripe/resources/exchange_rate.rb +1 -1
  43. data/lib/stripe/resources/file.rb +3 -13
  44. data/lib/stripe/resources/file_link.rb +1 -1
  45. data/lib/stripe/resources/invoice.rb +36 -11
  46. data/lib/stripe/resources/invoice_item.rb +1 -1
  47. data/lib/stripe/resources/invoice_line_item.rb +1 -1
  48. data/lib/stripe/resources/issuing/authorization.rb +13 -5
  49. data/lib/stripe/resources/issuing/card.rb +7 -3
  50. data/lib/stripe/resources/issuing/card_details.rb +1 -1
  51. data/lib/stripe/resources/issuing/cardholder.rb +1 -1
  52. data/lib/stripe/resources/issuing/dispute.rb +1 -1
  53. data/lib/stripe/resources/issuing/transaction.rb +1 -1
  54. data/lib/stripe/resources/login_link.rb +1 -1
  55. data/lib/stripe/resources/order.rb +13 -13
  56. data/lib/stripe/resources/order_return.rb +1 -1
  57. data/lib/stripe/resources/payment_intent.rb +19 -7
  58. data/lib/stripe/resources/payment_method.rb +13 -5
  59. data/lib/stripe/resources/payout.rb +7 -9
  60. data/lib/stripe/resources/person.rb +1 -1
  61. data/lib/stripe/resources/plan.rb +1 -1
  62. data/lib/stripe/resources/product.rb +1 -1
  63. data/lib/stripe/resources/radar/early_fraud_warning.rb +1 -1
  64. data/lib/stripe/resources/radar/value_list.rb +1 -1
  65. data/lib/stripe/resources/radar/value_list_item.rb +1 -1
  66. data/lib/stripe/resources/recipient.rb +1 -5
  67. data/lib/stripe/resources/recipient_transfer.rb +1 -1
  68. data/lib/stripe/resources/refund.rb +1 -1
  69. data/lib/stripe/resources/reporting/report_run.rb +1 -1
  70. data/lib/stripe/resources/reporting/report_type.rb +1 -1
  71. data/lib/stripe/resources/reversal.rb +1 -1
  72. data/lib/stripe/resources/review.rb +7 -3
  73. data/lib/stripe/resources/setup_intent.rb +32 -0
  74. data/lib/stripe/resources/sigma/scheduled_query_run.rb +1 -1
  75. data/lib/stripe/resources/sku.rb +1 -1
  76. data/lib/stripe/resources/source.rb +7 -9
  77. data/lib/stripe/resources/source_transaction.rb +1 -1
  78. data/lib/stripe/resources/subscription.rb +9 -9
  79. data/lib/stripe/resources/subscription_item.rb +4 -1
  80. data/lib/stripe/resources/subscription_schedule.rb +13 -13
  81. data/lib/stripe/resources/tax_id.rb +1 -1
  82. data/lib/stripe/resources/tax_rate.rb +1 -1
  83. data/lib/stripe/resources/terminal/connection_token.rb +1 -1
  84. data/lib/stripe/resources/terminal/location.rb +1 -1
  85. data/lib/stripe/resources/terminal/reader.rb +1 -1
  86. data/lib/stripe/resources/three_d_secure.rb +1 -1
  87. data/lib/stripe/resources/token.rb +1 -1
  88. data/lib/stripe/resources/topup.rb +7 -3
  89. data/lib/stripe/resources/transfer.rb +7 -8
  90. data/lib/stripe/resources/usage_record.rb +1 -17
  91. data/lib/stripe/resources/usage_record_summary.rb +1 -1
  92. data/lib/stripe/resources/webhook_endpoint.rb +1 -1
  93. data/lib/stripe/resources.rb +1 -2
  94. data/lib/stripe/stripe_client.rb +281 -183
  95. data/lib/stripe/stripe_object.rb +4 -23
  96. data/lib/stripe/stripe_response.rb +53 -21
  97. data/lib/stripe/util.rb +14 -11
  98. data/lib/stripe/version.rb +1 -1
  99. data/lib/stripe/webhook.rb +1 -1
  100. data/lib/stripe.rb +56 -15
  101. data/stripe.gemspec +10 -3
  102. data/test/stripe/account_test.rb +0 -16
  103. data/test/stripe/api_operations_test.rb +2 -2
  104. data/test/stripe/api_resource_test.rb +98 -8
  105. data/test/stripe/balance_transaction_test.rb +20 -0
  106. data/test/stripe/charge_test.rb +0 -16
  107. data/test/stripe/connection_manager_test.rb +138 -0
  108. data/test/stripe/customer_test.rb +1 -44
  109. data/test/stripe/errors_test.rb +29 -8
  110. data/test/stripe/file_test.rb +0 -10
  111. data/test/stripe/invoice_test.rb +17 -1
  112. data/test/stripe/list_object_test.rb +0 -16
  113. data/test/stripe/login_link_test.rb +1 -1
  114. data/test/stripe/multipart_encoder_test.rb +130 -0
  115. data/test/stripe/payment_intent_test.rb +2 -2
  116. data/test/stripe/setup_intent_test.rb +84 -0
  117. data/test/stripe/source_test.rb +0 -18
  118. data/test/stripe/stripe_client_test.rb +214 -29
  119. data/test/stripe/stripe_object_test.rb +7 -35
  120. data/test/stripe/stripe_response_test.rb +70 -24
  121. data/test/stripe/subscription_item_test.rb +12 -0
  122. data/test/stripe/subscription_schedule_test.rb +0 -34
  123. data/test/stripe/subscription_test.rb +2 -2
  124. data/test/stripe/webhook_test.rb +2 -2
  125. data/test/stripe_mock.rb +4 -3
  126. data/test/stripe_test.rb +0 -13
  127. data/test/test_helper.rb +10 -5
  128. metadata +23 -43
  129. data/lib/stripe/resources/issuer_fraud_record.rb +0 -9
  130. data/lib/stripe/resources/subscription_schedule_revision.rb +0 -34
  131. data/test/stripe/file_upload_test.rb +0 -79
  132. data/test/stripe/issuer_fraud_record_test.rb +0 -20
  133. data/test/stripe/subscription_schedule_revision_test.rb +0 -37
  134. data/test/stripe/usage_record_test.rb +0 -28
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class ConnectionManagerTest < Test::Unit::TestCase
7
+ setup do
8
+ @manager = Stripe::ConnectionManager.new
9
+ end
10
+
11
+ context "#clear" do
12
+ should "clear any active connections" do
13
+ stub_request(:post, "#{Stripe.api_base}/path")
14
+ .to_return(body: JSON.generate(object: "account"))
15
+
16
+ # Making a request lets us know that at least one connection is open.
17
+ @manager.execute_request(:post, "#{Stripe.api_base}/path")
18
+
19
+ # Now clear the manager.
20
+ @manager.clear
21
+
22
+ # This check isn't great, but it's otherwise difficult to tell that
23
+ # anything happened with just the public-facing API.
24
+ assert_equal({}, @manager.instance_variable_get(:@active_connections))
25
+ end
26
+ end
27
+
28
+ context "#connection_for" do
29
+ should "correctly initialize a connection" do
30
+ old_proxy = Stripe.proxy
31
+
32
+ old_open_timeout = Stripe.open_timeout
33
+ old_read_timeout = Stripe.read_timeout
34
+
35
+ begin
36
+ # Make sure any global initialization here is undone in the `ensure`
37
+ # block below.
38
+ Stripe.proxy = "http://user:pass@localhost:8080"
39
+
40
+ Stripe.open_timeout = 123
41
+ Stripe.read_timeout = 456
42
+
43
+ conn = @manager.connection_for("https://stripe.com")
44
+
45
+ # Host/port
46
+ assert_equal "stripe.com", conn.address
47
+ assert_equal 443, conn.port
48
+
49
+ # Proxy
50
+ assert_equal "localhost", conn.proxy_address
51
+ assert_equal 8080, conn.proxy_port
52
+ assert_equal "user", conn.proxy_user
53
+ assert_equal "pass", conn.proxy_pass
54
+
55
+ # Timeouts
56
+ assert_equal 123, conn.open_timeout
57
+ assert_equal 456, conn.read_timeout
58
+
59
+ assert_equal true, conn.use_ssl?
60
+ assert_equal OpenSSL::SSL::VERIFY_PEER, conn.verify_mode
61
+ assert_equal Stripe.ca_store, conn.cert_store
62
+ ensure
63
+ Stripe.proxy = old_proxy
64
+
65
+ Stripe.open_timeout = old_open_timeout
66
+ Stripe.read_timeout = old_read_timeout
67
+ end
68
+ end
69
+
70
+ should "produce the same connection multiple times" do
71
+ conn1 = @manager.connection_for("https://stripe.com")
72
+ conn2 = @manager.connection_for("https://stripe.com")
73
+
74
+ assert_equal conn1, conn2
75
+ end
76
+
77
+ should "produce different connections for different hosts" do
78
+ conn1 = @manager.connection_for("https://example.com")
79
+ conn2 = @manager.connection_for("https://stripe.com")
80
+
81
+ refute_equal conn1, conn2
82
+ end
83
+
84
+ should "produce different connections for different ports" do
85
+ conn1 = @manager.connection_for("https://stripe.com:80")
86
+ conn2 = @manager.connection_for("https://stripe.com:443")
87
+
88
+ refute_equal conn1, conn2
89
+ end
90
+ end
91
+
92
+ context "#execute_request" do
93
+ should "make a request" do
94
+ stub_request(:post, "#{Stripe.api_base}/path?query=bar")
95
+ .with(
96
+ body: "body=foo",
97
+ headers: { "Stripe-Account" => "bar" }
98
+ )
99
+ .to_return(body: JSON.generate(object: "account"))
100
+
101
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
102
+ body: "body=foo",
103
+ headers: { "Stripe-Account" => "bar" },
104
+ query: "query=bar")
105
+ end
106
+
107
+ should "perform basic argument validation" do
108
+ e = assert_raises ArgumentError do
109
+ @manager.execute_request("POST", "#{Stripe.api_base}/path")
110
+ end
111
+ assert_equal e.message, "method should be a symbol"
112
+
113
+ e = assert_raises ArgumentError do
114
+ @manager.execute_request(:post, :uri)
115
+ end
116
+ assert_equal e.message, "uri should be a string"
117
+
118
+ e = assert_raises ArgumentError do
119
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
120
+ body: {})
121
+ end
122
+ assert_equal e.message, "body should be a string"
123
+
124
+ e = assert_raises ArgumentError do
125
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
126
+ headers: "foo")
127
+ end
128
+ assert_equal e.message, "headers should be a hash"
129
+
130
+ e = assert_raises ArgumentError do
131
+ @manager.execute_request(:post, "#{Stripe.api_base}/path",
132
+ query: {})
133
+ end
134
+ assert_equal e.message, "query should be a string"
135
+ end
136
+ end
137
+ end
138
+ end
@@ -53,50 +53,6 @@ module Stripe
53
53
  end
54
54
  end
55
55
 
56
- context "#create_subscription" do
57
- should "create a new subscription" do
58
- customer = Stripe::Customer.retrieve("cus_123")
59
- subscription = customer.create_subscription(items: [{ plan: "silver" }])
60
- assert_requested :post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscriptions"
61
- assert subscription.is_a?(Stripe::Subscription)
62
- end
63
- end
64
-
65
- context "#create_upcoming_invoice" do
66
- should "create a new invoice" do
67
- customer = Stripe::Customer.retrieve("cus_123")
68
- invoice = customer.create_upcoming_invoice
69
- assert_requested :post, "#{Stripe.api_base}/v1/invoices"
70
- assert invoice.is_a?(Stripe::Invoice)
71
- end
72
- end
73
-
74
- context "#update_subscription" do
75
- should "update a subscription" do
76
- customer = Stripe::Customer.retrieve("cus_123")
77
-
78
- # deprecated API and not in schema
79
- stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription")
80
- .with(body: { plan: "silver" })
81
- .to_return(body: JSON.generate(object: "subscription"))
82
- subscription = customer.update_subscription(plan: "silver")
83
- assert subscription.is_a?(Stripe::Subscription)
84
- end
85
- end
86
-
87
- context "#cancel_subscription" do
88
- should "cancel a subscription" do
89
- customer = Stripe::Customer.retrieve("cus_123")
90
-
91
- # deprecated API and not in schema
92
- stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription")
93
- .with(query: { at_period_end: "true" })
94
- .to_return(body: JSON.generate(object: "subscription"))
95
- subscription = customer.cancel_subscription(at_period_end: "true")
96
- assert subscription.is_a?(Stripe::Subscription)
97
- end
98
- end
99
-
100
56
  context "#delete_discount" do
101
57
  should "delete a discount" do
102
58
  customer = Stripe::Customer.retrieve("cus_123")
@@ -113,6 +69,7 @@ module Stripe
113
69
  assert discount.is_a?(Stripe::Discount)
114
70
  end
115
71
  end
72
+
116
73
  context "#create_source" do
117
74
  should "create a source" do
118
75
  Stripe::Customer.create_source(
@@ -4,16 +4,37 @@ require ::File.expand_path("../test_helper", __dir__)
4
4
 
5
5
  module Stripe
6
6
  class StripeErrorTest < Test::Unit::TestCase
7
- context "#to_s" do
8
- should "convert to string" do
9
- e = StripeError.new("message")
10
- assert_equal "message", e.to_s
7
+ context "StripeError" do
8
+ context "#initialize" do
9
+ should "initialize error if json_body is set" do
10
+ e = StripeError.new("message", json_body: { error: { code: "some_error" } })
11
+ assert_not_nil e.error
12
+ assert_equal "some_error", e.error.code
13
+ assert_nil e.error.charge
14
+ end
15
+ end
16
+
17
+ context "#to_s" do
18
+ should "convert to string" do
19
+ e = StripeError.new("message")
20
+ assert_equal "message", e.to_s
21
+
22
+ e = StripeError.new("message", http_status: 200)
23
+ assert_equal "(Status 200) message", e.to_s
11
24
 
12
- e = StripeError.new("message", http_status: 200)
13
- assert_equal "(Status 200) message", e.to_s
25
+ e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
26
+ assert_equal "(Request request-id) message", e.to_s
27
+ end
28
+ end
29
+ end
14
30
 
15
- e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
16
- assert_equal "(Request request-id) message", e.to_s
31
+ context "OAuth::OAuthError" do
32
+ context "#initialize" do
33
+ should "initialize error if json_body is set" do
34
+ e = OAuth::OAuthError.new("message", "description", json_body: { error: "some_oauth_error" })
35
+ assert_not_nil e.error
36
+ assert_equal "some_oauth_error", e.error.error
37
+ end
17
38
  end
18
39
  end
19
40
  end
@@ -52,16 +52,6 @@ module Stripe
52
52
  assert file.is_a?(Stripe::File)
53
53
  end
54
54
 
55
- should "be creatable with Faraday::UploadIO" do
56
- file = Stripe::File.create(
57
- purpose: "dispute_evidence",
58
- file: Faraday::UploadIO.new(::File.new(__FILE__), nil),
59
- file_link_data: { create: true }
60
- )
61
- assert_requested :post, "#{Stripe.uploads_base}/v1/files"
62
- assert file.is_a?(Stripe::File)
63
- end
64
-
65
55
  should "be creatable with a string" do
66
56
  file = Stripe::File.create(
67
57
  purpose: "dispute_evidence",
@@ -142,7 +142,7 @@ module Stripe
142
142
  end
143
143
  end
144
144
 
145
- context "#upcoming" do
145
+ context ".upcoming" do
146
146
  should "retrieve upcoming invoices" do
147
147
  invoice = Stripe::Invoice.upcoming(
148
148
  customer: "cus_123",
@@ -192,6 +192,22 @@ module Stripe
192
192
  end
193
193
  end
194
194
 
195
+ context ".list_upcoming_line_items" do
196
+ should "retrieve upcoming invoices" do
197
+ line_items = Stripe::Invoice.list_upcoming_line_items(
198
+ customer: "cus_123",
199
+ subscription: "sub_123"
200
+ )
201
+ assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming/lines",
202
+ query: {
203
+ customer: "cus_123",
204
+ subscription: "sub_123",
205
+ }
206
+ assert line_items.data.is_a?(Array)
207
+ assert line_items.data[0].is_a?(Stripe::InvoiceLineItem)
208
+ end
209
+ end
210
+
195
211
  context "#void_invoice" do
196
212
  should "void invoice" do
197
213
  invoice = Stripe::Invoice.retrieve("in_123")
@@ -132,22 +132,6 @@ module Stripe
132
132
  next_list = list.previous_page
133
133
  assert_equal({ expand: ["data.source"], limit: 3 }, next_list.filters)
134
134
  end
135
-
136
- #
137
- # backward compatibility
138
- #
139
-
140
- # note that the name #all is deprecated, as is using it fetch the next page
141
- # in a list
142
- should "be able to retrieve full lists given a listobject" do
143
- c = Stripe::Charge.all
144
- assert c.is_a?(Stripe::ListObject)
145
- assert_equal("/v1/charges", c.resource_url)
146
- all = c.all
147
- assert all.is_a?(Stripe::ListObject)
148
- assert_equal("/v1/charges", all.resource_url)
149
- assert all.data.is_a?(Array)
150
- end
151
135
  end
152
136
  end
153
137
 
@@ -12,7 +12,7 @@ module Stripe
12
12
  "data" => [],
13
13
  "has_more" => false,
14
14
  "object" => "list",
15
- "url" => "/v1/accounts/acct_123/login_links",
15
+ "url" => "/v1/accounts/acct_123/login_links",
16
16
  },
17
17
  }
18
18
  @account = Stripe::Account.construct_from(account_fixture)
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class MultipartEncoderTest < Test::Unit::TestCase
7
+ should "multipart encode parameters" do
8
+ Tempfile.create("image.jpg") do |f|
9
+ f.write "file-content"
10
+ f.flush
11
+ f.rewind
12
+
13
+ encoder = MultipartEncoder.new
14
+ encoder.encode(
15
+ file: f,
16
+ other_param: "other-param-content"
17
+ )
18
+ encoder.close
19
+ body = encoder.body
20
+
21
+ assert_equal <<~BODY.rstrip, body
22
+ --#{encoder.boundary}\r
23
+ Content-Disposition: form-data; name="file"; filename="#{::File.basename(f.path)}"\r
24
+ Content-Type: application/octet-stream\r
25
+ \r
26
+ file-content\r
27
+ --#{encoder.boundary}\r
28
+ Content-Disposition: form-data; name="other_param"\r
29
+ \r
30
+ other-param-content\r
31
+ --#{encoder.boundary}--
32
+ BODY
33
+ end
34
+ end
35
+
36
+ should "encode file-like objects" do
37
+ klass = Class.new do
38
+ def read
39
+ "klass-read-content"
40
+ end
41
+ end
42
+
43
+ encoder = MultipartEncoder.new
44
+ encoder.encode(
45
+ file_like: klass.new
46
+ )
47
+ encoder.close
48
+ body = encoder.body
49
+
50
+ assert_equal <<~BODY.rstrip, body
51
+ --#{encoder.boundary}\r
52
+ Content-Disposition: form-data; name="file_like"; filename="blob"\r
53
+ Content-Type: application/octet-stream\r
54
+ \r
55
+ klass-read-content\r
56
+ --#{encoder.boundary}--
57
+ BODY
58
+ end
59
+
60
+ should "escape quotes and line break characters in parameter names" do
61
+ encoder = MultipartEncoder.new
62
+ encoder.encode(
63
+ %("quoted\n\r") => "content"
64
+ )
65
+ encoder.close
66
+ body = encoder.body
67
+
68
+ assert_equal <<~BODY.rstrip, body
69
+ --#{encoder.boundary}\r
70
+ Content-Disposition: form-data; name="%22quoted %22"\r
71
+ \r
72
+ content\r
73
+ --#{encoder.boundary}--
74
+ BODY
75
+ end
76
+
77
+ context ".encode" do
78
+ should "provide an easy encoding shortcut" do
79
+ body, content_type = MultipartEncoder.encode(
80
+ param: "content"
81
+ )
82
+ assert_include body, %(Content-Disposition: form-data; name="param")
83
+ assert_include content_type, "#{MultipartEncoder::MULTIPART_FORM_DATA}; boundary="
84
+ end
85
+ end
86
+
87
+ context "#body" do
88
+ should "error if not yet closed" do
89
+ encoder = MultipartEncoder.new
90
+
91
+ e = assert_raises RuntimeError do
92
+ encoder.body
93
+ end
94
+ assert_equal "object must be closed before getting body", e.message
95
+ end
96
+ end
97
+
98
+ context "#close" do
99
+ should "error if closed twice" do
100
+ encoder = MultipartEncoder.new
101
+ encoder.close
102
+
103
+ e = assert_raises RuntimeError do
104
+ encoder.close
105
+ end
106
+ assert_equal "object already closed", e.message
107
+ end
108
+ end
109
+
110
+ context "#content_type" do
111
+ should "produce a content type containing boundary" do
112
+ encoder = MultipartEncoder.new
113
+ assert_equal "#{MultipartEncoder::MULTIPART_FORM_DATA}; boundary=#{encoder.boundary}",
114
+ encoder.content_type
115
+ end
116
+ end
117
+
118
+ context "#encode" do
119
+ should "error if already closed" do
120
+ encoder = MultipartEncoder.new
121
+ encoder.close
122
+
123
+ e = assert_raises RuntimeError do
124
+ encoder.encode(param: "content")
125
+ end
126
+ assert_equal "no more parameters can be written to closed object", e.message
127
+ end
128
+ end
129
+ end
130
+ end
@@ -3,9 +3,9 @@
3
3
  require ::File.expand_path("../test_helper", __dir__)
4
4
 
5
5
  module Stripe
6
- TEST_RESOURCE_ID = "pi_123".freeze
7
-
8
6
  class PaymentIntentTest < Test::Unit::TestCase
7
+ TEST_RESOURCE_ID = "pi_123"
8
+
9
9
  should "be listable" do
10
10
  payment_intents = Stripe::PaymentIntent.list
11
11
  assert_requested :get, "#{Stripe.api_base}/v1/payment_intents"
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path("../test_helper", __dir__)
4
+
5
+ module Stripe
6
+ class SetupIntentTest < Test::Unit::TestCase
7
+ TEST_RESOURCE_ID = "seti_123"
8
+
9
+ should "be listable" do
10
+ setup_intents = Stripe::SetupIntent.list
11
+ assert_requested :get, "#{Stripe.api_base}/v1/setup_intents"
12
+ assert setup_intents.data.is_a?(Array)
13
+ assert setup_intents.data[0].is_a?(Stripe::SetupIntent)
14
+ end
15
+
16
+ should "be retrievable" do
17
+ setup_intent = Stripe::SetupIntent.retrieve("seti_123")
18
+ assert_requested :get, "#{Stripe.api_base}/v1/setup_intents/seti_123"
19
+ assert setup_intent.is_a?(Stripe::SetupIntent)
20
+ end
21
+
22
+ should "be creatable" do
23
+ setup_intent = Stripe::SetupIntent.create(
24
+ payment_method_types: ["card"]
25
+ )
26
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents"
27
+ assert setup_intent.is_a?(Stripe::SetupIntent)
28
+ end
29
+
30
+ should "be saveable" do
31
+ setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent", metadata: {})
32
+ setup_intent.metadata["key"] = "value"
33
+ setup_intent.save
34
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/#{setup_intent.id}"
35
+ end
36
+
37
+ should "be updateable" do
38
+ setup_intent = Stripe::SetupIntent.update("seti_123", metadata: { foo: "bar" })
39
+
40
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123"
41
+ assert setup_intent.is_a?(Stripe::SetupIntent)
42
+ end
43
+
44
+ context "#cancel" do
45
+ should "cancel a setup_intent" do
46
+ setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent")
47
+ setup_intent = setup_intent.cancel
48
+
49
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/cancel"
50
+ assert setup_intent.is_a?(Stripe::SetupIntent)
51
+ end
52
+ end
53
+
54
+ context ".cancel" do
55
+ should "cancel a setup_intent" do
56
+ setup_intent = Stripe::SetupIntent.cancel("seti_123")
57
+
58
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/cancel"
59
+ assert setup_intent.is_a?(Stripe::SetupIntent)
60
+ end
61
+ end
62
+
63
+ context "#confirm" do
64
+ should "confirm a setup_intent" do
65
+ setup_intent = Stripe::SetupIntent.construct_from(id: "seti_123", object: "setup_intent")
66
+ setup_intent = setup_intent.confirm(
67
+ payment_method: "pm_123"
68
+ )
69
+
70
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/confirm"
71
+ assert setup_intent.is_a?(Stripe::SetupIntent)
72
+ end
73
+ end
74
+
75
+ context ".confirm" do
76
+ should "confirm a setup_intent" do
77
+ setup_intent = Stripe::SetupIntent.confirm("seti_123", payment_method: "pm_123")
78
+
79
+ assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_123/confirm"
80
+ assert setup_intent.is_a?(Stripe::SetupIntent)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -51,24 +51,6 @@ module Stripe
51
51
  end
52
52
  end
53
53
 
54
- context "#delete" do
55
- should "warn that #delete is deprecated" do
56
- old_stderr = $stderr
57
- $stderr = StringIO.new
58
- begin
59
- source = Stripe::Source.construct_from(customer: "cus_123",
60
- id: "src_123",
61
- object: "source")
62
- source.delete
63
- message = "NOTE: Stripe::Source#delete is " \
64
- "deprecated; use #detach instead"
65
- assert_match Regexp.new(message), $stderr.string
66
- ensure
67
- $stderr = old_stderr
68
- end
69
- end
70
- end
71
-
72
54
  should "not be listable" do
73
55
  assert_raises NoMethodError do
74
56
  Stripe::Source.list