Skip to content

Conversation

@leogermani
Copy link
Contributor

@leogermani leogermani commented Aug 7, 2024

This epic refactors the strategy to check for users' subscriptions across the network, as well as recovering the Woo centralized data based on sync events.

I did this on a series of chained PRs to make it easier to parse. They need to be reviewed and merged in order into the Epic branch. Last step is to merge this epic branch into trunk.

In this epic branch, we revert #114, cb5bcb7 and e234425, and do a little fix to ensure the data is always parsed the same way (9140a8e)

PRs to be merged in order

1: #123

This simply creates backfillers for the existing Woo events and creates a user meta where we store the user's network subscriptions.

Testing:

  • On a site with existing Woo data, run wp newspack-network data-backfill newspack_node_subscription_changed and wp newspack-network data-backfill newspack_node_order_changed. Test it in verbose and normal modes
  • Make sure the events are created correctly
  • Propagate the events in the network and make sure the Central Woo dashboard looks right (use wp newspack-network process-webhooks in the Node to speed syncing up)
  • Find a user that has a subscription in a site and take note of their email
  • Find this user in another site in the network
  • Get the usermeta: get_user_meta( $user_id, '_newspack_network_subscriptions', true);
  • Confirm the user meta contains the subscriptions this user has in other sites in the network

2: #124

This PR creates the membership_plan_updated event

Testing

  • On a site with existing membership plans, run wp newspack-network data-backfill newspack_network_membership_plan_updated
  • Confirm events for all existing membership plans is created
  • Propagate the events (either pulling on the Node site or using process-webhooks to send events to the hub)
  • Check the option on the sites include all existing membership plans in the other sites get_option( 'newspack_network_membership_plans' );
  • Edit a membership plan in one site
  • Confirm it created a new membership_plan_updated event
  • Propagate the event
  • Make sure the option is updated in the target site

ALTERNATIVE

#134

The above PR brings back #114 .

We can merge it and release. Then we'll have all the new events. After they are deployed and all the backfills are executed. We can revert #114 again and proceed with the remaining PRs

END OF ALTERNATIVE

3: #125

This is a re-implementation of #114

Testing:

  • Create a granted-on-subscription memberships plan on two network sites, and make them synchronised (set same Network ID in the plan settings)
  • On the Hub, buy a subscription tied to that membership plan as a reader
  • On the Node, Pull all events
  • Visit the Node as an anonymous reader and buy a subscription that gives access to the same membership plan using the same email
  • Run wp newspack-network process-webhooks in the node to sync events to the Hub
  • On the Hub admin, Cancel the subscription
  • Confirm the subscription is kept active, and that a note is added to the user membership saying it was kept active because there is an active subscription in the Node

4: #126

This is a re-implementation of #112

Testing:

  • Create a granted-on-subscription memberships plan on two network sites, and make them synchronised (set same Network ID in the plan settings)
  • Make sure to sync the latest events by running wp newspack-network process-webhooks and wp newspack-network sync-all in the Node
  • you should see the newspack_network_membership_plan_updated events in the Event log for both the plan in the hub and the plan in the node
  • you also should see that the newspack_network_membership_plans option populated in both sites (this is what we tested in Add/membership plan updated #124
  • One one site, buy the subscription, which should grant you the plan
  • On the second site, log in/register using the same email address
  • On the second site, try to buy the membership-granting subscription – observe it's not allowed

Captura de tela de 2024-08-07 12-42-47

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

One oddity I've noticed while looking at the event log: when a new subscription is made on a node site and synchronized to the hub site, two newspack_node_subscription_changed are created. The only difference between the events is that one of them will have a products key in the JSON payload.

@leogermani
Copy link
Contributor Author

Thank you so much for the reviews @adekbadek

I've addressed the issues on the first one. Let's take it step by step. Once that is ok, I'll move to the next one

@leogermani
Copy link
Contributor Author

Actually I went ahead and replied at all the other comments

@leogermani
Copy link
Contributor Author

Merging this PR now that #134 has been incorporated.

I'll spin up a new epic branch to accomodate #125 and #126

@leogermani leogermani merged commit 4f45d61 into trunk Sep 9, 2024
@leogermani leogermani deleted the epic/subscription-membership-sync branch September 9, 2024 14:41
adekbadek pushed a commit that referenced this pull request Sep 10, 2024
* Revert "feat(admin): subscriptions view"

This reverts commit cb5bcb7.

* Revert "feat: remove hub's subscriptions and orders"

This reverts commit e234425.

* feat: remove api requests from woo item changed

* feat: add backfillers for order and subscription_changed

* feat: add user subscriptions metadata

* fix: ensure assoc array when processing webhook data

* feat: add membership plan updated event and backfiller

* feat: add subscription products to woo central dashboard

* fix: remove duplicate listeners
matticbot pushed a commit that referenced this pull request Sep 20, 2024
# [2.2.0-alpha.1](v2.1.0...v2.2.0-alpha.1) (2024-09-20)

### Bug Fixes

* **sync:** use `newspack_esp_sync_contact` filter for the `network_registration_site` field ([#132](#132)) ([3755d07](3755d07))

### Features

* subscriptions and  memberships sync reimplementation ([#122](#122)) ([04fc845](04fc845))
matticbot pushed a commit that referenced this pull request Oct 8, 2024
# [2.2.0](v2.1.0...v2.2.0) (2024-10-08)

### Bug Fixes

* **sync:** use `newspack_esp_sync_contact` filter for the `network_registration_site` field ([#132](#132)) ([3755d07](3755d07))

### Features

* subscriptions and  memberships sync reimplementation ([#122](#122)) ([04fc845](04fc845))
leogermani added a commit that referenced this pull request Nov 4, 2024
* Epic/subscription membership sync (#122)

* Revert "fix(memberships-sync): handle active subs from other nodes (#114)"

This reverts commit 97f9a58.

* Revert "feat(admin): subscriptions view"

This reverts commit cb5bcb7.

* Revert "feat: remove hub's subscriptions and orders"

This reverts commit e234425.

* feat: remove api requests from woo item changed

* feat: add backfillers for order and subscription_changed

* feat: add user subscriptions metadata

* fix: ensure assoc array when processing webhook data

* feat: add product id in the array keys

* feat: add membership plan updated event and backfiller

* feat: add product id to array jeys

* feat: add subscription products to woo central dashboard

* fix: remove duplicate listeners

* Revert "Revert "fix(memberships-sync): handle active subs from other nodes (#114)""

This reverts commit 4acd965.

* remove merge leftovers

* fix: fix constant name

* Revert "fix(memberships-sync): handle active subs from other nodes (#114)"

This reverts commit 97f9a58.

* feat: handle active subs in other sites when cancelling memberships

* feat: limit subscription purchase for user with network membership

* chore: remove unused file

* Update tests/unit-tests/test-subscription-integration.php

Co-authored-by: Adam Cassis <adam@adamcassis.com>

* tests: readability

* fix: prevent the same note being added multiple times

---------

Co-authored-by: Adam Cassis <adam@adamcassis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants