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>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-04 12:31:54 +00:00
committed by GitHub
parent 6378170d5a
commit e0d2150e2d
7 changed files with 50 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -60,18 +60,22 @@
<div class="flex items-center gap-2">
<%= image_tag "stripe-logo.svg", class: "w-5 h-5 shrink-0" %>
<p class="text-secondary text-sm">
<% 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 %>
</p>
</div>
</div>

View File

@@ -1,6 +0,0 @@
Rails.application.configure do
config.x.stripe.one_time_contribution_url = ENV.fetch(
"STRIPE_ONE_TIME_CONTRIBUTION_URL",
"https://buy.stripe.com/3cIcN6euM23D7GQ3wT97G00"
)
end

View File

@@ -24,6 +24,7 @@ en:
payments:
show:
page_title: Payments
payment_via_stripe: Payment via Stripe
payment_via_stripe_html: Payment via Stripe (%{contribution_link})
one_time_contribution_link_text: one-time contribution here
subscription_subtitle: Update your credit card details

View File

@@ -15,12 +15,15 @@ class Settings::PaymentsControllerTest < ActionDispatch::IntegrationTest
test "shows payment settings when family has stripe_customer_id" do
@family.update!(stripe_customer_id: "cus_test123")
stripe = mock
stripe.expects(:payment_link_url).returns("https://buy.stripe.com/test_payment_link")
Provider::Registry.stubs(:get_provider).with(:stripe).returns(stripe)
get settings_payment_path
assert_response :success
assert_select(
"a[href=?]",
Rails.application.config.x.stripe.one_time_contribution_url,
"https://buy.stripe.com/test_payment_link",
text: I18n.t("views.settings.payments.show.one_time_contribution_link_text")
)
end

View File

@@ -42,4 +42,22 @@ class Provider::StripeTest < ActiveSupport::TestCase
assert_match /sub_.*/, result.subscription_id
end
end
test "retrieves payment link url from stripe" do
payment_links = mock
payment_links.expects(:retrieve)
.with("plink_test123")
.returns(OpenStruct.new(url: "https://buy.stripe.com/test_payment_link"))
client = mock
client.stubs(:v1).returns(OpenStruct.new(payment_links: payment_links))
Stripe::StripeClient.stubs(:new).returns(client)
stripe = Provider::Stripe.new(secret_key: "foo", webhook_secret: "bar")
assert_equal(
"https://buy.stripe.com/test_payment_link",
stripe.payment_link_url(payment_link_id: "plink_test123")
)
end
end