Skip to content

Read one connection status from GoDAM Central and show renewal instead of signup - #2377

Open
rudrakshi-gupta wants to merge 6 commits into
developfrom
feat/one-connection-status
Open

rudrakshi-gupta wants to merge 6 commits into
developfrom
feat/one-connection-status

Conversation

@rudrakshi-gupta

@rudrakshi-gupta rudrakshi-gupta commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes rtCamp/godam-plugin-wp#101

GoDAM used to know only "valid key or not". So a site whose trial or plan lapsed was sent back to the signup screens instead of renewal, and nothing told the owner a trial was about to end. GoDAM Central now sends one connection status with every key check (rtCamp/godam-core#1957, rtCamp/frappe-stripe-subscription#289, both merged). This PR stores that status and uses it to pick the right screen and notice.

The connection status only chooses screens and notices. It never switches features on or off: that is still the key status (rtgodam_is_api_key_valid()), as agreed with Mayank and Subodh.

Status When What the site shows
connected Plan active (or in Central's payment grace) Nothing new
trial On a trial Media Library notice: "Your GoDAM trial ends in N days." + upgrade link
expired, key still works Subscription ended but the licence is still active (200 + expired) Dismissible wp-admin notice: "Your GoDAM subscription has ended. Renew to keep Pro features." No full screen
expired, key stopped working Licence inactive (403) GoDAM screens open on "Your GoDAM plan has expired" with Renew, not on signup
unreachable Central didn't answer (plugin side only) Nothing covers the page; the site keeps working
none No key, or a key Central doesn't know (401) The connect screens, as before

A site Central refuses because it isn't on the key's allowed sites (403 whitelist) gets the plan's real status. Renewing can't fix that, so it gets the "check your settings" message, never the renewal screen.

What Central sends (final contract)

verify_api_key now returns connection_status, trial_ends_at, expired_at and organization on every answer:

  • 200:
    • connection_status: connected (Active or Grace Period), trial, expired (subscription lapsed) or none (no subscription yet)
    • trial_ends_at: only on a trial
    • expired_at: the day the subscription lapsed
    • organization
  • 401, unknown key: none, with no organization
  • 403, inactive licence: expired with the organization, but expired_at is null
  • 403, site not on the allowed sites: the subscription's real status and dates

trial_ends_at and expired_at are calendar dates sent as that date's UTC midnight.

Changes

New: inc/classes/enums/class-connection-status.php

  • connected, trial, expired, unreachable, none; from_central() lists the values Central can send.

New: inc/helpers/class-connection.php (RTGODAM\Inc\Helpers\Connection)

  • record( $message, $succeeded, $http_status ) stores Central's answer for the stored key in rtgodam-connection (status, trial end, lapse date, organization):
    • Older Central (no status): a 200 counts as connected and a 401 as none (a key Central doesn't know: the connect screens, not renewal); otherwise the key status decides.
    • 200 + none (the key works but the subscription is still being set up): the key status decides, so a working key is never sent to the connect screen.
    • Organization: kept when a later answer leaves it out.
    • Status no longer expired: clears the dismissed "subscription ended" notice, so it comes back on the next lapse.
  • get_status():
    • No key: none.
    • Last check couldn't reach Central: unreachable.
    • Otherwise: Central's status, falling back to the key status.
  • get_trial_days_left(): calendar days in the site's timezone, so a site west of UTC isn't shown one day short.
  • get_licence_failed_since(): when the licence stopped working on this site, which is the start of GoDAM for Woo's grace period (Hide Transcoded MPD URL #113).
    • Counted from: the first failed check (rtgodam-api-key-error-since), not Central's expired_at. expired_at is when the subscription lapsed, and the licence can keep working long after it, so counting from it could cut Woo's grace period short.
    • expired_at is used only when no failed check is on record.
    • Returns 0 while the licence works.
  • get_renewal_url(): https://app.godam.io/godam_upgrade?organization=<org>&wp_return=<dashboard>, or the plans page when the organization is unknown. Filterable with rtgodam_renewal_url.
  • should_show_subscription_ended_notice() and dismiss_subscription_ended_notice().
  • clear(): called when the key is removed, and before a different key's answer is recorded.

Key check (admin/godam-transcoder-functions.php)

  • Records Central's answer for the stored key on success (200) and on refusal (401/403), with the HTTP status. A mistyped new key changes nothing.
  • Saving a different key starts from a fresh answer, so the previous key's organization never ends up in the new key's renewal link.

Uninstall (uninstall.php)

  • Removes rtgodam-connection and rtgodam-subscription-ended-notice-dismissed with the other key options.

Data sent to the admin pages (inc/helpers/custom-functions.php)

  • window.userData gets connectionStatus, trialDaysLeft and renewalUrl, also when there's no key.

Renewal screen (pages/onboarding)

  • New RenewScreen: "Your GoDAM plan has expired", with:
    • Renew plan: the organization's upgrade link
    • I've renewed, check again: checks the key again. If GoDAM couldn't reach Central (verification_failed) or the request failed (e.g. an expired nonce), it says "Couldn't reach GoDAM"; it says "still expired" only when Central answered
    • Have a different license key? Use it instead
    • Contact support
  • Back from the license key screen returns to this screen for a site with a lapsed plan, instead of the new-user signup (LicenseKeyScreen.jsx).
  • The onboarding overlay opens on this screen when the status is expired and the key no longer works (class-pages.php). A site whose subscription ended but whose licence still works gets the notice below instead of a screen.

Notices (admin/class-rtgodam-transcoder-admin.php, assets/src/js/admin.js)

  • Trial: info notice in the Media Library with days left and an upgrade link (only while the key works).
  • Subscription ended, licence active: dismissible warning on wp-admin for administrators. The dismissal is saved over AJAX (nonce-checked), and the notice comes back on the next lapse.
  • Key expired: the existing message now links to the organization's renewal page instead of settings.
  • Refused but plan not lapsed (site not on allowed sites, or a key Central doesn't know): the generic "check your settings" message, since renewing can't fix it.

Dependencies

Screenshots

Renewal screen (plan expired, key stopped working)
1-renewal-screen
Subscription ended, licence still active (dismissible)
2-subscription-ended-notice
Trial: days left in the Media Library
3-trial-notice-media-library
Key expired: Media Library message links to renewal
4-expired-media-library-notice
Site refused, plan still live: points to settings, not renewal
5-refused-site-notice

How to test

Build first: npm run build.

On a site with a working key, first stop GoDAM re-checking the key while you test (it re-checks about once an hour and would overwrite the test values):

wp eval '$d = get_option( "rtgodam_user_data" ); $d["timestamp"] = $d["checked_at"] = time() + YEAR_IN_SECONDS; unset( $d["retry_at"] ); update_option( "rtgodam_user_data", $d );'

1. Real Central answer

  • Reset (see below) and open GoDAM → Settings → API Key, then verify the key.
  • wp option get rtgodam-connection --format=json shows status connected (or trial) and your organization.

2. Trial

wp eval 'update_option( "rtgodam-connection", array( "status" => "trial", "trial_ends_at" => strtotime( "today UTC +5 days" ), "expired_at" => 0, "organization" => "acme" ) );'
  • Media Library: "Your GoDAM trial ends in 5 days." with "Upgrade to keep transcoding and other Pro features" linking to app.godam.io/godam_upgrade?organization=acme&wp_return=… in a new tab.
  • Change +5 days to +0 days: "Your GoDAM trial ends today." To +1 days: "1 day".

3. Subscription ended, licence still active (200 + expired)

wp option update rtgodam-connection '{"status":"expired","trial_ends_at":0,"expired_at":0,"organization":"acme"}' --format=json
  • Every wp-admin page shows the yellow "Your GoDAM subscription has ended. Renew to keep Pro features." notice. Renew opens the upgrade link.
  • GoDAM screens are not covered; Pro features keep working.
  • Dismiss it and reload → it stays hidden (rtgodam-subscription-ended-notice-dismissed is set).
  • Set the status to connected, then back to expired → the notice is back.
  • Not shown to non-administrators.

4. Plan expired, key stopped working (403 inactive licence)

wp option update rtgodam-connection '{"status":"expired","trial_ends_at":0,"expired_at":0,"organization":"acme"}' --format=json
wp option update rtgodam-api-key-status expired
wp option update rtgodam-api-key-error-since $(date +%s)
wp eval '$d = get_option( "rtgodam_user_data" ); $d["valid_api_key"] = false; $d["api_key_status"] = "expired"; update_option( "rtgodam_user_data", $d );'
  • GoDAM → Dashboard opens on "Your GoDAM plan has expired", not on signup.
  • Renew plan opens the organization's upgrade link.
  • I've renewed, check again, while still expired: "Your plan still shows as expired…". With Central unreachable, or after the page's nonce expires: "Couldn't reach GoDAM…". After a real renewal it closes and the dashboard loads.
  • Use it instead goes to the license key screen, and its Back returns to the renewal screen (not the free trial signup).
  • Media Library: "Your GoDAM API key has expired… renew your subscription" links to the upgrade page.
  • wp eval 'echo RTGODAM\Inc\Helpers\Connection::get_licence_failed_since();' prints the error-since time, not expired_at.

5. Site refused, plan live (403 site not on allowed sites)

Same as 4, but with "status":"connected".

  • No renewal screen; the dashboard loads.
  • Media Library: "There is an issue with your GoDAM API key… check your settings".

6. Central unreachable

  • Add "retry_at": <future time> to rtgodam_user_data → connectionStatus is unreachable, nothing covers the page, no renewal screen.

7. No key / unknown key

  • Remove the key in Settings → rtgodam-connection is deleted and the connect screens show, as before.

Reset

wp option delete rtgodam-connection rtgodam-api-key-error-since rtgodam-subscription-ended-notice-dismissed rtgodam_user_data
wp option update rtgodam-api-key-status valid
wp eval 'rtgodam_get_user_data( false, HOUR_IN_SECONDS, true );'

Tests

  • tests/php/ConnectionStatusTest.php (37 tests):
    • Central's statuses, with a key-status fallback for an older Central
    • every final Central answer: 200 connected / trial / subscription ended / no subscription yet, 401 unknown key, 403 inactive licence, 403 site not allowed
    • unknown values ignored, unreachable
    • trial days as calendar days, including the last day and timezones
    • grace start from the first failed check (not expired_at), and expired_at only without one
    • renewal URL with and without the organization, organization kept
    • subscription-ended notice: shown, dismissed, comes back on the next lapse
    • key removed
  • tests/php/ApiKeyVerificationResilienceTest.php: a trial recorded with its end date; a success without a status read as connected; a subscription ended on a 200 recorded with its lapse date; an inactive licence (403, expired_at: null) counting from the first failed check; an older Central's 401 read as none and its 403 left to the key status; saving a different key forgetting the previous organization; a rejected new key leaving the stored status alone.
  • pages/onboarding/components/screens/RenewScreen.test.js: opens on renewal for a lapsed plan, renew link for the organization, check again (still expired / Central unreachable / the browser can't fetch / a failed request), use a different key.
  • pages/onboarding/components/screens/LicenseKeyScreen.test.js (new): Back goes to renewal for a lapsed plan, to the start otherwise.
  • All PHP and JS tests pass; phpcs is clean.

…d of signup

- Add a Connection_Status enum (connected, trial, expired, unreachable, none)
  and a Connection helper that stores what verify_api_key returns:
  connection_status, trial_ends_at, organization and (when sent) expired_at
- Read those fields from Central's 200, 401 and 403 answers, only for the stored
  key or a new key being saved, so a mistyped key changes nothing
- On an older Central that doesn't send connection_status, work the status out
  from the key status as before
- Treat a 200 with "none" (subscription still being set up) as connected, and a
  403 that still says connected or trial (site not on the key's allowed sites)
  as no usable key, so neither shows the wrong screen
- Report "unreachable" while Central can't be reached and the last good answer
  is still trusted
- Show a renewal screen in the onboarding overlay when the plan has expired,
  instead of the signup screens: Renew plan, "I've renewed, check again",
  use a different license key, Contact support
- Show the onboarding overlay only for "none" and "expired"; never while Central
  is unreachable
- Build the renewal link from the organization:
  /godam_upgrade?organization=<org>&wp_return=<dashboard>, falling back to the
  Plans page when the organization isn't known
- Count trial days left by calendar date in the site's timezone, since Central
  sends the trial's last day as UTC midnight
- Show "Your GoDAM trial ends in N days" in the Media Library with an upgrade
  link; point the expired notice at renewal, and at Settings when Central
  refused the key for another reason
- Add connectionStatus, trialDaysLeft and renewalUrl to the data the admin
  pages get, for the Woo add-on and the dashboard to use
- Expose when the plan lapsed (Central's expired_at, otherwise the first time the
  site saw the key as expired) for the Woo grace period
- Clear the stored status when the API key is removed
- Add PHP tests for the status helper and for what verify_api_key stores, and
  JS tests for the renewal screen

Refs rtCamp/godam-plugin-wp#101
@rudrakshi-gupta rudrakshi-gupta self-assigned this Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
13 0 13

⚠️ Warnings (13)

📁 readme.txt (1 warning)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM".
📁 assets/build/pages/video-editor.min.js (1 warning)
📍 Line 🔖 Check 💬 Message
2 react_removed_api This file calls "ReactDOM.findDOMNode", which was removed in React 19 and stops working once WordPress upgrades React. Use a ref on the element instead.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/18/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/18/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

- Keep Central's connection_status as sent, including on the not-allowed-site
  403; it describes the plan, while the key status still decides features
- Show the renewal screen only when the plan has expired and the key stopped
  working; when the key still works, show a renewal notice instead
- Show the trial notice only when the key works, and point a refused key with a
  live plan to settings instead of renewal
- Update the connection status tests
- Show a dismissible wp-admin notice when the subscription has ended but the
  licence still works: "Your GoDAM subscription has ended. Renew to keep Pro
  features." Never on the site, never a full screen
- Save the dismissal for the whole site, and show the notice again for the next
  lapse
- Replace get_expired_since() with get_licence_failed_since(): count Woo's grace
  period from the licence failing, not from connection_status saying expired
- Return nothing while the licence works; use Central's expired_at once sent,
  otherwise the first failed check; Central being unreachable never starts it
- Update the connection status tests
- Start Woo's grace period from the first failed key check, not Central's expired_at (the subscription can lapse while the licence still works)
- Use expired_at only when no failed check is on record
- Document what Central sends for 200, 401 and both 403 cases
- Add tests for every final Central answer and the grace start date
@rudrakshi-gupta
rudrakshi-gupta marked this pull request as ready for review November 18, 2026 09:49

@subodhr258 subodhr258 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary: The plugin side matches Central's merged contract, adds no new Central calls, and a Central outage cannot change the stored status or lock a paying site out, so I found no blockers; five small non-blocking items are inline.

Tested commit: 431552ed897b5069f02492272a041b984c85dbe7 (base develop, merge-base ed01a0b4).

Claim / how checked / result

Claim (PR title, body, issue #101) How checked Result
One connection status is stored per key check in rtgodam-connection (status, trial end, lapse date, organization) Read Connection::record() and the two call sites in rtgodam_verify_api_key(); ran ConnectionStatusTest (37) and ApiKeyVerificationResilienceTest (22) on PHP 7.4.33 Holds
Reads Central's final contract: connection_status, trial_ends_at, expired_at, organization; 200 / 401 none / 403 expired with null expired_at / 403 whitelist keeps real status Compared with Central's merged verification.py (godam-core#1957, merge commit 6f78cc18) and the HTTP codes in its error_types.py; frappe-stripe-subscription#289 for custom_expired_at Holds: field names, codes and the UTC-midnight date format match. Note: Central raises 503 before it can send 200 + none, so that case is never sent today (the plugin handles it anyway)
No new Central calls before Central ships; older Central falls back to the key status Read every Central URL in the diff; replayed an older-Central answer (200 without a status) Holds: only the existing verify_api_key is called, and the renewal links use the existing /godam_upgrade (already used on develop by ProUpgradeNotice) and /web/billing. See note 2 below for one older-Central side effect
The status only chooses screens and notices, never features Read the whole diff for feature gates Holds: rtgodam_is_api_key_valid() and every feature check are untouched
Central down, timeout, 404 or 5xx does not flip the site to "renew" or lock it out Followed rtgodam_verify_api_key(): 5xx, 408, 429, transport errors and non-JSON 404 never reach record(); the keep-last-good path is unchanged Holds
Subscription ended but licence works: dismissible admin-only notice, no screen; dismissal is nonce and capability checked; notice returns on the next lapse Read subscription_ended_notice(), dismiss_subscription_ended_notice(), admin.js, and the reset in record() Holds by code. Not exercised in a browser
Licence 403 opens the renewal screen; whitelist 403 gets the "check your settings" message, never the renewal screen Read should_overlay_onboarding() and api_key_status_notice() Holds, with one nuance: a site that is both off the allowed list and on a really expired plan still gets the renewal screen, because Central sends expired
"I've renewed, check again" says "Couldn't reach GoDAM" when Central is unreachable Read RenewScreen.jsx and the refresh-api-key-status route; reproduced with a stored expired key and a 503 from Central Does not hold: the route answers 200 with valid_api_key: false and api_key_status: verification_failed, so the screen says "still shows as expired". See inline comment 1
Trial notice shows days left as calendar days in the site's timezone Read get_trial_days_left(); the trial-day tests pass Holds
get_licence_failed_since() counts from the first failed check, not expired_at; GoDAM for Woo can use it Read it, ran its tests, read the open Woo licence-grace PR Holds: Woo calls get_status(), get_licence_failed_since() and get_renewal_url() behind is_callable, and the signatures match
Removing the key clears the stored answer deactivate_api_key() calls Connection::clear(); no other code deletes rtgodam-api-key Partly: uninstall does not remove the two new options (inline comment 3)
Nothing renamed or removed that GoDAM for Woo reads Grepped godam-for-woo (current checkout and the Woo licence-grace PR branch) for rtgodam_get_user_data, api_key_status, rtgodam-api-key-error-since, window.userData, Connection:: Holds: Woo reads api_key_status and window.userData; the PR only adds keys to them
PHP 7.4 compatible php -l under 7.4.33 on all 11 changed PHP files and the tests; Connection_Status is a plain class of constants, no enum, match, readonly, named args or union types Holds
All PHP and JS tests pass, phpcs clean Full jest run: 90 suites, 1273 tests pass. phpcs on the changed PHP files: clean. eslint on pages/onboarding and admin.js: clean. Full PHPUnit on my machine: 28 errors, the same count on current develop (a local PHP setup problem in separate-process tests); the PR's own CI "Run PHP unit tests" is green Holds
Plugin items in issue #101: one status helper, the renewal screen, the renewal link, the Woo grace-period hook Mapped each to the code Holds

Notes (non-blocking)

  1. Inline comments cover: the check-again message, the Back button from "Use it instead", the two options missing from uninstall.php, the organization carried over to a newly saved key, and a test fixture that does not match Central's 403 shape.
  2. Until Central ships, an older Central that answers 401 (key unknown) reads as expired through the key-status fallback, so the renewal screen would open for an unknown key. I replayed this. It goes away once Central's change is live; if you want it independent of Central, pass the HTTP status into record() and map 401 to none.
  3. While a check is being retried (retry_at set) get_status() returns unreachable, so the trial and subscription-ended notices disappear until the next good check. This is tested and intended; just flagging it.

Not tested

  • No browser run: the renewal screen, the notices and the dismissal AJAX call were read, not clicked. The PR screenshots are the only UI evidence.
  • No real WordPress: the PHP tests stub WordPress functions, so update_option autoload, nonces and admin_notices were not exercised.
  • No call to the real Central, and I did not check that Central's change is deployed to production.
  • npm run build, multisite, and the Woo licence-grace PR running against this branch.
  • The repo's hook-coverage lint ran out of memory in my scratch worktree (it scanned the symlinked node_modules); the PR's CI check for it is green.

Comment thread inc/helpers/class-connection.php Resolved
Comment thread inc/helpers/class-connection.php Resolved
- "Check again" says GoDAM couldn't be reached when the refresh can't reach Central or the request fails, not "still expired"
- Back from the license key screen returns to renewal for a site with a lapsed plan
- Remove rtgodam-connection and the dismissed-notice option on uninstall
- Forget the previous key's answer, including its organization, when a different key is saved
- Read an older Central's 401 as a key it doesn't know (connect screens, not renewal)
- Match the key-check test answers to Central's shapes: subscription ended on a 200 with its date, an inactive licence on a 403 with no date
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.

2 participants