diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index da02534bd..f1bd3a8cf 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7f0aad0bd..88f128e08 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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). diff --git a/app/views/settings/payments/show.html.erb b/app/views/settings/payments/show.html.erb index 7836da5a5..609c321b1 100644 --- a/app/views/settings/payments/show.html.erb +++ b/app/views/settings/payments/show.html.erb @@ -60,22 +60,7 @@
- <% 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) %>
+ <%= stripe_one_time_contribution_text(@one_time_contribution_url) %> +
+ <%= render DS::Button.new( text: t("subscriptions.upgrade.contribute_and_support_sure"), variant: "primary", diff --git a/test/controllers/subscriptions_controller_test.rb b/test/controllers/subscriptions_controller_test.rb index c8076218a..2cb67ea08 100644 --- a/test/controllers/subscriptions_controller_test.rb +++ b/test/controllers/subscriptions_controller_test.rb @@ -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( diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index e4c3bf361..0603b4de1 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -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} ( + #{link_text} + ) + 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