mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Handle missing Stripe payment link gracefully
Agent-Logs-Url: https://github.com/we-promise/sure/sessions/efba0c75-5f82-41a1-b618-532d38e222da Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e0d2150e2d
commit
f1f1bc91cc
@@ -71,6 +71,10 @@ 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}"
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -27,4 +27,20 @@ class Settings::PaymentsControllerTest < ActionDispatch::IntegrationTest
|
||||
text: I18n.t("views.settings.payments.show.one_time_contribution_link_text")
|
||||
)
|
||||
end
|
||||
|
||||
test "shows payment settings without contribution link when payment link is unavailable" do
|
||||
@family.update!(stripe_customer_id: "cus_test123")
|
||||
stripe = mock
|
||||
stripe.expects(:payment_link_url).returns(nil)
|
||||
Provider::Registry.stubs(:get_provider).with(:stripe).returns(stripe)
|
||||
|
||||
get settings_payment_path
|
||||
assert_response :success
|
||||
assert_select(
|
||||
"a",
|
||||
text: I18n.t("views.settings.payments.show.one_time_contribution_link_text"),
|
||||
count: 0
|
||||
)
|
||||
assert_select "p", text: I18n.t("views.settings.payments.show.payment_via_stripe")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,4 +60,20 @@ class Provider::StripeTest < ActiveSupport::TestCase
|
||||
stripe.payment_link_url(payment_link_id: "plink_test123")
|
||||
)
|
||||
end
|
||||
|
||||
test "returns nil when payment link retrieval fails" do
|
||||
payment_links = mock
|
||||
payment_links.expects(:retrieve)
|
||||
.with("plink_test123")
|
||||
.raises(StandardError, "not found")
|
||||
|
||||
client = mock
|
||||
client.stubs(:v1).returns(OpenStruct.new(payment_links: payment_links))
|
||||
|
||||
Stripe::StripeClient.stubs(:new).returns(client)
|
||||
Sentry.expects(:capture_exception).with(instance_of(StandardError))
|
||||
stripe = Provider::Stripe.new(secret_key: "foo", webhook_secret: "bar")
|
||||
|
||||
assert_nil stripe.payment_link_url(payment_link_id: "plink_test123")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user