stripe 3.8.2 → 5.45.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 +424 -1
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +15 -20
- data/README.md +201 -58
- data/Rakefile +12 -9
- data/VERSION +1 -1
- data/bin/stripe-console +3 -1
- data/lib/stripe/api_operations/create.rb +3 -1
- data/lib/stripe/api_operations/delete.rb +30 -2
- data/lib/stripe/api_operations/list.rb +3 -12
- data/lib/stripe/api_operations/nested_resource.rb +40 -28
- data/lib/stripe/api_operations/request.rb +83 -9
- data/lib/stripe/api_operations/save.rb +19 -7
- data/lib/stripe/api_resource.rb +65 -4
- data/lib/stripe/connection_manager.rb +200 -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 +43 -7
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +14 -7
- data/lib/stripe/object_types.rb +110 -0
- data/lib/stripe/{account.rb → resources/account.rb} +60 -28
- 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} +4 -1
- 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} +6 -6
- data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
- data/lib/stripe/resources/capability.rb +34 -0
- data/lib/stripe/{card.rb → resources/card.rb} +15 -4
- data/lib/stripe/resources/charge.rb +23 -0
- data/lib/stripe/resources/checkout/session.rb +27 -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 +52 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
- data/lib/stripe/resources/discount.rb +8 -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 +10 -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 +53 -0
- data/lib/stripe/resources/payment_link.rb +23 -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/{recipient.rb → resources/recipient.rb} +5 -6
- 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 +43 -0
- data/lib/stripe/resources/shipping_rate.rb +12 -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 +8 -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/resources/test_helpers/test_clock.rb +25 -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/resources/webhook_endpoint.rb +13 -0
- data/lib/stripe/resources.rb +93 -0
- data/lib/stripe/singleton_api_resource.rb +8 -2
- data/lib/stripe/stripe_client.rb +712 -233
- data/lib/stripe/stripe_configuration.rb +194 -0
- data/lib/stripe/stripe_object.rb +180 -67
- data/lib/stripe/stripe_response.rb +89 -27
- data/lib/stripe/util.rb +87 -168
- data/lib/stripe/version.rb +3 -1
- data/lib/stripe/webhook.rb +45 -10
- data/lib/stripe.rb +47 -160
- data/stripe.gemspec +27 -8
- metadata +112 -178
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -6
- data/.rubocop.yml +0 -20
- data/.rubocop_todo.yml +0 -60
- data/.travis.yml +0 -38
- data/lib/stripe/alipay_account.rb +0 -25
- data/lib/stripe/application_fee.rb +0 -25
- 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 -13
- data/lib/stripe/charge.rb +0 -82
- data/lib/stripe/country_spec.rb +0 -11
- data/lib/stripe/customer.rb +0 -88
- 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/exchange_rate.rb +0 -11
- data/lib/stripe/file_upload.rb +0 -35
- data/lib/stripe/invoice.rb +0 -30
- data/lib/stripe/invoice_line_item.rb +0 -5
- data/lib/stripe/login_link.rb +0 -9
- data/lib/stripe/order.rb +0 -35
- data/lib/stripe/order_return.rb +0 -11
- data/lib/stripe/payout.rb +0 -18
- data/lib/stripe/recipient_transfer.rb +0 -5
- data/lib/stripe/reversal.rb +0 -20
- data/lib/stripe/source.rb +0 -36
- data/lib/stripe/source_transaction.rb +0 -5
- data/lib/stripe/subscription.rb +0 -43
- data/lib/stripe/subscription_item.rb +0 -14
- data/lib/stripe/token.rb +0 -7
- data/lib/stripe/transfer.rb +0 -21
- data/test/api_stub_helpers.rb +0 -0
- data/test/stripe/account_external_accounts_operations_test.rb +0 -66
- data/test/stripe/account_login_links_operations_test.rb +0 -19
- data/test/stripe/account_test.rb +0 -190
- data/test/stripe/alipay_account_test.rb +0 -35
- data/test/stripe/api_operations_test.rb +0 -76
- data/test/stripe/api_resource_test.rb +0 -522
- 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_refunds_operations_test.rb +0 -54
- 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 -34
- 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 -42
- data/test/stripe/customer_sources_operations_test.rb +0 -66
- data/test/stripe/customer_test.rb +0 -113
- 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/exchange_rate_test.rb +0 -18
- data/test/stripe/file_upload_test.rb +0 -83
- 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 -111
- data/test/stripe/list_object_test.rb +0 -154
- data/test/stripe/login_link_test.rb +0 -35
- data/test/stripe/oauth_test.rb +0 -77
- 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_test.rb +0 -47
- 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 -84
- data/test/stripe/source_transaction_test.rb +0 -28
- data/test/stripe/stripe_client_test.rb +0 -728
- data/test/stripe/stripe_object_test.rb +0 -448
- data/test/stripe/stripe_response_test.rb +0 -47
- data/test/stripe/subscription_item_test.rb +0 -52
- data/test/stripe/subscription_test.rb +0 -104
- data/test/stripe/three_d_secure_test.rb +0 -21
- data/test/stripe/transfer_reversals_operations_test.rb +0 -55
- data/test/stripe/transfer_test.rb +0 -41
- data/test/stripe/util_test.rb +0 -432
- data/test/stripe/webhook_test.rb +0 -94
- data/test/stripe_test.rb +0 -59
- data/test/test_data.rb +0 -59
- data/test/test_helper.rb +0 -60
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class TransferReversalsOperationsTest < Test::Unit::TestCase
|
5
|
-
setup do
|
6
|
-
@transfer_id = "tr_123"
|
7
|
-
@reversal_id = "trr_123"
|
8
|
-
end
|
9
|
-
|
10
|
-
context "#create_reversal" do
|
11
|
-
should "create a reversal" do
|
12
|
-
reversal = Stripe::Transfer.create_reversal(
|
13
|
-
@transfer_id,
|
14
|
-
amount: 100
|
15
|
-
)
|
16
|
-
assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{@transfer_id}/reversals"
|
17
|
-
assert reversal.is_a?(Stripe::Reversal)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "#retrieve_reversal" do
|
22
|
-
should "retrieve a reversal" do
|
23
|
-
reversal = Stripe::Transfer.retrieve_reversal(
|
24
|
-
@transfer_id,
|
25
|
-
@reversal_id
|
26
|
-
)
|
27
|
-
assert_requested :get, "#{Stripe.api_base}/v1/transfers/#{@transfer_id}/reversals/#{@reversal_id}"
|
28
|
-
assert reversal.is_a?(Stripe::Reversal)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "#update_reversal" do
|
33
|
-
should "update a reversal" do
|
34
|
-
reversal = Stripe::Transfer.update_reversal(
|
35
|
-
@transfer_id,
|
36
|
-
@reversal_id,
|
37
|
-
metadata: { foo: "bar" }
|
38
|
-
)
|
39
|
-
assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{@transfer_id}/reversals/#{@reversal_id}"
|
40
|
-
assert reversal.is_a?(Stripe::Reversal)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "#list_reversals" do
|
45
|
-
should "list the transfer's reversals" do
|
46
|
-
reversals = Stripe::Transfer.list_reversals(
|
47
|
-
@transfer_id
|
48
|
-
)
|
49
|
-
assert_requested :get, "#{Stripe.api_base}/v1/transfers/#{@transfer_id}/reversals"
|
50
|
-
assert reversals.is_a?(Stripe::ListObject)
|
51
|
-
assert reversals.data.is_a?(Array)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class TransferTest < Test::Unit::TestCase
|
5
|
-
should "be listable" do
|
6
|
-
transfers = Stripe::Transfer.list
|
7
|
-
assert_requested :get, "#{Stripe.api_base}/v1/transfers"
|
8
|
-
assert transfers.data.is_a?(Array)
|
9
|
-
assert transfers.data[0].is_a?(Stripe::Transfer)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "be retrievable" do
|
13
|
-
transfer = Stripe::Transfer.retrieve("tr_123")
|
14
|
-
assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_123"
|
15
|
-
assert transfer.is_a?(Stripe::Transfer)
|
16
|
-
end
|
17
|
-
|
18
|
-
should "be creatable" do
|
19
|
-
transfer = Stripe::Transfer.create(
|
20
|
-
amount: 100,
|
21
|
-
currency: "USD",
|
22
|
-
destination: "acct_123"
|
23
|
-
)
|
24
|
-
assert_requested :post, "#{Stripe.api_base}/v1/transfers"
|
25
|
-
assert transfer.is_a?(Stripe::Transfer)
|
26
|
-
end
|
27
|
-
|
28
|
-
should "be saveable" do
|
29
|
-
transfer = Stripe::Transfer.retrieve("tr_123")
|
30
|
-
transfer.metadata["key"] = "value"
|
31
|
-
transfer.save
|
32
|
-
assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{transfer.id}"
|
33
|
-
end
|
34
|
-
|
35
|
-
should "be updateable" do
|
36
|
-
transfer = Stripe::Transfer.update("tr_123", metadata: { foo: "bar" })
|
37
|
-
assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_123"
|
38
|
-
assert transfer.is_a?(Stripe::Transfer)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/stripe/util_test.rb
DELETED
@@ -1,432 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class UtilTest < Test::Unit::TestCase
|
5
|
-
context "OPTS_COPYABLE" do
|
6
|
-
should "include :apibase" do
|
7
|
-
assert_include Stripe::Util::OPTS_COPYABLE, :api_base
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context "OPTS_PERSISTABLE" do
|
12
|
-
should "include :client" do
|
13
|
-
assert_include Stripe::Util::OPTS_PERSISTABLE, :client
|
14
|
-
end
|
15
|
-
|
16
|
-
should "not include :idempotency_key" do
|
17
|
-
refute_includes Stripe::Util::OPTS_PERSISTABLE, :idempotency_key
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
should "#encode_parameters should prepare parameters for an HTTP request" do
|
22
|
-
params = {
|
23
|
-
a: 3,
|
24
|
-
b: "+foo?",
|
25
|
-
c: "bar&baz",
|
26
|
-
d: { a: "a", b: "b" },
|
27
|
-
e: [0, 1],
|
28
|
-
f: "",
|
29
|
-
|
30
|
-
# note the empty hash won't even show up in the request
|
31
|
-
g: [],
|
32
|
-
}
|
33
|
-
assert_equal(
|
34
|
-
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1&f=",
|
35
|
-
Stripe::Util.encode_parameters(params)
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
should "#encode_params should throw an error on an array of maps that cannot be encoded" do
|
40
|
-
params = {
|
41
|
-
a: [
|
42
|
-
{ a: 1, b: 2 },
|
43
|
-
{ c: 3, a: 4 },
|
44
|
-
],
|
45
|
-
}
|
46
|
-
e = assert_raises(ArgumentError) do
|
47
|
-
Stripe::Util.encode_parameters(params)
|
48
|
-
end
|
49
|
-
expected = "All maps nested in an array should start with the same key " \
|
50
|
-
"(expected starting key 'a', got 'c')"
|
51
|
-
assert_equal expected, e.message
|
52
|
-
|
53
|
-
# Make sure the check is recursive by taking our original params and
|
54
|
-
# nesting it into yet another map and array. Should throw exactly the
|
55
|
-
# same error because it's still the in inner array of maps that's wrong.
|
56
|
-
params = {
|
57
|
-
x: [
|
58
|
-
params,
|
59
|
-
],
|
60
|
-
}
|
61
|
-
e = assert_raises(ArgumentError) do
|
62
|
-
Stripe::Util.encode_parameters(params)
|
63
|
-
end
|
64
|
-
assert_equal expected, e.message
|
65
|
-
end
|
66
|
-
|
67
|
-
should "#url_encode should prepare strings for HTTP" do
|
68
|
-
assert_equal "foo", Stripe::Util.url_encode("foo")
|
69
|
-
assert_equal "foo", Stripe::Util.url_encode(:foo)
|
70
|
-
assert_equal "foo%2B", Stripe::Util.url_encode("foo+")
|
71
|
-
assert_equal "foo%26", Stripe::Util.url_encode("foo&")
|
72
|
-
assert_equal "foo[bar]", Stripe::Util.url_encode("foo[bar]")
|
73
|
-
end
|
74
|
-
|
75
|
-
should "#flatten_params should encode parameters according to Rails convention" do
|
76
|
-
params = [
|
77
|
-
[:a, 3],
|
78
|
-
[:b, "foo?"],
|
79
|
-
[:c, "bar&baz"],
|
80
|
-
[:d, { a: "a", b: "b" }],
|
81
|
-
[:e, [0, 1]],
|
82
|
-
[:f, [
|
83
|
-
{ foo: "1", ghi: "2" },
|
84
|
-
{ foo: "3", bar: "4" },
|
85
|
-
],],
|
86
|
-
]
|
87
|
-
assert_equal([
|
88
|
-
["a", 3],
|
89
|
-
["b", "foo?"],
|
90
|
-
["c", "bar&baz"],
|
91
|
-
["d[a]", "a"],
|
92
|
-
["d[b]", "b"],
|
93
|
-
["e[]", 0],
|
94
|
-
["e[]", 1],
|
95
|
-
|
96
|
-
# *The key here is the order*. In order to be properly interpreted as
|
97
|
-
# an array of hashes on the server, everything from a single hash must
|
98
|
-
# come in at once. A duplicate key in an array triggers a new element.
|
99
|
-
["f[][foo]", "1"],
|
100
|
-
["f[][ghi]", "2"],
|
101
|
-
["f[][foo]", "3"],
|
102
|
-
["f[][bar]", "4"],
|
103
|
-
], Stripe::Util.flatten_params(params))
|
104
|
-
end
|
105
|
-
|
106
|
-
should "#symbolize_names should convert names to symbols" do
|
107
|
-
start = {
|
108
|
-
"foo" => "bar",
|
109
|
-
"array" => [{ "foo" => "bar" }],
|
110
|
-
"nested" => {
|
111
|
-
1 => 2,
|
112
|
-
:symbol => 9,
|
113
|
-
"string" => nil,
|
114
|
-
},
|
115
|
-
}
|
116
|
-
finish = {
|
117
|
-
foo: "bar",
|
118
|
-
array: [{ foo: "bar" }],
|
119
|
-
nested: {
|
120
|
-
1 => 2,
|
121
|
-
:symbol => 9,
|
122
|
-
:string => nil,
|
123
|
-
},
|
124
|
-
}
|
125
|
-
|
126
|
-
symbolized = Stripe::Util.symbolize_names(start)
|
127
|
-
assert_equal(finish, symbolized)
|
128
|
-
end
|
129
|
-
|
130
|
-
should "#normalize_opts should reject nil keys" do
|
131
|
-
assert_raise { Stripe::Util.normalize_opts(nil) }
|
132
|
-
assert_raise { Stripe::Util.normalize_opts(api_key: nil) }
|
133
|
-
end
|
134
|
-
|
135
|
-
should "#convert_to_stripe_object should pass through unknown types" do
|
136
|
-
obj = Util.convert_to_stripe_object(7, {})
|
137
|
-
assert_equal 7, obj
|
138
|
-
end
|
139
|
-
|
140
|
-
should "#convert_to_stripe_object should turn hashes into StripeObjects" do
|
141
|
-
obj = Util.convert_to_stripe_object({ foo: "bar" }, {})
|
142
|
-
assert obj.is_a?(StripeObject)
|
143
|
-
assert_equal "bar", obj.foo
|
144
|
-
end
|
145
|
-
|
146
|
-
should "#convert_to_stripe_object should turn lists into ListObjects" do
|
147
|
-
obj = Util.convert_to_stripe_object({ object: "list" }, {})
|
148
|
-
assert obj.is_a?(ListObject)
|
149
|
-
end
|
150
|
-
|
151
|
-
should "#convert_to_stripe_object should marshal other classes" do
|
152
|
-
obj = Util.convert_to_stripe_object({ object: "account" }, {})
|
153
|
-
assert obj.is_a?(Account)
|
154
|
-
end
|
155
|
-
|
156
|
-
should "#convert_to_stripe_object should marshal arrays" do
|
157
|
-
obj = Util.convert_to_stripe_object([1, 2, 3], {})
|
158
|
-
assert_equal [1, 2, 3], obj
|
159
|
-
end
|
160
|
-
|
161
|
-
should "#array_to_hash should convert an array into a hash with integer keys" do
|
162
|
-
assert_equal({ "0" => 1, "1" => 2, "2" => 3 }, Util.array_to_hash([1, 2, 3]))
|
163
|
-
end
|
164
|
-
|
165
|
-
context ".request_id_dashboard_url" do
|
166
|
-
should "generate a livemode URL" do
|
167
|
-
assert_equal "https://dashboard.stripe.com/live/logs/request-id",
|
168
|
-
Util.request_id_dashboard_url("request-id", "sk_live_123")
|
169
|
-
end
|
170
|
-
|
171
|
-
should "generate a testmode URL" do
|
172
|
-
assert_equal "https://dashboard.stripe.com/test/logs/request-id",
|
173
|
-
Util.request_id_dashboard_url("request-id", "sk_test_123")
|
174
|
-
end
|
175
|
-
|
176
|
-
should "default to a testmode URL" do
|
177
|
-
assert_equal "https://dashboard.stripe.com/test/logs/request-id",
|
178
|
-
Util.request_id_dashboard_url("request-id", nil)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context ".log_*" do
|
183
|
-
setup do
|
184
|
-
@old_log_level = Stripe.log_level
|
185
|
-
Stripe.log_level = nil
|
186
|
-
|
187
|
-
@old_stderr = $stderr
|
188
|
-
$stderr = StringIO.new
|
189
|
-
|
190
|
-
@old_stdout = $stdout
|
191
|
-
$stdout = StringIO.new
|
192
|
-
end
|
193
|
-
|
194
|
-
teardown do
|
195
|
-
Stripe.log_level = @old_log_level
|
196
|
-
$stderr = @old_stderr
|
197
|
-
$stdout = @old_stdout
|
198
|
-
end
|
199
|
-
|
200
|
-
context ".log_debug" do
|
201
|
-
should "not log if logging is disabled" do
|
202
|
-
Util.log_debug("foo")
|
203
|
-
assert_equal "", $stdout.string
|
204
|
-
end
|
205
|
-
|
206
|
-
should "log if level set to debug" do
|
207
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
208
|
-
Util.log_debug("foo")
|
209
|
-
assert_equal "message=foo level=debug \n", $stdout.string
|
210
|
-
end
|
211
|
-
|
212
|
-
should "not log if level set to error" do
|
213
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
214
|
-
Util.log_debug("foo")
|
215
|
-
assert_equal "", $stdout.string
|
216
|
-
end
|
217
|
-
|
218
|
-
should "not log if level set to info" do
|
219
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
220
|
-
Util.log_debug("foo")
|
221
|
-
assert_equal "", $stdout.string
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context ".log_error" do
|
226
|
-
should "not log if logging is disabled" do
|
227
|
-
Util.log_error("foo")
|
228
|
-
assert_equal "", $stdout.string
|
229
|
-
end
|
230
|
-
|
231
|
-
should "log if level set to debug" do
|
232
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
233
|
-
Util.log_error("foo")
|
234
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
235
|
-
end
|
236
|
-
|
237
|
-
should "log if level set to error" do
|
238
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
239
|
-
Util.log_error("foo")
|
240
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
241
|
-
end
|
242
|
-
|
243
|
-
should "log if level set to info" do
|
244
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
245
|
-
Util.log_error("foo")
|
246
|
-
assert_equal "message=foo level=error \n", $stderr.string
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context ".log_info" do
|
251
|
-
should "not log if logging is disabled" do
|
252
|
-
Util.log_info("foo")
|
253
|
-
assert_equal "", $stdout.string
|
254
|
-
end
|
255
|
-
|
256
|
-
should "log if level set to debug" do
|
257
|
-
Stripe.log_level = Stripe::LEVEL_DEBUG
|
258
|
-
Util.log_info("foo")
|
259
|
-
assert_equal "message=foo level=info \n", $stdout.string
|
260
|
-
end
|
261
|
-
|
262
|
-
should "not log if level set to error" do
|
263
|
-
Stripe.log_level = Stripe::LEVEL_ERROR
|
264
|
-
Util.log_debug("foo")
|
265
|
-
assert_equal "", $stdout.string
|
266
|
-
end
|
267
|
-
|
268
|
-
should "log if level set to info" do
|
269
|
-
Stripe.log_level = Stripe::LEVEL_INFO
|
270
|
-
Util.log_info("foo")
|
271
|
-
assert_equal "message=foo level=info \n", $stdout.string
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context ".log_* with a logger" do
|
277
|
-
setup do
|
278
|
-
@out = StringIO.new
|
279
|
-
logger = ::Logger.new(@out)
|
280
|
-
|
281
|
-
# Set a really simple formatter to make matching output as easy as
|
282
|
-
# possible.
|
283
|
-
logger.formatter = proc { |_severity, _datetime, _progname, message|
|
284
|
-
message
|
285
|
-
}
|
286
|
-
|
287
|
-
Stripe.logger = logger
|
288
|
-
end
|
289
|
-
|
290
|
-
context ".log_debug" do
|
291
|
-
should "log to the logger" do
|
292
|
-
Util.log_debug("foo")
|
293
|
-
assert_equal "message=foo ", @out.string
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context ".log_error" do
|
298
|
-
should "log to the logger" do
|
299
|
-
Util.log_error("foo")
|
300
|
-
assert_equal "message=foo ", @out.string
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
context ".log_info" do
|
305
|
-
should "log to the logger" do
|
306
|
-
Util.log_info("foo")
|
307
|
-
assert_equal "message=foo ", @out.string
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context ".normalize_headers" do
|
313
|
-
should "normalize the format of a header key" do
|
314
|
-
assert_equal({ "Request-Id" => nil },
|
315
|
-
Util.normalize_headers("Request-Id" => nil))
|
316
|
-
assert_equal({ "Request-Id" => nil },
|
317
|
-
Util.normalize_headers("request-id" => nil))
|
318
|
-
assert_equal({ "Request-Id" => nil },
|
319
|
-
Util.normalize_headers("Request-ID" => nil))
|
320
|
-
assert_equal({ "Request-Id" => nil },
|
321
|
-
Util.normalize_headers(request_id: nil))
|
322
|
-
end
|
323
|
-
|
324
|
-
should "tolerate bad formatting" do
|
325
|
-
assert_equal({ "Request-Id" => nil },
|
326
|
-
Util.normalize_headers("-Request--Id-" => nil))
|
327
|
-
assert_equal({ "Request-Id" => nil },
|
328
|
-
Util.normalize_headers(request__id: nil))
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
#
|
333
|
-
# private
|
334
|
-
#
|
335
|
-
# I don't feel particularly good about using #send to invoke these, but I
|
336
|
-
# want them hidden from the public interface, and each method is far easier
|
337
|
-
# to test in isolation (as opposed to going through a public method).
|
338
|
-
#
|
339
|
-
|
340
|
-
context ".colorize" do
|
341
|
-
should "colorize for a TTY" do
|
342
|
-
assert_equal "\033[0;32;49mfoo\033[0m",
|
343
|
-
Util.send(:colorize, "foo", :green, true)
|
344
|
-
end
|
345
|
-
|
346
|
-
should "not colorize otherwise" do
|
347
|
-
assert_equal "foo", Util.send(:colorize, "foo", :green, false)
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
context ".level_name" do
|
352
|
-
should "convert levels to names" do
|
353
|
-
assert_equal "debug", Util.send(:level_name, LEVEL_DEBUG)
|
354
|
-
assert_equal "error", Util.send(:level_name, LEVEL_ERROR)
|
355
|
-
assert_equal "info", Util.send(:level_name, LEVEL_INFO)
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
context ".log_internal" do
|
360
|
-
should "log in a terminal friendly way" do
|
361
|
-
out = StringIO.new
|
362
|
-
|
363
|
-
# Sketchy as anything, but saves us from pulling in a mocking library.
|
364
|
-
# Open this instance of StringIO, and add a method override so that it
|
365
|
-
# looks like a TTY.
|
366
|
-
out.instance_eval do
|
367
|
-
def isatty
|
368
|
-
true
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
373
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: nil, out: out)
|
374
|
-
assert_equal "\e[0;32;49mDEBU\e[0m message \e[0;32;49mfoo\e[0m=bar\n",
|
375
|
-
out.string
|
376
|
-
end
|
377
|
-
|
378
|
-
should "log in a data friendly way" do
|
379
|
-
out = StringIO.new
|
380
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
381
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: nil, out: out)
|
382
|
-
assert_equal "message=message level=debug foo=bar\n",
|
383
|
-
out.string
|
384
|
-
end
|
385
|
-
|
386
|
-
should "log to a logger if set" do
|
387
|
-
out = StringIO.new
|
388
|
-
logger = ::Logger.new(out)
|
389
|
-
|
390
|
-
# Set a really simple formatter to make matching output as easy as
|
391
|
-
# possible.
|
392
|
-
logger.formatter = proc { |_severity, _datetime, _progname, message|
|
393
|
-
message
|
394
|
-
}
|
395
|
-
|
396
|
-
Util.send(:log_internal, "message", { foo: "bar" },
|
397
|
-
color: :green, level: Stripe::LEVEL_DEBUG, logger: logger, out: nil)
|
398
|
-
assert_equal "message=message foo=bar",
|
399
|
-
out.string
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
context ".wrap_logfmt_value" do
|
404
|
-
should "pass through simple values" do
|
405
|
-
assert_equal "abc", Util.send(:wrap_logfmt_value, "abc")
|
406
|
-
assert_equal "123", Util.send(:wrap_logfmt_value, "123")
|
407
|
-
assert_equal "a-b_c/d", Util.send(:wrap_logfmt_value, "a-b_c/d")
|
408
|
-
end
|
409
|
-
|
410
|
-
should "pass through numerics" do
|
411
|
-
assert_equal 123, Util.send(:wrap_logfmt_value, 123)
|
412
|
-
assert_equal 1.23, Util.send(:wrap_logfmt_value, 1.23)
|
413
|
-
end
|
414
|
-
|
415
|
-
should "wrap more complex values in double quotes" do
|
416
|
-
assert_equal %("abc=123"), Util.send(:wrap_logfmt_value, %(abc=123))
|
417
|
-
end
|
418
|
-
|
419
|
-
should "escape double quotes already in the value" do
|
420
|
-
assert_equal %("abc=\\"123\\""), Util.send(:wrap_logfmt_value, %(abc="123"))
|
421
|
-
end
|
422
|
-
|
423
|
-
should "remove newlines" do
|
424
|
-
assert_equal %("abc"), Util.send(:wrap_logfmt_value, "a\nb\nc")
|
425
|
-
end
|
426
|
-
|
427
|
-
should "not error if given a non-string" do
|
428
|
-
assert_equal "true", Util.send(:wrap_logfmt_value, true)
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
432
|
-
end
|
data/test/stripe/webhook_test.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class WebhookTest < Test::Unit::TestCase
|
5
|
-
EVENT_PAYLOAD = <<-PAYLOAD.freeze
|
6
|
-
{
|
7
|
-
"id": "evt_test_webhook",
|
8
|
-
"object": "event"
|
9
|
-
}
|
10
|
-
PAYLOAD
|
11
|
-
SECRET = "whsec_test_secret".freeze
|
12
|
-
|
13
|
-
def generate_header(opts = {})
|
14
|
-
opts[:timestamp] ||= Time.now.to_i
|
15
|
-
opts[:payload] ||= EVENT_PAYLOAD
|
16
|
-
opts[:secret] ||= SECRET
|
17
|
-
opts[:scheme] ||= Stripe::Webhook::Signature::EXPECTED_SCHEME
|
18
|
-
opts[:signature] ||= Stripe::Webhook::Signature.send(:compute_signature, "#{opts[:timestamp]}.#{opts[:payload]}", opts[:secret])
|
19
|
-
"t=#{opts[:timestamp]},#{opts[:scheme]}=#{opts[:signature]}"
|
20
|
-
end
|
21
|
-
|
22
|
-
context ".construct_event" do
|
23
|
-
should "return an Event instance from a valid JSON payload and valid signature header" do
|
24
|
-
header = generate_header
|
25
|
-
event = Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
|
26
|
-
assert event.is_a?(Stripe::Event)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "raise a JSON::ParserError from an invalid JSON payload" do
|
30
|
-
assert_raises JSON::ParserError do
|
31
|
-
payload = "this is not valid JSON"
|
32
|
-
header = generate_header(payload: payload)
|
33
|
-
Stripe::Webhook.construct_event(payload, header, SECRET)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
should "raise a SignatureVerificationError from a valid JSON payload and an invalid signature header" do
|
38
|
-
header = "bad_header"
|
39
|
-
assert_raises Stripe::SignatureVerificationError do
|
40
|
-
Stripe::Webhook.construct_event(EVENT_PAYLOAD, header, SECRET)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context ".verify_signature_header" do
|
46
|
-
should "raise a SignatureVerificationError when the header does not have the expected format" do
|
47
|
-
header = 'i\'m not even a real signature header'
|
48
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
49
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
|
50
|
-
end
|
51
|
-
assert_match("Unable to extract timestamp and signatures from header", e.message)
|
52
|
-
end
|
53
|
-
|
54
|
-
should "raise a SignatureVerificationError when there are no signatures with the expected scheme" do
|
55
|
-
header = generate_header(scheme: "v0")
|
56
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
57
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
|
58
|
-
end
|
59
|
-
assert_match("No signatures found with expected scheme", e.message)
|
60
|
-
end
|
61
|
-
|
62
|
-
should "raise a SignatureVerificationError when there are no valid signatures for the payload" do
|
63
|
-
header = generate_header(signature: "bad_signature")
|
64
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
65
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, "secret")
|
66
|
-
end
|
67
|
-
assert_match("No signatures found matching the expected signature for payload", e.message)
|
68
|
-
end
|
69
|
-
|
70
|
-
should "raise a SignatureVerificationError when the timestamp is not within the tolerance" do
|
71
|
-
header = generate_header(timestamp: Time.now.to_i - 15)
|
72
|
-
e = assert_raises(Stripe::SignatureVerificationError) do
|
73
|
-
Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10)
|
74
|
-
end
|
75
|
-
assert_match("Timestamp outside the tolerance zone", e.message)
|
76
|
-
end
|
77
|
-
|
78
|
-
should "return true when the header contains a valid signature and the timestamp is within the tolerance" do
|
79
|
-
header = generate_header
|
80
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
|
81
|
-
end
|
82
|
-
|
83
|
-
should "return true when the header contains at least one valid signature" do
|
84
|
-
header = generate_header + ",v1=bad_signature"
|
85
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET, tolerance: 10))
|
86
|
-
end
|
87
|
-
|
88
|
-
should "return true when the header contains a valid signature and the timestamp is off but no tolerance is provided" do
|
89
|
-
header = generate_header(timestamp: 12_345)
|
90
|
-
assert(Stripe::Webhook::Signature.verify_header(EVENT_PAYLOAD, header, SECRET))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
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
|