From 822b5f4da08ee2d742091a3b3e0a797cf419697c Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Tue, 26 Nov 2024 14:41:57 -0600 Subject: [PATCH] Add LemonSqueezy webhook metadata to objects Fixes #1107 --- lib/pay/lemon_squeezy.rb | 4 +++- test/pay/lemon_squeezy/webhooks_test.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pay/lemon_squeezy.rb b/lib/pay/lemon_squeezy.rb index 34436c3b..1fdd639c 100644 --- a/lib/pay/lemon_squeezy.rb +++ b/lib/pay/lemon_squeezy.rb @@ -68,7 +68,9 @@ def self.construct_from_webhook_event(event) "subscription-invoices" => ::LemonSqueezy::SubscriptionInvoice }.fetch(data["type"]) - type.new(data) + object = type.new(data) + object.meta = event["meta"] + object end end diff --git a/test/pay/lemon_squeezy/webhooks_test.rb b/test/pay/lemon_squeezy/webhooks_test.rb index 1f791aa1..3fba98fa 100644 --- a/test/pay/lemon_squeezy/webhooks_test.rb +++ b/test/pay/lemon_squeezy/webhooks_test.rb @@ -1,6 +1,12 @@ require "test_helper" class Pay::LemonSqueezy::WebhooksTest < ActiveSupport::TestCase + test "lemon squeezy webhook metadata" do + object = Pay::LemonSqueezy.construct_from_webhook_event json_fixture("lemon_squeezy/order_created") + assert_equal ::LemonSqueezy::Order, object.class + assert_equal {"event_name" => "order_created"}, object.meta + end + test "lemon squeezy order_created webhook" do json = json_fixture("lemon_squeezy/order_created") event = Pay::Webhook.new(processor: :lemon_squeezy, event: json).rehydrated_event