Skip to content

Commit

Permalink
Update Pro subscription cancellation
Browse files Browse the repository at this point in the history
Collect cancellation reason and pass this to Stripe.

Will allow us to analyse why Pro users cancel their subscriptions.

Fixes #8563
  • Loading branch information
gbp committed Feb 20, 2025
1 parent 1c79af7 commit a633c76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,19 @@ $(document).ready(function() {
// Pro subscription cancellation message controls
$(document).ready(function() {
$(".js-cancel-subscription__message").toggle();

$("input.js-cancel-subscription__submit").prop(
'disabled',
!$("select.js-cancel-subscription__reason").val()
);
});

$(".js-control-cancel-subscription__message").click(function(){
$(".js-cancel-subscription__message").slideToggle( 150 );
});

$("select.js-cancel-subscription__reason").on('change', function(){
$("input.js-cancel-subscription__submit").prop(
'disabled', !$(this).val()
);
});
8 changes: 7 additions & 1 deletion app/controllers/alaveteli_pro/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ def destroy

@subscription = current_user.pro_account.subscriptions.
retrieve(params[:id])
@subscription.update(cancel_at_period_end: true)

@subscription.update(
cancel_at_period_end: true,
cancellation_details: {
feedback: params[:cancellation_reason]
}
)

flash[:notice] = _('You have successfully cancelled your subscription ' \
'to {{pro_site_name}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,25 @@
</li>
</ul>
<% unless cancelled %>
<%= link_to _('I understand and still want to cancel'),
subscription_path(subscription.id),
method: :delete,
data: { confirm: _('Are you sure?') },
class: "button" %>
<%= form_tag subscription_path(subscription.id), method: :delete do %>
<%= select_tag :cancellation_reason,
options_for_select(
[[_("Please select a cancellation reason..."), ""]] +
{
customer_service: _("Customer service was less than expected"),
low_quality: _("Quality was less than expected"),
missing_features: _("Some features are missing"),
other: _("Other reason"),
switched_service: _("I'm switching to a different service"),
too_complex: _("Ease of use was less than expected"),
too_expensive: _("It's too expensive"),
unused: _("I don't use the service enough")
}.invert.to_a
), class: 'js-cancel-subscription__reason' %>

<%= submit_tag _('I understand and still want to cancel'),
data: { confirm: _('Are you sure?') },
class: "button js-cancel-subscription__submit" %>
<% end %>
<% end %>
</div>
2 changes: 2 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Highlighted Features

* Collect cancellation reasons when Pro users cancel their subscriptions (Graeme
Porteous)
* Add Pro upsell on the user rate limited page (Graeme Porteous)
* Update Stripe payment description after Pro payments (Graeme Porteous)
* Add additional InfoRequest embargo scopes (Graeme Porteous)
Expand Down

0 comments on commit a633c76

Please sign in to comment.