stripe 5.31.0 → 5.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/VERSION +1 -1
  4. data/lib/stripe/version.rb +1 -1
  5. data/stripe.gemspec +9 -2
  6. metadata +3 -195
  7. data/.editorconfig +0 -10
  8. data/.gitattributes +0 -4
  9. data/.github/ISSUE_TEMPLATE.md +0 -5
  10. data/.github/workflows/ci.yml +0 -34
  11. data/.gitignore +0 -8
  12. data/.rubocop.yml +0 -81
  13. data/.rubocop_todo.yml +0 -33
  14. data/.travis.yml +0 -38
  15. data/.vscode/extensions.json +0 -7
  16. data/.vscode/settings.json +0 -8
  17. data/test/openapi/README.md +0 -9
  18. data/test/stripe/account_link_test.rb +0 -18
  19. data/test/stripe/account_test.rb +0 -412
  20. data/test/stripe/alipay_account_test.rb +0 -37
  21. data/test/stripe/api_operations_test.rb +0 -80
  22. data/test/stripe/api_resource_test.rb +0 -646
  23. data/test/stripe/apple_pay_domain_test.rb +0 -46
  24. data/test/stripe/application_fee_refund_test.rb +0 -37
  25. data/test/stripe/application_fee_test.rb +0 -58
  26. data/test/stripe/balance_test.rb +0 -13
  27. data/test/stripe/balance_transaction_test.rb +0 -20
  28. data/test/stripe/bank_account_test.rb +0 -36
  29. data/test/stripe/billing_portal/configuration_test.rb +0 -37
  30. data/test/stripe/billing_portal/session_test.rb +0 -18
  31. data/test/stripe/capability_test.rb +0 -45
  32. data/test/stripe/charge_test.rb +0 -64
  33. data/test/stripe/checkout/session_test.rb +0 -53
  34. data/test/stripe/connection_manager_test.rb +0 -210
  35. data/test/stripe/country_spec_test.rb +0 -20
  36. data/test/stripe/coupon_test.rb +0 -61
  37. data/test/stripe/credit_note_test.rb +0 -90
  38. data/test/stripe/customer_balance_transaction_test.rb +0 -37
  39. data/test/stripe/customer_card_test.rb +0 -48
  40. data/test/stripe/customer_test.rb +0 -226
  41. data/test/stripe/dispute_test.rb +0 -51
  42. data/test/stripe/ephemeral_key_test.rb +0 -93
  43. data/test/stripe/errors_test.rb +0 -53
  44. data/test/stripe/exchange_rate_test.rb +0 -20
  45. data/test/stripe/file_link_test.rb +0 -41
  46. data/test/stripe/file_test.rb +0 -87
  47. data/test/stripe/instrumentation_test.rb +0 -74
  48. data/test/stripe/invoice_item_test.rb +0 -66
  49. data/test/stripe/invoice_line_item_test.rb +0 -8
  50. data/test/stripe/invoice_test.rb +0 -229
  51. data/test/stripe/issuing/authorization_test.rb +0 -72
  52. data/test/stripe/issuing/card_test.rb +0 -74
  53. data/test/stripe/issuing/cardholder_test.rb +0 -53
  54. data/test/stripe/issuing/dispute_test.rb +0 -54
  55. data/test/stripe/issuing/transaction_test.rb +0 -48
  56. data/test/stripe/list_object_test.rb +0 -202
  57. data/test/stripe/login_link_test.rb +0 -37
  58. data/test/stripe/mandate_test.rb +0 -14
  59. data/test/stripe/multipart_encoder_test.rb +0 -130
  60. data/test/stripe/oauth_test.rb +0 -149
  61. data/test/stripe/order_return_test.rb +0 -21
  62. data/test/stripe/order_test.rb +0 -82
  63. data/test/stripe/payment_intent_test.rb +0 -107
  64. data/test/stripe/payment_method_test.rb +0 -84
  65. data/test/stripe/payout_test.rb +0 -72
  66. data/test/stripe/person_test.rb +0 -46
  67. data/test/stripe/plan_test.rb +0 -98
  68. data/test/stripe/price_test.rb +0 -48
  69. data/test/stripe/product_test.rb +0 -58
  70. data/test/stripe/promotion_code_test.rb +0 -42
  71. data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
  72. data/test/stripe/radar/value_list_item_test.rb +0 -48
  73. data/test/stripe/radar/value_list_test.rb +0 -61
  74. data/test/stripe/recipient_test.rb +0 -62
  75. data/test/stripe/refund_test.rb +0 -39
  76. data/test/stripe/reporting/report_run_test.rb +0 -33
  77. data/test/stripe/reporting/report_type_test.rb +0 -22
  78. data/test/stripe/reversal_test.rb +0 -43
  79. data/test/stripe/review_test.rb +0 -27
  80. data/test/stripe/setup_attempt_test.rb +0 -16
  81. data/test/stripe/setup_intent_test.rb +0 -84
  82. data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
  83. data/test/stripe/sku_test.rb +0 -60
  84. data/test/stripe/source_test.rb +0 -119
  85. data/test/stripe/stripe_client_test.rb +0 -1456
  86. data/test/stripe/stripe_configuration_test.rb +0 -159
  87. data/test/stripe/stripe_object_test.rb +0 -510
  88. data/test/stripe/stripe_response_test.rb +0 -95
  89. data/test/stripe/subscription_item_test.rb +0 -84
  90. data/test/stripe/subscription_schedule_test.rb +0 -82
  91. data/test/stripe/subscription_test.rb +0 -80
  92. data/test/stripe/tax_id_test.rb +0 -31
  93. data/test/stripe/tax_rate_test.rb +0 -43
  94. data/test/stripe/terminal/connection_token_test.rb +0 -16
  95. data/test/stripe/terminal/location_test.rb +0 -68
  96. data/test/stripe/terminal/reader_test.rb +0 -62
  97. data/test/stripe/three_d_secure_test.rb +0 -23
  98. data/test/stripe/topup_test.rb +0 -62
  99. data/test/stripe/transfer_test.rb +0 -88
  100. data/test/stripe/usage_record_summary_test.rb +0 -29
  101. data/test/stripe/util_test.rb +0 -402
  102. data/test/stripe/webhook_endpoint_test.rb +0 -59
  103. data/test/stripe/webhook_test.rb +0 -135
  104. data/test/stripe_mock.rb +0 -78
  105. data/test/stripe_test.rb +0 -137
  106. data/test/test_data.rb +0 -61
  107. data/test/test_helper.rb +0 -74
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../../test_helper", __dir__)
4
-
5
- module Stripe
6
- module Issuing
7
- class TransactionTest < Test::Unit::TestCase
8
- should "be listable" do
9
- stub_request(:get, "#{Stripe.api_base}/v1/issuing/transactions")
10
- .to_return(body: JSON.generate(object: "list", data: [{ id: "ipi_123", object: "issuing.transaction" }]))
11
-
12
- transactions = Stripe::Issuing::Transaction.list
13
- assert_requested :get, "#{Stripe.api_base}/v1/issuing/transactions"
14
- assert transactions.data.is_a?(Array)
15
- assert transactions.data[0].is_a?(Stripe::Issuing::Transaction)
16
- end
17
-
18
- should "be retrievable" do
19
- stub_request(:get, "#{Stripe.api_base}/v1/issuing/transactions/ipi_123")
20
- .to_return(body: JSON.generate(id: "ipi_123", object: "issuing.transaction"))
21
-
22
- transaction = Stripe::Issuing::Transaction.retrieve("ipi_123")
23
- assert_requested :get, "#{Stripe.api_base}/v1/issuing/transactions/ipi_123"
24
- assert transaction.is_a?(Stripe::Issuing::Transaction)
25
- end
26
-
27
- should "be saveable" do
28
- stub_request(:post, "#{Stripe.api_base}/v1/issuing/transactions/ipi_123")
29
- .to_return(body: JSON.generate(id: "ipi_123", object: "issuing.transaction"))
30
-
31
- transaction = Stripe::Issuing::Transaction.construct_from(id: "ipi_123", object: "issuing.transaction", metadata: {})
32
- transaction.metadata["key"] = "value"
33
- transaction.save
34
- assert_requested :post, "#{Stripe.api_base}/v1/issuing/transactions/#{transaction.id}"
35
- assert transaction.is_a?(Stripe::Issuing::Transaction)
36
- end
37
-
38
- should "be updateable" do
39
- stub_request(:post, "#{Stripe.api_base}/v1/issuing/transactions/ipi_123")
40
- .to_return(body: JSON.generate(id: "ipi_123", object: "issuing.transaction"))
41
-
42
- transaction = Stripe::Issuing::Transaction.update("ipi_123", metadata: { foo: "bar" })
43
- assert_requested :post, "#{Stripe.api_base}/v1/issuing/transactions/ipi_123"
44
- assert transaction.is_a?(Stripe::Issuing::Transaction)
45
- end
46
- end
47
- end
48
- end
@@ -1,202 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class ListObjectTest < Test::Unit::TestCase
7
- should "provide .empty_list" do
8
- list = Stripe::ListObject.empty_list
9
- assert list.empty?
10
- end
11
-
12
- should "provide #count via enumerable" do
13
- list = Stripe::ListObject.construct_from(data: [{ object: "charge" }])
14
- assert_equal 1, list.count
15
- end
16
-
17
- should "provide #each" do
18
- arr = [
19
- { id: 1 },
20
- { id: 2 },
21
- { id: 3 },
22
- ]
23
- expected = Util.convert_to_stripe_object(arr, {})
24
- list = Stripe::ListObject.construct_from(data: arr)
25
- assert_equal expected, list.each.to_a
26
- end
27
-
28
- should "provide #reverse_each" do
29
- arr = [
30
- { id: 1 },
31
- { id: 2 },
32
- { id: 3 },
33
- ]
34
- expected = Util.convert_to_stripe_object(arr.reverse, {})
35
- list = Stripe::ListObject.construct_from(data: arr)
36
- assert_equal expected, list.reverse_each.to_a
37
- end
38
-
39
- should "provide #auto_paging_each that supports forward pagination" do
40
- arr = [
41
- { id: 1 },
42
- { id: 2 },
43
- { id: 3 },
44
- { id: 4 },
45
- { id: 5 },
46
- { id: 6 },
47
- ]
48
- expected = Util.convert_to_stripe_object(arr, {})
49
-
50
- # Initial list object to page on. Notably, its last data element will be
51
- # used as a cursor to fetch the next page.
52
- list = TestListObject.construct_from(data: [{ id: 1 }],
53
- has_more: true,
54
- url: "/things")
55
- list.filters = { limit: 3 }
56
-
57
- # The test will start with the synthetic list object above, and use it as
58
- # a starting point to fetch two more pages. The second page indicates
59
- # that there are no more elements by setting `has_more` to `false`, and
60
- # iteration stops.
61
- stub_request(:get, "#{Stripe.api_base}/things")
62
- .with(query: { starting_after: "1", limit: "3" })
63
- .to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }, { id: 4 }], has_more: true, url: "/things"))
64
- stub_request(:get, "#{Stripe.api_base}/things")
65
- .with(query: { starting_after: "4", limit: "3" })
66
- .to_return(body: JSON.generate(data: [{ id: 5 }, { id: 6 }], has_more: false, url: "/things"))
67
-
68
- assert_equal expected, list.auto_paging_each.to_a
69
- end
70
-
71
- should "provide #auto_paging_each that supports backward pagination with `ending_before`" do
72
- arr = [
73
- { id: 6 },
74
- { id: 5 },
75
- { id: 4 },
76
- { id: 3 },
77
- { id: 2 },
78
- { id: 1 },
79
- ]
80
- expected = Util.convert_to_stripe_object(arr, {})
81
-
82
- # Initial list object to page on. Notably, its first data element will be
83
- # used as a cursor to fetch the next page.
84
- list = TestListObject.construct_from(data: [{ id: 6 }],
85
- has_more: true,
86
- url: "/things")
87
-
88
- # We also add an `ending_before` filter on the list to simulate backwards
89
- # pagination.
90
- list.filters = { ending_before: 7, limit: 3 }
91
-
92
- # The test will start with the synthetic list object above, and use it as
93
- # a starting point to fetch two more pages. The second page indicates
94
- # that there are no more elements by setting `has_more` to `false`, and
95
- # iteration stops.
96
- stub_request(:get, "#{Stripe.api_base}/things")
97
- .with(query: { ending_before: "6", limit: "3" })
98
- .to_return(body: JSON.generate(data: [{ id: 3 }, { id: 4 }, { id: 5 }], has_more: true, url: "/things"))
99
- stub_request(:get, "#{Stripe.api_base}/things")
100
- .with(query: { ending_before: "3", limit: "3" })
101
- .to_return(body: JSON.generate(data: [{ id: 1 }, { id: 2 }], has_more: false, url: "/things"))
102
-
103
- assert_equal expected, list.auto_paging_each.to_a
104
- end
105
-
106
- should "provide #auto_paging_each that responds to a block" do
107
- arr = [
108
- { id: 1 },
109
- { id: 2 },
110
- { id: 3 },
111
- ]
112
- expected = Util.convert_to_stripe_object(arr, {})
113
-
114
- list = TestListObject.construct_from(data: [{ id: 1 }],
115
- has_more: true,
116
- url: "/things")
117
- stub_request(:get, "#{Stripe.api_base}/things")
118
- .with(query: { starting_after: "1" })
119
- .to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
120
-
121
- actual = []
122
- list.auto_paging_each do |obj|
123
- actual << obj
124
- end
125
-
126
- assert_equal expected, actual
127
- end
128
-
129
- should "provide #empty?" do
130
- list = Stripe::ListObject.construct_from(data: [])
131
- assert list.empty?
132
- list = Stripe::ListObject.construct_from(data: [{}])
133
- refute list.empty?
134
- end
135
-
136
- #
137
- # next_page
138
- #
139
-
140
- should "fetch a next page through #next_page" do
141
- list = TestListObject.construct_from(data: [{ id: 1 }],
142
- has_more: true,
143
- url: "/things")
144
- stub_request(:get, "#{Stripe.api_base}/things")
145
- .with(query: { starting_after: "1" })
146
- .to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
147
- next_list = list.next_page
148
- refute next_list.empty?
149
- end
150
-
151
- should "fetch a next page through #next_page and respect limit" do
152
- list = TestListObject.construct_from(data: [{ id: 1 }],
153
- has_more: true,
154
- url: "/things")
155
- list.filters = { expand: ["data.source"], limit: 3 }
156
- stub_request(:get, "#{Stripe.api_base}/things")
157
- .with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" })
158
- .to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
159
- next_list = list.next_page
160
- assert_equal({ expand: ["data.source"], limit: 3, starting_after: 1 }, next_list.filters)
161
- end
162
-
163
- should "fetch an empty page through #next_page" do
164
- list = TestListObject.construct_from(data: [{ id: 1 }],
165
- has_more: false,
166
- url: "/things")
167
- next_list = list.next_page
168
- assert_equal Stripe::ListObject.empty_list, next_list
169
- end
170
-
171
- #
172
- # previous_page
173
- #
174
-
175
- should "fetch a next page through #previous_page" do
176
- list = TestListObject.construct_from(data: [{ id: 2 }],
177
- has_more: true,
178
- url: "/things")
179
- stub_request(:get, "#{Stripe.api_base}/things")
180
- .with(query: { ending_before: "2" })
181
- .to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false))
182
- next_list = list.previous_page
183
- refute next_list.empty?
184
- end
185
-
186
- should "fetch a next page through #previous_page and respect limit" do
187
- list = TestListObject.construct_from(data: [{ id: 2 }],
188
- has_more: true,
189
- url: "/things")
190
- list.filters = { expand: ["data.source"], limit: 3 }
191
- stub_request(:get, "#{Stripe.api_base}/things")
192
- .with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" })
193
- .to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false))
194
- next_list = list.previous_page
195
- assert_equal({ ending_before: 2, expand: ["data.source"], limit: 3 }, next_list.filters)
196
- end
197
- end
198
- end
199
-
200
- # A helper class with a URL that allows us to try out pagination.
201
- class TestListObject < Stripe::ListObject
202
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class LoginLinkTest < Test::Unit::TestCase
7
- setup do
8
- account_fixture = {
9
- "id" => "acct_123",
10
- "object" => "account",
11
- "login_links" => {
12
- "data" => [],
13
- "has_more" => false,
14
- "object" => "list",
15
- "url" => "/v1/accounts/acct_123/login_links",
16
- },
17
- }
18
- @account = Stripe::Account.construct_from(account_fixture)
19
- end
20
-
21
- should "not be retrievable" do
22
- assert_raises NotImplementedError do
23
- Stripe::LoginLink.retrieve("foo")
24
- end
25
- end
26
-
27
- should "be creatable" do
28
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/#{@account.id}/login_links")
29
- .to_return(body: JSON.generate(object: "login_link"))
30
-
31
- login_link = @account.login_links.create
32
- assert_requested :post,
33
- "#{Stripe.api_base}/v1/accounts/#{@account.id}/login_links"
34
- assert login_link.is_a?(Stripe::LoginLink)
35
- end
36
- end
37
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class MandateTest < Test::Unit::TestCase
7
- should "be retrievable" do
8
- schedule = Stripe::Mandate.retrieve("mandate_123")
9
- assert_requested :get,
10
- "#{Stripe.api_base}/v1/mandates/mandate_123"
11
- assert schedule.is_a?(Stripe::Mandate)
12
- end
13
- end
14
- end
@@ -1,130 +0,0 @@
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
@@ -1,149 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require ::File.expand_path("../test_helper", __dir__)
4
-
5
- module Stripe
6
- class OAuthTest < Test::Unit::TestCase
7
- setup do
8
- Stripe.client_id = "ca_test"
9
- end
10
-
11
- teardown do
12
- Stripe.client_id = nil
13
- end
14
-
15
- context ".authorize_url" do
16
- should "return the authorize URL" do
17
- uri_str = OAuth.authorize_url(scope: "read_write",
18
- state: "csrf_token",
19
- stripe_user: {
20
- email: "test@example.com",
21
- url: "https://example.com/profile/test",
22
- country: "US",
23
- })
24
-
25
- uri = URI.parse(uri_str)
26
- params = CGI.parse(uri.query)
27
-
28
- assert_equal("https", uri.scheme)
29
- assert_equal("connect.stripe.com", uri.host)
30
- assert_equal("/oauth/authorize", uri.path)
31
-
32
- assert_equal(["ca_test"], params["client_id"])
33
- assert_equal(["read_write"], params["scope"])
34
- assert_equal(["test@example.com"], params["stripe_user[email]"])
35
- assert_equal(["https://example.com/profile/test"], params["stripe_user[url]"])
36
- assert_equal(["US"], params["stripe_user[country]"])
37
- end
38
-
39
- should "optionally return an express path" do
40
- uri_str = OAuth.authorize_url({}, express: true)
41
-
42
- uri = URI.parse(uri_str)
43
- assert_equal("https", uri.scheme)
44
- assert_equal("connect.stripe.com", uri.host)
45
- assert_equal("/express/oauth/authorize", uri.path)
46
- end
47
-
48
- should "override the api base path when a StripeClient is provided" do
49
- client = Stripe::StripeClient.new(connect_base: "https://other.stripe.com")
50
- uri_str = OAuth.authorize_url({}, client: client)
51
-
52
- uri = URI.parse(uri_str)
53
- assert_equal("other.stripe.com", uri.host)
54
- end
55
- end
56
-
57
- context ".token" do
58
- should "exchange a code for an access token" do
59
- # The OpenAPI fixtures don't cover the OAuth endpoints, so we just
60
- # stub the request manually.
61
- stub_request(:post, "#{Stripe.connect_base}/oauth/token")
62
- .with(body: {
63
- "grant_type" => "authorization_code",
64
- "code" => "this_is_an_authorization_code",
65
- })
66
- .to_return(body: JSON.generate(access_token: "sk_access_token",
67
- scope: "read_only",
68
- livemode: false,
69
- token_type: "bearer",
70
- refresh_token: "sk_refresh_token",
71
- stripe_user_id: "acct_test",
72
- stripe_publishable_key: "pk_test"))
73
-
74
- resp = OAuth.token(grant_type: "authorization_code",
75
- code: "this_is_an_authorization_code")
76
- assert_equal("sk_access_token", resp.access_token)
77
- end
78
-
79
- should "override the API key when client_secret is passed" do
80
- stub_request(:post, "#{Stripe.connect_base}/oauth/token")
81
- .with(body: {
82
- "client_secret" => "client_secret_override",
83
- "grant_type" => "authorization_code",
84
- "code" => "this_is_an_authorization_code",
85
- })
86
- .with(headers: { "Authorization": "Bearer client_secret_override" })
87
- .to_return(body: JSON.generate(access_token: "another_access_token"))
88
-
89
- resp = OAuth.token(client_secret: "client_secret_override",
90
- grant_type: "authorization_code",
91
- code: "this_is_an_authorization_code")
92
- assert_equal("another_access_token", resp.access_token)
93
- end
94
-
95
- should "override the api base path when a StripeClient is provided" do
96
- stub_request(:post, "https://other.stripe.com/oauth/token")
97
- .with(body: {
98
- "grant_type" => "authorization_code",
99
- "code" => "this_is_an_authorization_code",
100
- })
101
- .to_return(body: JSON.generate(access_token: "sk_access_token",
102
- scope: "read_only",
103
- livemode: false,
104
- token_type: "bearer",
105
- refresh_token: "sk_refresh_token",
106
- stripe_user_id: "acct_test",
107
- stripe_publishable_key: "pk_test"))
108
-
109
- client = Stripe::StripeClient.new(connect_base: "https://other.stripe.com")
110
- resp = OAuth.token(
111
- { grant_type: "authorization_code", code: "this_is_an_authorization_code" },
112
- client: client
113
- )
114
-
115
- assert_equal("sk_access_token", resp.access_token)
116
- end
117
- end
118
-
119
- context ".deauthorize" do
120
- should "deauthorize an account" do
121
- # The OpenAPI fixtures don't cover the OAuth endpoints, so we just
122
- # stub the request manually.
123
- stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize")
124
- .with(body: {
125
- "client_id" => "ca_test",
126
- "stripe_user_id" => "acct_test_deauth",
127
- })
128
- .to_return(body: JSON.generate(stripe_user_id: "acct_test_deauth"))
129
-
130
- resp = OAuth.deauthorize(stripe_user_id: "acct_test_deauth")
131
- assert_equal("acct_test_deauth", resp.stripe_user_id)
132
- end
133
-
134
- should "override the api base path when a StripeClient is provided" do
135
- stub_request(:post, "https://other.stripe.com/oauth/deauthorize")
136
- .with(body: {
137
- "client_id" => "ca_test",
138
- "stripe_user_id" => "acct_test_deauth",
139
- })
140
- .to_return(body: JSON.generate(stripe_user_id: "acct_test_deauth"))
141
-
142
- client = Stripe::StripeClient.new(connect_base: "https://other.stripe.com")
143
- resp = OAuth.deauthorize({ stripe_user_id: "acct_test_deauth" }, client: client)
144
-
145
- assert_equal("acct_test_deauth", resp.stripe_user_id)
146
- end
147
- end
148
- end
149
- end