Add Stripe contribution text to upgrade page

Agent-Logs-Url: https://github.com/we-promise/sure/sessions/38c25233-f774-4eb1-a88a-bca97d95d848

Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-06 16:02:19 +00:00
committed by GitHub
parent 64424428e7
commit f82e203bdd
6 changed files with 69 additions and 16 deletions

View File

@@ -11,6 +11,7 @@ class SubscriptionsController < ApplicationController
redirect_to root_path, notice: "You are already contributing. Thank you!"
else
@plan = params[:plan] || "annual"
@one_time_contribution_url = stripe&.one_time_contribution_url
render layout: "onboardings"
end
end

View File

@@ -144,6 +144,20 @@ module ApplicationHelper
markdown.render(text).html_safe
end
def stripe_one_time_contribution_text(url)
return t("settings.payments.show.payment_via_stripe") if url.blank?
contribution_link = link_to(
t("settings.payments.show.one_time_contribution_link_text"),
url,
class: "font-medium text-primary hover:underline transition",
target: "_blank",
rel: "noopener noreferrer"
)
t("settings.payments.show.payment_via_stripe_html", contribution_link: contribution_link)
end
# Generate the callback URL for Enable Banking OAuth (used in views and controller).
# In production, uses the standard Rails route.
# In development, uses DEV_WEBHOOKS_URL if set (e.g., ngrok URL).

View File

@@ -60,22 +60,7 @@
<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">
<% 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
) %>
<% else %>
<%= t(".payment_via_stripe") %>
<% end %>
<%= stripe_one_time_contribution_text(@one_time_contribution_url) %>
</p>
</div>
</div>

View File

@@ -45,6 +45,10 @@
</div>
<div class="text-center space-y-2">
<p class="text-sm text-secondary">
<%= stripe_one_time_contribution_text(@one_time_contribution_url) %>
</p>
<%= render DS::Button.new(
text: t("subscriptions.upgrade.contribute_and_support_sure"),
variant: "primary",

View File

@@ -61,6 +61,36 @@ class SubscriptionsControllerTest < ActionDispatch::IntegrationTest
assert_equal "test-customer-id", @family.reload.stripe_customer_id
end
test "upgrade shows one-time contribution link when available" do
@mock_stripe.expects(:one_time_contribution_url)
.returns("https://buy.stripe.com/test_payment_link")
get upgrade_subscription_path
assert_response :success
assert_select(
"a[href=?]",
"https://buy.stripe.com/test_payment_link",
text: I18n.t("settings.payments.show.one_time_contribution_link_text")
)
assert_select "button", text: I18n.t("subscriptions.upgrade.contribute_and_support_sure")
end
test "upgrade shows default stripe payment text when contribution link unavailable" do
@mock_stripe.expects(:one_time_contribution_url).returns(nil)
get upgrade_subscription_path
assert_response :success
assert_select(
"a",
text: I18n.t("settings.payments.show.one_time_contribution_link_text"),
count: 0
)
assert_select "p.text-sm.text-secondary", text: I18n.t("settings.payments.show.payment_via_stripe")
assert_select "button", text: I18n.t("subscriptions.upgrade.contribute_and_support_sure")
end
test "creates active subscription on checkout success" do
@mock_stripe.expects(:get_checkout_result).with("test-session-id").returns(
OpenStruct.new(

View File

@@ -24,4 +24,23 @@ class ApplicationHelperTest < ActionView::TestCase
assert_equal "$0.00", totals_by_currency(collection: [ Account.new(currency: "USD", balance: 0) ], money_method: :balance_money)
assert_equal "-$3.00 | €7.00", totals_by_currency(collection: [ @account1, @account2, @account3 ], money_method: :balance_money, negate: true)
end
test "#stripe_one_time_contribution_text(url) renders the contribution link when available" do
link_text = I18n.t("settings.payments.show.one_time_contribution_link_text")
payment_text = I18n.t("settings.payments.show.payment_via_stripe")
expected_html = <<~HTML
#{payment_text} (
<a class="font-medium text-primary hover:underline transition" target="_blank" rel="noopener noreferrer" href="https://buy.stripe.com/test_payment_link">#{link_text}</a>
)
HTML
actual_html = stripe_one_time_contribution_text("https://buy.stripe.com/test_payment_link")
assert_dom_equal expected_html, actual_html
end
test "#stripe_one_time_contribution_text(url) renders default stripe payment text when unavailable" do
assert_equal I18n.t("settings.payments.show.payment_via_stripe"), stripe_one_time_contribution_text(nil)
end
end