stripe 3.3.1 → 5.38.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +962 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +24 -22
- data/History.txt +1 -689
- data/README.md +202 -55
- data/Rakefile +18 -12
- data/VERSION +1 -1
- data/bin/stripe-console +5 -3
- data/lib/stripe/api_operations/create.rb +4 -2
- data/lib/stripe/api_operations/delete.rb +31 -3
- data/lib/stripe/api_operations/list.rb +4 -13
- data/lib/stripe/api_operations/nested_resource.rb +73 -0
- data/lib/stripe/api_operations/request.rb +84 -17
- data/lib/stripe/api_operations/save.rb +25 -13
- data/lib/stripe/api_resource.rb +70 -11
- data/lib/stripe/connection_manager.rb +179 -0
- data/lib/stripe/error_object.rb +93 -0
- data/lib/stripe/errors.rb +47 -19
- data/lib/stripe/instrumentation.rb +84 -0
- data/lib/stripe/list_object.rb +54 -22
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +29 -20
- data/lib/stripe/object_types.rb +107 -0
- data/lib/stripe/{account.rb → resources/account.rb} +70 -36
- data/lib/stripe/resources/account_link.rb +10 -0
- data/lib/stripe/resources/alipay_account.rb +34 -0
- data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +5 -2
- data/lib/stripe/resources/application_fee.rb +14 -0
- data/lib/stripe/resources/application_fee_refund.rb +31 -0
- data/lib/stripe/resources/balance.rb +8 -0
- data/lib/stripe/resources/balance_transaction.rb +10 -0
- data/lib/stripe/resources/bank_account.rb +43 -0
- data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
- data/lib/stripe/resources/billing_portal/session.rb +12 -0
- data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +7 -5
- data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
- data/lib/stripe/resources/capability.rb +34 -0
- data/lib/stripe/resources/card.rb +38 -0
- data/lib/stripe/resources/charge.rb +23 -0
- data/lib/stripe/resources/checkout/session.rb +16 -0
- data/lib/stripe/resources/country_spec.rb +10 -0
- data/lib/stripe/{coupon.rb → resources/coupon.rb} +5 -2
- data/lib/stripe/resources/credit_note.rb +33 -0
- data/lib/stripe/resources/credit_note_line_item.rb +8 -0
- data/lib/stripe/resources/customer.rb +41 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
- data/lib/stripe/resources/discount.rb +7 -0
- data/lib/stripe/resources/dispute.rb +22 -0
- data/lib/stripe/resources/ephemeral_key.rb +20 -0
- data/lib/stripe/resources/event.rb +10 -0
- data/lib/stripe/resources/exchange_rate.rb +10 -0
- data/lib/stripe/resources/file.rb +36 -0
- data/lib/stripe/resources/file_link.rb +12 -0
- 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.rb +74 -0
- data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +5 -2
- data/lib/stripe/resources/invoice_line_item.rb +8 -0
- data/lib/stripe/resources/issuing/authorization.rb +34 -0
- data/lib/stripe/resources/issuing/card.rb +25 -0
- data/lib/stripe/resources/issuing/card_details.rb +9 -0
- data/lib/stripe/resources/issuing/cardholder.rb +14 -0
- data/lib/stripe/resources/issuing/dispute.rb +25 -0
- data/lib/stripe/resources/issuing/transaction.rb +13 -0
- data/lib/stripe/resources/line_item.rb +8 -0
- data/lib/stripe/resources/login_link.rb +15 -0
- data/lib/stripe/resources/mandate.rb +8 -0
- data/lib/stripe/resources/order.rb +33 -0
- data/lib/stripe/resources/order_return.rb +10 -0
- data/lib/stripe/resources/payment_intent.rb +43 -0
- data/lib/stripe/resources/payment_method.rb +33 -0
- data/lib/stripe/resources/payout.rb +33 -0
- data/lib/stripe/resources/person.rb +32 -0
- data/lib/stripe/{plan.rb → resources/plan.rb} +4 -1
- data/lib/stripe/resources/price.rb +12 -0
- data/lib/stripe/{product.rb → resources/product.rb} +6 -3
- data/lib/stripe/resources/promotion_code.rb +12 -0
- data/lib/stripe/resources/quote.rb +105 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
- data/lib/stripe/resources/radar/value_list.rb +15 -0
- data/lib/stripe/resources/radar/value_list_item.rb +14 -0
- data/lib/stripe/resources/recipient.rb +14 -0
- data/lib/stripe/resources/recipient_transfer.rb +7 -0
- data/lib/stripe/{refund.rb → resources/refund.rb} +4 -1
- data/lib/stripe/resources/reporting/report_run.rb +13 -0
- data/lib/stripe/resources/reporting/report_type.rb +13 -0
- data/lib/stripe/resources/reversal.rb +30 -0
- data/lib/stripe/resources/review.rb +21 -0
- data/lib/stripe/resources/setup_attempt.rb +10 -0
- data/lib/stripe/resources/setup_intent.rb +33 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
- data/lib/stripe/{sku.rb → resources/sku.rb} +6 -3
- data/lib/stripe/resources/source.rb +47 -0
- data/lib/stripe/resources/source_transaction.rb +7 -0
- data/lib/stripe/resources/subscription.rb +26 -0
- data/lib/stripe/resources/subscription_item.rb +26 -0
- data/lib/stripe/resources/subscription_schedule.rb +33 -0
- data/lib/stripe/resources/tax_code.rb +10 -0
- data/lib/stripe/resources/tax_id.rb +27 -0
- data/lib/stripe/resources/tax_rate.rb +12 -0
- data/lib/stripe/resources/terminal/connection_token.rb +12 -0
- data/lib/stripe/resources/terminal/location.rb +15 -0
- data/lib/stripe/resources/terminal/reader.rb +15 -0
- data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +4 -1
- data/lib/stripe/resources/token.rb +10 -0
- data/lib/stripe/resources/topup.rb +23 -0
- data/lib/stripe/resources/transfer.rb +27 -0
- data/lib/stripe/resources/usage_record.rb +8 -0
- data/lib/stripe/resources/usage_record_summary.rb +8 -0
- data/lib/stripe/{recipient.rb → resources/webhook_endpoint.rb} +6 -7
- data/lib/stripe/resources.rb +90 -0
- data/lib/stripe/singleton_api_resource.rb +10 -4
- data/lib/stripe/stripe_client.rb +798 -346
- data/lib/stripe/stripe_configuration.rb +194 -0
- data/lib/stripe/stripe_object.rb +271 -126
- data/lib/stripe/stripe_response.rb +89 -27
- data/lib/stripe/util.rb +134 -194
- data/lib/stripe/version.rb +3 -1
- data/lib/stripe/webhook.rb +57 -18
- data/lib/stripe.rb +74 -186
- data/stripe.gemspec +35 -16
- metadata +110 -165
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -5
- data/.travis.yml +0 -38
- data/lib/stripe/alipay_account.rb +0 -22
- data/lib/stripe/application_fee.rb +0 -22
- data/lib/stripe/application_fee_refund.rb +0 -20
- data/lib/stripe/balance.rb +0 -5
- data/lib/stripe/balance_transaction.rb +0 -11
- data/lib/stripe/bank_account.rb +0 -30
- data/lib/stripe/bitcoin_transaction.rb +0 -11
- data/lib/stripe/card.rb +0 -27
- data/lib/stripe/charge.rb +0 -82
- data/lib/stripe/country_spec.rb +0 -11
- data/lib/stripe/customer.rb +0 -79
- data/lib/stripe/dispute.rb +0 -17
- data/lib/stripe/ephemeral_key.rb +0 -18
- data/lib/stripe/event.rb +0 -7
- data/lib/stripe/file_upload.rb +0 -33
- data/lib/stripe/invoice.rb +0 -29
- data/lib/stripe/invoice_line_item.rb +0 -5
- data/lib/stripe/login_link.rb +0 -9
- data/lib/stripe/order.rb +0 -29
- data/lib/stripe/order_return.rb +0 -11
- data/lib/stripe/payout.rb +0 -18
- data/lib/stripe/recipient_transfer.rb +0 -6
- data/lib/stripe/reversal.rb +0 -20
- data/lib/stripe/source.rb +0 -23
- data/lib/stripe/subscription.rb +0 -33
- data/lib/stripe/subscription_item.rb +0 -14
- data/lib/stripe/token.rb +0 -7
- data/lib/stripe/transfer.rb +0 -18
- data/test/api_stub_helpers.rb +0 -0
- data/test/stripe/account_test.rb +0 -202
- data/test/stripe/alipay_account_test.rb +0 -17
- data/test/stripe/api_operations_test.rb +0 -31
- data/test/stripe/api_resource_test.rb +0 -558
- data/test/stripe/apple_pay_domain_test.rb +0 -31
- data/test/stripe/application_fee_refund_test.rb +0 -35
- data/test/stripe/application_fee_test.rb +0 -12
- data/test/stripe/balance_test.rb +0 -11
- data/test/stripe/bank_account_test.rb +0 -36
- data/test/stripe/bitcoin_receiver_test.rb +0 -67
- data/test/stripe/bitcoin_transaction_test.rb +0 -19
- data/test/stripe/charge_test.rb +0 -57
- data/test/stripe/country_spec_test.rb +0 -18
- data/test/stripe/coupon_test.rb +0 -42
- data/test/stripe/customer_card_test.rb +0 -46
- data/test/stripe/customer_test.rb +0 -114
- data/test/stripe/dispute_test.rb +0 -40
- data/test/stripe/ephemeral_key_test.rb +0 -84
- data/test/stripe/errors_test.rb +0 -18
- data/test/stripe/file_upload_test.rb +0 -66
- data/test/stripe/invoice_item_test.rb +0 -53
- data/test/stripe/invoice_line_item_test.rb +0 -6
- data/test/stripe/invoice_test.rb +0 -110
- data/test/stripe/list_object_test.rb +0 -170
- data/test/stripe/login_link_test.rb +0 -35
- data/test/stripe/oauth_test.rb +0 -85
- data/test/stripe/order_return_test.rb +0 -19
- data/test/stripe/order_test.rb +0 -57
- data/test/stripe/payout_test.rb +0 -48
- data/test/stripe/plan_test.rb +0 -50
- data/test/stripe/product_test.rb +0 -45
- data/test/stripe/recipient_card_test.rb +0 -44
- data/test/stripe/recipient_test.rb +0 -48
- data/test/stripe/refund_test.rb +0 -37
- data/test/stripe/reversal_test.rb +0 -41
- data/test/stripe/sku_test.rb +0 -48
- data/test/stripe/source_test.rb +0 -68
- data/test/stripe/stripe_client_test.rb +0 -750
- data/test/stripe/stripe_object_test.rb +0 -398
- data/test/stripe/stripe_response_test.rb +0 -46
- data/test/stripe/subscription_item_test.rb +0 -52
- data/test/stripe/subscription_test.rb +0 -58
- data/test/stripe/three_d_secure_test.rb +0 -21
- data/test/stripe/transfer_test.rb +0 -41
- data/test/stripe/util_test.rb +0 -414
- data/test/stripe/webhook_test.rb +0 -92
- data/test/stripe_test.rb +0 -59
- data/test/test_data.rb +0 -59
- data/test/test_helper.rb +0 -56
data/test/stripe/util_test.rb
DELETED
@@ -1,414 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class UtilTest < Test::Unit::TestCase
|
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
|
-
:f => "",
|
13
|
-
|
14
|
-
# note the empty hash won't even show up in the request
|
15
|
-
:g => [],
|
16
|
-
}
|
17
|
-
assert_equal(
|
18
|
-
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1&f=",
|
19
|
-
Stripe::Util.encode_parameters(params)
|
20
|
-
)
|
21
|
-
end
|
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
|
-
|
51
|
-
should "#url_encode should prepare strings for HTTP" do
|
52
|
-
assert_equal "foo", Stripe::Util.url_encode("foo")
|
53
|
-
assert_equal "foo", Stripe::Util.url_encode(:foo)
|
54
|
-
assert_equal "foo%2B", Stripe::Util.url_encode("foo+")
|
55
|
-
assert_equal "foo%26", Stripe::Util.url_encode("foo&")
|
56
|
-
assert_equal "foo[bar]", Stripe::Util.url_encode("foo[bar]")
|
57
|
-
end
|
58
|
-
|
59
|
-
should "#flatten_params should encode parameters according to Rails convention" do
|
60
|
-
params = [
|
61
|
-
[:a, 3],
|
62
|
-
[:b, "foo?"],
|
63
|
-
[:c, "bar&baz"],
|
64
|
-
[:d, { :a => "a", :b => "b" }],
|
65
|
-
[:e, [0, 1]],
|
66
|
-
[:f, [
|
67
|
-
{ :foo => "1", :ghi => "2" },
|
68
|
-
{ :foo => "3", :bar => "4" },
|
69
|
-
]],
|
70
|
-
]
|
71
|
-
assert_equal([
|
72
|
-
["a", 3],
|
73
|
-
["b", "foo?"],
|
74
|
-
["c", "bar&baz"],
|
75
|
-
["d[a]", "a"],
|
76
|
-
["d[b]", "b"],
|
77
|
-
["e[]", 0],
|
78
|
-
["e[]", 1],
|
79
|
-
|
80
|
-
# *The key here is the order*. In order to be properly interpreted as
|
81
|
-
# an array of hashes on the server, everything from a single hash must
|
82
|
-
# come in at once. A duplicate key in an array triggers a new element.
|
83
|
-
["f[][foo]", "1"],
|
84
|
-
["f[][ghi]", "2"],
|
85
|
-
["f[][foo]", "3"],
|
86
|
-
["f[][bar]", "4"],
|
87
|
-
], Stripe::Util.flatten_params(params))
|
88
|
-
end
|
89
|
-
|
90
|
-
should "#symbolize_names should convert names to symbols" do
|
91
|
-
start = {
|
92
|
-
'foo' => 'bar',
|
93
|
-
'array' => [{ 'foo' => 'bar' }],
|
94
|
-
'nested' => {
|
95
|
-
1 => 2,
|
96
|
-
:symbol => 9,
|
97
|
-
'string' => nil
|
98
|
-
}
|
99
|
-
}
|
100
|
-
finish = {
|
101
|
-
:foo => 'bar',
|
102
|
-
:array => [{ :foo => 'bar' }],
|
103
|
-
:nested => {
|
104
|
-
1 => 2,
|
105
|
-
:symbol => 9,
|
106
|
-
:string => nil
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
symbolized = Stripe::Util.symbolize_names(start)
|
111
|
-
assert_equal(finish, symbolized)
|
112
|
-
end
|
113
|
-
|
114
|
-
should "#normalize_opts should reject nil keys" do
|
115
|
-
assert_raise { Stripe::Util.normalize_opts(nil) }
|
116
|
-
assert_raise { Stripe::Util.normalize_opts(:api_key => nil) }
|
117
|
-
end
|
118
|
-
|
119
|
-
should "#convert_to_stripe_object should pass through unknown types" do
|
120
|
-
obj = Util.convert_to_stripe_object(7, {})
|
121
|
-
assert_equal 7, obj
|
122
|
-
end
|
123
|
-
|
124
|
-
should "#convert_to_stripe_object should turn hashes into StripeObjects" do
|
125
|
-
obj = Util.convert_to_stripe_object({ :foo => "bar" }, {})
|
126
|
-
assert obj.is_a?(StripeObject)
|
127
|
-
assert_equal "bar", obj.foo
|
128
|
-
end
|
129
|
-
|
130
|
-
should "#convert_to_stripe_object should turn lists into ListObjects" do
|
131
|
-
obj = Util.convert_to_stripe_object({ :object => "list" }, {})
|
132
|
-
assert obj.is_a?(ListObject)
|
133
|
-
end
|
134
|
-
|
135
|
-
should "#convert_to_stripe_object should marshal other classes" do
|
136
|
-
obj = Util.convert_to_stripe_object({ :object => "account" }, {})
|
137
|
-
assert obj.is_a?(Account)
|
138
|
-
end
|
139
|
-
|
140
|
-
should "#convert_to_stripe_object should marshal arrays" do
|
141
|
-
obj = Util.convert_to_stripe_object([1, 2, 3], {})
|
142
|
-
assert_equal [1, 2, 3], obj
|
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
|
148
|
-
|
149
|
-
context ".request_id_dashboard_url" do
|
150
|
-
should "generate a livemode URL" do
|
151
|
-
assert_equal "https://dashboard.stripe.com/live/logs/request-id",
|
152
|
-
Util.request_id_dashboard_url("request-id", "sk_live_123")
|
153
|
-
end
|
154
|
-
|
155
|
-
should "generate a testmode URL" do
|
156
|
-
assert_equal "https://dashboard.stripe.com/test/logs/request-id",
|
157
|
-
Util.request_id_dashboard_url("request-id", "sk_test_123")
|
158
|
-
end
|
159
|
-
|
160
|
-
should "default to a testmode URL" do
|
161
|
-
assert_equal "https://dashboard.stripe.com/test/logs/request-id",
|
162
|
-
Util.request_id_dashboard_url("request-id", nil)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context ".log_*" do
|
167
|
-
setup do
|
168
|
-
@old_log_level = Stripe.log_level
|
169
|
-
Stripe.log_level = nil
|
170
|
-
|
171
|
-
@old_stderr = $stderr
|
172
|
-
$stderr = StringIO.new
|
173
|
-
|
174
|
-
@old_stdout = $stdout
|
175
|
-
$stdout = StringIO.new
|
176
|
-
end
|
177
|
-
|
178
|
-
teardown do
|
179
|
-
Stripe.log_level = @old_log_level
|
180
|
-
$stderr = @old_stderr
|
181
|
-
$stdout = @old_stdout
|
182
|
-
end
|
183
|
-
|
184
|
-
context ".log_debug" do
|
185
|
-
should "not log if logging is disabled" do
|
186
|
-
Util.log_debug("foo")
|
187
|
-
assert_equal "", $stdout.string
|
188
|
-
end
|
189
|
-
|
190
|
-
should "log if level set to debug" do
|
191
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
192
|
-
Util.log_debug("foo")
|
193
|
-
assert_equal "message=foo level=debug \n", $stdout.string
|
194
|
-
end
|
195
|
-
|
196
|
-
should "not log if level set to error" do
|
197
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
198
|
-
Util.log_debug("foo")
|
199
|
-
assert_equal "", $stdout.string
|
200
|
-
end
|
201
|
-
|
202
|
-
should "not log if level set to info" do
|
203
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
204
|
-
Util.log_debug("foo")
|
205
|
-
assert_equal "", $stdout.string
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context ".log_error" do
|
210
|
-
should "not log if logging is disabled" do
|
211
|
-
Util.log_error("foo")
|
212
|
-
assert_equal "", $stdout.string
|
213
|
-
end
|
214
|
-
|
215
|
-
should "log if level set to debug" do
|
216
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
217
|
-
Util.log_error("foo")
|
218
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
219
|
-
end
|
220
|
-
|
221
|
-
should "log if level set to error" do
|
222
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
223
|
-
Util.log_error("foo")
|
224
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
225
|
-
end
|
226
|
-
|
227
|
-
should "log if level set to info" do
|
228
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
229
|
-
Util.log_error("foo")
|
230
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context ".log_info" do
|
235
|
-
should "not log if logging is disabled" do
|
236
|
-
Util.log_info("foo")
|
237
|
-
assert_equal "", $stdout.string
|
238
|
-
end
|
239
|
-
|
240
|
-
should "log if level set to debug" do
|
241
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
242
|
-
Util.log_info("foo")
|
243
|
-
assert_equal "message=foo level=info \n", $stdout.string
|
244
|
-
end
|
245
|
-
|
246
|
-
should "not log if level set to error" do
|
247
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
248
|
-
Util.log_debug("foo")
|
249
|
-
assert_equal "", $stdout.string
|
250
|
-
end
|
251
|
-
|
252
|
-
should "log if level set to info" do
|
253
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
254
|
-
Util.log_info("foo")
|
255
|
-
assert_equal "message=foo level=info \n", $stdout.string
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context ".log_* with a logger" do
|
261
|
-
setup do
|
262
|
-
@out = StringIO.new
|
263
|
-
logger = ::Logger.new(@out)
|
264
|
-
|
265
|
-
# Set a really simple formatter to make matching output as easy as
|
266
|
-
# possible.
|
267
|
-
logger.formatter = proc { |_severity, _datetime, _progname, message|
|
268
|
-
message
|
269
|
-
}
|
270
|
-
|
271
|
-
Stripe.logger = logger
|
272
|
-
end
|
273
|
-
|
274
|
-
context ".log_debug" do
|
275
|
-
should "log to the logger" do
|
276
|
-
Util.log_debug("foo")
|
277
|
-
assert_equal "message=foo ", @out.string
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
context ".log_error" do
|
282
|
-
should "log to the logger" do
|
283
|
-
Util.log_error("foo")
|
284
|
-
assert_equal "message=foo ", @out.string
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context ".log_info" do
|
289
|
-
should "log to the logger" do
|
290
|
-
Util.log_info("foo")
|
291
|
-
assert_equal "message=foo ", @out.string
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
context ".normalize_headers" do
|
297
|
-
should "normalize the format of a header key" do
|
298
|
-
assert_equal({ "Request-Id" => nil },
|
299
|
-
Util.normalize_headers({ "Request-Id" => nil }))
|
300
|
-
assert_equal({ "Request-Id" => nil },
|
301
|
-
Util.normalize_headers({ "request-id" => nil }))
|
302
|
-
assert_equal({ "Request-Id" => nil },
|
303
|
-
Util.normalize_headers({ "Request-ID" => nil }))
|
304
|
-
assert_equal({ "Request-Id" => nil },
|
305
|
-
Util.normalize_headers({ :request_id => nil }))
|
306
|
-
end
|
307
|
-
|
308
|
-
should "tolerate bad formatting" do
|
309
|
-
assert_equal({ "Request-Id" => nil },
|
310
|
-
Util.normalize_headers({ "-Request--Id-" => nil }))
|
311
|
-
assert_equal({ "Request-Id" => nil },
|
312
|
-
Util.normalize_headers({ :request__id => nil }))
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
#
|
317
|
-
# private
|
318
|
-
#
|
319
|
-
# I don't feel particularly good about using #send to invoke these, but I
|
320
|
-
# want them hidden from the public interface, and each method is far easier
|
321
|
-
# to test in isolation (as opposed to going through a public method).
|
322
|
-
#
|
323
|
-
|
324
|
-
context ".colorize" do
|
325
|
-
should "colorize for a TTY" do
|
326
|
-
assert_equal "\033[0;32;49mfoo\033[0m",
|
327
|
-
Util.send(:colorize, "foo", :green, true)
|
328
|
-
end
|
329
|
-
|
330
|
-
should "not colorize otherwise" do
|
331
|
-
assert_equal "foo", Util.send(:colorize, "foo", :green, false)
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context ".level_name" do
|
336
|
-
should "convert levels to names" do
|
337
|
-
assert_equal "debug", Util.send(:level_name, LEVEL_DEBUG)
|
338
|
-
assert_equal "error", Util.send(:level_name, LEVEL_ERROR)
|
339
|
-
assert_equal "info", Util.send(:level_name, LEVEL_INFO)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
context ".log_internal" do
|
344
|
-
should "log in a terminal friendly way" do
|
345
|
-
out = StringIO.new
|
346
|
-
|
347
|
-
# Sketchy as anything, but saves us from pulling in a mocking library.
|
348
|
-
# Open this instance of StringIO, and add a method override so that it
|
349
|
-
# looks like a TTY.
|
350
|
-
out.instance_eval do
|
351
|
-
def isatty; true; end
|
352
|
-
end
|
353
|
-
|
354
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
355
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: nil, out: out)
|
356
|
-
assert_equal "\e[0;32;49mDEBU\e[0m message \e[0;32;49mfoo\e[0m=bar\n",
|
357
|
-
out.string
|
358
|
-
end
|
359
|
-
|
360
|
-
should "log in a data friendly way" do
|
361
|
-
out = StringIO.new
|
362
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
363
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: nil, out: out)
|
364
|
-
assert_equal "message=message level=debug foo=bar\n",
|
365
|
-
out.string
|
366
|
-
end
|
367
|
-
|
368
|
-
should "log to a logger if set" do
|
369
|
-
out = StringIO.new
|
370
|
-
logger = ::Logger.new(out)
|
371
|
-
|
372
|
-
# Set a really simple formatter to make matching output as easy as
|
373
|
-
# possible.
|
374
|
-
logger.formatter = proc { |_severity, _datetime, _progname, message|
|
375
|
-
message
|
376
|
-
}
|
377
|
-
|
378
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
379
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: logger, out: nil)
|
380
|
-
assert_equal "message=message foo=bar",
|
381
|
-
out.string
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
context ".wrap_logfmt_value" do
|
386
|
-
should "pass through simple values" do
|
387
|
-
assert_equal "abc", Util.send(:wrap_logfmt_value, "abc")
|
388
|
-
assert_equal "123", Util.send(:wrap_logfmt_value, "123")
|
389
|
-
assert_equal "a-b_c/d", Util.send(:wrap_logfmt_value, "a-b_c/d")
|
390
|
-
end
|
391
|
-
|
392
|
-
should "pass through numerics" do
|
393
|
-
assert_equal 123, Util.send(:wrap_logfmt_value, 123)
|
394
|
-
assert_equal 1.23, Util.send(:wrap_logfmt_value, 1.23)
|
395
|
-
end
|
396
|
-
|
397
|
-
should "wrap more complex values in double quotes" do
|
398
|
-
assert_equal %{"abc=123"}, Util.send(:wrap_logfmt_value, %{abc=123})
|
399
|
-
end
|
400
|
-
|
401
|
-
should "escape double quotes already in the value" do
|
402
|
-
assert_equal %{"abc=\\"123\\""}, Util.send(:wrap_logfmt_value, %{abc="123"})
|
403
|
-
end
|
404
|
-
|
405
|
-
should "remove newlines" do
|
406
|
-
assert_equal %{"abc"}, Util.send(:wrap_logfmt_value, "a\nb\nc")
|
407
|
-
end
|
408
|
-
|
409
|
-
should "not error if given a non-string" do
|
410
|
-
assert_equal "true", Util.send(:wrap_logfmt_value, true)
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
data/test/stripe/webhook_test.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class WebhookTest < Test::Unit::TestCase
|
5
|
-
EVENT_PAYLOAD = '''{
|
6
|
-
"id": "evt_test_webhook",
|
7
|
-
"object": "event"
|
8
|
-
}'''
|
9
|
-
SECRET = 'whsec_test_secret'
|
10
|
-
|
11
|
-
def generate_header(opts={})
|
12
|
-
opts[:timestamp] ||= Time.now.to_i
|
13
|
-
opts[:payload] ||= EVENT_PAYLOAD
|
14
|
-
opts[:secret] ||= SECRET
|
15
|
-
opts[:scheme] ||= Stripe::Webhook::Signature::EXPECTED_SCHEME
|
16
|
-
opts[:signature] ||= Stripe::Webhook::Signature.send(:compute_signature, "#{opts[:timestamp]}.#{opts[:payload]}", opts[:secret])
|
17
|
-
"t=#{opts[:timestamp]},#{opts[:scheme]}=#{opts[:signature]}"
|
18
|
-
end
|
19
|
-
|
20
|
-
context ".construct_event" do
|
21
|
-
should "return an Event instance from a valid JSON payload and valid signature header" do
|
22
|
-
header = generate_header
|
23
|
-
event = Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
|
24
|
-
assert event.kind_of?(Stripe::Event)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "raise a JSON::ParserError from an invalid JSON payload" do
|
28
|
-
assert_raises JSON::ParserError do
|
29
|
-
payload = 'this is not valid JSON'
|
30
|
-
header = generate_header(payload: payload)
|
31
|
-
Stripe::Webhook.construct_event(payload, header, SECRET)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
should "raise a SignatureVerificationError from a valid JSON payload and an invalid signature header" do
|
36
|
-
header = 'bad_header'
|
37
|
-
assert_raises Stripe::SignatureVerificationError do
|
38
|
-
Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context ".verify_signature_header" do
|
44
|
-
should "raise a SignatureVerificationError when the header does not have the expected format" do
|
45
|
-
header = 'i\'m not even a real signature header'
|
46
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
47
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, 'secret')
|
48
|
-
end
|
49
|
-
assert_match("Unable to extract timestamp and signatures from header", e.message)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "raise a SignatureVerificationError when there are no signatures with the expected scheme" do
|
53
|
-
header = generate_header(scheme: 'v0')
|
54
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
55
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, 'secret')
|
56
|
-
end
|
57
|
-
assert_match("No signatures found with expected scheme", e.message)
|
58
|
-
end
|
59
|
-
|
60
|
-
should "raise a SignatureVerificationError when there are no valid signatures for the payload" do
|
61
|
-
header = generate_header(signature: 'bad_signature')
|
62
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
63
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, 'secret')
|
64
|
-
end
|
65
|
-
assert_match("No signatures found matching the expected signature for payload", e.message)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "raise a SignatureVerificationError when the timestamp is not within the tolerance" do
|
69
|
-
header = generate_header(timestamp: Time.now.to_i - 15)
|
70
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
71
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10)
|
72
|
-
end
|
73
|
-
assert_match("Timestamp outside the tolerance zone", e.message)
|
74
|
-
end
|
75
|
-
|
76
|
-
should "return true when the header contains a valid signature and the timestamp is within the tolerance" do
|
77
|
-
header = generate_header
|
78
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
|
79
|
-
end
|
80
|
-
|
81
|
-
should "return true when the header contains at least one valid signature" do
|
82
|
-
header = generate_header + ",v1=bad_signature"
|
83
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
|
84
|
-
end
|
85
|
-
|
86
|
-
should "return true when the header contains a valid signature and the timestamp is off but no tolerance is provided" do
|
87
|
-
header = generate_header(timestamp: 12345)
|
88
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET))
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/test/stripe_test.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
|
-
|
17
|
-
should "allow app_info to be configured" do
|
18
|
-
begin
|
19
|
-
old = Stripe.app_info
|
20
|
-
Stripe.set_app_info(
|
21
|
-
"MyAwesomePlugin",
|
22
|
-
url: "https://myawesomeplugin.info",
|
23
|
-
version: "1.2.34"
|
24
|
-
)
|
25
|
-
assert_equal({
|
26
|
-
name: "MyAwesomePlugin",
|
27
|
-
url: "https://myawesomeplugin.info",
|
28
|
-
version: "1.2.34"
|
29
|
-
}, Stripe.app_info)
|
30
|
-
ensure
|
31
|
-
Stripe.app_info = old
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
should "allow ca_bundle_path to be configured" do
|
36
|
-
begin
|
37
|
-
old = Stripe.ca_bundle_path
|
38
|
-
Stripe.ca_bundle_path = "path/to/ca/bundle"
|
39
|
-
assert_equal "path/to/ca/bundle", Stripe.ca_bundle_path
|
40
|
-
ensure
|
41
|
-
Stripe.ca_bundle_path = old
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
should "allow max_network_retries to be configured" do
|
46
|
-
begin
|
47
|
-
old = Stripe.max_network_retries
|
48
|
-
Stripe.max_network_retries = 99
|
49
|
-
assert_equal 99, Stripe.max_network_retries
|
50
|
-
ensure
|
51
|
-
Stripe.max_network_retries = old
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
should "have default open and read timeouts" do
|
56
|
-
assert_equal Stripe.open_timeout, 30
|
57
|
-
assert_equal Stripe.read_timeout, 80
|
58
|
-
end
|
59
|
-
end
|
data/test/test_data.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module Stripe
|
2
|
-
module TestData
|
3
|
-
def make_error(type, message)
|
4
|
-
{
|
5
|
-
:error => {
|
6
|
-
:type => type,
|
7
|
-
:message => message,
|
8
|
-
}
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
def make_invalid_api_key_error
|
13
|
-
{
|
14
|
-
:error => {
|
15
|
-
:type => "invalid_request_error",
|
16
|
-
:message => "Invalid API Key provided: invalid"
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def make_invalid_exp_year_error
|
22
|
-
{
|
23
|
-
:error => {
|
24
|
-
:code => "invalid_expiry_year",
|
25
|
-
:param => "exp_year",
|
26
|
-
:type => "card_error",
|
27
|
-
:message => "Your card's expiration year is invalid"
|
28
|
-
}
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def make_missing_id_error
|
33
|
-
{
|
34
|
-
:error => {
|
35
|
-
:param => "id",
|
36
|
-
:type => "invalid_request_error",
|
37
|
-
:message => "Missing id"
|
38
|
-
}
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def make_rate_limit_error
|
43
|
-
{
|
44
|
-
:error => {
|
45
|
-
:type => "invalid_request_error",
|
46
|
-
:message => "Too many requests in a period of time."
|
47
|
-
}
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
def make_api_error
|
52
|
-
{
|
53
|
-
:error => {
|
54
|
-
:type => "api_error"
|
55
|
-
}
|
56
|
-
}
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'stripe'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'mocha/setup'
|
4
|
-
require 'stringio'
|
5
|
-
require 'shoulda/context'
|
6
|
-
require "timecop"
|
7
|
-
require 'webmock/test_unit'
|
8
|
-
|
9
|
-
PROJECT_ROOT = File.expand_path("../../", __FILE__)
|
10
|
-
|
11
|
-
require File.expand_path('../test_data', __FILE__)
|
12
|
-
|
13
|
-
MOCK_MINIMUM_VERSION = "0.1.12"
|
14
|
-
MOCK_PORT = ENV["STRIPE_MOCK_PORT"] || 12111
|
15
|
-
|
16
|
-
# Disable all real network connections except those that are outgoing to
|
17
|
-
# stripe-mock.
|
18
|
-
WebMock.disable_net_connect!(allow: "localhost:#{MOCK_PORT}")
|
19
|
-
|
20
|
-
# Try one initial test connection to stripe-mock so that if there's a problem
|
21
|
-
# we can print one error and fail fast so that it's more clear to the user how
|
22
|
-
# they should fix the problem.
|
23
|
-
begin
|
24
|
-
resp = Faraday.get("http://localhost:#{MOCK_PORT}/")
|
25
|
-
version = resp.headers['Stripe-Mock-Version']
|
26
|
-
if version != "master" &&
|
27
|
-
Gem::Version.new(version) < Gem::Version.new(MOCK_MINIMUM_VERSION)
|
28
|
-
abort("Your version of stripe-mock (#{version}) is too old. The minimum " \
|
29
|
-
"version to run this test suite is #{MOCK_MINIMUM_VERSION}. Please " \
|
30
|
-
"see its repository for upgrade instructions.")
|
31
|
-
end
|
32
|
-
rescue Faraday::ConnectionFailed
|
33
|
-
abort("Couldn't reach stripe-mock at `localhost:#{MOCK_PORT}`. Is " \
|
34
|
-
"it running? Please see README for setup instructions.")
|
35
|
-
end
|
36
|
-
|
37
|
-
class Test::Unit::TestCase
|
38
|
-
include Stripe::TestData
|
39
|
-
include Mocha
|
40
|
-
|
41
|
-
setup do
|
42
|
-
Stripe.api_key = "sk_test_123"
|
43
|
-
Stripe.api_base = "http://localhost:#{MOCK_PORT}"
|
44
|
-
stub_connect
|
45
|
-
end
|
46
|
-
|
47
|
-
teardown do
|
48
|
-
Stripe.api_key = nil
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def stub_connect
|
54
|
-
stub_request(:any, /^#{Stripe.connect_base}/).to_return(:body => "{}")
|
55
|
-
end
|
56
|
-
end
|