stripe 1.27.2 → 5.33.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 +942 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +29 -4
- data/History.txt +1 -361
- data/README.md +349 -0
- data/Rakefile +33 -3
- data/VERSION +1 -1
- data/bin/stripe-console +14 -5
- data/lib/data/ca-certificates.crt +4016 -5138
- data/lib/stripe.rb +102 -320
- data/lib/stripe/api_operations/create.rb +5 -9
- data/lib/stripe/api_operations/delete.rb +32 -4
- data/lib/stripe/api_operations/list.rb +11 -9
- data/lib/stripe/api_operations/nested_resource.rb +73 -0
- data/lib/stripe/api_operations/request.rb +66 -11
- data/lib/stripe/api_operations/save.rb +97 -0
- data/lib/stripe/api_resource.rb +96 -12
- data/lib/stripe/connection_manager.rb +164 -0
- data/lib/stripe/error_object.rb +94 -0
- data/lib/stripe/errors.rb +177 -0
- data/lib/stripe/instrumentation.rb +82 -0
- data/lib/stripe/list_object.rb +118 -13
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +65 -0
- data/lib/stripe/object_types.rb +104 -0
- data/lib/stripe/resources.rb +87 -0
- data/lib/stripe/resources/account.rb +170 -0
- data/lib/stripe/resources/account_link.rb +10 -0
- data/lib/stripe/resources/alipay_account.rb +34 -0
- data/lib/stripe/resources/apple_pay_domain.rb +17 -0
- data/lib/stripe/resources/application_fee.rb +14 -0
- data/lib/stripe/resources/application_fee_refund.rb +30 -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/resources/bitcoin_receiver.rb +24 -0
- data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
- data/lib/stripe/resources/capability.rb +33 -0
- data/lib/stripe/resources/card.rb +38 -0
- data/lib/stripe/resources/charge.rb +23 -0
- data/lib/stripe/resources/checkout/session.rb +16 -0
- data/lib/stripe/resources/country_spec.rb +10 -0
- data/lib/stripe/resources/coupon.rb +13 -0
- data/lib/stripe/resources/credit_note.rb +33 -0
- data/lib/stripe/resources/credit_note_line_item.rb +7 -0
- data/lib/stripe/resources/customer.rb +41 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
- data/lib/stripe/resources/discount.rb +7 -0
- data/lib/stripe/resources/dispute.rb +22 -0
- data/lib/stripe/resources/ephemeral_key.rb +20 -0
- data/lib/stripe/resources/event.rb +10 -0
- data/lib/stripe/resources/exchange_rate.rb +10 -0
- data/lib/stripe/resources/file.rb +36 -0
- data/lib/stripe/resources/file_link.rb +12 -0
- data/lib/stripe/resources/identity/verification_report.rb +12 -0
- data/lib/stripe/resources/identity/verification_session.rb +35 -0
- data/lib/stripe/resources/invoice.rb +74 -0
- data/lib/stripe/resources/invoice_item.rb +13 -0
- data/lib/stripe/resources/invoice_line_item.rb +7 -0
- data/lib/stripe/resources/issuing/authorization.rb +34 -0
- data/lib/stripe/resources/issuing/card.rb +25 -0
- data/lib/stripe/resources/issuing/card_details.rb +9 -0
- data/lib/stripe/resources/issuing/cardholder.rb +14 -0
- data/lib/stripe/resources/issuing/dispute.rb +25 -0
- data/lib/stripe/resources/issuing/transaction.rb +13 -0
- data/lib/stripe/resources/line_item.rb +7 -0
- data/lib/stripe/resources/login_link.rb +14 -0
- data/lib/stripe/resources/mandate.rb +8 -0
- data/lib/stripe/resources/order.rb +33 -0
- data/lib/stripe/resources/order_return.rb +10 -0
- data/lib/stripe/resources/payment_intent.rb +43 -0
- data/lib/stripe/resources/payment_method.rb +33 -0
- data/lib/stripe/resources/payout.rb +33 -0
- data/lib/stripe/resources/person.rb +31 -0
- data/lib/stripe/resources/plan.rb +13 -0
- data/lib/stripe/resources/price.rb +12 -0
- data/lib/stripe/resources/product.rb +13 -0
- data/lib/stripe/resources/promotion_code.rb +12 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
- data/lib/stripe/resources/radar/value_list.rb +15 -0
- data/lib/stripe/resources/radar/value_list_item.rb +14 -0
- data/lib/stripe/resources/recipient.rb +14 -0
- data/lib/stripe/resources/recipient_transfer.rb +7 -0
- data/lib/stripe/resources/refund.rb +12 -0
- 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 +29 -0
- data/lib/stripe/resources/review.rb +21 -0
- data/lib/stripe/resources/setup_attempt.rb +10 -0
- data/lib/stripe/resources/setup_intent.rb +33 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
- data/lib/stripe/resources/sku.rb +13 -0
- data/lib/stripe/resources/source.rb +47 -0
- data/lib/stripe/resources/source_transaction.rb +7 -0
- data/lib/stripe/resources/subscription.rb +26 -0
- data/lib/stripe/resources/subscription_item.rb +26 -0
- data/lib/stripe/resources/subscription_schedule.rb +33 -0
- data/lib/stripe/resources/tax_id.rb +26 -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/three_d_secure.rb +14 -0
- 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 +7 -0
- data/lib/stripe/resources/usage_record_summary.rb +7 -0
- data/lib/stripe/resources/webhook_endpoint.rb +13 -0
- data/lib/stripe/singleton_api_resource.rb +13 -7
- data/lib/stripe/stripe_client.rb +989 -0
- data/lib/stripe/stripe_configuration.rb +194 -0
- data/lib/stripe/stripe_object.rb +481 -148
- data/lib/stripe/stripe_response.rb +82 -0
- data/lib/stripe/util.rb +265 -70
- data/lib/stripe/version.rb +3 -1
- data/lib/stripe/webhook.rb +121 -0
- data/stripe.gemspec +35 -21
- metadata +118 -198
- data/.gitignore +0 -4
- data/.travis.yml +0 -22
- data/README.rdoc +0 -43
- data/gemfiles/default-with-activesupport.gemfile +0 -10
- data/gemfiles/json.gemfile +0 -12
- data/gemfiles/yajl.gemfile +0 -12
- data/lib/stripe/account.rb +0 -39
- data/lib/stripe/api_operations/update.rb +0 -19
- data/lib/stripe/application_fee.rb +0 -20
- data/lib/stripe/application_fee_refund.rb +0 -14
- data/lib/stripe/balance.rb +0 -4
- data/lib/stripe/balance_transaction.rb +0 -9
- data/lib/stripe/bank_account.rb +0 -19
- data/lib/stripe/bitcoin_receiver.rb +0 -20
- data/lib/stripe/bitcoin_transaction.rb +0 -9
- data/lib/stripe/card.rb +0 -21
- data/lib/stripe/charge.rb +0 -62
- data/lib/stripe/coupon.rb +0 -8
- data/lib/stripe/customer.rb +0 -75
- data/lib/stripe/dispute.rb +0 -16
- data/lib/stripe/errors/api_connection_error.rb +0 -4
- data/lib/stripe/errors/api_error.rb +0 -4
- data/lib/stripe/errors/authentication_error.rb +0 -4
- data/lib/stripe/errors/card_error.rb +0 -12
- data/lib/stripe/errors/invalid_request_error.rb +0 -11
- data/lib/stripe/errors/rate_limit_error.rb +0 -4
- data/lib/stripe/errors/stripe_error.rb +0 -26
- data/lib/stripe/event.rb +0 -5
- data/lib/stripe/file_upload.rb +0 -22
- data/lib/stripe/invoice.rb +0 -27
- data/lib/stripe/invoice_item.rb +0 -8
- data/lib/stripe/order.rb +0 -19
- data/lib/stripe/plan.rb +0 -8
- data/lib/stripe/product.rb +0 -16
- data/lib/stripe/recipient.rb +0 -12
- data/lib/stripe/refund.rb +0 -7
- data/lib/stripe/reversal.rb +0 -14
- data/lib/stripe/sku.rb +0 -8
- data/lib/stripe/subscription.rb +0 -25
- data/lib/stripe/token.rb +0 -5
- data/lib/stripe/transfer.rb +0 -17
- data/test/stripe/account_test.rb +0 -118
- data/test/stripe/api_resource_test.rb +0 -632
- data/test/stripe/application_fee_refund_test.rb +0 -47
- data/test/stripe/application_fee_test.rb +0 -22
- data/test/stripe/balance_test.rb +0 -11
- data/test/stripe/bitcoin_receiver_test.rb +0 -61
- data/test/stripe/bitcoin_transaction_test.rb +0 -29
- data/test/stripe/charge_refund_test.rb +0 -55
- data/test/stripe/charge_test.rb +0 -118
- data/test/stripe/coupon_test.rb +0 -20
- data/test/stripe/customer_card_test.rb +0 -63
- data/test/stripe/customer_test.rb +0 -88
- data/test/stripe/dispute_test.rb +0 -45
- data/test/stripe/file_upload_test.rb +0 -28
- data/test/stripe/invoice_test.rb +0 -40
- data/test/stripe/list_object_test.rb +0 -16
- data/test/stripe/metadata_test.rb +0 -129
- data/test/stripe/order_test.rb +0 -52
- data/test/stripe/product_test.rb +0 -41
- data/test/stripe/recipient_card_test.rb +0 -57
- data/test/stripe/refund_test.rb +0 -55
- data/test/stripe/reversal_test.rb +0 -47
- data/test/stripe/sku_test.rb +0 -24
- data/test/stripe/stripe_object_test.rb +0 -28
- data/test/stripe/subscription_test.rb +0 -72
- data/test/stripe/transfer_test.rb +0 -25
- data/test/stripe/util_test.rb +0 -34
- data/test/test_data.rb +0 -666
- data/test/test_helper.rb +0 -41
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
# Manages connections across multiple hosts which is useful because the
|
5
|
+
# library may connect to multiple hosts during a typical session (main API,
|
6
|
+
# Connect, Uploads). Ruby doesn't provide an easy way to make this happen
|
7
|
+
# easily, so this class is designed to track what we're connected to and
|
8
|
+
# manage the lifecycle of those connections.
|
9
|
+
#
|
10
|
+
# Note that this class in itself is *not* thread safe. We expect it to be
|
11
|
+
# instantiated once per thread.
|
12
|
+
class ConnectionManager
|
13
|
+
# Timestamp (in seconds procured from the system's monotonic clock)
|
14
|
+
# indicating when the connection manager last made a request. This is used
|
15
|
+
# by `StripeClient` to determine whether a connection manager should be
|
16
|
+
# garbage collected or not.
|
17
|
+
attr_reader :last_used
|
18
|
+
attr_reader :config
|
19
|
+
|
20
|
+
def initialize(config = Stripe.config)
|
21
|
+
@config = config
|
22
|
+
@active_connections = {}
|
23
|
+
@last_used = Util.monotonic_time
|
24
|
+
|
25
|
+
# A connection manager may be accessed across threads as one thread makes
|
26
|
+
# requests on it while another is trying to clear it (either because it's
|
27
|
+
# trying to garbage collect the manager or trying to clear it because a
|
28
|
+
# configuration setting has changed). That's probably thread-safe already
|
29
|
+
# because of Ruby's GIL, but just in case the library's running on JRuby
|
30
|
+
# or the like, use a mutex to synchronize access in this connection
|
31
|
+
# manager.
|
32
|
+
@mutex = Mutex.new
|
33
|
+
end
|
34
|
+
|
35
|
+
# Finishes any active connections by closing their TCP connection and
|
36
|
+
# clears them from internal tracking.
|
37
|
+
def clear
|
38
|
+
@mutex.synchronize do
|
39
|
+
@active_connections.each do |_, connection|
|
40
|
+
connection.finish
|
41
|
+
end
|
42
|
+
@active_connections = {}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gets a connection for a given URI. This is for internal use only as it's
|
47
|
+
# subject to change (we've moved between HTTP client schemes in the past
|
48
|
+
# and may do it again).
|
49
|
+
#
|
50
|
+
# `uri` is expected to be a string.
|
51
|
+
def connection_for(uri)
|
52
|
+
@mutex.synchronize do
|
53
|
+
u = URI.parse(uri)
|
54
|
+
connection = @active_connections[[u.host, u.port]]
|
55
|
+
|
56
|
+
if connection.nil?
|
57
|
+
connection = create_connection(u)
|
58
|
+
connection.start
|
59
|
+
|
60
|
+
@active_connections[[u.host, u.port]] = connection
|
61
|
+
end
|
62
|
+
|
63
|
+
connection
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Executes an HTTP request to the given URI with the given method. Also
|
68
|
+
# allows a request body, headers, and query string to be specified.
|
69
|
+
def execute_request(method, uri, body: nil, headers: nil, query: nil)
|
70
|
+
# Perform some basic argument validation because it's easy to get
|
71
|
+
# confused between strings and hashes for things like body and query
|
72
|
+
# parameters.
|
73
|
+
raise ArgumentError, "method should be a symbol" \
|
74
|
+
unless method.is_a?(Symbol)
|
75
|
+
raise ArgumentError, "uri should be a string" \
|
76
|
+
unless uri.is_a?(String)
|
77
|
+
raise ArgumentError, "body should be a string" \
|
78
|
+
if body && !body.is_a?(String)
|
79
|
+
raise ArgumentError, "headers should be a hash" \
|
80
|
+
if headers && !headers.is_a?(Hash)
|
81
|
+
raise ArgumentError, "query should be a string" \
|
82
|
+
if query && !query.is_a?(String)
|
83
|
+
|
84
|
+
@last_used = Util.monotonic_time
|
85
|
+
|
86
|
+
connection = connection_for(uri)
|
87
|
+
|
88
|
+
u = URI.parse(uri)
|
89
|
+
path = if query
|
90
|
+
u.path + "?" + query
|
91
|
+
else
|
92
|
+
u.path
|
93
|
+
end
|
94
|
+
|
95
|
+
@mutex.synchronize do
|
96
|
+
connection.send_request(method.to_s.upcase, path, body, headers)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# private
|
102
|
+
#
|
103
|
+
|
104
|
+
# `uri` should be a parsed `URI` object.
|
105
|
+
private def create_connection(uri)
|
106
|
+
# These all come back as `nil` if no proxy is configured.
|
107
|
+
proxy_host, proxy_port, proxy_user, proxy_pass = proxy_parts
|
108
|
+
|
109
|
+
connection = Net::HTTP.new(uri.host, uri.port,
|
110
|
+
proxy_host, proxy_port,
|
111
|
+
proxy_user, proxy_pass)
|
112
|
+
|
113
|
+
# Time in seconds within which Net::HTTP will try to reuse an already
|
114
|
+
# open connection when issuing a new operation. Outside this window, Ruby
|
115
|
+
# will transparently close and re-open the connection without trying to
|
116
|
+
# reuse it.
|
117
|
+
#
|
118
|
+
# Ruby's default of 2 seconds is almost certainly too short. Here I've
|
119
|
+
# reused Go's default for `DefaultTransport`.
|
120
|
+
connection.keep_alive_timeout = 30
|
121
|
+
|
122
|
+
connection.open_timeout = config.open_timeout
|
123
|
+
connection.read_timeout = config.read_timeout
|
124
|
+
if connection.respond_to?(:write_timeout=)
|
125
|
+
connection.write_timeout = config.write_timeout
|
126
|
+
end
|
127
|
+
|
128
|
+
connection.use_ssl = uri.scheme == "https"
|
129
|
+
|
130
|
+
if config.verify_ssl_certs
|
131
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
132
|
+
connection.cert_store = config.ca_store
|
133
|
+
else
|
134
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
135
|
+
warn_ssl_verify_none
|
136
|
+
end
|
137
|
+
|
138
|
+
connection
|
139
|
+
end
|
140
|
+
|
141
|
+
# `Net::HTTP` somewhat awkwardly requires each component of a proxy URI
|
142
|
+
# (host, port, etc.) rather than the URI itself. This method simply parses
|
143
|
+
# out those pieces to make passing them into a new connection a little less
|
144
|
+
# ugly.
|
145
|
+
private def proxy_parts
|
146
|
+
if config.proxy.nil?
|
147
|
+
[nil, nil, nil, nil]
|
148
|
+
else
|
149
|
+
u = URI.parse(config.proxy)
|
150
|
+
[u.host, u.port, u.user, u.password]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
private def warn_ssl_verify_none
|
155
|
+
return if @verify_ssl_warned
|
156
|
+
|
157
|
+
@verify_ssl_warned = true
|
158
|
+
warn("WARNING: Running without SSL cert verification. " \
|
159
|
+
"You should never do this in production. " \
|
160
|
+
"Execute `Stripe.verify_ssl_certs = true` to enable " \
|
161
|
+
"verification.")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
# Represents an error object as returned by the API.
|
5
|
+
#
|
6
|
+
# @see https://stripe.com/docs/api/errors
|
7
|
+
class ErrorObject < StripeObject
|
8
|
+
# Unlike other objects, we explicitly declare getter methods here. This
|
9
|
+
# is because the API doesn't return `null` values for fields on this
|
10
|
+
# object, rather the fields are omitted entirely. Not declaring the getter
|
11
|
+
# methods would cause users to run into `NoMethodError` exceptions and
|
12
|
+
# get in the way of generic error handling.
|
13
|
+
|
14
|
+
# For card errors, the ID of the failed charge.
|
15
|
+
def charge
|
16
|
+
@values[:charge]
|
17
|
+
end
|
18
|
+
|
19
|
+
# For some errors that could be handled programmatically, a short string
|
20
|
+
# indicating the error code reported.
|
21
|
+
def code
|
22
|
+
@values[:code]
|
23
|
+
end
|
24
|
+
|
25
|
+
# For card errors resulting from a card issuer decline, a short string
|
26
|
+
# indicating the card issuer's reason for the decline if they provide one.
|
27
|
+
def decline_code
|
28
|
+
@values[:decline_code]
|
29
|
+
end
|
30
|
+
|
31
|
+
# A URL to more information about the error code reported.
|
32
|
+
def doc_url
|
33
|
+
@values[:doc_url]
|
34
|
+
end
|
35
|
+
|
36
|
+
# A human-readable message providing more details about the error. For card
|
37
|
+
# errors, these messages can be shown to your users.
|
38
|
+
def message
|
39
|
+
@values[:message]
|
40
|
+
end
|
41
|
+
|
42
|
+
# If the error is parameter-specific, the parameter related to the error.
|
43
|
+
# For example, you can use this to display a message near the correct form
|
44
|
+
# field.
|
45
|
+
def param
|
46
|
+
@values[:param]
|
47
|
+
end
|
48
|
+
|
49
|
+
# The PaymentIntent object for errors returned on a request involving a
|
50
|
+
# PaymentIntent.
|
51
|
+
def payment_intent
|
52
|
+
@values[:payment_intent]
|
53
|
+
end
|
54
|
+
|
55
|
+
# The PaymentMethod object for errors returned on a request involving a
|
56
|
+
# PaymentMethod.
|
57
|
+
def payment_method
|
58
|
+
@values[:payment_method]
|
59
|
+
end
|
60
|
+
|
61
|
+
# The SetupIntent object for errors returned on a request involving a
|
62
|
+
# SetupIntent.
|
63
|
+
def setup_intent
|
64
|
+
@values[:setup_intent]
|
65
|
+
end
|
66
|
+
|
67
|
+
# The source object for errors returned on a request involving a source.
|
68
|
+
def source
|
69
|
+
@values[:source]
|
70
|
+
end
|
71
|
+
|
72
|
+
# The type of error returned. One of `api_connection_error`, `api_error`,
|
73
|
+
# `authentication_error`, `card_error`, `idempotency_error`,
|
74
|
+
# `invalid_request_error`, or `rate_limit_error`.
|
75
|
+
def type
|
76
|
+
@values[:type]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Represents on OAuth error returned by the OAuth API.
|
81
|
+
#
|
82
|
+
# @see https://stripe.com/docs/connect/oauth-reference#post-token-errors
|
83
|
+
class OAuthErrorObject < StripeObject
|
84
|
+
# A unique error code per error type.
|
85
|
+
def error
|
86
|
+
@values[:error]
|
87
|
+
end
|
88
|
+
|
89
|
+
# A human readable description of the error.
|
90
|
+
def error_description
|
91
|
+
@values[:error_description]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
# StripeError is the base error from which all other more specific Stripe
|
5
|
+
# errors derive.
|
6
|
+
class StripeError < StandardError
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
# Response contains a StripeResponse object that has some basic information
|
10
|
+
# about the response that conveyed the error.
|
11
|
+
attr_accessor :response
|
12
|
+
|
13
|
+
attr_reader :code
|
14
|
+
attr_reader :error
|
15
|
+
attr_reader :http_body
|
16
|
+
attr_reader :http_headers
|
17
|
+
attr_reader :http_status
|
18
|
+
attr_reader :json_body # equivalent to #data
|
19
|
+
attr_reader :request_id
|
20
|
+
|
21
|
+
# Initializes a StripeError.
|
22
|
+
def initialize(message = nil, http_status: nil, http_body: nil,
|
23
|
+
json_body: nil, http_headers: nil, code: nil)
|
24
|
+
@message = message
|
25
|
+
@http_status = http_status
|
26
|
+
@http_body = http_body
|
27
|
+
@http_headers = http_headers || {}
|
28
|
+
@idempotent_replayed = @http_headers["idempotent-replayed"] == "true"
|
29
|
+
@json_body = json_body
|
30
|
+
@code = code
|
31
|
+
@request_id = @http_headers["request-id"]
|
32
|
+
@error = construct_error_object
|
33
|
+
end
|
34
|
+
|
35
|
+
def construct_error_object
|
36
|
+
return nil if @json_body.nil? || !@json_body.key?(:error)
|
37
|
+
|
38
|
+
ErrorObject.construct_from(@json_body[:error])
|
39
|
+
end
|
40
|
+
|
41
|
+
# Whether the error was the result of an idempotent replay, meaning that it
|
42
|
+
# originally occurred on a previous request and is being replayed back
|
43
|
+
# because the user sent the same idempotency key for this one.
|
44
|
+
def idempotent_replayed?
|
45
|
+
@idempotent_replayed
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
50
|
+
id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
|
51
|
+
"#{status_string}#{id_string}#{@message}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# AuthenticationError is raised when invalid credentials are used to connect
|
56
|
+
# to Stripe's servers.
|
57
|
+
class AuthenticationError < StripeError
|
58
|
+
end
|
59
|
+
|
60
|
+
# APIConnectionError is raised in the event that the SDK can't connect to
|
61
|
+
# Stripe's servers. That can be for a variety of different reasons from a
|
62
|
+
# downed network to a bad TLS certificate.
|
63
|
+
class APIConnectionError < StripeError
|
64
|
+
end
|
65
|
+
|
66
|
+
# APIError is a generic error that may be raised in cases where none of the
|
67
|
+
# other named errors cover the problem. It could also be raised in the case
|
68
|
+
# that a new error has been introduced in the API, but this version of the
|
69
|
+
# Ruby SDK doesn't know how to handle it.
|
70
|
+
class APIError < StripeError
|
71
|
+
end
|
72
|
+
|
73
|
+
# CardError is raised when a user enters a card that can't be charged for
|
74
|
+
# some reason.
|
75
|
+
class CardError < StripeError
|
76
|
+
attr_reader :param
|
77
|
+
|
78
|
+
def initialize(message, param, code: nil, http_status: nil, http_body: nil,
|
79
|
+
json_body: nil, http_headers: nil)
|
80
|
+
super(message, http_status: http_status, http_body: http_body,
|
81
|
+
json_body: json_body, http_headers: http_headers,
|
82
|
+
code: code)
|
83
|
+
@param = param
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# IdempotencyError is raised in cases where an idempotency key was used
|
88
|
+
# improperly.
|
89
|
+
class IdempotencyError < StripeError
|
90
|
+
end
|
91
|
+
|
92
|
+
# InvalidRequestError is raised when a request is initiated with invalid
|
93
|
+
# parameters.
|
94
|
+
class InvalidRequestError < StripeError
|
95
|
+
attr_accessor :param
|
96
|
+
|
97
|
+
def initialize(message, param, http_status: nil, http_body: nil,
|
98
|
+
json_body: nil, http_headers: nil, code: nil)
|
99
|
+
super(message, http_status: http_status, http_body: http_body,
|
100
|
+
json_body: json_body, http_headers: http_headers,
|
101
|
+
code: code)
|
102
|
+
@param = param
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# PermissionError is raised in cases where access was attempted on a resource
|
107
|
+
# that wasn't allowed.
|
108
|
+
class PermissionError < StripeError
|
109
|
+
end
|
110
|
+
|
111
|
+
# RateLimitError is raised in cases where an account is putting too much load
|
112
|
+
# on Stripe's API servers (usually by performing too many requests). Please
|
113
|
+
# back off on request rate.
|
114
|
+
class RateLimitError < StripeError
|
115
|
+
end
|
116
|
+
|
117
|
+
# SignatureVerificationError is raised when the signature verification for a
|
118
|
+
# webhook fails
|
119
|
+
class SignatureVerificationError < StripeError
|
120
|
+
attr_accessor :sig_header
|
121
|
+
|
122
|
+
def initialize(message, sig_header, http_body: nil)
|
123
|
+
super(message, http_body: http_body)
|
124
|
+
@sig_header = sig_header
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module OAuth
|
129
|
+
# OAuthError is raised when the OAuth API returns an error.
|
130
|
+
class OAuthError < StripeError
|
131
|
+
def initialize(code, description, http_status: nil, http_body: nil,
|
132
|
+
json_body: nil, http_headers: nil)
|
133
|
+
super(description, http_status: http_status, http_body: http_body,
|
134
|
+
json_body: json_body, http_headers: http_headers,
|
135
|
+
code: code)
|
136
|
+
end
|
137
|
+
|
138
|
+
def construct_error_object
|
139
|
+
return nil if @json_body.nil?
|
140
|
+
|
141
|
+
OAuthErrorObject.construct_from(@json_body)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# InvalidClientError is raised when the client doesn't belong to you, or
|
146
|
+
# the API key mode (live or test) doesn't match the client mode. Or the
|
147
|
+
# stripe_user_id doesn't exist or isn't connected to your application.
|
148
|
+
class InvalidClientError < OAuthError
|
149
|
+
end
|
150
|
+
|
151
|
+
# InvalidGrantError is raised when a specified code doesn't exist, is
|
152
|
+
# expired, has been used, or doesn't belong to you; a refresh token doesn't
|
153
|
+
# exist, or doesn't belong to you; or if an API key's mode (live or test)
|
154
|
+
# doesn't match the mode of a code or refresh token.
|
155
|
+
class InvalidGrantError < OAuthError
|
156
|
+
end
|
157
|
+
|
158
|
+
# InvalidRequestError is raised when a code, refresh token, or grant type
|
159
|
+
# parameter is not provided, but was required.
|
160
|
+
class InvalidRequestError < OAuthError
|
161
|
+
end
|
162
|
+
|
163
|
+
# InvalidScopeError is raised when an invalid scope parameter is provided.
|
164
|
+
class InvalidScopeError < OAuthError
|
165
|
+
end
|
166
|
+
|
167
|
+
# UnsupportedGrantTypeError is raised when an unuspported grant type
|
168
|
+
# parameter is specified.
|
169
|
+
class UnsupportedGrantTypeError < OAuthError
|
170
|
+
end
|
171
|
+
|
172
|
+
# UnsupportedResponseTypeError is raised when an unsupported response type
|
173
|
+
# parameter is specified.
|
174
|
+
class UnsupportedResponseTypeError < OAuthError
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class Instrumentation
|
5
|
+
# Event emitted on `request_begin` callback.
|
6
|
+
class RequestBeginEvent
|
7
|
+
attr_reader :method
|
8
|
+
attr_reader :path
|
9
|
+
|
10
|
+
# Arbitrary user-provided data in the form of a Ruby hash that's passed
|
11
|
+
# from subscribers on `request_begin` to subscribers on `request_end`.
|
12
|
+
# `request_begin` subscribers can set keys which will then be available
|
13
|
+
# in `request_end`.
|
14
|
+
#
|
15
|
+
# Note that all subscribers of `request_begin` share the same object, so
|
16
|
+
# they must be careful to set unique keys so as to not conflict with data
|
17
|
+
# set by other subscribers.
|
18
|
+
attr_reader :user_data
|
19
|
+
|
20
|
+
def initialize(method:, path:, user_data:)
|
21
|
+
@method = method
|
22
|
+
@path = path
|
23
|
+
@user_data = user_data
|
24
|
+
freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Event emitted on `request_end` callback.
|
29
|
+
class RequestEndEvent
|
30
|
+
attr_reader :duration
|
31
|
+
attr_reader :http_status
|
32
|
+
attr_reader :method
|
33
|
+
attr_reader :num_retries
|
34
|
+
attr_reader :path
|
35
|
+
|
36
|
+
# Arbitrary user-provided data in the form of a Ruby hash that's passed
|
37
|
+
# from subscribers on `request_begin` to subscribers on `request_end`.
|
38
|
+
# `request_begin` subscribers can set keys which will then be available
|
39
|
+
# in `request_end`.
|
40
|
+
attr_reader :user_data
|
41
|
+
|
42
|
+
def initialize(duration:, http_status:, method:, num_retries:, path:,
|
43
|
+
user_data: nil)
|
44
|
+
@duration = duration
|
45
|
+
@http_status = http_status
|
46
|
+
@method = method
|
47
|
+
@num_retries = num_retries
|
48
|
+
@path = path
|
49
|
+
@user_data = user_data
|
50
|
+
freeze
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# This class was renamed for consistency. This alias is here for backwards
|
55
|
+
# compatibility.
|
56
|
+
RequestEvent = RequestEndEvent
|
57
|
+
|
58
|
+
# Returns true if there are a non-zero number of subscribers on the given
|
59
|
+
# topic, and false otherwise.
|
60
|
+
def self.any_subscribers?(topic)
|
61
|
+
!subscribers[topic].empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.subscribe(topic, name = rand, &block)
|
65
|
+
subscribers[topic][name] = block
|
66
|
+
name
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.unsubscribe(topic, name)
|
70
|
+
subscribers[topic].delete(name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.notify(topic, event)
|
74
|
+
subscribers[topic].each_value { |subscriber| subscriber.call(event) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.subscribers
|
78
|
+
@subscribers ||= Hash.new { |hash, key| hash[key] = {} }
|
79
|
+
end
|
80
|
+
private_class_method :subscribers
|
81
|
+
end
|
82
|
+
end
|