Quiet optional Stripe payment link failures

Agent-Logs-Url: https://github.com/we-promise/sure/sessions/8eaf6809-26d1-4b47-9d44-b15b179c18c7

Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-05 07:52:15 +00:00
committed by GitHub
parent 2ab71ef5a4
commit 64424428e7
2 changed files with 14 additions and 7 deletions

View File

@@ -75,9 +75,8 @@ class Provider::Stripe
return nil if payment_link_id.blank?
client.v1.payment_links.retrieve(payment_link_id).url
rescue StandardError => e
Sentry.capture_exception(e)
Rails.logger.error "Error fetching payment link #{payment_link_id}: #{e.message}"
rescue Stripe::StripeError => e
Rails.logger.debug { "Unable to fetch optional Stripe payment link #{payment_link_id}: #{e.message}" }
nil
end

View File

@@ -85,17 +85,25 @@ class Provider::StripeTest < ActiveSupport::TestCase
payment_links = mock
payment_links.expects(:retrieve)
.with("plink_test123")
.raises(StandardError, "not found")
.raises(Stripe::StripeError, "not found")
client = mock
client.stubs(:v1).returns(OpenStruct.new(payment_links: payment_links))
captured_message = nil
logger = Object.new
logger.define_singleton_method(:debug) do |&block|
captured_message = block.call
end
Stripe::StripeClient.stubs(:new).returns(client)
Sentry.expects(:capture_exception).with(instance_of(StandardError))
Rails.logger.expects(:error)
.with("Error fetching payment link plink_test123: not found")
Rails.stubs(:logger).returns(logger)
stripe = Provider::Stripe.new(secret_key: "foo", webhook_secret: "bar")
assert_nil stripe.payment_link_url(payment_link_id: "plink_test123")
assert_equal(
"Unable to fetch optional Stripe payment link plink_test123: not found",
captured_message
)
end
end