stripe 5.28.0 → 8.7.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 +286 -0
- data/Gemfile +5 -3
- data/Makefile +13 -0
- data/OPENAPI_VERSION +1 -0
- data/README.md +43 -5
- data/VERSION +1 -1
- data/lib/data/ca-certificates.crt +1241 -1937
- data/lib/stripe/api_operations/create.rb +6 -2
- data/lib/stripe/api_operations/delete.rb +12 -7
- data/lib/stripe/api_operations/list.rb +6 -9
- data/lib/stripe/api_operations/nested_resource.rb +62 -34
- data/lib/stripe/api_operations/request.rb +45 -2
- data/lib/stripe/api_operations/save.rb +13 -3
- data/lib/stripe/api_operations/search.rb +16 -0
- data/lib/stripe/api_resource.rb +11 -18
- data/lib/stripe/api_resource_test_helpers.rb +49 -0
- data/lib/stripe/api_version.rb +8 -0
- data/lib/stripe/connection_manager.rb +49 -11
- data/lib/stripe/error_object.rb +2 -3
- data/lib/stripe/instrumentation.rb +46 -6
- data/lib/stripe/oauth.rb +4 -3
- data/lib/stripe/object_types.rb +36 -10
- data/lib/stripe/resources/account.rb +39 -17
- data/lib/stripe/resources/account_link.rb +4 -0
- data/lib/stripe/resources/application_fee_refund.rb +7 -1
- data/lib/stripe/resources/apps/secret.rb +40 -0
- data/lib/stripe/resources/balance.rb +11 -0
- data/lib/stripe/resources/balance_transaction.rb +4 -0
- data/lib/stripe/resources/bank_account.rb +7 -0
- data/lib/stripe/resources/billing_portal/configuration.rb +15 -0
- data/lib/stripe/resources/billing_portal/session.rb +14 -0
- data/lib/stripe/resources/capability.rb +5 -1
- data/lib/stripe/resources/card.rb +6 -3
- data/lib/stripe/resources/cash_balance.rb +23 -0
- data/lib/stripe/resources/charge.rb +23 -3
- data/lib/stripe/resources/checkout/session.rb +49 -2
- data/lib/stripe/resources/country_spec.rb +6 -0
- data/lib/stripe/resources/coupon.rb +3 -0
- data/lib/stripe/resources/credit_note.rb +27 -9
- data/lib/stripe/resources/credit_note_line_item.rb +2 -0
- data/lib/stripe/resources/customer.rb +132 -4
- data/lib/stripe/resources/customer_balance_transaction.rb +9 -2
- data/lib/stripe/resources/customer_cash_balance_transaction.rb +14 -0
- data/lib/stripe/resources/discount.rb +5 -0
- data/lib/stripe/resources/dispute.rb +17 -3
- data/lib/stripe/resources/event.rb +29 -0
- data/lib/stripe/resources/exchange_rate.rb +11 -0
- data/lib/stripe/resources/file.rb +9 -1
- data/lib/stripe/resources/file_link.rb +3 -0
- data/lib/stripe/resources/financial_connections/account.rb +67 -0
- data/lib/stripe/resources/financial_connections/account_owner.rb +11 -0
- data/lib/stripe/resources/financial_connections/account_ownership.rb +11 -0
- data/lib/stripe/resources/financial_connections/session.rb +13 -0
- data/lib/stripe/resources/funding_instructions.rb +21 -0
- data/lib/stripe/resources/identity/verification_report.rb +23 -0
- data/lib/stripe/resources/identity/verification_session.rb +61 -0
- data/lib/stripe/resources/invoice.rb +105 -17
- data/lib/stripe/resources/invoice_item.rb +11 -0
- data/lib/stripe/resources/invoice_line_item.rb +1 -0
- data/lib/stripe/resources/issuing/authorization.rb +25 -5
- data/lib/stripe/resources/issuing/card.rb +78 -8
- data/lib/stripe/resources/issuing/cardholder.rb +3 -0
- data/lib/stripe/resources/issuing/dispute.rb +13 -3
- data/lib/stripe/resources/issuing/transaction.rb +5 -0
- data/lib/stripe/resources/line_item.rb +2 -0
- data/lib/stripe/resources/login_link.rb +2 -0
- data/lib/stripe/resources/mandate.rb +1 -0
- data/lib/stripe/resources/payment_intent.rb +103 -6
- data/lib/stripe/resources/payment_link.rb +35 -0
- data/lib/stripe/resources/payment_method.rb +25 -5
- data/lib/stripe/resources/payout.rb +28 -5
- data/lib/stripe/resources/person.rb +7 -0
- data/lib/stripe/resources/plan.rb +8 -0
- data/lib/stripe/resources/price.rb +15 -0
- data/lib/stripe/resources/product.rb +17 -0
- data/lib/stripe/resources/promotion_code.rb +2 -0
- data/lib/stripe/resources/quote.rb +128 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +4 -0
- data/lib/stripe/resources/radar/value_list.rb +3 -0
- data/lib/stripe/resources/radar/value_list_item.rb +3 -0
- data/lib/stripe/resources/refund.rb +49 -0
- data/lib/stripe/resources/reporting/report_run.rb +8 -0
- data/lib/stripe/resources/reporting/report_type.rb +8 -1
- data/lib/stripe/resources/reversal.rb +16 -2
- data/lib/stripe/resources/review.rb +14 -3
- data/lib/stripe/resources/setup_attempt.rb +4 -0
- data/lib/stripe/resources/setup_intent.rb +60 -5
- data/lib/stripe/resources/shipping_rate.rb +14 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +4 -0
- data/lib/stripe/resources/source.rb +26 -6
- data/lib/stripe/resources/source_transaction.rb +5 -0
- data/lib/stripe/resources/subscription.rb +57 -3
- data/lib/stripe/resources/subscription_item.rb +2 -7
- data/lib/stripe/resources/subscription_schedule.rb +23 -5
- data/lib/stripe/resources/tax/calculation.rb +33 -0
- data/lib/stripe/resources/tax/calculation_line_item.rb +10 -0
- data/lib/stripe/resources/tax/settings.rb +15 -0
- data/lib/stripe/resources/tax/transaction.rb +49 -0
- data/lib/stripe/resources/tax/transaction_line_item.rb +10 -0
- data/lib/stripe/resources/tax_code.rb +11 -0
- data/lib/stripe/resources/tax_id.rb +5 -0
- data/lib/stripe/resources/tax_rate.rb +3 -0
- data/lib/stripe/resources/terminal/configuration.rb +16 -0
- data/lib/stripe/resources/terminal/connection_token.rb +3 -0
- data/lib/stripe/resources/terminal/location.rb +3 -0
- data/lib/stripe/resources/terminal/reader.rb +119 -0
- data/lib/stripe/resources/test_helpers/test_clock.rb +35 -0
- data/lib/stripe/resources/token.rb +20 -0
- data/lib/stripe/resources/topup.rb +15 -3
- data/lib/stripe/resources/transfer.rb +10 -11
- data/lib/stripe/resources/treasury/credit_reversal.rb +14 -0
- data/lib/stripe/resources/treasury/debit_reversal.rb +14 -0
- data/lib/stripe/resources/treasury/financial_account.rb +52 -0
- data/lib/stripe/resources/treasury/financial_account_features.rb +12 -0
- data/lib/stripe/resources/treasury/inbound_transfer.rb +94 -0
- data/lib/stripe/resources/treasury/outbound_payment.rb +96 -0
- data/lib/stripe/resources/treasury/outbound_transfer.rb +100 -0
- data/lib/stripe/resources/treasury/received_credit.rb +30 -0
- data/lib/stripe/resources/treasury/received_debit.rb +30 -0
- data/lib/stripe/resources/treasury/transaction.rb +13 -0
- data/lib/stripe/resources/treasury/transaction_entry.rb +17 -0
- data/lib/stripe/resources/usage_record.rb +5 -0
- data/lib/stripe/resources/usage_record_summary.rb +1 -0
- data/lib/stripe/resources/webhook_endpoint.rb +7 -0
- data/lib/stripe/resources.rb +34 -10
- data/lib/stripe/search_result_object.rb +86 -0
- data/lib/stripe/stripe_client.rb +267 -121
- data/lib/stripe/stripe_configuration.rb +29 -10
- data/lib/stripe/stripe_object.rb +25 -2
- data/lib/stripe/stripe_response.rb +80 -52
- data/lib/stripe/util.rb +100 -9
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +27 -23
- data/stripe.gemspec +12 -5
- metadata +46 -204
- 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/lib/stripe/resources/bitcoin_receiver.rb +0 -24
- data/lib/stripe/resources/bitcoin_transaction.rb +0 -15
- data/lib/stripe/resources/issuing/card_details.rb +0 -9
- data/lib/stripe/resources/order.rb +0 -33
- data/lib/stripe/resources/order_return.rb +0 -10
- data/lib/stripe/resources/recipient.rb +0 -14
- data/lib/stripe/resources/sku.rb +0 -13
- data/lib/stripe/resources/three_d_secure.rb +0 -14
- 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,131 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require ::File.expand_path("../test_helper", __dir__)
|
4
|
-
|
5
|
-
module Stripe
|
6
|
-
class StripeConfigurationTest < Test::Unit::TestCase
|
7
|
-
context ".setup" do
|
8
|
-
should "initialize a new configuration with defaults" do
|
9
|
-
config = Stripe::StripeConfiguration.setup
|
10
|
-
|
11
|
-
assert_equal Stripe::DEFAULT_CA_BUNDLE_PATH, config.ca_bundle_path
|
12
|
-
assert_equal true, config.enable_telemetry
|
13
|
-
assert_equal true, config.verify_ssl_certs
|
14
|
-
assert_equal 2, config.max_network_retry_delay
|
15
|
-
assert_equal 0.5, config.initial_network_retry_delay
|
16
|
-
assert_equal 0, config.max_network_retries
|
17
|
-
assert_equal 30, config.open_timeout
|
18
|
-
assert_equal 80, config.read_timeout
|
19
|
-
assert_equal 30, config.write_timeout
|
20
|
-
assert_equal "https://api.stripe.com", config.api_base
|
21
|
-
assert_equal "https://connect.stripe.com", config.connect_base
|
22
|
-
assert_equal "https://files.stripe.com", config.uploads_base
|
23
|
-
end
|
24
|
-
|
25
|
-
should "allow for overrides when a block is passed" do
|
26
|
-
config = Stripe::StripeConfiguration.setup do |c|
|
27
|
-
c.open_timeout = 100
|
28
|
-
c.read_timeout = 100
|
29
|
-
c.write_timeout = 100 if WRITE_TIMEOUT_SUPPORTED
|
30
|
-
end
|
31
|
-
|
32
|
-
assert_equal 100, config.open_timeout
|
33
|
-
assert_equal 100, config.read_timeout
|
34
|
-
assert_equal 100, config.write_timeout if WRITE_TIMEOUT_SUPPORTED
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "#reverse_duplicate_merge" do
|
39
|
-
should "return a duplicate object with overrides" do
|
40
|
-
config = Stripe::StripeConfiguration.setup do |c|
|
41
|
-
c.open_timeout = 100
|
42
|
-
end
|
43
|
-
|
44
|
-
duped_config = config.reverse_duplicate_merge(read_timeout: 500)
|
45
|
-
|
46
|
-
assert_equal config.open_timeout, duped_config.open_timeout
|
47
|
-
assert_equal 500, duped_config.read_timeout
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "#max_network_retries=" do
|
52
|
-
should "coerce the option into an integer" do
|
53
|
-
config = Stripe::StripeConfiguration.setup
|
54
|
-
|
55
|
-
config.max_network_retries = "10"
|
56
|
-
assert_equal 10, config.max_network_retries
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "#log_level=" do
|
61
|
-
should "be backwards compatible with old values" do
|
62
|
-
config = Stripe::StripeConfiguration.setup
|
63
|
-
|
64
|
-
config.log_level = "debug"
|
65
|
-
assert_equal Stripe::LEVEL_DEBUG, config.log_level
|
66
|
-
|
67
|
-
config.log_level = "info"
|
68
|
-
assert_equal Stripe::LEVEL_INFO, config.log_level
|
69
|
-
end
|
70
|
-
|
71
|
-
should "raise an error if the value isn't valid" do
|
72
|
-
config = Stripe::StripeConfiguration.setup
|
73
|
-
|
74
|
-
assert_raises ArgumentError do
|
75
|
-
config.log_level = "Foo"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "options that require all connection managers to be cleared" do
|
81
|
-
should "clear when setting allow ca_bundle_path" do
|
82
|
-
config = Stripe::StripeConfiguration.setup
|
83
|
-
|
84
|
-
StripeClient.expects(:clear_all_connection_managers)
|
85
|
-
config.ca_bundle_path = "/path/to/ca/bundle"
|
86
|
-
end
|
87
|
-
|
88
|
-
should "clear when setting open timeout" do
|
89
|
-
config = Stripe::StripeConfiguration.setup
|
90
|
-
|
91
|
-
StripeClient.expects(:clear_all_connection_managers)
|
92
|
-
config.open_timeout = 10
|
93
|
-
end
|
94
|
-
|
95
|
-
should "clear when setting read timeout" do
|
96
|
-
config = Stripe::StripeConfiguration.setup
|
97
|
-
|
98
|
-
StripeClient.expects(:clear_all_connection_managers)
|
99
|
-
config.read_timeout = 10
|
100
|
-
end
|
101
|
-
|
102
|
-
should "clear when setting uploads_base" do
|
103
|
-
config = Stripe::StripeConfiguration.setup
|
104
|
-
|
105
|
-
StripeClient.expects(:clear_all_connection_managers)
|
106
|
-
config.uploads_base = "https://other.stripe.com"
|
107
|
-
end
|
108
|
-
|
109
|
-
should "clearn when setting api_base to be configured" do
|
110
|
-
config = Stripe::StripeConfiguration.setup
|
111
|
-
|
112
|
-
StripeClient.expects(:clear_all_connection_managers)
|
113
|
-
config.api_base = "https://other.stripe.com"
|
114
|
-
end
|
115
|
-
|
116
|
-
should "clear when setting connect_base" do
|
117
|
-
config = Stripe::StripeConfiguration.setup
|
118
|
-
|
119
|
-
StripeClient.expects(:clear_all_connection_managers)
|
120
|
-
config.connect_base = "https://other.stripe.com"
|
121
|
-
end
|
122
|
-
|
123
|
-
should "clear when setting verify_ssl_certs" do
|
124
|
-
config = Stripe::StripeConfiguration.setup
|
125
|
-
|
126
|
-
StripeClient.expects(:clear_all_connection_managers)
|
127
|
-
config.verify_ssl_certs = false
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,500 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require ::File.expand_path("../test_helper", __dir__)
|
4
|
-
|
5
|
-
module Stripe
|
6
|
-
class StripeObjectTest < Test::Unit::TestCase
|
7
|
-
should "implement #==" do
|
8
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
9
|
-
obj2 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
10
|
-
obj3 = Stripe::StripeObject.construct_from(id: 1, foo: "rab")
|
11
|
-
|
12
|
-
assert obj1 == obj2
|
13
|
-
refute obj1 == obj3
|
14
|
-
end
|
15
|
-
|
16
|
-
should "implement #deleted?" do
|
17
|
-
obj = Stripe::StripeObject.construct_from({})
|
18
|
-
refute obj.deleted?
|
19
|
-
|
20
|
-
obj = Stripe::StripeObject.construct_from(deleted: false)
|
21
|
-
refute obj.deleted?
|
22
|
-
|
23
|
-
obj = Stripe::StripeObject.construct_from(deleted: true)
|
24
|
-
assert obj.deleted?
|
25
|
-
end
|
26
|
-
|
27
|
-
should "implement #respond_to" do
|
28
|
-
obj = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
29
|
-
assert obj.respond_to?(:id)
|
30
|
-
assert obj.respond_to?(:foo)
|
31
|
-
assert !obj.respond_to?(:baz)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "marshal be insensitive to strings vs. symbols when constructin" do
|
35
|
-
obj = Stripe::StripeObject.construct_from(:id => 1, "name" => "Stripe")
|
36
|
-
assert_equal 1, obj[:id]
|
37
|
-
assert_equal "Stripe", obj[:name]
|
38
|
-
end
|
39
|
-
|
40
|
-
context "#deep_copy" do
|
41
|
-
should "produce a deep copy" do
|
42
|
-
opts = {
|
43
|
-
api_base: Stripe.api_base,
|
44
|
-
api_key: "apikey",
|
45
|
-
}
|
46
|
-
values = {
|
47
|
-
id: 1,
|
48
|
-
name: "Stripe",
|
49
|
-
arr: [
|
50
|
-
StripeObject.construct_from({ id: "index0" }, opts),
|
51
|
-
"index1",
|
52
|
-
2,
|
53
|
-
],
|
54
|
-
map: {
|
55
|
-
"0": StripeObject.construct_from({ id: "index0" }, opts),
|
56
|
-
"1": "index1",
|
57
|
-
"2": 2,
|
58
|
-
},
|
59
|
-
}
|
60
|
-
|
61
|
-
# it's not good to test methods with `#send` like this, but I've done
|
62
|
-
# it in the interest of trying to keep `.deep_copy` as internal as
|
63
|
-
# possible
|
64
|
-
copy_values = Stripe::StripeObject.send(:deep_copy, values)
|
65
|
-
|
66
|
-
# we can't compare the hashes directly because they have embedded
|
67
|
-
# objects which are different from each other
|
68
|
-
assert_equal values[:id], copy_values[:id]
|
69
|
-
assert_equal values[:name], copy_values[:name]
|
70
|
-
|
71
|
-
assert_equal values[:arr].length, copy_values[:arr].length
|
72
|
-
|
73
|
-
# internal values of the copied StripeObject should be the same
|
74
|
-
# (including opts), but the object itself should be new (hence the
|
75
|
-
# refutation of equality on #object_id)
|
76
|
-
assert_equal values[:arr][0][:id], copy_values[:arr][0][:id]
|
77
|
-
refute_equal values[:arr][0].object_id, copy_values[:arr][0].object_id
|
78
|
-
assert_equal values[:arr][0].instance_variable_get(:@opts),
|
79
|
-
copy_values[:arr][0].instance_variable_get(:@opts)
|
80
|
-
|
81
|
-
# scalars however, can be compared
|
82
|
-
assert_equal values[:arr][1], copy_values[:arr][1]
|
83
|
-
assert_equal values[:arr][2], copy_values[:arr][2]
|
84
|
-
|
85
|
-
# and a similar story with the hash
|
86
|
-
assert_equal values[:map].keys, copy_values[:map].keys
|
87
|
-
assert_equal values[:map][:"0"][:id], copy_values[:map][:"0"][:id]
|
88
|
-
refute_equal values[:map][:"0"].object_id, copy_values[:map][:"0"].object_id
|
89
|
-
assert_equal values[:map][:"0"].instance_variable_get(:@opts),
|
90
|
-
copy_values[:map][:"0"].instance_variable_get(:@opts)
|
91
|
-
assert_equal values[:map][:"1"], copy_values[:map][:"1"]
|
92
|
-
assert_equal values[:map][:"2"], copy_values[:map][:"2"]
|
93
|
-
end
|
94
|
-
|
95
|
-
should "not copy a client" do
|
96
|
-
opts = {
|
97
|
-
api_key: "apikey",
|
98
|
-
client: StripeClient.active_client,
|
99
|
-
}
|
100
|
-
values = { id: 1, name: "Stripe" }
|
101
|
-
|
102
|
-
obj = Stripe::StripeObject.construct_from(values, opts)
|
103
|
-
copy_obj = Stripe::StripeObject.send(:deep_copy, obj)
|
104
|
-
|
105
|
-
assert_equal values, copy_obj.instance_variable_get(:@values)
|
106
|
-
assert_equal opts.reject { |k, _v| k == :client },
|
107
|
-
copy_obj.instance_variable_get(:@opts)
|
108
|
-
end
|
109
|
-
|
110
|
-
should "return an instance of the same class" do
|
111
|
-
class TestObject < Stripe::StripeObject; end
|
112
|
-
|
113
|
-
obj = TestObject.construct_from(id: 1)
|
114
|
-
copy_obj = obj.class.send(:deep_copy, obj)
|
115
|
-
|
116
|
-
assert_equal obj.class, copy_obj.class
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "#eql?" do
|
121
|
-
should "produce true for two equivalent Stripe objects" do
|
122
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
123
|
-
obj2 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
124
|
-
assert obj1.eql?(obj2)
|
125
|
-
end
|
126
|
-
|
127
|
-
should "produce false for non-equivalent Stripe objects" do
|
128
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
129
|
-
obj2 = Stripe::StripeObject.construct_from(id: 2, name: "Stripe")
|
130
|
-
refute obj1.eql?(obj2)
|
131
|
-
end
|
132
|
-
|
133
|
-
should "produce false for different types" do
|
134
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
135
|
-
obj2 = 7
|
136
|
-
refute obj1.eql?(obj2)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "#hash" do
|
141
|
-
should "produce the same hash for two equivalent Stripe objects" do
|
142
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
143
|
-
obj2 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
144
|
-
assert_equal obj1.hash, obj2.hash
|
145
|
-
end
|
146
|
-
|
147
|
-
should "produce different hashes for non-equivalent Stripe objects" do
|
148
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
149
|
-
obj2 = Stripe::StripeObject.construct_from(id: 2, name: "Stripe")
|
150
|
-
refute_equal obj1.hash, obj2.hash
|
151
|
-
end
|
152
|
-
|
153
|
-
should "produce different hashes for different types" do
|
154
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
155
|
-
obj2 = 7
|
156
|
-
refute_equal obj1.hash, obj2.hash
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context "#to_hash" do
|
161
|
-
should "skip calling to_hash on nil" do
|
162
|
-
begin
|
163
|
-
module NilWithToHash
|
164
|
-
def to_hash
|
165
|
-
raise "Can't call to_hash on nil"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
::NilClass.include NilWithToHash
|
169
|
-
|
170
|
-
hash_with_nil = { id: 3, foo: nil }
|
171
|
-
obj = StripeObject.construct_from(hash_with_nil)
|
172
|
-
expected_hash = { id: 3, foo: nil }
|
173
|
-
assert_equal expected_hash, obj.to_hash
|
174
|
-
ensure
|
175
|
-
::NilClass.send(:undef_method, :to_hash)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
should "recursively call to_hash on its values" do
|
180
|
-
# deep nested hash (when contained in an array) or StripeObject
|
181
|
-
nested_hash = { id: 7, foo: "bar" }
|
182
|
-
nested = Stripe::StripeObject.construct_from(nested_hash)
|
183
|
-
|
184
|
-
obj = Stripe::StripeObject.construct_from(id: 1,
|
185
|
-
# simple hash that contains a StripeObject to help us test deep
|
186
|
-
# recursion
|
187
|
-
nested: { object: "list", data: [nested] },
|
188
|
-
list: [nested])
|
189
|
-
|
190
|
-
expected_hash = {
|
191
|
-
id: 1,
|
192
|
-
nested: { object: "list", data: [nested_hash] },
|
193
|
-
list: [nested_hash],
|
194
|
-
}
|
195
|
-
assert_equal expected_hash, obj.to_hash
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
should "assign question mark accessors for booleans" do
|
200
|
-
obj = Stripe::StripeObject.construct_from(id: 1, bool: true, not_bool: "bar")
|
201
|
-
assert obj.respond_to?(:bool?)
|
202
|
-
assert obj.bool?
|
203
|
-
refute obj.respond_to?(:not_bool?)
|
204
|
-
end
|
205
|
-
|
206
|
-
should "assign question mark accessors for booleans added after initialization" do
|
207
|
-
obj = Stripe::StripeObject.new
|
208
|
-
obj.bool = true
|
209
|
-
assert obj.respond_to?(:bool?)
|
210
|
-
assert obj.bool?
|
211
|
-
end
|
212
|
-
|
213
|
-
should "mass assign values with #update_attributes" do
|
214
|
-
obj = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
215
|
-
|
216
|
-
obj.update_attributes({ name: "STRIPE" })
|
217
|
-
|
218
|
-
assert_equal "STRIPE", obj.name
|
219
|
-
|
220
|
-
# unfortunately, we even assign unknown properties to duplicate the
|
221
|
-
# behavior that we currently have via magic accessors with
|
222
|
-
# method_missing
|
223
|
-
obj.update_attributes({ unknown: "foo" })
|
224
|
-
|
225
|
-
assert_equal "foo", obj.unknown
|
226
|
-
end
|
227
|
-
|
228
|
-
should "#update_attributes with a hash" do
|
229
|
-
obj = Stripe::StripeObject.construct_from({})
|
230
|
-
obj.update_attributes({ metadata: { foo: "bar" } })
|
231
|
-
assert_equal Stripe::StripeObject, obj.metadata.class
|
232
|
-
end
|
233
|
-
|
234
|
-
should "create accessors when #update_attributes is called" do
|
235
|
-
obj = Stripe::StripeObject.construct_from({})
|
236
|
-
assert_equal false, obj.send(:metaclass).method_defined?(:foo)
|
237
|
-
obj.update_attributes({ foo: "bar" })
|
238
|
-
assert_equal true, obj.send(:metaclass).method_defined?(:foo)
|
239
|
-
end
|
240
|
-
|
241
|
-
should "pass opts down to children when initializing" do
|
242
|
-
opts = { custom: "opts" }
|
243
|
-
|
244
|
-
# customer comes with a `sources` list that makes a convenient object to
|
245
|
-
# perform tests on
|
246
|
-
obj = Stripe::StripeObject.construct_from({
|
247
|
-
sources: [
|
248
|
-
{},
|
249
|
-
],
|
250
|
-
}, opts)
|
251
|
-
|
252
|
-
source = obj.sources.first
|
253
|
-
# Pulling `@opts` as an instance variable here is not ideal, but it's
|
254
|
-
# important enough argument that the test here is worth it. we should
|
255
|
-
# consider exposing it publicly on a future pull (and possibly renaming
|
256
|
-
# it to something more useful).
|
257
|
-
assert_equal opts, source.instance_variable_get(:@opts)
|
258
|
-
end
|
259
|
-
|
260
|
-
should "#serialize_params on an empty object" do
|
261
|
-
obj = Stripe::StripeObject.construct_from({})
|
262
|
-
assert_equal({}, obj.serialize_params)
|
263
|
-
end
|
264
|
-
|
265
|
-
should "#serialize_params on a new object with a subobject" do
|
266
|
-
obj = Stripe::StripeObject.new
|
267
|
-
obj.metadata = { foo: "bar" }
|
268
|
-
assert_equal({ metadata: { foo: "bar" } },
|
269
|
-
obj.serialize_params)
|
270
|
-
end
|
271
|
-
|
272
|
-
should "#serialize_params on a basic object" do
|
273
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
274
|
-
obj.update_attributes({ foo: "bar" })
|
275
|
-
assert_equal({ foo: "bar" }, obj.serialize_params)
|
276
|
-
end
|
277
|
-
|
278
|
-
should "#serialize_params on a more complex object" do
|
279
|
-
obj = Stripe::StripeObject.construct_from(foo: Stripe::StripeObject.construct_from(bar: nil,
|
280
|
-
baz: nil))
|
281
|
-
obj.foo.bar = "newbar"
|
282
|
-
assert_equal({ foo: { bar: "newbar" } },
|
283
|
-
obj.serialize_params)
|
284
|
-
end
|
285
|
-
|
286
|
-
should "#serialize_params on an array" do
|
287
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
288
|
-
obj.foo = ["new-value"]
|
289
|
-
assert_equal({ foo: ["new-value"] },
|
290
|
-
obj.serialize_params)
|
291
|
-
end
|
292
|
-
|
293
|
-
should "#serialize_params on an array that shortens" do
|
294
|
-
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
|
295
|
-
obj.foo = ["new-value"]
|
296
|
-
assert_equal({ foo: ["new-value"] },
|
297
|
-
obj.serialize_params)
|
298
|
-
end
|
299
|
-
|
300
|
-
should "#serialize_params on an array that lengthens" do
|
301
|
-
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
|
302
|
-
obj.foo = ["new-value"] * 4
|
303
|
-
assert_equal({ foo: ["new-value"] * 4 },
|
304
|
-
obj.serialize_params)
|
305
|
-
end
|
306
|
-
|
307
|
-
should "#serialize_params on an array of hashes" do
|
308
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
309
|
-
obj.foo = [
|
310
|
-
Stripe::StripeObject.construct_from(bar: nil),
|
311
|
-
]
|
312
|
-
obj.foo[0].bar = "baz"
|
313
|
-
assert_equal({ foo: [{ bar: "baz" }] },
|
314
|
-
obj.serialize_params)
|
315
|
-
end
|
316
|
-
|
317
|
-
should "#serialize_params doesn't include unchanged values" do
|
318
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
319
|
-
assert_equal({}, obj.serialize_params)
|
320
|
-
end
|
321
|
-
|
322
|
-
should "#serialize_params on an array that is unchanged" do
|
323
|
-
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
|
324
|
-
obj.foo = %w[0-index 1-index 2-index]
|
325
|
-
assert_equal({}, obj.serialize_params)
|
326
|
-
end
|
327
|
-
|
328
|
-
should "#serialize_params with a StripeObject" do
|
329
|
-
obj = Stripe::StripeObject.construct_from({})
|
330
|
-
|
331
|
-
# using an #update_attributes will end up converting a Hash into a
|
332
|
-
# StripeObject
|
333
|
-
obj.metadata =
|
334
|
-
Stripe::StripeObject.construct_from(foo: "bar")
|
335
|
-
|
336
|
-
serialized = obj.serialize_params
|
337
|
-
assert_equal({ foo: "bar" }, serialized[:metadata])
|
338
|
-
end
|
339
|
-
|
340
|
-
should "#serialize_params with StripeObject that's been replaced" do
|
341
|
-
obj = Stripe::StripeObject.construct_from(source: Stripe::StripeObject.construct_from(bar: "foo"))
|
342
|
-
|
343
|
-
# Here we replace the object wholesale.
|
344
|
-
obj.source =
|
345
|
-
Stripe::StripeObject.construct_from(baz: "foo")
|
346
|
-
|
347
|
-
serialized = obj.serialize_params
|
348
|
-
assert_equal({ baz: "foo" }, serialized[:source])
|
349
|
-
end
|
350
|
-
|
351
|
-
should "#serialize_params with StripeObject that's been replaced which is `metadata`" do
|
352
|
-
class WithAdditiveObjectParam < Stripe::StripeObject
|
353
|
-
additive_object_param :metadata
|
354
|
-
end
|
355
|
-
|
356
|
-
obj = WithAdditiveObjectParam.construct_from(metadata: Stripe::StripeObject.construct_from(bar: "foo"))
|
357
|
-
|
358
|
-
# Here we replace the object wholesale. Because it's `metadata`, the
|
359
|
-
# client must be able to blank out the values that were in the old
|
360
|
-
# object, but which are no longer present in the new one.
|
361
|
-
obj.metadata =
|
362
|
-
Stripe::StripeObject.construct_from(baz: "foo")
|
363
|
-
|
364
|
-
serialized = obj.serialize_params
|
365
|
-
assert_equal({ bar: "", baz: "foo" }, serialized[:metadata])
|
366
|
-
end
|
367
|
-
|
368
|
-
should "#serialize_params with an array of StripeObjects" do
|
369
|
-
obj = Stripe::StripeObject.construct_from({})
|
370
|
-
obj.metadata = [
|
371
|
-
Stripe::StripeObject.construct_from(foo: "bar"),
|
372
|
-
]
|
373
|
-
|
374
|
-
serialized = obj.serialize_params
|
375
|
-
assert_equal([{ foo: "bar" }], serialized[:metadata])
|
376
|
-
end
|
377
|
-
|
378
|
-
should "#serialize_params and embed an API resource that's been set and has an ID" do
|
379
|
-
customer = Customer.construct_from(id: "cus_123")
|
380
|
-
obj = Stripe::StripeObject.construct_from({})
|
381
|
-
|
382
|
-
# the key here is that the property is set explicitly (and therefore
|
383
|
-
# marked as unsaved), which is why it gets included below
|
384
|
-
obj.customer = customer
|
385
|
-
|
386
|
-
serialized = obj.serialize_params
|
387
|
-
assert_equal({ customer: customer }, serialized)
|
388
|
-
end
|
389
|
-
|
390
|
-
should "#serialize_params and not include API resources that have not been set" do
|
391
|
-
customer = Customer.construct_from(id: "cus_123")
|
392
|
-
obj = Stripe::StripeObject.construct_from(customer: customer)
|
393
|
-
|
394
|
-
serialized = obj.serialize_params
|
395
|
-
assert_equal({}, serialized)
|
396
|
-
end
|
397
|
-
|
398
|
-
should "#serialize_params serializes API resources flagged with save_with_parent" do
|
399
|
-
c = Customer.construct_from({})
|
400
|
-
c.save_with_parent = true
|
401
|
-
|
402
|
-
obj = Stripe::StripeObject.construct_from(customer: c)
|
403
|
-
|
404
|
-
serialized = obj.serialize_params
|
405
|
-
assert_equal({ customer: {} }, serialized)
|
406
|
-
end
|
407
|
-
|
408
|
-
should "#serialize_params should raise an error on other embedded API resources" do
|
409
|
-
# This customer doesn't have an ID and therefore the library doesn't know
|
410
|
-
# what to do with it and throws an ArgumentError because it's probably
|
411
|
-
# not what the user expected to happen.
|
412
|
-
customer = Customer.construct_from({})
|
413
|
-
|
414
|
-
obj = Stripe::StripeObject.construct_from({})
|
415
|
-
obj.customer = customer
|
416
|
-
|
417
|
-
e = assert_raises(ArgumentError) do
|
418
|
-
obj.serialize_params
|
419
|
-
end
|
420
|
-
assert_equal "Cannot save property `customer` containing " \
|
421
|
-
"an API resource. It doesn't appear to be persisted and is " \
|
422
|
-
"not marked as `save_with_parent`.", e.message
|
423
|
-
end
|
424
|
-
|
425
|
-
should "#serialize_params takes a force option" do
|
426
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
427
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
428
|
-
|
429
|
-
serialized = obj.serialize_params(force: true)
|
430
|
-
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
431
|
-
end
|
432
|
-
|
433
|
-
should "#dirty! forces an object and its subobjects to be saved" do
|
434
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
435
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
436
|
-
|
437
|
-
# note that `force` and `dirty!` are for different things, but are
|
438
|
-
# functionally equivalent
|
439
|
-
obj.dirty!
|
440
|
-
|
441
|
-
serialized = obj.serialize_params
|
442
|
-
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
443
|
-
end
|
444
|
-
|
445
|
-
should "#to_s will call to_s for all embedded stripe objects" do
|
446
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
447
|
-
# embedded list object
|
448
|
-
refunds: Stripe::ListObject.construct_from(data: [
|
449
|
-
# embedded object in list
|
450
|
-
Stripe::StripeObject.construct_from(id: "id",
|
451
|
-
# embedded object in an object in a list object
|
452
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar")),
|
453
|
-
]),
|
454
|
-
# embedded stripe object
|
455
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
456
|
-
expected = JSON.pretty_generate(id: "id",
|
457
|
-
refunds: {
|
458
|
-
data: [
|
459
|
-
{ id: "id", metadata: { foo: "bar" } },
|
460
|
-
],
|
461
|
-
},
|
462
|
-
metadata: { foo: "bar" })
|
463
|
-
|
464
|
-
assert_equal(expected, obj.to_s)
|
465
|
-
end
|
466
|
-
|
467
|
-
should "error on setting a property to an empty string" do
|
468
|
-
obj = Stripe::StripeObject.construct_from(foo: "bar")
|
469
|
-
e = assert_raises ArgumentError do
|
470
|
-
obj.foo = ""
|
471
|
-
end
|
472
|
-
assert_match(/\(object\).foo = nil/, e.message)
|
473
|
-
end
|
474
|
-
|
475
|
-
should "marshal and unmarshal using custom encoder and decoder" do
|
476
|
-
obj = Stripe::StripeObject.construct_from(
|
477
|
-
{ id: 1, name: "Stripe" },
|
478
|
-
api_key: "apikey",
|
479
|
-
client: StripeClient.active_client
|
480
|
-
)
|
481
|
-
m = Marshal.load(Marshal.dump(obj))
|
482
|
-
assert_equal 1, m.id
|
483
|
-
assert_equal "Stripe", m.name
|
484
|
-
expected_hash = { api_key: "apikey" }
|
485
|
-
assert_equal expected_hash, m.instance_variable_get("@opts")
|
486
|
-
end
|
487
|
-
|
488
|
-
context "#method" do
|
489
|
-
should "act as a getter if no arguments are provided" do
|
490
|
-
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
491
|
-
assert_equal "foo", obj.method
|
492
|
-
end
|
493
|
-
|
494
|
-
should "call Object#method if an argument is provided" do
|
495
|
-
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
496
|
-
assert obj.method(:id).is_a?(Method)
|
497
|
-
end
|
498
|
-
end
|
499
|
-
end
|
500
|
-
end
|