From da191661734320fbb65f9e0728b8a82df950968f Mon Sep 17 00:00:00 2001 From: jar-stripe Date: Mon, 13 Jan 2025 13:36:48 -0800 Subject: [PATCH 1/2] pinned the ubuntu version in the Test action, to ensure support for jruby 9.4.0.0 (#1518) --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e813ebe4..af0234135 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,8 @@ jobs: test: name: Test (${{ matrix.ruby-version }}) - runs-on: ubuntu-latest + # this is needed because our JRuby test version isnt supported on ubuntu-24 (which is now ubuntu-latest) + runs-on: ubuntu-22.04 strategy: matrix: ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, '3.3', jruby-9.4.0.0, truffleruby-head] From 36b1c7c8f00433b998008af1bfb8012eea04c223 Mon Sep 17 00:00:00 2001 From: jar-stripe Date: Mon, 13 Jan 2025 14:04:14 -0800 Subject: [PATCH 2/2] 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 --- lib/stripe/thin_event.rb | 24 ++++++++++++++++++++++-- test/stripe/v2_event_test.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/stripe/thin_event.rb b/lib/stripe/thin_event.rb index 0612af469..9e2978662 100644 --- a/lib/stripe/thin_event.rb +++ b/lib/stripe/thin_event.rb @@ -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 @@ def initialize(event_payload = {}) @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 diff --git a/test/stripe/v2_event_test.rb b/test/stripe/v2_event_test.rb index e53cdcb27..130e659f2 100644 --- a/test/stripe/v2_event_test.rb +++ b/test/stripe/v2_event_test.rb @@ -36,6 +36,26 @@ def retrieve_event(evt_id) }, }.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 @@ def retrieve_event(evt_id) 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