mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-07-09 00:00:35 -04:00
Compare commits
4 Commits
e03fa884f4
...
256d6a601a
Author | SHA1 | Date | |
---|---|---|---|
|
256d6a601a | ||
|
fcfeac740e | ||
|
e0a50213e7 | ||
|
c1d0ced565 |
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 8.1.0 - 2023-01-12
|
||||||
|
* [#1162](https://github.com/stripe/stripe-ruby/pull/1162) Improve request events instrumentation
|
||||||
|
|
||||||
## 8.0.0 - 2022-11-16
|
## 8.0.0 - 2022-11-16
|
||||||
* [#1144](https://github.com/stripe/stripe-ruby/pull/1144) Next major release changes
|
* [#1144](https://github.com/stripe/stripe-ruby/pull/1144) Next major release changes
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
v204
|
v219
|
@ -253,7 +253,11 @@ a success or error. Receives `RequestEndEvent` with the following properties:
|
|||||||
- `path`: Request path. (`String`)
|
- `path`: Request path. (`String`)
|
||||||
- `user_data`: A hash on which users may have set arbitrary data in
|
- `user_data`: A hash on which users may have set arbitrary data in
|
||||||
`request_begin`. See above for more information. (`Hash`)
|
`request_begin`. See above for more information. (`Hash`)
|
||||||
- `request_id`. HTTP request identifier.
|
- `request_id`: HTTP request identifier. (`String`)
|
||||||
|
- `response_header`: The response headers. (`Hash`)
|
||||||
|
- `response_body` = The response body. (`String`)
|
||||||
|
- `request_header` = The request headers. (`Hash`)
|
||||||
|
- `request_body` = The request body. (`String`)
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
|
@ -33,6 +33,10 @@ module Stripe
|
|||||||
attr_reader :num_retries
|
attr_reader :num_retries
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
attr_reader :request_id
|
attr_reader :request_id
|
||||||
|
attr_reader :response_header
|
||||||
|
attr_reader :response_body
|
||||||
|
attr_reader :request_header
|
||||||
|
attr_reader :request_body
|
||||||
|
|
||||||
# Arbitrary user-provided data in the form of a Ruby hash that's passed
|
# Arbitrary user-provided data in the form of a Ruby hash that's passed
|
||||||
# from subscribers on `request_begin` to subscribers on `request_end`.
|
# from subscribers on `request_begin` to subscribers on `request_end`.
|
||||||
@ -40,19 +44,53 @@ module Stripe
|
|||||||
# in `request_end`.
|
# in `request_end`.
|
||||||
attr_reader :user_data
|
attr_reader :user_data
|
||||||
|
|
||||||
def initialize(duration:, http_status:, method:, num_retries:, path:,
|
def initialize(request_context:, response_context:,
|
||||||
request_id:, user_data: nil)
|
num_retries:, user_data: nil)
|
||||||
@duration = duration
|
@duration = request_context.duration
|
||||||
@http_status = http_status
|
@http_status = response_context.http_status
|
||||||
@method = method
|
@method = request_context.method
|
||||||
@num_retries = num_retries
|
@num_retries = num_retries
|
||||||
@path = path
|
@path = request_context.path
|
||||||
@request_id = request_id
|
@request_id = request_context.request_id
|
||||||
@user_data = user_data
|
@user_data = user_data
|
||||||
|
@response_header = response_context.header
|
||||||
|
@response_body = response_context.body
|
||||||
|
@request_header = request_context.header
|
||||||
|
@request_body = request_context.body
|
||||||
freeze
|
freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class RequestContext
|
||||||
|
attr_reader :duration
|
||||||
|
attr_reader :method
|
||||||
|
attr_reader :path
|
||||||
|
attr_reader :request_id
|
||||||
|
attr_reader :body
|
||||||
|
attr_reader :header
|
||||||
|
|
||||||
|
def initialize(duration:, context:, header:)
|
||||||
|
@duration = duration
|
||||||
|
@method = context.method
|
||||||
|
@path = context.path
|
||||||
|
@request_id = context.request_id
|
||||||
|
@body = context.body
|
||||||
|
@header = header
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ResponseContext
|
||||||
|
attr_reader :http_status
|
||||||
|
attr_reader :body
|
||||||
|
attr_reader :header
|
||||||
|
|
||||||
|
def initialize(http_status:, response:)
|
||||||
|
@http_status = http_status
|
||||||
|
@header = response ? response.to_hash : nil
|
||||||
|
@body = response ? response.body : nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This class was renamed for consistency. This alias is here for backwards
|
# This class was renamed for consistency. This alias is here for backwards
|
||||||
# compatibility.
|
# compatibility.
|
||||||
RequestEvent = RequestEndEvent
|
RequestEvent = RequestEndEvent
|
||||||
|
@ -64,7 +64,6 @@ module Stripe
|
|||||||
|
|
||||||
nested_resource_class_methods :external_account,
|
nested_resource_class_methods :external_account,
|
||||||
operations: %i[create retrieve update delete list]
|
operations: %i[create retrieve update delete list]
|
||||||
|
|
||||||
nested_resource_class_methods :login_link, operations: %i[create]
|
nested_resource_class_methods :login_link, operations: %i[create]
|
||||||
|
|
||||||
def resource_url
|
def resource_url
|
||||||
|
@ -494,15 +494,16 @@ module Stripe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
http_resp = execute_request_with_rescues(method, api_base, context) do
|
http_resp =
|
||||||
self.class
|
execute_request_with_rescues(method, api_base, headers, context) do
|
||||||
.default_connection_manager(config)
|
self.class
|
||||||
.execute_request(method, url,
|
.default_connection_manager(config)
|
||||||
body: body,
|
.execute_request(method, url,
|
||||||
headers: headers,
|
body: body,
|
||||||
query: query,
|
headers: headers,
|
||||||
&response_block)
|
query: query,
|
||||||
end
|
&response_block)
|
||||||
|
end
|
||||||
|
|
||||||
[http_resp, api_key]
|
[http_resp, api_key]
|
||||||
end
|
end
|
||||||
@ -564,7 +565,7 @@ module Stripe
|
|||||||
http_status >= 400
|
http_status >= 400
|
||||||
end
|
end
|
||||||
|
|
||||||
private def execute_request_with_rescues(method, api_base, context)
|
private def execute_request_with_rescues(method, api_base, headers, context)
|
||||||
num_retries = 0
|
num_retries = 0
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -587,7 +588,7 @@ module Stripe
|
|||||||
|
|
||||||
log_response(context, request_start, http_status, resp.body, resp)
|
log_response(context, request_start, http_status, resp.body, resp)
|
||||||
notify_request_end(context, request_duration, http_status,
|
notify_request_end(context, request_duration, http_status,
|
||||||
num_retries, user_data)
|
num_retries, user_data, resp, headers)
|
||||||
|
|
||||||
if config.enable_telemetry? && context.request_id
|
if config.enable_telemetry? && context.request_id
|
||||||
request_duration_ms = (request_duration * 1000).to_i
|
request_duration_ms = (request_duration * 1000).to_i
|
||||||
@ -614,7 +615,7 @@ module Stripe
|
|||||||
log_response_error(error_context, request_start, e)
|
log_response_error(error_context, request_start, e)
|
||||||
end
|
end
|
||||||
notify_request_end(context, request_duration, http_status, num_retries,
|
notify_request_end(context, request_duration, http_status, num_retries,
|
||||||
user_data)
|
user_data, resp, headers)
|
||||||
|
|
||||||
if self.class.should_retry?(e,
|
if self.class.should_retry?(e,
|
||||||
method: method,
|
method: method,
|
||||||
@ -657,17 +658,24 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def notify_request_end(context, duration, http_status, num_retries,
|
private def notify_request_end(context, duration, http_status, num_retries,
|
||||||
user_data)
|
user_data, resp, headers)
|
||||||
return if !Instrumentation.any_subscribers?(:request_end) &&
|
return if !Instrumentation.any_subscribers?(:request_end) &&
|
||||||
!Instrumentation.any_subscribers?(:request)
|
!Instrumentation.any_subscribers?(:request)
|
||||||
|
|
||||||
event = Instrumentation::RequestEndEvent.new(
|
request_context = Stripe::Instrumentation::RequestContext.new(
|
||||||
duration: duration,
|
duration: duration,
|
||||||
|
context: context,
|
||||||
|
header: headers
|
||||||
|
)
|
||||||
|
response_context = Stripe::Instrumentation::ResponseContext.new(
|
||||||
http_status: http_status,
|
http_status: http_status,
|
||||||
method: context.method,
|
response: resp
|
||||||
|
)
|
||||||
|
|
||||||
|
event = Instrumentation::RequestEndEvent.new(
|
||||||
|
request_context: request_context,
|
||||||
|
response_context: response_context,
|
||||||
num_retries: num_retries,
|
num_retries: num_retries,
|
||||||
path: context.path,
|
|
||||||
request_id: context.request_id,
|
|
||||||
user_data: user_data || {}
|
user_data: user_data || {}
|
||||||
)
|
)
|
||||||
Stripe::Instrumentation.notify(:request_end, event)
|
Stripe::Instrumentation.notify(:request_end, event)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
VERSION = "8.0.0"
|
VERSION = "8.1.0"
|
||||||
end
|
end
|
||||||
|
@ -32,6 +32,12 @@ module Stripe
|
|||||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts?limit=3"
|
assert_requested :get, "#{Stripe.api_base}/v1/accounts?limit=3"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context "Account.persons" do
|
||||||
|
should "support requests with args: limit, parent_id" do
|
||||||
|
Stripe::Account.persons("acct_xxxxxxxxxxxxx", { limit: 3 })
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_xxxxxxxxxxxxx/persons?limit=3"
|
||||||
|
end
|
||||||
|
end
|
||||||
context "Account.reject" do
|
context "Account.reject" do
|
||||||
should "support requests with args: reason, id" do
|
should "support requests with args: reason, id" do
|
||||||
Stripe::Account.reject("acct_xxxxxxxxxxxxx", { reason: "fraud" })
|
Stripe::Account.reject("acct_xxxxxxxxxxxxx", { reason: "fraud" })
|
||||||
@ -78,6 +84,31 @@ module Stripe
|
|||||||
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx?"
|
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx?"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context "ApplicationFeeRefund.list" do
|
||||||
|
should "support requests with args: limit, parent_id" do
|
||||||
|
Stripe::ApplicationFee.list_refunds("fee_xxxxxxxxxxxxx", { limit: 3 })
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds?limit=3"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "ApplicationFeeRefund.retrieve" do
|
||||||
|
should "support requests with args: parent_id, id" do
|
||||||
|
Stripe::ApplicationFee.retrieve_refund(
|
||||||
|
"fee_xxxxxxxxxxxxx",
|
||||||
|
"fr_xxxxxxxxxxxxx"
|
||||||
|
)
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds/fr_xxxxxxxxxxxxx?"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "ApplicationFeeRefund.update" do
|
||||||
|
should "support requests with args: metadata, parent_id, id" do
|
||||||
|
Stripe::ApplicationFee.update_refund(
|
||||||
|
"fee_xxxxxxxxxxxxx",
|
||||||
|
"fr_xxxxxxxxxxxxx",
|
||||||
|
{ metadata: { order_id: "6735" } }
|
||||||
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds/fr_xxxxxxxxxxxxx"
|
||||||
|
end
|
||||||
|
end
|
||||||
context "Apps.Secret.create" do
|
context "Apps.Secret.create" do
|
||||||
should "support requests with args: name, payload, scope" do
|
should "support requests with args: name, payload, scope" do
|
||||||
Stripe::Apps::Secret.create(
|
Stripe::Apps::Secret.create(
|
||||||
@ -571,31 +602,6 @@ module Stripe
|
|||||||
assert_requested :get, "#{Stripe.api_base}/v1/events/evt_xxxxxxxxxxxxx?"
|
assert_requested :get, "#{Stripe.api_base}/v1/events/evt_xxxxxxxxxxxxx?"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "FeeRefund.list" do
|
|
||||||
should "support requests with args: limit, parent_id" do
|
|
||||||
Stripe::ApplicationFee.list_refunds("fee_xxxxxxxxxxxxx", { limit: 3 })
|
|
||||||
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds?limit=3"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "FeeRefund.retrieve" do
|
|
||||||
should "support requests with args: parent_id, id" do
|
|
||||||
Stripe::ApplicationFee.retrieve_refund(
|
|
||||||
"fee_xxxxxxxxxxxxx",
|
|
||||||
"fr_xxxxxxxxxxxxx"
|
|
||||||
)
|
|
||||||
assert_requested :get, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds/fr_xxxxxxxxxxxxx?"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "FeeRefund.update" do
|
|
||||||
should "support requests with args: metadata, parent_id, id" do
|
|
||||||
Stripe::ApplicationFee.update_refund(
|
|
||||||
"fee_xxxxxxxxxxxxx",
|
|
||||||
"fr_xxxxxxxxxxxxx",
|
|
||||||
{ metadata: { order_id: "6735" } }
|
|
||||||
)
|
|
||||||
assert_requested :post, "#{Stripe.api_base}/v1/application_fees/fee_xxxxxxxxxxxxx/refunds/fr_xxxxxxxxxxxxx"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "File.list" do
|
context "File.list" do
|
||||||
should "support requests with args: limit" do
|
should "support requests with args: limit" do
|
||||||
Stripe::File.list({ limit: 3 })
|
Stripe::File.list({ limit: 3 })
|
||||||
@ -1294,12 +1300,6 @@ module Stripe
|
|||||||
assert_requested :post, "#{Stripe.api_base}/v1/payouts/po_xxxxxxxxxxxxx"
|
assert_requested :post, "#{Stripe.api_base}/v1/payouts/po_xxxxxxxxxxxxx"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "Person.list" do
|
|
||||||
should "support requests with args: limit, parent_id" do
|
|
||||||
Stripe::Account.list_persons("acct_xxxxxxxxxxxxx", { limit: 3 })
|
|
||||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_xxxxxxxxxxxxx/persons?limit=3"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "Person.retrieve" do
|
context "Person.retrieve" do
|
||||||
should "support requests with args: parent_id, id" do
|
should "support requests with args: parent_id, id" do
|
||||||
Stripe::Account.retrieve_person(
|
Stripe::Account.retrieve_person(
|
||||||
@ -1684,6 +1684,31 @@ module Stripe
|
|||||||
assert_requested :get, "#{Stripe.api_base}/v1/reporting/report_types/balance.summary.1?"
|
assert_requested :get, "#{Stripe.api_base}/v1/reporting/report_types/balance.summary.1?"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context "Reversal.list" do
|
||||||
|
should "support requests with args: limit, parent_id" do
|
||||||
|
Stripe::Transfer.list_reversals("tr_xxxxxxxxxxxxx", { limit: 3 })
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals?limit=3"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "Reversal.retrieve" do
|
||||||
|
should "support requests with args: parent_id, id" do
|
||||||
|
Stripe::Transfer.retrieve_reversal(
|
||||||
|
"tr_xxxxxxxxxxxxx",
|
||||||
|
"trr_xxxxxxxxxxxxx"
|
||||||
|
)
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals/trr_xxxxxxxxxxxxx?"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "Reversal.update" do
|
||||||
|
should "support requests with args: metadata, parent_id, id" do
|
||||||
|
Stripe::Transfer.update_reversal(
|
||||||
|
"tr_xxxxxxxxxxxxx",
|
||||||
|
"trr_xxxxxxxxxxxxx",
|
||||||
|
{ metadata: { order_id: "6735" } }
|
||||||
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals/trr_xxxxxxxxxxxxx"
|
||||||
|
end
|
||||||
|
end
|
||||||
context "Review.approve" do
|
context "Review.approve" do
|
||||||
should "support requests with args: id" do
|
should "support requests with args: id" do
|
||||||
Stripe::Review.approve("prv_xxxxxxxxxxxxx")
|
Stripe::Review.approve("prv_xxxxxxxxxxxxx")
|
||||||
@ -2383,31 +2408,6 @@ module Stripe
|
|||||||
assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx"
|
assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "TransferReversal.list" do
|
|
||||||
should "support requests with args: limit, parent_id" do
|
|
||||||
Stripe::Transfer.list_reversals("tr_xxxxxxxxxxxxx", { limit: 3 })
|
|
||||||
assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals?limit=3"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "TransferReversal.retrieve" do
|
|
||||||
should "support requests with args: parent_id, id" do
|
|
||||||
Stripe::Transfer.retrieve_reversal(
|
|
||||||
"tr_xxxxxxxxxxxxx",
|
|
||||||
"trr_xxxxxxxxxxxxx"
|
|
||||||
)
|
|
||||||
assert_requested :get, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals/trr_xxxxxxxxxxxxx?"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "TransferReversal.update" do
|
|
||||||
should "support requests with args: metadata, parent_id, id" do
|
|
||||||
Stripe::Transfer.update_reversal(
|
|
||||||
"tr_xxxxxxxxxxxxx",
|
|
||||||
"trr_xxxxxxxxxxxxx",
|
|
||||||
{ metadata: { order_id: "6735" } }
|
|
||||||
)
|
|
||||||
assert_requested :post, "#{Stripe.api_base}/v1/transfers/tr_xxxxxxxxxxxxx/reversals/trr_xxxxxxxxxxxxx"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "Treasury.CreditReversal.create" do
|
context "Treasury.CreditReversal.create" do
|
||||||
should "support requests with args: received_credit" do
|
should "support requests with args: received_credit" do
|
||||||
Stripe::Treasury::CreditReversal.create(
|
Stripe::Treasury::CreditReversal.create(
|
||||||
|
@ -58,13 +58,29 @@ module Stripe
|
|||||||
|
|
||||||
context "RequestEventEnd" do
|
context "RequestEventEnd" do
|
||||||
should "return a frozen object" do
|
should "return a frozen object" do
|
||||||
event = Stripe::Instrumentation::RequestEndEvent.new(
|
mock_context = stub(
|
||||||
duration: 0.1,
|
duration: 0.1,
|
||||||
http_status: 200,
|
|
||||||
method: :get,
|
method: :get,
|
||||||
num_retries: 0,
|
|
||||||
path: "/v1/test",
|
path: "/v1/test",
|
||||||
request_id: "req_123",
|
request_id: "req_123",
|
||||||
|
body: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
request_context = Stripe::Instrumentation::RequestContext.new(
|
||||||
|
duration: 0.1,
|
||||||
|
context: mock_context,
|
||||||
|
header: nil
|
||||||
|
)
|
||||||
|
|
||||||
|
response_context = Stripe::Instrumentation::ResponseContext.new(
|
||||||
|
http_status: 200,
|
||||||
|
response: nil
|
||||||
|
)
|
||||||
|
|
||||||
|
event = Stripe::Instrumentation::RequestEndEvent.new(
|
||||||
|
num_retries: 0,
|
||||||
|
request_context: request_context,
|
||||||
|
response_context: response_context,
|
||||||
user_data: nil
|
user_data: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1443,19 +1443,25 @@ module Stripe
|
|||||||
should "notify a subscriber of a successful HTTP request" do
|
should "notify a subscriber of a successful HTTP request" do
|
||||||
events = []
|
events = []
|
||||||
Stripe::Instrumentation.subscribe(:request_end, :test) { |event| events << event }
|
Stripe::Instrumentation.subscribe(:request_end, :test) { |event| events << event }
|
||||||
|
stub_response_body = JSON.generate(object: "charge")
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
stub_request(:post, "#{Stripe.api_base}/v1/charges")
|
||||||
.to_return(body: JSON.generate(object: "charge"), headers: { "Request-ID": "req_123" })
|
.with(body: { "amount" => "50", "currency" => "usd", "card" => "sc_token" })
|
||||||
Stripe::Charge.list
|
.to_return(body: stub_response_body, headers: { "Request-ID": "req_123" })
|
||||||
|
|
||||||
|
Stripe::Charge.create(amount: 50, currency: "usd", card: "sc_token")
|
||||||
|
|
||||||
assert_equal(1, events.size)
|
assert_equal(1, events.size)
|
||||||
event = events.first
|
event = events.first
|
||||||
assert_equal(:get, event.method)
|
assert_equal(:post, event.method)
|
||||||
assert_equal("/v1/charges", event.path)
|
assert_equal("/v1/charges", event.path)
|
||||||
assert_equal(200, event.http_status)
|
assert_equal(200, event.http_status)
|
||||||
assert(event.duration.positive?)
|
assert(event.duration.positive?)
|
||||||
assert_equal(0, event.num_retries)
|
assert_equal(0, event.num_retries)
|
||||||
assert_equal("req_123", event.request_id)
|
assert_equal("req_123", event.request_id)
|
||||||
|
assert_equal(stub_response_body, event.response_body)
|
||||||
|
assert_equal("amount=50¤cy=usd&card=sc_token", event.request_body)
|
||||||
|
assert(event.request_header)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "notify a subscriber of a StripeError" do
|
should "notify a subscriber of a StripeError" do
|
||||||
@ -1484,6 +1490,7 @@ module Stripe
|
|||||||
assert_equal(500, event.http_status)
|
assert_equal(500, event.http_status)
|
||||||
assert(event.duration.positive?)
|
assert(event.duration.positive?)
|
||||||
assert_equal(0, event.num_retries)
|
assert_equal(0, event.num_retries)
|
||||||
|
assert_equal(JSON.generate(error: error), event.response_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "notify a subscriber of a network error" do
|
should "notify a subscriber of a network error" do
|
||||||
@ -1526,8 +1533,9 @@ module Stripe
|
|||||||
events = []
|
events = []
|
||||||
Stripe::Instrumentation.subscribe(:request, :test) { |event| events << event }
|
Stripe::Instrumentation.subscribe(:request, :test) { |event| events << event }
|
||||||
|
|
||||||
|
stub_response_body = JSON.generate(object: "charge")
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
||||||
.to_return(body: JSON.generate(object: "charge"))
|
.to_return(body: stub_response_body)
|
||||||
Stripe::Charge.list
|
Stripe::Charge.list
|
||||||
|
|
||||||
assert_equal(1, events.size)
|
assert_equal(1, events.size)
|
||||||
@ -1537,6 +1545,8 @@ module Stripe
|
|||||||
assert_equal(200, event.http_status)
|
assert_equal(200, event.http_status)
|
||||||
assert(event.duration.positive?)
|
assert(event.duration.positive?)
|
||||||
assert_equal(0, event.num_retries)
|
assert_equal(0, event.num_retries)
|
||||||
|
assert_equal(stub_response_body, event.response_body)
|
||||||
|
assert(event.request_header)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user