mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-22 00:05:58 -05:00
ThinEvent reason and livemode (#1516)
* added test for parsing v2 thin events with livemode and reason * added attr_reader to ThinEvent for livemode and reason * added EventReason and EventReasonRequest type to thin_event.rb
This commit is contained in:
parent
da19166173
commit
36b1c7c8f0
@ -1,8 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
class EventReasonRequest
|
||||
attr_reader :id, :idempotency_key
|
||||
|
||||
def initialize(event_reason_request_payload = {})
|
||||
@id = event_reason_request_payload[:id]
|
||||
@idempotency_key = event_reason_request_payload[:idempotency_key]
|
||||
end
|
||||
end
|
||||
|
||||
class EventReason
|
||||
attr_reader :type, :request
|
||||
|
||||
def initialize(event_reason_payload = {})
|
||||
@type = event_reason_payload[:type]
|
||||
@request = EventReasonRequest.new(event_reason_payload[:request])
|
||||
end
|
||||
end
|
||||
|
||||
class ThinEvent
|
||||
attr_reader :id, :type, :created, :context, :related_object
|
||||
attr_reader :id, :type, :created, :context, :related_object, :livemode, :reason
|
||||
|
||||
def initialize(event_payload = {})
|
||||
@id = event_payload[:id]
|
||||
@ -11,7 +29,9 @@ module Stripe
|
||||
@context = event_payload[:context]
|
||||
@livemode = event_payload[:livemode]
|
||||
@related_object = event_payload[:related_object]
|
||||
@reason = event_payload[:reason]
|
||||
return if event_payload[:reason].nil?
|
||||
|
||||
@reason = EventReason.new(event_payload[:reason])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -36,6 +36,26 @@ module Stripe
|
||||
},
|
||||
}.to_json
|
||||
|
||||
@v2_push_payload_with_livemode_and_reason = {
|
||||
"id" => "evt_234",
|
||||
"object" => "v2.core.event",
|
||||
"type" => "v1.billing.meter.error_report_triggered",
|
||||
"created" => "2022-02-15T00:27:45.330Z",
|
||||
"related_object" => {
|
||||
"id" => "mtr_123",
|
||||
"type" => "billing.meter",
|
||||
"url" => "/v1/billing/meters/mtr_123",
|
||||
},
|
||||
"livemode" => true,
|
||||
"reason" => {
|
||||
"type" => "a.b.c",
|
||||
"request" => {
|
||||
"id" => "r_123",
|
||||
"idempotency_key" => "key",
|
||||
},
|
||||
},
|
||||
}.to_json
|
||||
|
||||
@v2_pull_payload = {
|
||||
"id" => "evt_234",
|
||||
"object" => "v2.core.event",
|
||||
@ -76,6 +96,20 @@ module Stripe
|
||||
assert_equal "evt_234", event.id
|
||||
assert_equal "v1.billing.meter.error_report_triggered", event.type
|
||||
assert_equal "2022-02-15T00:27:45.330Z", event.created
|
||||
assert_nil event.reason
|
||||
end
|
||||
|
||||
should "parse v2 events with livemode and reason" do
|
||||
event = parse_signed_event(@v2_push_payload_with_livemode_and_reason)
|
||||
assert event.is_a?(Stripe::ThinEvent)
|
||||
assert_equal "evt_234", event.id
|
||||
assert_equal "v1.billing.meter.error_report_triggered", event.type
|
||||
assert_equal "2022-02-15T00:27:45.330Z", event.created
|
||||
assert_true event.livemode
|
||||
assert_not_nil event.reason
|
||||
assert_equal "a.b.c", event.reason.type
|
||||
assert_equal "r_123", event.reason.request.id
|
||||
assert_equal "key", event.reason.request.idempotency_key
|
||||
end
|
||||
|
||||
should "raise a JSON::ParserError from an invalid JSON payload" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user