[4.x]: Users are unable to cancel their subscriptions #3105
Replies: 5 comments
-
@martyspain This is the expected behavior on the latest version. We are planning to add more granular subscription permission in future releases. |
Beta Was this translation helpful? Give feedback.
-
OK, thanks for clarifying. I think that this should be added to the Commerce docs and release notes, to help others coming along who may have encountered the same issue. |
Beta Was this translation helpful? Give feedback.
-
@pdaleramirez @martyspain Sorry for necroing this, but there still aren't any more granular permissions. I don't feel comfortable giving 'commerce-manageSubscriptions' permissions to users/groups, as any logged in user with that permission can in theory modify other peoples subscription if they get access to the uid. EVENT_AUTHORIZE_VIEW doesn't seem to be a good workaround as the subscription is not pushed as part of the event. |
Beta Was this translation helpful? Give feedback.
-
I was bitten by this, too, just last week. I created a PR to add this change to the docs and Commerce 4 upgrade guide. |
Beta Was this translation helpful? Give feedback.
-
This was fixed and coming in next version: #3155 (comment) |
Beta Was this translation helpful? Give feedback.
-
What happened?
Description
We are experiencing issues with users unable to cancel subscriptions by submitting a form to
commerce/subscriptions/cancel
. Doing so returns an 'Unable to cancel subscription at this time' error, which seems to be related to a change to the line that checks if the user can modify this subscription.This line in
commerce/controllers/Subscription.php
checks if the user can modify the subscription by calling the subscription'scanSave
method:This in turn calls the parent Element class's
canView
method, and if this returns false it falls through to checking if the user has permissions to manage subscriptions:The call to the Element
canView
method just creates a newAuthorizationCheckEvent
which sets anauthorized
property to befalse
, then triggers theEVENT_AUTHORIZE_VIEW
event and returns theauthorized
property of the event. I can't find any Subscription-specific code that listens to this event and checks if the user should be authorized to modify their subscription, so it seems that this call will always return false.This suggests that for customers to cancel their subscriptions, we have to either assign them to a user group that has the
commerce-manageSubscriptions
permission applied, or write an event listener into our own application logic that listens forEVENT_AUTHORIZE_VIEW
and modifies theauthorized
property accordingly.I can't find anything in the Commerce 4 migration documentation, the Commerce Subscription documentation or the Commerce Stripe plugin documentation that mentions this permission now being required.
Am I correct in thinking that this is all working as expected and as of Commerce 4 we must make sure we assign the
commerce-manageSubscriptions
permission to customers now in order to allow them to cancel their own subscriptions? Or is this a bug that needs resolving?Steps to reproduce
commerce/subscriptions/cancel
endpointExpected behavior
The subscription to be cancelled successfully
Actual behavior
The cancel controller method returns an error and the subscription is not cancelled.
Craft CMS version
4.2.3
Craft Commerce version
4.1.1
PHP version
8.0
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
Beta Was this translation helpful? Give feedback.
All reactions