stripe 5.28.0 → 5.38.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/Gemfile +0 -1
- data/README.md +5 -1
- data/VERSION +1 -1
- data/lib/stripe/api_operations/request.rb +35 -2
- data/lib/stripe/api_resource.rb +8 -0
- data/lib/stripe/connection_manager.rb +27 -10
- data/lib/stripe/error_object.rb +2 -3
- data/lib/stripe/instrumentation.rb +3 -1
- data/lib/stripe/oauth.rb +4 -3
- data/lib/stripe/object_types.rb +7 -1
- data/lib/stripe/resources/account.rb +3 -8
- data/lib/stripe/resources/application_fee_refund.rb +2 -1
- data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
- data/lib/stripe/resources/bitcoin_transaction.rb +3 -2
- data/lib/stripe/resources/capability.rb +2 -1
- data/lib/stripe/resources/credit_note_line_item.rb +1 -0
- data/lib/stripe/resources/customer.rb +6 -1
- data/lib/stripe/resources/customer_balance_transaction.rb +3 -2
- data/lib/stripe/resources/file.rb +2 -1
- data/lib/stripe/resources/identity/verification_report.rb +12 -0
- data/lib/stripe/resources/identity/verification_session.rb +35 -0
- data/lib/stripe/resources/invoice_line_item.rb +1 -0
- data/lib/stripe/resources/line_item.rb +1 -0
- data/lib/stripe/resources/login_link.rb +1 -0
- data/lib/stripe/resources/person.rb +1 -0
- data/lib/stripe/resources/quote.rb +105 -0
- data/lib/stripe/resources/reversal.rb +3 -2
- data/lib/stripe/resources/tax_code.rb +10 -0
- data/lib/stripe/resources/tax_id.rb +1 -0
- data/lib/stripe/resources/usage_record.rb +1 -0
- data/lib/stripe/resources/usage_record_summary.rb +1 -0
- data/lib/stripe/resources.rb +6 -0
- data/lib/stripe/stripe_client.rb +242 -111
- data/lib/stripe/stripe_configuration.rb +25 -9
- data/lib/stripe/stripe_object.rb +23 -0
- data/lib/stripe/stripe_response.rb +80 -52
- data/lib/stripe/util.rb +15 -7
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +23 -22
- data/stripe.gemspec +9 -2
- metadata +8 -192
- data/.editorconfig +0 -10
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -80
- data/.rubocop_todo.yml +0 -33
- data/.travis.yml +0 -38
- data/.vscode/extensions.json +0 -7
- data/.vscode/settings.json +0 -8
- data/test/openapi/README.md +0 -9
- data/test/stripe/account_link_test.rb +0 -18
- data/test/stripe/account_test.rb +0 -412
- data/test/stripe/alipay_account_test.rb +0 -37
- data/test/stripe/api_operations_test.rb +0 -80
- data/test/stripe/api_resource_test.rb +0 -646
- data/test/stripe/apple_pay_domain_test.rb +0 -46
- data/test/stripe/application_fee_refund_test.rb +0 -37
- data/test/stripe/application_fee_test.rb +0 -58
- data/test/stripe/balance_test.rb +0 -13
- data/test/stripe/balance_transaction_test.rb +0 -20
- data/test/stripe/bank_account_test.rb +0 -36
- data/test/stripe/billing_portal/session_test.rb +0 -18
- data/test/stripe/capability_test.rb +0 -45
- data/test/stripe/charge_test.rb +0 -64
- data/test/stripe/checkout/session_test.rb +0 -53
- data/test/stripe/connection_manager_test.rb +0 -167
- data/test/stripe/country_spec_test.rb +0 -20
- data/test/stripe/coupon_test.rb +0 -61
- data/test/stripe/credit_note_test.rb +0 -90
- data/test/stripe/customer_balance_transaction_test.rb +0 -37
- data/test/stripe/customer_card_test.rb +0 -48
- data/test/stripe/customer_test.rb +0 -226
- data/test/stripe/dispute_test.rb +0 -51
- data/test/stripe/ephemeral_key_test.rb +0 -93
- data/test/stripe/errors_test.rb +0 -53
- data/test/stripe/exchange_rate_test.rb +0 -20
- data/test/stripe/file_link_test.rb +0 -41
- data/test/stripe/file_test.rb +0 -87
- data/test/stripe/instrumentation_test.rb +0 -74
- data/test/stripe/invoice_item_test.rb +0 -66
- data/test/stripe/invoice_line_item_test.rb +0 -8
- data/test/stripe/invoice_test.rb +0 -229
- data/test/stripe/issuing/authorization_test.rb +0 -72
- data/test/stripe/issuing/card_test.rb +0 -74
- data/test/stripe/issuing/cardholder_test.rb +0 -53
- data/test/stripe/issuing/dispute_test.rb +0 -54
- data/test/stripe/issuing/transaction_test.rb +0 -48
- data/test/stripe/list_object_test.rb +0 -202
- data/test/stripe/login_link_test.rb +0 -37
- data/test/stripe/mandate_test.rb +0 -14
- data/test/stripe/multipart_encoder_test.rb +0 -130
- data/test/stripe/oauth_test.rb +0 -104
- data/test/stripe/order_return_test.rb +0 -21
- data/test/stripe/order_test.rb +0 -82
- data/test/stripe/payment_intent_test.rb +0 -107
- data/test/stripe/payment_method_test.rb +0 -84
- data/test/stripe/payout_test.rb +0 -72
- data/test/stripe/person_test.rb +0 -46
- data/test/stripe/plan_test.rb +0 -98
- data/test/stripe/price_test.rb +0 -48
- data/test/stripe/product_test.rb +0 -58
- data/test/stripe/promotion_code_test.rb +0 -42
- data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
- data/test/stripe/radar/value_list_item_test.rb +0 -48
- data/test/stripe/radar/value_list_test.rb +0 -61
- data/test/stripe/recipient_test.rb +0 -62
- data/test/stripe/refund_test.rb +0 -39
- data/test/stripe/reporting/report_run_test.rb +0 -33
- data/test/stripe/reporting/report_type_test.rb +0 -22
- data/test/stripe/reversal_test.rb +0 -43
- data/test/stripe/review_test.rb +0 -27
- data/test/stripe/setup_attempt_test.rb +0 -16
- data/test/stripe/setup_intent_test.rb +0 -84
- data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
- data/test/stripe/sku_test.rb +0 -60
- data/test/stripe/source_test.rb +0 -119
- data/test/stripe/stripe_client_test.rb +0 -1291
- data/test/stripe/stripe_configuration_test.rb +0 -131
- data/test/stripe/stripe_object_test.rb +0 -500
- data/test/stripe/stripe_response_test.rb +0 -95
- data/test/stripe/subscription_item_test.rb +0 -84
- data/test/stripe/subscription_schedule_test.rb +0 -82
- data/test/stripe/subscription_test.rb +0 -80
- data/test/stripe/tax_id_test.rb +0 -31
- data/test/stripe/tax_rate_test.rb +0 -43
- data/test/stripe/terminal/connection_token_test.rb +0 -16
- data/test/stripe/terminal/location_test.rb +0 -68
- data/test/stripe/terminal/reader_test.rb +0 -62
- data/test/stripe/three_d_secure_test.rb +0 -23
- data/test/stripe/topup_test.rb +0 -62
- data/test/stripe/transfer_test.rb +0 -88
- data/test/stripe/usage_record_summary_test.rb +0 -29
- data/test/stripe/util_test.rb +0 -402
- data/test/stripe/webhook_endpoint_test.rb +0 -59
- data/test/stripe/webhook_test.rb +0 -135
- data/test/stripe_mock.rb +0 -78
- data/test/stripe_test.rb +0 -132
- data/test/test_data.rb +0 -61
- data/test/test_helper.rb +0 -77
@@ -1,54 +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 DisputeTest < Test::Unit::TestCase
|
8
|
-
should "be creatable" do
|
9
|
-
dispute = Stripe::Issuing::Dispute.create(transaction: "ipi_123")
|
10
|
-
|
11
|
-
assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes"
|
12
|
-
assert dispute.is_a?(Stripe::Issuing::Dispute)
|
13
|
-
end
|
14
|
-
|
15
|
-
should "be listable" do
|
16
|
-
disputes = Stripe::Issuing::Dispute.list
|
17
|
-
assert_requested :get, "#{Stripe.api_base}/v1/issuing/disputes"
|
18
|
-
assert disputes.data.is_a?(Array)
|
19
|
-
assert disputes.data[0].is_a?(Stripe::Issuing::Dispute)
|
20
|
-
end
|
21
|
-
|
22
|
-
should "be retrievable" do
|
23
|
-
dispute = Stripe::Issuing::Dispute.retrieve("ich_123")
|
24
|
-
assert_requested :get, "#{Stripe.api_base}/v1/issuing/disputes/ich_123"
|
25
|
-
assert dispute.is_a?(Stripe::Issuing::Dispute)
|
26
|
-
end
|
27
|
-
|
28
|
-
should "be updateable" do
|
29
|
-
dispute = Stripe::Issuing::Dispute.update("ich_123", {})
|
30
|
-
assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes/ich_123"
|
31
|
-
assert dispute.is_a?(Stripe::Issuing::Dispute)
|
32
|
-
end
|
33
|
-
|
34
|
-
context "#submit" do
|
35
|
-
should "submit the dispute" do
|
36
|
-
dispute = Stripe::Issuing::Dispute.retrieve("idp_123")
|
37
|
-
dispute = dispute.submit
|
38
|
-
assert_requested :post,
|
39
|
-
"#{Stripe.api_base}/v1/issuing/disputes/idp_123/submit"
|
40
|
-
assert dispute.is_a?(Stripe::Issuing::Dispute)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context ".submit" do
|
45
|
-
should "submit the dispute" do
|
46
|
-
dispute = Stripe::Issuing::Dispute.submit("idp_123")
|
47
|
-
assert_requested :post,
|
48
|
-
"#{Stripe.api_base}/v1/issuing/disputes/idp_123/submit"
|
49
|
-
assert dispute.is_a?(Stripe::Issuing::Dispute)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -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
|
data/test/stripe/mandate_test.rb
DELETED
@@ -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
|
data/test/stripe/oauth_test.rb
DELETED
@@ -1,104 +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
|
-
end
|
48
|
-
|
49
|
-
context ".token" do
|
50
|
-
should "exchange a code for an access token" do
|
51
|
-
# The OpenAPI fixtures don't cover the OAuth endpoints, so we just
|
52
|
-
# stub the request manually.
|
53
|
-
stub_request(:post, "#{Stripe.connect_base}/oauth/token")
|
54
|
-
.with(body: {
|
55
|
-
"grant_type" => "authorization_code",
|
56
|
-
"code" => "this_is_an_authorization_code",
|
57
|
-
})
|
58
|
-
.to_return(body: JSON.generate(access_token: "sk_access_token",
|
59
|
-
scope: "read_only",
|
60
|
-
livemode: false,
|
61
|
-
token_type: "bearer",
|
62
|
-
refresh_token: "sk_refresh_token",
|
63
|
-
stripe_user_id: "acct_test",
|
64
|
-
stripe_publishable_key: "pk_test"))
|
65
|
-
|
66
|
-
resp = OAuth.token(grant_type: "authorization_code",
|
67
|
-
code: "this_is_an_authorization_code")
|
68
|
-
assert_equal("sk_access_token", resp.access_token)
|
69
|
-
end
|
70
|
-
|
71
|
-
should "override the API key when client_secret is passed" do
|
72
|
-
stub_request(:post, "#{Stripe.connect_base}/oauth/token")
|
73
|
-
.with(body: {
|
74
|
-
"client_secret" => "client_secret_override",
|
75
|
-
"grant_type" => "authorization_code",
|
76
|
-
"code" => "this_is_an_authorization_code",
|
77
|
-
})
|
78
|
-
.with(headers: { "Authorization": "Bearer client_secret_override" })
|
79
|
-
.to_return(body: JSON.generate(access_token: "another_access_token"))
|
80
|
-
|
81
|
-
resp = OAuth.token(client_secret: "client_secret_override",
|
82
|
-
grant_type: "authorization_code",
|
83
|
-
code: "this_is_an_authorization_code")
|
84
|
-
assert_equal("another_access_token", resp.access_token)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context ".deauthorize" do
|
89
|
-
should "deauthorize an account" do
|
90
|
-
# The OpenAPI fixtures don't cover the OAuth endpoints, so we just
|
91
|
-
# stub the request manually.
|
92
|
-
stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize")
|
93
|
-
.with(body: {
|
94
|
-
"client_id" => "ca_test",
|
95
|
-
"stripe_user_id" => "acct_test_deauth",
|
96
|
-
})
|
97
|
-
.to_return(body: JSON.generate(stripe_user_id: "acct_test_deauth"))
|
98
|
-
|
99
|
-
resp = OAuth.deauthorize(stripe_user_id: "acct_test_deauth")
|
100
|
-
assert_equal("acct_test_deauth", resp.stripe_user_id)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require ::File.expand_path("../test_helper", __dir__)
|
4
|
-
|
5
|
-
module Stripe
|
6
|
-
class OrderReturnTest < Test::Unit::TestCase
|
7
|
-
should "be listable" do
|
8
|
-
order_returns = Stripe::OrderReturn.list
|
9
|
-
assert_requested :get, "#{Stripe.api_base}/v1/order_returns"
|
10
|
-
assert order_returns.data.is_a?(Array)
|
11
|
-
assert order_returns.data[0].is_a?(Stripe::OrderReturn)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "be retrievable" do
|
15
|
-
order_return = Stripe::OrderReturn.retrieve("orret_123")
|
16
|
-
assert_requested :get,
|
17
|
-
"#{Stripe.api_base}/v1/order_returns/orret_123"
|
18
|
-
assert order_return.is_a?(Stripe::OrderReturn)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|