From e0d2150e2d47b927171434d10e1ecfd9edf61e97 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 12:31:54 +0000 Subject: [PATCH] Use Stripe payment link id for contribution URL 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> --- .../settings/payments_controller.rb | 6 +++++ app/models/provider/stripe.rb | 6 +++++ app/views/settings/payments/show.html.erb | 26 +++++++++++-------- config/initializers/stripe.rb | 6 ----- config/locales/views/settings/en.yml | 1 + .../settings/payments_controller_test.rb | 5 +++- test/models/provider/stripe_test.rb | 18 +++++++++++++ 7 files changed, 50 insertions(+), 18 deletions(-) delete mode 100644 config/initializers/stripe.rb diff --git a/app/controllers/settings/payments_controller.rb b/app/controllers/settings/payments_controller.rb index 69a422d52..a5f014c3f 100644 --- a/app/controllers/settings/payments_controller.rb +++ b/app/controllers/settings/payments_controller.rb @@ -5,5 +5,11 @@ class Settings::PaymentsController < ApplicationController def show @family = Current.family + @one_time_contribution_url = stripe&.payment_link_url end + + private + def stripe + @stripe ||= Provider::Registry.get_provider(:stripe) + end end diff --git a/app/models/provider/stripe.rb b/app/models/provider/stripe.rb index 3a75dd257..e0786bf83 100644 --- a/app/models/provider/stripe.rb +++ b/app/models/provider/stripe.rb @@ -67,6 +67,12 @@ class Provider::Stripe client.v1.customers.update(customer_id, metadata: metadata) end + def payment_link_url(payment_link_id: ENV["STRIPE_PAYMENT_LINK_ID"]) + return nil if payment_link_id.blank? + + client.v1.payment_links.retrieve(payment_link_id).url + end + private attr_reader :client, :webhook_secret diff --git a/app/views/settings/payments/show.html.erb b/app/views/settings/payments/show.html.erb index 9967b9116..7836da5a5 100644 --- a/app/views/settings/payments/show.html.erb +++ b/app/views/settings/payments/show.html.erb @@ -60,18 +60,22 @@
- <% contribution_link = link_to( - t(".one_time_contribution_link_text"), - Rails.application.config.x.stripe.one_time_contribution_url, - class: "font-medium text-primary hover:underline transition", - target: "_blank", - rel: "noopener noreferrer" - ) %> + <% if @one_time_contribution_url.present? %> + <% contribution_link = link_to( + t(".one_time_contribution_link_text"), + @one_time_contribution_url, + class: "font-medium text-primary hover:underline transition", + target: "_blank", + rel: "noopener noreferrer" + ) %> - <%= t( - ".payment_via_stripe_html", - contribution_link: contribution_link - ) %> + <%= t( + ".payment_via_stripe_html", + contribution_link: contribution_link + ) %> + <% else %> + <%= t(".payment_via_stripe") %> + <% end %>