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

Assistant: Add site discount endpoints #23574

Merged
merged 23 commits into from
Apr 20, 2022
Merged

Conversation

monsieur-z
Copy link
Contributor

@monsieur-z monsieur-z commented Mar 23, 2022

Changes proposed in this Pull Request:

This PR adds an endpoint to fetch a site specific discount.

Jetpack product discussion

Context: pbNhbs-1xX-p2

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Prerequisites:

  • Download this branch and build the plugin
  • Make sure that your Jetpack test site is talking to your sandbox
  • Run the command to watch changes
  • Apply D76497-code to your sandbox, and follow the diff instructions

PR instructions:

  • After having followed the diff instructions, your site should now have a site coupon
  • In projects/plugins/jetpack/_inc/client/recommendations/index.jsx, add <QuerySiteDiscount /> to the fragment returned by the component
  • Open the Network panel of your browser, and refresh the /wp-admin/admin.php?page=jetpack#/recommendations page
  • You should see that a call was made to /wp-json/jetpack/v4/site/discount
  • Check that the payload matches the information you see in the coupon tool (code, expiry date, discount, used or not)

@monsieur-z monsieur-z changed the base branch from master to update/assistant-discount-card March 23, 2022 14:50
@github-actions github-actions bot added [JS Package] API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Admin Page React-powered dashboard under the Jetpack menu RNA labels Mar 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 23, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: May 3, 2022.
  • Scheduled code freeze: April 25, 2022.

Backup plugin:

  • Next scheduled release: May 3, 2022.
  • Scheduled code freeze: April 25, 2022.

Social plugin:

  • Next scheduled release: May 3, 2022.
  • Scheduled code freeze: April 25, 2022.

Starter Plugin plugin:

  • Next scheduled release: May 3, 2022.
  • Scheduled code freeze: April 25, 2022.

Protect plugin:

  • Next scheduled release: April 29, 2022.
  • Scheduled code freeze: April 22, 2022.

@monsieur-z monsieur-z changed the title Add/assistant discount endpoint Assistant: Add site discount endpoints Mar 23, 2022
@@ -32,6 +32,9 @@
// Each of these is a class that will register its own routes on 'rest_api_init'.
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php';

// Create discount after site has been successfully connected.
add_action( 'jetpack_authorize_ending_authorized', array( 'Jetpack_Core_Json_Api_Endpoints', 'create_site_discount' ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the best place to add that action?

Copy link

Choose a reason for hiding this comment

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

We're not actually using create_site_discount as an endpoint, right? Instead it's used to make the call to the WPCOM API. If that's true then it seems like this and the function itself might fit better somewhere else. I'm not familiar enough with the code base to know where though. Maybe somewhere that gets executed after a successful connection is established?

My understanding is that create_site_discount would be called after a successful connection and can be called directly rather than via an API request. Let me know if I'm mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @travisw!

We're not actually using create_site_discount as an endpoint, right? Instead it's used to make the call to the WPCOM API.

That's right, create_site_discount is called directly by the hook, and calls the WPCOM API.

My understanding is that create_site_discount would be called after a successful connection and can be called directly rather than via an API request. Let me know if I'm mistaken.

True, that's the current implementation. Maybe I don't understand your statement correctly.

I'm not familiar enough with the code base to know where though. Maybe somewhere that gets executed after a successful connection is established?

Gotcha, I'll ask around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the hook for jetpack_site_registered, as it was recommended to me. It's more appropriate as the coupon is site based.

Copy link

Choose a reason for hiding this comment

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

I'm still wondering if the code for creating a coupon should actually live in a different area (not in class.core-rest-api-endpoints.php) since it's not really defining an endpoint, but rather just calling a wpcom endpoint. But maybe Crew can clarify that once they give it a review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, the endpoint to create the discount was removed from this PR.

@monsieur-z monsieur-z marked this pull request as ready for review March 23, 2022 16:49
@monsieur-z monsieur-z force-pushed the update/assistant-discount-card branch from 038334a to f5d7d0f Compare March 24, 2022 21:08
@jboland88
Copy link
Contributor

@monsieur-z - It looks like this PR has a lot of the same changes as the base branch. I'm not sure if some of the commits from the base branch are repeated here? Maybe rebasing against the base branch would resolve this?

@monsieur-z monsieur-z force-pushed the add/assistant-discount-endpoint branch from 19d11a7 to 563e56a Compare March 29, 2022 15:53
@@ -32,6 +32,9 @@
// Each of these is a class that will register its own routes on 'rest_api_init'.
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/load-wpcom-endpoints.php';

// Create discount after site has been successfully connected.
add_action( 'jetpack_authorize_ending_authorized', array( 'Jetpack_Core_Json_Api_Endpoints', 'create_site_discount' ) );
Copy link

Choose a reason for hiding this comment

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

We're not actually using create_site_discount as an endpoint, right? Instead it's used to make the call to the WPCOM API. If that's true then it seems like this and the function itself might fit better somewhere else. I'm not familiar enough with the code base to know where though. Maybe somewhere that gets executed after a successful connection is established?

My understanding is that create_site_discount would be called after a successful connection and can be called directly rather than via an API request. Let me know if I'm mistaken.

@monsieur-z monsieur-z force-pushed the update/assistant-discount-card branch from 1b7f7bf to 8ef2c1d Compare April 7, 2022 16:14
@monsieur-z monsieur-z requested a review from a team as a code owner April 7, 2022 16:14
@github-actions github-actions bot added [JS Package] Base Styles [JS Package] Connection [JS Package] Components [JS Package] IDC [JS Package] Licensing [JS Package] Partner Coupon [Package] My Jetpack [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin labels Apr 7, 2022
@monsieur-z monsieur-z added this to the jetpack/10.9 milestone Apr 15, 2022
@monsieur-z monsieur-z force-pushed the add/assistant-discount-endpoint branch from 683f339 to 9acf705 Compare April 19, 2022 17:35
@kraftbj kraftbj enabled auto-merge (squash) April 20, 2022 20:38
@kraftbj kraftbj merged commit 7c5c06c into master Apr 20, 2022
@kraftbj kraftbj deleted the add/assistant-discount-endpoint branch April 20, 2022 20:51
@github-actions github-actions bot removed the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [JS Package] API [JS Package] Base Styles [JS Package] Components [JS Package] Connection [JS Package] IDC [JS Package] Licensing [JS Package] Partner Coupon [Package] My Jetpack [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin RNA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants