Skip to content

feat(integrations): add subscription and donation metadata#4597

Open
chickenn00dle wants to merge 4 commits intotrunkfrom
feat/add-subscription-donation-metadata
Open

feat(integrations): add subscription and donation metadata#4597
chickenn00dle wants to merge 4 commits intotrunkfrom
feat/add-subscription-donation-metadata

Conversation

@chickenn00dle
Copy link
Copy Markdown
Contributor

@chickenn00dle chickenn00dle commented Mar 24, 2026

Summary

  • Implements get_metadata() for the Subscription contact metadata class with 13 get methods covering subscriber status, active count, dates, billing cycle, payments, product names, coupon codes, and cancellation reasons — all filtered to non-donation subscriptions only.
  • Implements get_metadata() for the Donation class by extending Subscription, inverting the filter to donation-only, and adding donor status labels (Monthly/Yearly/Ex-* Donor), one-time donation fallbacks, and previous donation amount tracking.

Closes NPPD-1388

Test plan

  1. Enabled the following in wp-config.php:
define( 'NEWSPACK_LOG_LEVEL', 3 );
define( `NEWSPACK_SYNC_METADATA_VERSION`, '1.0' );
define( 'NEWSPACK_INTEGRATIONS_SETTINGS_ENABLED', true );
  1. Navigate to Audience > Integrations > ESP and confirm the donation and subscription fields listed in the linear task are available in the outgoing metadata section
  2. Check them all and save, confirming they persist on reload
  3. As a new reader, register to the site
  4. Check the logs and verify the contact is synced with the relevant metadata in a default empty state (note you can also just check the connected ESP, however you may run into issues with merge field limits depending on the ESP):
    Screenshot 2026-03-25 at 16 47 37
  5. As the same reader, purchase a one-time donation
  6. Check the logs for another sync entry, this time with the donation status, product name, amount, and date populated
  7. As the same reader, purchase a recurring donation
  8. Check the logs for another sync entry, this time with all relevant donation fields populated (only end date and previous product/amount should be empty)
  9. As the reader, purchase a non-donation subscription product
  10. Check the logs for another sync entry, this time with all the relevant subscription fields populated (only end date, cancellation reason, and previous product fields should be empty)
  11. Now cancel the subscription (either as the reader or manually as the admin)
  12. Check the logs for another sync entry, this time the subscription status, count, end date, and reason should be populated
  13. Finally, cancel the recurring donation
  14. Check the logs for another sync entry, this time the donation status, count, and end date should be populated

🤖 Generated with Claude Code

@chickenn00dle chickenn00dle force-pushed the feat/add-subscription-donation-metadata branch 2 times, most recently from 0980297 to ec9dfe1 Compare March 24, 2026 21:34
chickenn00dle and others added 2 commits March 25, 2026 15:50
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chickenn00dle chickenn00dle force-pushed the feat/add-subscription-donation-metadata branch from ec9dfe1 to 33c8baf Compare March 25, 2026 21:41
@chickenn00dle chickenn00dle marked this pull request as ready for review March 25, 2026 21:41
@chickenn00dle chickenn00dle requested a review from a team as a code owner March 25, 2026 21:41
Copilot AI review requested due to automatic review settings March 25, 2026 21:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Reader Activation contact metadata for WooCommerce Subscriptions and Donations so ESP syncs can include richer subscription/donation lifecycle fields.

Changes:

  • Implemented Subscription::get_metadata() with 13 subscription-related fields (status, counts, dates, billing, product, coupon, last payment, cancellation reason).
  • Implemented Donation::get_metadata() by extending Subscription, filtering to donation-only, and adding donor status + one-time donation fallbacks and previous amount tracking.
  • Added unit tests + expanded WooCommerce test mocks; added a shared date formatter in the Contact_Metadata base class and extra sync logging.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit-tests/reader-activation-sync/class-test-subscription-metadata.php New unit tests covering Subscription metadata fields and edge cases.
tests/unit-tests/reader-activation-sync/class-test-donation-metadata.php New unit tests covering Donation metadata fields, donor labels, and switch/previous amount logic.
tests/mocks/wc-mocks.php Extends WC mocks to support new metadata logic (products/items, coupons, related orders, order lookup).
includes/reader-activation/sync/contact-metadata/class-subscription.php Implements Subscription metadata retrieval with caching and helpers.
includes/reader-activation/sync/contact-metadata/class-donation.php Implements Donation metadata by reusing Subscription helpers + donation-specific fallbacks.
includes/reader-activation/sync/class-contact-sync.php Adds additional logging around contact sync calls.
includes/reader-activation/sync/class-contact-metadata.php Adds a shared date format constant and formatter helper.
Comments suppressed due to low confidence (1)

tests/mocks/wc-mocks.php:318

  • The mock WC_Subscription::get_date() only accepts one parameter, but production WC_Subscription::get_date() is commonly called with a timezone/context argument (e.g., get_date('start','site')). The new Subscription metadata code passes a second argument, which can trigger warnings/errors in tests on newer PHP versions; update the mock signature to accept an optional second parameter (and ignore it).
	public function get_date( $type ) {
		return $this->data['dates'][ $type ] ?? 0;
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tests/mocks/wc-mocks.php:318

  • WC_Subscription::get_date() in this test mock only accepts one argument, but the new metadata code calls $subscription->get_date( ..., 'site' ) (matching the real WooCommerce Subscriptions signature). In PHP 8 this will throw an ArgumentCountError in unit tests. Update the mock method signature to accept the optional timezone/context parameter (or use variadic args) and ignore it as needed so tests exercise the production call shape.
	public function get_date( $type ) {
		return $this->data['dates'][ $type ] ?? 0;
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chickenn00dle chickenn00dle added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants