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,448 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class StripeObjectTest < Test::Unit::TestCase
|
5
|
-
should "implement #==" do
|
6
|
-
obj1 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
7
|
-
obj2 = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
8
|
-
obj3 = Stripe::StripeObject.construct_from(id: 1, foo: "rab")
|
9
|
-
|
10
|
-
assert obj1 == obj2
|
11
|
-
refute obj1 == obj3
|
12
|
-
end
|
13
|
-
|
14
|
-
should "implement #deleted?" do
|
15
|
-
obj = Stripe::StripeObject.construct_from({})
|
16
|
-
refute obj.deleted?
|
17
|
-
|
18
|
-
obj = Stripe::StripeObject.construct_from(deleted: false)
|
19
|
-
refute obj.deleted?
|
20
|
-
|
21
|
-
obj = Stripe::StripeObject.construct_from(deleted: true)
|
22
|
-
assert obj.deleted?
|
23
|
-
end
|
24
|
-
|
25
|
-
should "implement #respond_to" do
|
26
|
-
obj = Stripe::StripeObject.construct_from(id: 1, foo: "bar")
|
27
|
-
assert obj.respond_to?(:id)
|
28
|
-
assert obj.respond_to?(:foo)
|
29
|
-
assert !obj.respond_to?(:baz)
|
30
|
-
end
|
31
|
-
|
32
|
-
should "marshal be insensitive to strings vs. symbols when constructin" do
|
33
|
-
obj = Stripe::StripeObject.construct_from(:id => 1, "name" => "Stripe")
|
34
|
-
assert_equal 1, obj[:id]
|
35
|
-
assert_equal "Stripe", obj[:name]
|
36
|
-
end
|
37
|
-
|
38
|
-
context "#deep_copy" do
|
39
|
-
should "produce a deep copy" do
|
40
|
-
opts = {
|
41
|
-
api_base: Stripe.api_base,
|
42
|
-
api_key: "apikey",
|
43
|
-
}
|
44
|
-
values = {
|
45
|
-
id: 1,
|
46
|
-
name: "Stripe",
|
47
|
-
arr: [
|
48
|
-
StripeObject.construct_from({ id: "index0" }, opts),
|
49
|
-
"index1",
|
50
|
-
2,
|
51
|
-
],
|
52
|
-
map: {
|
53
|
-
:"0" => StripeObject.construct_from({ id: "index0" }, opts),
|
54
|
-
:"1" => "index1",
|
55
|
-
:"2" => 2,
|
56
|
-
},
|
57
|
-
}
|
58
|
-
|
59
|
-
# it's not good to test methods with `#send` like this, but I've done
|
60
|
-
# it in the interest of trying to keep `.deep_copy` as internal as
|
61
|
-
# possible
|
62
|
-
copy_values = Stripe::StripeObject.send(:deep_copy, values)
|
63
|
-
|
64
|
-
# we can't compare the hashes directly because they have embedded
|
65
|
-
# objects which are different from each other
|
66
|
-
assert_equal values[:id], copy_values[:id]
|
67
|
-
assert_equal values[:name], copy_values[:name]
|
68
|
-
|
69
|
-
assert_equal values[:arr].length, copy_values[:arr].length
|
70
|
-
|
71
|
-
# internal values of the copied StripeObject should be the same
|
72
|
-
# (including opts), but the object itself should be new (hence the
|
73
|
-
# refutation of equality on #object_id)
|
74
|
-
assert_equal values[:arr][0][:id], copy_values[:arr][0][:id]
|
75
|
-
refute_equal values[:arr][0].object_id, copy_values[:arr][0].object_id
|
76
|
-
assert_equal values[:arr][0].instance_variable_get(:@opts),
|
77
|
-
copy_values[:arr][0].instance_variable_get(:@opts)
|
78
|
-
|
79
|
-
# scalars however, can be compared
|
80
|
-
assert_equal values[:arr][1], copy_values[:arr][1]
|
81
|
-
assert_equal values[:arr][2], copy_values[:arr][2]
|
82
|
-
|
83
|
-
# and a similar story with the hash
|
84
|
-
assert_equal values[:map].keys, copy_values[:map].keys
|
85
|
-
assert_equal values[:map][:"0"][:id], copy_values[:map][:"0"][:id]
|
86
|
-
refute_equal values[:map][:"0"].object_id, copy_values[:map][:"0"].object_id
|
87
|
-
assert_equal values[:map][:"0"].instance_variable_get(:@opts),
|
88
|
-
copy_values[:map][:"0"].instance_variable_get(:@opts)
|
89
|
-
assert_equal values[:map][:"1"], copy_values[:map][:"1"]
|
90
|
-
assert_equal values[:map][:"2"], copy_values[:map][:"2"]
|
91
|
-
end
|
92
|
-
|
93
|
-
should "not copy a client" do
|
94
|
-
opts = {
|
95
|
-
api_key: "apikey",
|
96
|
-
client: StripeClient.active_client,
|
97
|
-
}
|
98
|
-
values = { id: 1, name: "Stripe" }
|
99
|
-
|
100
|
-
obj = Stripe::StripeObject.construct_from(values, opts)
|
101
|
-
copy_obj = Stripe::StripeObject.send(:deep_copy, obj)
|
102
|
-
|
103
|
-
assert_equal values, copy_obj.instance_variable_get(:@values)
|
104
|
-
assert_equal opts.reject { |k, _v| k == :client },
|
105
|
-
copy_obj.instance_variable_get(:@opts)
|
106
|
-
end
|
107
|
-
|
108
|
-
should "return an instance of the same class" do
|
109
|
-
class TestObject < Stripe::StripeObject; end
|
110
|
-
|
111
|
-
obj = TestObject.construct_from(id: 1)
|
112
|
-
copy_obj = obj.class.send(:deep_copy, obj)
|
113
|
-
|
114
|
-
assert_equal obj.class, copy_obj.class
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
should "recursively call to_hash on its values" do
|
119
|
-
# deep nested hash (when contained in an array) or StripeObject
|
120
|
-
nested_hash = { id: 7, foo: "bar" }
|
121
|
-
nested = Stripe::StripeObject.construct_from(nested_hash)
|
122
|
-
|
123
|
-
obj = Stripe::StripeObject.construct_from(id: 1,
|
124
|
-
# simple hash that contains a StripeObject to help us test deep
|
125
|
-
# recursion
|
126
|
-
nested: { object: "list", data: [nested] },
|
127
|
-
list: [nested])
|
128
|
-
|
129
|
-
expected_hash = {
|
130
|
-
id: 1,
|
131
|
-
nested: { object: "list", data: [nested_hash] },
|
132
|
-
list: [nested_hash],
|
133
|
-
}
|
134
|
-
assert_equal expected_hash, obj.to_hash
|
135
|
-
end
|
136
|
-
|
137
|
-
should "assign question mark accessors for booleans" do
|
138
|
-
obj = Stripe::StripeObject.construct_from(id: 1, bool: true, not_bool: "bar")
|
139
|
-
assert obj.respond_to?(:bool?)
|
140
|
-
assert obj.bool?
|
141
|
-
refute obj.respond_to?(:not_bool?)
|
142
|
-
end
|
143
|
-
|
144
|
-
should "assign question mark accessors for booleans added after initialization" do
|
145
|
-
obj = Stripe::StripeObject.new
|
146
|
-
obj.bool = true
|
147
|
-
assert obj.respond_to?(:bool?)
|
148
|
-
assert obj.bool?
|
149
|
-
end
|
150
|
-
|
151
|
-
should "mass assign values with #update_attributes" do
|
152
|
-
obj = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
|
153
|
-
obj.update_attributes(name: "STRIPE")
|
154
|
-
assert_equal "STRIPE", obj.name
|
155
|
-
|
156
|
-
# unfortunately, we even assign unknown properties to duplicate the
|
157
|
-
# behavior that we currently have via magic accessors with
|
158
|
-
# method_missing
|
159
|
-
obj.update_attributes(unknown: "foo")
|
160
|
-
assert_equal "foo", obj.unknown
|
161
|
-
end
|
162
|
-
|
163
|
-
should "#update_attributes with a hash" do
|
164
|
-
obj = Stripe::StripeObject.construct_from({})
|
165
|
-
obj.update_attributes(metadata: { foo: "bar" })
|
166
|
-
assert_equal Stripe::StripeObject, obj.metadata.class
|
167
|
-
end
|
168
|
-
|
169
|
-
should "create accessors when #update_attributes is called" do
|
170
|
-
obj = Stripe::StripeObject.construct_from({})
|
171
|
-
assert_equal false, obj.send(:metaclass).method_defined?(:foo)
|
172
|
-
obj.update_attributes(foo: "bar")
|
173
|
-
assert_equal true, obj.send(:metaclass).method_defined?(:foo)
|
174
|
-
end
|
175
|
-
|
176
|
-
should "warn that #refresh_from is deprecated" do
|
177
|
-
old_stderr = $stderr
|
178
|
-
$stderr = StringIO.new
|
179
|
-
begin
|
180
|
-
obj = Stripe::StripeObject.construct_from({})
|
181
|
-
obj.refresh_from({}, {})
|
182
|
-
message = "NOTE: Stripe::StripeObject#refresh_from is " \
|
183
|
-
"deprecated; use #update_attributes instead"
|
184
|
-
assert_match Regexp.new(message), $stderr.string
|
185
|
-
ensure
|
186
|
-
$stderr = old_stderr
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
should "pass opts down to children when initializing" do
|
191
|
-
opts = { custom: "opts" }
|
192
|
-
|
193
|
-
# customer comes with a `sources` list that makes a convenient object to
|
194
|
-
# perform tests on
|
195
|
-
obj = Stripe::StripeObject.construct_from({
|
196
|
-
sources: [
|
197
|
-
{},
|
198
|
-
],
|
199
|
-
}, opts)
|
200
|
-
|
201
|
-
source = obj.sources.first
|
202
|
-
# Pulling `@opts` as an instance variable here is not ideal, but it's
|
203
|
-
# important enough argument that the test here is worth it. we should
|
204
|
-
# consider exposing it publicly on a future pull (and possibly renaming
|
205
|
-
# it to something more useful).
|
206
|
-
assert_equal opts, source.instance_variable_get(:@opts)
|
207
|
-
end
|
208
|
-
|
209
|
-
should "#serialize_params on an empty object" do
|
210
|
-
obj = Stripe::StripeObject.construct_from({})
|
211
|
-
assert_equal({}, obj.serialize_params)
|
212
|
-
end
|
213
|
-
|
214
|
-
should "#serialize_params on a new object with a subobject" do
|
215
|
-
obj = Stripe::StripeObject.new
|
216
|
-
obj.metadata = { foo: "bar" }
|
217
|
-
assert_equal({ metadata: { foo: "bar" } },
|
218
|
-
obj.serialize_params)
|
219
|
-
end
|
220
|
-
|
221
|
-
should "#serialize_params on a basic object" do
|
222
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
223
|
-
obj.update_attributes(foo: "bar")
|
224
|
-
assert_equal({ foo: "bar" }, obj.serialize_params)
|
225
|
-
end
|
226
|
-
|
227
|
-
should "#serialize_params on a more complex object" do
|
228
|
-
obj = Stripe::StripeObject.construct_from(foo: Stripe::StripeObject.construct_from(bar: nil,
|
229
|
-
baz: nil))
|
230
|
-
obj.foo.bar = "newbar"
|
231
|
-
assert_equal({ foo: { bar: "newbar" } },
|
232
|
-
obj.serialize_params)
|
233
|
-
end
|
234
|
-
|
235
|
-
should "#serialize_params on an array" do
|
236
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
237
|
-
obj.foo = ["new-value"]
|
238
|
-
assert_equal({ foo: ["new-value"] },
|
239
|
-
obj.serialize_params)
|
240
|
-
end
|
241
|
-
|
242
|
-
should "#serialize_params on an array that shortens" do
|
243
|
-
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
244
|
-
obj.foo = ["new-value"]
|
245
|
-
assert_equal({ foo: ["new-value"] },
|
246
|
-
obj.serialize_params)
|
247
|
-
end
|
248
|
-
|
249
|
-
should "#serialize_params on an array that lengthens" do
|
250
|
-
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
251
|
-
obj.foo = ["new-value"] * 4
|
252
|
-
assert_equal({ foo: ["new-value"] * 4 },
|
253
|
-
obj.serialize_params)
|
254
|
-
end
|
255
|
-
|
256
|
-
should "#serialize_params on an array of hashes" do
|
257
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
258
|
-
obj.foo = [
|
259
|
-
Stripe::StripeObject.construct_from(bar: nil),
|
260
|
-
]
|
261
|
-
obj.foo[0].bar = "baz"
|
262
|
-
assert_equal({ foo: [{ bar: "baz" }] },
|
263
|
-
obj.serialize_params)
|
264
|
-
end
|
265
|
-
|
266
|
-
should "#serialize_params doesn't include unchanged values" do
|
267
|
-
obj = Stripe::StripeObject.construct_from(foo: nil)
|
268
|
-
assert_equal({}, obj.serialize_params)
|
269
|
-
end
|
270
|
-
|
271
|
-
should "#serialize_params on an array that is unchanged" do
|
272
|
-
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
|
273
|
-
obj.foo = ["0-index", "1-index", "2-index"]
|
274
|
-
assert_equal({}, obj.serialize_params)
|
275
|
-
end
|
276
|
-
|
277
|
-
should "#serialize_params with a StripeObject" do
|
278
|
-
obj = Stripe::StripeObject.construct_from({})
|
279
|
-
|
280
|
-
# using an #update_attributes will end up converting a Hash into a
|
281
|
-
# StripeObject
|
282
|
-
obj.metadata =
|
283
|
-
Stripe::StripeObject.construct_from(foo: "bar")
|
284
|
-
|
285
|
-
serialized = obj.serialize_params
|
286
|
-
assert_equal({ foo: "bar" }, serialized[:metadata])
|
287
|
-
end
|
288
|
-
|
289
|
-
should "#serialize_params with a StripeObject that's been replaced" do
|
290
|
-
obj = Stripe::StripeObject.construct_from(metadata: Stripe::StripeObject.construct_from(bar: "foo"))
|
291
|
-
|
292
|
-
# Here we replace the object wholesale which means that the client must
|
293
|
-
# be able to blank out the values that were in the old object, but which
|
294
|
-
# are no longer present in the new one.
|
295
|
-
obj.metadata =
|
296
|
-
Stripe::StripeObject.construct_from(baz: "foo")
|
297
|
-
|
298
|
-
serialized = obj.serialize_params
|
299
|
-
assert_equal({ bar: "", baz: "foo" }, serialized[:metadata])
|
300
|
-
end
|
301
|
-
|
302
|
-
should "#serialize_params with an array of StripeObjects" do
|
303
|
-
obj = Stripe::StripeObject.construct_from({})
|
304
|
-
obj.metadata = [
|
305
|
-
Stripe::StripeObject.construct_from(foo: "bar"),
|
306
|
-
]
|
307
|
-
|
308
|
-
serialized = obj.serialize_params
|
309
|
-
assert_equal([{ foo: "bar" }], serialized[:metadata])
|
310
|
-
end
|
311
|
-
|
312
|
-
should "#serialize_params and embed an API resource that's been set and has an ID" do
|
313
|
-
customer = Customer.construct_from(id: "cus_123")
|
314
|
-
obj = Stripe::StripeObject.construct_from({})
|
315
|
-
|
316
|
-
# the key here is that the property is set explicitly (and therefore
|
317
|
-
# marked as unsaved), which is why it gets included below
|
318
|
-
obj.customer = customer
|
319
|
-
|
320
|
-
serialized = obj.serialize_params
|
321
|
-
assert_equal({ customer: customer }, serialized)
|
322
|
-
end
|
323
|
-
|
324
|
-
should "#serialize_params and not include API resources that have not been set" do
|
325
|
-
customer = Customer.construct_from(id: "cus_123")
|
326
|
-
obj = Stripe::StripeObject.construct_from(customer: customer)
|
327
|
-
|
328
|
-
serialized = obj.serialize_params
|
329
|
-
assert_equal({}, serialized)
|
330
|
-
end
|
331
|
-
|
332
|
-
should "#serialize_params serializes API resources flagged with save_with_parent" do
|
333
|
-
c = Customer.construct_from({})
|
334
|
-
c.save_with_parent = true
|
335
|
-
|
336
|
-
obj = Stripe::StripeObject.construct_from(customer: c)
|
337
|
-
|
338
|
-
serialized = obj.serialize_params
|
339
|
-
assert_equal({ customer: {} }, serialized)
|
340
|
-
end
|
341
|
-
|
342
|
-
should "#serialize_params should raise an error on other embedded API resources" do
|
343
|
-
# This customer doesn't have an ID and therefore the library doesn't know
|
344
|
-
# what to do with it and throws an ArgumentError because it's probably
|
345
|
-
# not what the user expected to happen.
|
346
|
-
customer = Customer.construct_from({})
|
347
|
-
|
348
|
-
obj = Stripe::StripeObject.construct_from({})
|
349
|
-
obj.customer = customer
|
350
|
-
|
351
|
-
e = assert_raises(ArgumentError) do
|
352
|
-
obj.serialize_params
|
353
|
-
end
|
354
|
-
assert_equal "Cannot save property `customer` containing " \
|
355
|
-
"an API resource. It doesn't appear to be persisted and is " \
|
356
|
-
"not marked as `save_with_parent`.", e.message
|
357
|
-
end
|
358
|
-
|
359
|
-
should "#serialize_params takes a force option" do
|
360
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
361
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
362
|
-
|
363
|
-
serialized = obj.serialize_params(force: true)
|
364
|
-
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
365
|
-
end
|
366
|
-
|
367
|
-
should "#dirty! forces an object and its subobjects to be saved" do
|
368
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
369
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
370
|
-
|
371
|
-
# note that `force` and `dirty!` are for different things, but are
|
372
|
-
# functionally equivalent
|
373
|
-
obj.dirty!
|
374
|
-
|
375
|
-
serialized = obj.serialize_params
|
376
|
-
assert_equal({ id: "id", metadata: { foo: "bar" } }, serialized)
|
377
|
-
end
|
378
|
-
|
379
|
-
should "#to_s will call to_s for all embedded stripe objects" do
|
380
|
-
obj = Stripe::StripeObject.construct_from(id: "id",
|
381
|
-
# embeded list object
|
382
|
-
refunds: Stripe::ListObject.construct_from(data: [
|
383
|
-
# embedded object in list
|
384
|
-
Stripe::StripeObject.construct_from(id: "id",
|
385
|
-
# embedded object in an object in a list object
|
386
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar")),
|
387
|
-
]),
|
388
|
-
# embeded stripe object
|
389
|
-
metadata: Stripe::StripeObject.construct_from(foo: "bar"))
|
390
|
-
expected = JSON.pretty_generate(id: "id",
|
391
|
-
refunds: {
|
392
|
-
data: [
|
393
|
-
{ id: "id", metadata: { foo: "bar" } },
|
394
|
-
],
|
395
|
-
},
|
396
|
-
metadata: { foo: "bar" })
|
397
|
-
|
398
|
-
assert_equal(expected, obj.to_s)
|
399
|
-
end
|
400
|
-
|
401
|
-
should "warn that .serialize_params is deprecated" do
|
402
|
-
old_stderr = $stderr
|
403
|
-
$stderr = StringIO.new
|
404
|
-
begin
|
405
|
-
obj = Stripe::StripeObject.construct_from({})
|
406
|
-
Stripe::StripeObject.serialize_params(obj)
|
407
|
-
message = "NOTE: Stripe::StripeObject.serialize_params is " \
|
408
|
-
"deprecated; use #serialize_params instead"
|
409
|
-
assert_match Regexp.new(message), $stderr.string
|
410
|
-
ensure
|
411
|
-
$stderr = old_stderr
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
should "error on setting a property to an empty string" do
|
416
|
-
obj = Stripe::StripeObject.construct_from(foo: "bar")
|
417
|
-
e = assert_raises ArgumentError do
|
418
|
-
obj.foo = ""
|
419
|
-
end
|
420
|
-
assert_match(/\(object\).foo = nil/, e.message)
|
421
|
-
end
|
422
|
-
|
423
|
-
should "marshal and unmarshal using custom encoder and decoder" do
|
424
|
-
obj = Stripe::StripeObject.construct_from(
|
425
|
-
{ id: 1, name: "Stripe" },
|
426
|
-
api_key: "apikey",
|
427
|
-
client: StripeClient.active_client
|
428
|
-
)
|
429
|
-
m = Marshal.load(Marshal.dump(obj))
|
430
|
-
assert_equal 1, m.id
|
431
|
-
assert_equal "Stripe", m.name
|
432
|
-
expected_hash = { api_key: "apikey" }
|
433
|
-
assert_equal expected_hash, m.instance_variable_get("@opts")
|
434
|
-
end
|
435
|
-
|
436
|
-
context "#method" do
|
437
|
-
should "act as a getter if no arguments are provided" do
|
438
|
-
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
439
|
-
assert_equal "foo", obj.method
|
440
|
-
end
|
441
|
-
|
442
|
-
should "call Object#method if an argument is provided" do
|
443
|
-
obj = Stripe::StripeObject.construct_from(id: 1, method: "foo")
|
444
|
-
assert obj.method(:id).is_a?(Method)
|
445
|
-
end
|
446
|
-
end
|
447
|
-
end
|
448
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class StripeResponseTest < Test::Unit::TestCase
|
5
|
-
context ".from_faraday_hash" do
|
6
|
-
should "converts to StripeResponse" do
|
7
|
-
body = '{"foo": "bar"}'
|
8
|
-
headers = { "Request-Id" => "request-id" }
|
9
|
-
|
10
|
-
http_resp = {
|
11
|
-
body: body,
|
12
|
-
headers: headers,
|
13
|
-
status: 200,
|
14
|
-
}
|
15
|
-
|
16
|
-
resp = StripeResponse.from_faraday_hash(http_resp)
|
17
|
-
|
18
|
-
assert_equal JSON.parse(body, symbolize_names: true), resp.data
|
19
|
-
assert_equal body, resp.http_body
|
20
|
-
assert_equal headers, resp.http_headers
|
21
|
-
assert_equal 200, resp.http_status
|
22
|
-
assert_equal "request-id", resp.request_id
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context ".from_faraday_response" do
|
27
|
-
should "converts to StripeResponse" do
|
28
|
-
body = '{"foo": "bar"}'
|
29
|
-
headers = { "Request-Id" => "request-id" }
|
30
|
-
|
31
|
-
env = Faraday::Env.from(
|
32
|
-
status: 200, body: body,
|
33
|
-
response_headers: headers
|
34
|
-
)
|
35
|
-
http_resp = Faraday::Response.new(env)
|
36
|
-
|
37
|
-
resp = StripeResponse.from_faraday_response(http_resp)
|
38
|
-
|
39
|
-
assert_equal JSON.parse(body, symbolize_names: true), resp.data
|
40
|
-
assert_equal body, resp.http_body
|
41
|
-
assert_equal headers, resp.http_headers
|
42
|
-
assert_equal 200, resp.http_status
|
43
|
-
assert_equal "request-id", resp.request_id
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class SubscriptionItemTest < Test::Unit::TestCase
|
5
|
-
should "be listable" do
|
6
|
-
items = Stripe::SubscriptionItem.list(
|
7
|
-
subscription: "sub_123"
|
8
|
-
)
|
9
|
-
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items",
|
10
|
-
query: { subscription: "sub_123" }
|
11
|
-
assert items.data.is_a?(Array)
|
12
|
-
assert items.data[0].is_a?(Stripe::SubscriptionItem)
|
13
|
-
end
|
14
|
-
|
15
|
-
should "be retrievable" do
|
16
|
-
item = Stripe::SubscriptionItem.retrieve("si_123")
|
17
|
-
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/si_123"
|
18
|
-
assert item.is_a?(Stripe::SubscriptionItem)
|
19
|
-
end
|
20
|
-
|
21
|
-
should "be creatable" do
|
22
|
-
item = Stripe::SubscriptionItem.create(
|
23
|
-
item: "silver",
|
24
|
-
plan: "sapphire-elite",
|
25
|
-
quantity: 3,
|
26
|
-
subscription: "sub_123"
|
27
|
-
)
|
28
|
-
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items"
|
29
|
-
assert item.is_a?(Stripe::SubscriptionItem)
|
30
|
-
end
|
31
|
-
|
32
|
-
should "be saveable" do
|
33
|
-
item = Stripe::SubscriptionItem.retrieve("si_123")
|
34
|
-
item.quantity = 4
|
35
|
-
item.save
|
36
|
-
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{item.id}"
|
37
|
-
end
|
38
|
-
|
39
|
-
should "be updateable" do
|
40
|
-
item = Stripe::SubscriptionItem.update("si_123", metadata: { foo: "bar" })
|
41
|
-
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/si_123"
|
42
|
-
assert item.is_a?(Stripe::SubscriptionItem)
|
43
|
-
end
|
44
|
-
|
45
|
-
should "be deletable" do
|
46
|
-
item = Stripe::SubscriptionItem.retrieve("si_123")
|
47
|
-
item = item.delete
|
48
|
-
assert_requested :delete, "#{Stripe.api_base}/v1/subscription_items/#{item.id}"
|
49
|
-
assert item.is_a?(Stripe::SubscriptionItem)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class SubscriptionTest < Test::Unit::TestCase
|
5
|
-
should "be listable" do
|
6
|
-
subscriptions = Stripe::Subscription.list
|
7
|
-
assert_requested :get, "#{Stripe.api_base}/v1/subscriptions"
|
8
|
-
assert subscriptions.data.is_a?(Array)
|
9
|
-
assert subscriptions.data[0].is_a?(Stripe::Subscription)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "be retrievable" do
|
13
|
-
subscription = Stripe::Subscription.retrieve("sub_123")
|
14
|
-
assert_requested :get,
|
15
|
-
"#{Stripe.api_base}/v1/subscriptions/sub_123"
|
16
|
-
assert subscription.is_a?(Stripe::Subscription)
|
17
|
-
end
|
18
|
-
|
19
|
-
should "be creatable" do
|
20
|
-
subscription = Stripe::Subscription.create(
|
21
|
-
customer: "cus_123"
|
22
|
-
)
|
23
|
-
assert_requested :post, "#{Stripe.api_base}/v1/subscriptions"
|
24
|
-
assert subscription.is_a?(Stripe::Subscription)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "be saveable" do
|
28
|
-
subscription = Stripe::Subscription.retrieve("sub_123")
|
29
|
-
subscription.metadata["key"] = "value"
|
30
|
-
subscription.save
|
31
|
-
assert_requested :post,
|
32
|
-
"#{Stripe.api_base}/v1/subscriptions/#{subscription.id}"
|
33
|
-
end
|
34
|
-
|
35
|
-
should "be updateable" do
|
36
|
-
subscription = Stripe::Subscription.update("sub_123", metadata: { foo: "bar" })
|
37
|
-
assert_requested :post,
|
38
|
-
"#{Stripe.api_base}/v1/subscriptions/sub_123"
|
39
|
-
assert subscription.is_a?(Stripe::Subscription)
|
40
|
-
end
|
41
|
-
|
42
|
-
should "be deletable" do
|
43
|
-
subscription = Stripe::Subscription.retrieve("sub_123")
|
44
|
-
subscription = subscription.delete
|
45
|
-
assert_requested :delete,
|
46
|
-
"#{Stripe.api_base}/v1/subscriptions/#{subscription.id}"
|
47
|
-
assert subscription.is_a?(Stripe::Subscription)
|
48
|
-
end
|
49
|
-
|
50
|
-
context "#delete_discount" do
|
51
|
-
should "be able to delete a subscriptions's discount" do
|
52
|
-
subscription = Stripe::Subscription.retrieve("sub_123")
|
53
|
-
subscription = subscription.delete_discount
|
54
|
-
assert subscription.is_a?(Stripe::Subscription)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "#serialize_params" do
|
59
|
-
should "serialize when items is set to an Array" do
|
60
|
-
obj = Stripe::Util.convert_to_stripe_object({
|
61
|
-
object: "subscription",
|
62
|
-
items: Stripe::Util.convert_to_stripe_object(
|
63
|
-
object: "list",
|
64
|
-
data: []
|
65
|
-
),
|
66
|
-
}, {})
|
67
|
-
obj.items = [
|
68
|
-
{ id: "si_foo", deleted: true },
|
69
|
-
{ plan: "plan_bar" },
|
70
|
-
]
|
71
|
-
|
72
|
-
expected = {
|
73
|
-
items: {
|
74
|
-
:"0" => { id: "si_foo", deleted: true },
|
75
|
-
:"1" => { plan: "plan_bar" },
|
76
|
-
},
|
77
|
-
}
|
78
|
-
assert_equal(expected, obj.serialize_params)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "serialize when items is set to a Hash" do
|
82
|
-
obj = Stripe::Util.convert_to_stripe_object({
|
83
|
-
object: "subscription",
|
84
|
-
items: Stripe::Util.convert_to_stripe_object(
|
85
|
-
object: "list",
|
86
|
-
data: []
|
87
|
-
),
|
88
|
-
}, {})
|
89
|
-
obj.items = {
|
90
|
-
"0" => { id: "si_foo", deleted: true },
|
91
|
-
"1" => { plan: "plan_bar" },
|
92
|
-
}
|
93
|
-
|
94
|
-
expected = {
|
95
|
-
items: {
|
96
|
-
:"0" => { id: "si_foo", deleted: true },
|
97
|
-
:"1" => { plan: "plan_bar" },
|
98
|
-
},
|
99
|
-
}
|
100
|
-
assert_equal(expected, obj.serialize_params)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
module Stripe
|
4
|
-
class ThreeDSecureTest < Test::Unit::TestCase
|
5
|
-
should "be retrievable" do
|
6
|
-
secure = Stripe::ThreeDSecure.retrieve("tdsrc_123")
|
7
|
-
assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/tdsrc_123"
|
8
|
-
assert secure.is_a?(Stripe::ThreeDSecure)
|
9
|
-
end
|
10
|
-
|
11
|
-
should "be creatable" do
|
12
|
-
_ = Stripe::ThreeDSecure.create(
|
13
|
-
card: "tok_123",
|
14
|
-
amount: 1500,
|
15
|
-
currency: "usd",
|
16
|
-
return_url: "https://example.org/3d-secure-result"
|
17
|
-
)
|
18
|
-
assert_requested :post, "#{Stripe.api_base}/v1/3d_secure"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|