-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(subscriptions): add cancellation reason metadata #3568
Conversation
a4963d1
to
79f9590
Compare
c09ba1b
to
6deebfd
Compare
return; | ||
} | ||
if ( 'cancelled' === $to_status && ! in_array( $from_status, [ 'cancelled', 'expired' ], true ) ) { | ||
$meta_value = is_admin() ? self::CANCELLATION_REASON_ADMIN_CANCELLED : self::CANCELLATION_REASON_USER_CANCELLED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want a third expired
option here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, let's leave this for another PR, but I left another comment because it didn't work for me
@@ -285,6 +285,12 @@ private static function get_order_metadata( $order, $payment_page_url = false ) | |||
$metadata['product_name'] = reset( $subscription_order_items )->get_name(); | |||
} | |||
} | |||
|
|||
// Record the cancellation reason if the subscription was cancelled. | |||
$cancellation_reason = $current_subscription->get_meta( WooCommerce_Subscriptions::CANCELLATION_REASON_META_KEY, '' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting an error that I believe is coming from this line
Class "Newspack\Reader_Activation\Sync\WooCommerce_Subscriptions" not found
The meta was not added neither to the subscription nor to the ESP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Good catch! Fixed in 2a51cf4
The meta was not added neither to the subscription nor to the ESP
Strange that the meta was not being added to the subscription though. I just updated the testing instructions, but make sure you've defined the ff constant to see the changes at work.
Also, I've run into this problem in the past so thought I'd mention it here as well, but if you have a contact with too many meta fields in MC, the newer fields will simply not be added. You can still check the logs for what will be synced with Newspack logging enabled in these cases:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure you've defined the ff constant to see the changes at work.
I'd never make such a mistake........ 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I've run into this problem in the past so thought I'd mention it here as well, but if you have a contact with too many meta fields in MC, the newer fields will simply not be added.
Yes. This is a known issue. It's a limitation we have to deal with Mailchimp, that's why we can choose which fields we want. If you scroll the logs up a little you will see that there was an attempt to create the merge field and it failed because it reached the limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chickenn00dle I'm not getting an infinite loop when I cancel the subscription.
I added some logging and I can see the maybe_record_cancelled_subscription_meta
method being called over and over again...
the woo_meta was added successfully though
class Subscriptions_Meta { | ||
const CANCELLATION_REASON_META_KEY = 'newspack_subscriptions_cancellation_reason'; | ||
const CANCELLATION_REASON_USER_CANCELLED = 'user-cancelled'; | ||
const CANCELLATION_REASON_ADMIN_CANCELLED = 'manually-cancelled'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time I see this value I have to ask myself if manually means by the admin or by the user. Why not call this admin-cancelled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the names @kmwilkerson decided on here. But am happy to change this if there is a strong preference otherwise.
I will say that from the perspective of a non-technical publisher, I think manual
probably makes more sense than admin
.
That's odd. I can't reproduce this on my end when I cancel as admin or as the user. This hook should only trigger when a subscription status is actually updated and once a subscription is cancelled it should no longer be possible to update the status again? That said, I went ahead and added a preliminary check for cancellation reason meta before updating in the method in 7c582fb. Maybe this can help resolve things on your end? If not, would you mind sharing your steps to reproduce. |
This will be triggered by any request. If I close the reader window and navigate as an admin, it will trigger the cancellation and store |
Yes. As I user, I cancelled the subscription and then closed the window... did everything else having only the admin tab active |
b13e91f
to
c531e69
Compare
c531e69
to
558d515
Compare
*/ | ||
public function test_is_enabled() { | ||
$is_enabled = WooCommerce_Subscriptions::is_enabled(); | ||
$this->assertTrue( $is_enabled, 'WooCommerce Subscriptions integration should be enabled when Feature Flag is present.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to test the case where FF is not defined, as well as when Reader Activation is not enabled, but could not find a way to modify globally defined constants between test runs. I tried @preserveGlobalState
paired with @runInSeparateProcess
, but this ended up removing other globals the tested method relied on.
Would love any advice on how to approach this if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no good way to test constants... The best we could do would be to change the approach we use for Feature Flags and use something else to handle these things
This is now ready for another round of review @leogermani. I updated the strategy for determining admin vs. reader cancellations by adding an additional set of meta values for the This means that if a reader "cancels" to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit to avoid that infinite loop again. Everything looks good now :)
Hey @chickenn00dle, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
This PR adds meta data to cancelled woo subscriptions and uses this new meta to sync cancellation reason to ESPs for cancelled subscriptions.
# [5.10.0-alpha.1](v5.9.1...v5.10.0-alpha.1) (2024-12-12) ### Bug Fixes * duplicate orders save on cron ([#3604](#3604)) ([ec69167](ec69167)) * **ras-acc:** re-add recaptcha to the WooCommerce checkout ([#3605](#3605)) ([f42a75b](f42a75b)) * **ras:** do not require Woo plugins if using NRH ([#3614](#3614)) ([363a834](363a834)) * **wcs:** remove subscriptions expiration feature flag ([#3618](#3618)) ([7c175d9](7c175d9)) * **wcs:** update subscription expiration feature ([#3613](#3613)) ([ebf6e6d](ebf6e6d)) * **wcs:** update subscriptions expiration cli behavior ([#3617](#3617)) ([07e768c](07e768c)) ### Features * **subscriptions:** add cancellation reason metadata ([#3568](#3568)) ([de83e02](de83e02)) * **wc:** duplicate orders admin notice ([#3555](#3555)) ([cb764e3](cb764e3)) * **wcs:** add expired subscription cli tool ([#3593](#3593)) ([5d39398](5d39398)) * **webhooks:** filter request priority ([#3587](#3587)) ([1928a6a](1928a6a)) * **woocommerce-subscriptions:** add url redirect for wc subscription renewals ([#3525](#3525)) ([5b14aeb](5b14aeb)) ### Reverts * Revert "feat: command to initialize cron job to slowly backfill CAP term data (#3425)" (#3620) ([c9a9d45](c9a9d45)), closes [#3425](#3425) [#3620](#3620)
🎉 This PR is included in version 5.10.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Closes https://app.asana.com/0/1208702687864922/1208702687865961
This PR adds meta data to cancelled woo subscriptions and uses this new meta to sync cancellation reason to ESPs for cancelled subscriptions.
How to test the changes in this Pull Request:
Before testing be sure to set the feature flag in wp-config:
define( 'NEWSPACK_SUBSCRIPTIONS_EXPIRATION', true );
. Also ensure Newspack logging is active on the site:define( 'WP_NEWSPACK_DEBUG', true )
Subscription Cancellation Reason
is checked:manually-cancelled
:user-cancelled
Subscription Cancellation Reason
field with the expected value is present in the normalized ESP sync data:Other information: