Renewal page should not open if subscription has expired for over 15 days
Problem
After Allow users to manually renew subscription up t... (#3341 - closed), we show users the renew button on the subscription card only up to 45 days post expiry of the subscription. However if any user directly enters the renewal url in the browser, it opens up the renewal flow. Details in point 2 of this comment.
Proposal
Right now in the renew
action in subscriptions_controller.rb
, we do not have the check for expiry period to be within 45 days.
def renew
redirect_to(subscription_path, alert: @subscription.renew_enabled_from_message) unless @subscription.renew_enabled?
@available_plans = available_renewal_plans
load_transaction_viewer(TransactionViewer::RENEW)
end
We need to add this check and return to dashboard path (/subscriptions/
) if subscription has expired for over 30 days.
Suggestion (needs to be evaluated): We could also take this opportunity to unify the logic to check if subscription is valid for renewal. We have a logic in subscription_presenter.rb
which checks if the subscription is allowed to be renewed and based on this decides whether to send the attribute renew_subscription_path
to frontend:
def subscription_not_valid_for_renewal?
community_edu_oss_plan = Plan.community_edu_oss_plan?(subscription.plan&.id)
(subscription.educational_or_oss? && !community_edu_oss_plan) ||
(community_edu_oss_plan && !Unleash.enabled?(:community_program_renewals)) ||
subscription.add_on? ||
subscription.expired?(with_grace_period: true) ||
namespace_already_paid
end
We could move this logic to a helper (or on the subscription instance maybe?) so that it can be used in the presenter and controller and we have a unified logic across all scenarios.
Result
User should not be able to open renewal flow by entering url in browser (or by any other means).