Skip to content
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

✨ Add support for Single Post Subscription (including fix as per Google Extended Access UX) #2

Open
wants to merge 31 commits into
base: trunk
Choose a base branch
from

Conversation

AnuragVasanwala
Copy link
Contributor

The goal of the PR is to add support for Single Post Subscription by utilizing Google Extended Access and COOKIE based authentication for the post.

Google Extended Access Prompt

Changes proposed in this Pull Request:

  • 📜 Register Google Extended Script and Callbacks.
  • ⚙️ Add Option Tab (Dashboard -> WooCommerce -> Settings -> Memberships -> Newspack Extended Access).
  • ✅ Checks to verify valid dependencies.
  • ⛔️ Show admin notice when dependencies do not met or configured incorrectly.
  • 🧩 Google Prompts
    • 🔐 Display Google Login Prompt when no user is logged.
    • 🔏 Display Google Subscribe Prompt when user is logged in but not subscribed to the post.
  • 🍪 COOKIE based authentication (based on 'newspack_' . md5( $post_id . $user_id )).
  • 🧪 Unit Test
    • Google Extended Access Script Registration
    • REST Controller
    • Dependency Manager (tests cannot be performed due to dependency plugin WooCommerce Memberships)
    • Single Post Subscription controller (tests cannot be performed due to dependency plugin WooCommerce Memberships)

How to test the changes in this Pull Request

  1. Change branch to this PR branch.
  2. Install dependencies composer install
  3. Prepare zip and upload to site OR directly copy content of the repository to you site.
  4. Make sure to install and configure dependencies.
  5. Configure Google Client API ID.
  6. Goto one of the premium post and make sure to add test URL parameters:
    ?gaa_at=testp&gaa_n=1234567&gaa_sig=testsig&gaa_ts=999999999

Important Note
Account with Administrator or Editor role cannot subscribe. This is Newspack restriction thus users cannot login via Extended Access. Hence, you need another Google account to login & subscribe to a post via Extended Access dialog.

UX Flow

Scene 1: Anonymous User (New User)

  1. User opens a premium post (that includes ?gaa_at=testp&gaa_n=1234567&gaa_sig=testsig&gaa_ts=999999999 parameters embedded by Google News).
  2. Google Extended Access requests REST Controller to get logged in user.
    a. REST Controller responds with NO_USER_LOGGED_IN.
    b. Google Extended Access now displays Google Login Prompt.
    c. User login through Google Login Prompt (and user gets automatically registered by controller as customer).
  3. Google Extended Access now ask REST Controller for user's subscription status for the post (by verifying COOKIE).
    a. REST Controller responds with NO_SUBSCRIPTION found for user for the post.
    b. Google Extended Access displays Google Subscription Prompt.
    c. Here, if user click on Subscribe button, user will be forwarded to the paywall page.
    d. If user click X button, Google Subscription Prompt went away, a COOKIE on the machine will be created and Google Extended Access unlocks article.

Scene 2: Logged in User with No Subscription

  1. User opens a premium post (that includes ?gaa_at=testp&gaa_n=1234567&gaa_sig=testsig&gaa_ts=999999999 parameters embedded by Google News).
  2. Google Extended Access requests REST Controller to get logged in user.
    a. REST Controller responds with LOGGED_IN user but post NOT_GRANTED.
  3. Google Extended Access now ask REST Controller for user's subscription status for the post (by verifying COOKIE).
    a. REST Controller responds with NO_SUBSCRIPTION found for user for the post.
    b. Google Extended Access displays Google Subscription Prompt.
    c. Here, if user click on Subscribe button, user will be forwarded to the paywall page.
    d. If user click X button, Google Subscription Prompt went away, a COOKIE on the machine will be created and Google Extended Access unlocks article.

Scene 3: Registered in User with Subscription

  1. User opens a premium post (that includes ?gaa_at=testp&gaa_n=1234567&gaa_sig=testsig&gaa_ts=999999999 parameters embedded by Google News).
  2. Google Extended Access requests REST Controller to get logged in user.
    a. REST Controller responds with NO_USER_LOGGED_IN.
    b. Google Extended Access now displays Google Login Prompt.
    c. User login through Google Login Prompt.
  3. Google Extended Access now ask REST Controller for user's subscription status for the post (by verifying COOKIE).
    a. REST Controller responds with VALID_SUBSCRIPTION found for user for the post.
    b. Google Extended Access unlocks article.

Scene 4: Logged in User with Subscription

  1. User opens a premium post (that includes ?gaa_at=testp&gaa_n=1234567&gaa_sig=testsig&gaa_ts=999999999 parameters embedded by Google News).
  2. Google Extended Access requests REST Controller to get logged in user.
    a. REST Controller responds with LOGGED_IN user with VALID_SUBSCRIPTION.
    b. Google Extended Access unlocks article.

Dependency

This plugin requires following plugin to be installed, configured and active:

Configuration

This plugin requires a valid Google Client API ID specific to your Newspack Site domain. Please create a new Google Client API ID for your site, if not already created. Follow instruction provided on Setting up Google Client API ID.

Make sure dependent plugins are installed, configured and active on your site.

Setting up Google Client API ID

Login to you Newspack site dashboard as an Administrator:

  1. Open WooCommerce menu
  2. Select Settings menu
  3. Select Memberships tab
  4. Select sub-tab Newspack Extended Access
  5. Add your valid Google Client API ID

Configure Google Client API ID

Update php and js scripts to use fields defined by option page.
✨ Add `Extended Access` submenu option page inside `WooCommerce`
When saving Google Client API ID, notice displayed/hide after second attempt. This has been fixed by using `admin_notices` hook.
🔥 Fix critical issue where `$allowed_referrers` is not set correctly
This commit addresses:
- Test files are prefixed with `test-*`
- Remove unnecessary codeblock
- Update few constants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant