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

Donations: Save fallback for non-frontend contexts #17381

Merged
merged 15 commits into from
Oct 27, 2020

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Oct 5, 2020

Fixes #17358
Fixes 241-gh-dotcom-manage
Fixes #17359

Changes proposed in this Pull Request:

This PR continues the work initiated in #17256 and adapts the Donations block so the save function is used as a proper fallback for non-frontend contexts while render_callback is used for augmenting the content dynamically for frontend contexts.

The block saves now a fallback output into the post content. That fallback includes a textual call-to-action linking to the post so folks can donate from the website.
The block also sets a render callback that augments the UI with working donate buttons.

Jetpack product discussion

N/A.

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

No.

Testing instructions:

Web

  • Spin up a JN site running master.
  • Set up Jetpack and start for free.
  • You need to sandbox the WP.com store now:
    • Edit your /etc/hosts file and point public-api.wordpress.com and subscribe.wordpress.com to your WP.com sandbox IP.
    • Go to WP Admin > Settings > Jetpack Constants and enter your WP.com sandbox address in JETPACK__SANDBOX_DOMAIN.
    • Add the code below to /wp-content/mu-plugins/0-sandbox.php in your WP.com sandbox:
define( 'USE_STORE_SANDBOX', true );
define( 'USE_BILLING_SANDBOX', true );
define( 'BILLINGDADDY_SANDBOX', rtrim( 'https://' . `hostname` ) );
  • Purchase a Jetpack Security plan.
  • Go to WP Admin > Posts > Add new.
  • Insert a Donations block.
  • Connect to Stripe.
  • Publish the post.
  • Go to WP Admin > Jetpack > Jetpack Beta.
  • Switch to the branch of this PR (update/donations-fallback).
  • Visit the frontend of the post you published before.
  • Make sure there are no regressions in the Donations block.
  • Go to WP Admin > Posts.
  • Edit the post you published before.
  • Make sure there are no regressions in the Donations block.
  • Open the "More" menu and activate the "Code editor" view.
  • Make sure the HTML markup is the fallback output (the one with a link to the post).

Screen Shot 2020-10-20 at 16 28 37

  • Switch back to the "Visual editor" view.
  • Click on the "Update" button.
  • Visit the frontend of the post.
  • Make sure the augmented UI is displayed (the one with a working donate button).

API

  • Go to the WP.com API console.
  • Make a GET request to /sites/:site/posts/:post-id (where :post-id is the ID of a post that contains a Donations block).
  • Make sure the post content uses the fallback.

Screen Shot 2020-10-20 at 16 42 07

Email, notifications, and reader (only testable in WP.com)

  • Apply D51410-code to your WP.com sandbox.
  • Sandbox a WP.com site under a paid plan.
  • Go to https://wordpress.com/following/manage.
  • Make sure to follow the site you sandboxed above.
  • Enable the "Notify me of new posts" option.

Screen Shot 2020-09-28 at 16 25 18

  • Go to https://wordpress.com/post.
  • Select the site you sandboxed above.
  • Publish a post that contains a "Donations" block.
  • Grab the IDs of the post and the site where the post has been published.
  • In a WP.com sandbox run php ./bin/subscriptions/send.php <BLOG_ID> post <POST_ID> <YOUR_EMAIL>.
  • Check the email received and make sure it contains the fallback link.

Screen Shot 2020-10-20 at 16 57 26

  • Open the masterbar notifications.
  • Make sure it includes the fallback link.

Screen Shot 2020-10-20 at 16 58 01

  • Go to Reader.
  • Open the post you just published above.
  • Make sure it includes the fallback link.

Screen Shot 2020-10-20 at 16 58 29

Proposed changelog entry for your changes:

Donations: Save fallback for non-frontend contexts

@jetpackbot
Copy link

jetpackbot commented Oct 5, 2020

Scheduled Jetpack release: November 10, 2020.
Scheduled code freeze: November 3, 2020

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17381

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 4030797

@blackjackkent
Copy link
Contributor

Is there anything to look at here at this point? (It's listed in the "Needs Review" column but it doesn't look like there's anything testing-wise here right now.)

@mmtr
Copy link
Member Author

mmtr commented Oct 13, 2020

Is there anything to look at here at this point? (It's listed in the "Needs Review" column but it doesn't look like there's anything testing-wise here right now.)

Nope, that's why I added the "[Status] In Progress" label 🙂. I usually add all the PRs I work on to our board as per our Team Board guidelines (PaYKcK-w0-p2).

Working on something? Assign the PR to the project, and move the PR into Needs Review.

@mmtr mmtr force-pushed the update/donations-fallback branch from 64f402f to 14d3f50 Compare October 19, 2020 15:40
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello mmtr! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D51410-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@@ -26,6 +26,63 @@ function register_block() {
array(
'render_callback' => __NAMESPACE__ . '\render_block',
'plan_check' => true,
'attributes' => array(
Copy link
Member Author

Choose a reason for hiding this comment

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

Block attributes need to be defined server-side because default values of attributes defined client-side are not available in render_callback.

See WordPress/gutenberg#7342 or WordPress/gutenberg#22491

@mmtr mmtr added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Oct 20, 2020
@mmtr mmtr requested a review from a team October 20, 2020 15:03
/**
* Currencies definition
*/
const CURRENCIES = array(
Copy link
Member Author

Choose a reason for hiding this comment

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

* @param bool $symbol Whether to display the currency symbol.
* @return string Formatted price.
*/
public static function format_price( $price, $currency, $symbol = true ) {
Copy link
Member Author

@mmtr mmtr Oct 20, 2020

Choose a reason for hiding this comment

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

@krymson24
Copy link
Contributor

krymson24 commented Oct 21, 2020

I don't know why I keep running into this. I double-checked and triple-checked the steps.

  1. Spin up a JN site running master.
  2. Set up Jetpack and go ahead with a free plan.
  3. You need to sandbox the WP.com store now:
    Edit your /etc/hosts file and point public-api.wordpress.com to your WP.com sandbox IP.
  4. Go to WP Admin > Settings > Jetpack constants and enter your WP.com sandbox address in JETPACK__SANDBOX_DOMAIN.
  5. Add the code below to /mu-plugins/0-sandbox.php in your WP.com sandbox:
    define( 'USE_STORE_SANDBOX', true );
    define( 'USE_BILLING_SANDBOX', true );
    define( 'BILLINGDADDY_SANDBOX', rtrim( 'https://' . hostname ) );
  6. Purchase any paid plan.
  7. Go to WP Admin > Posts > Add new.
  8. Insert a Donations block.

Donations block not present in the list.
2020-10-21 01 21 41

Trying to add a post from Wordpress.com instead of wp-admin
2020-10-21 01 22 03

I don't think anything is wrong with your PR; this just prevents me from testing it all the way through.

@mmtr
Copy link
Member Author

mmtr commented Oct 21, 2020

@krymson24 I double checked the instructions, followed them once more and they are working for me. It seems your site is missing a paid plan.

What do you get when you run Jetpack_Editor_Initial_State.available_blocks.donations in the browser JS console while in the editor?

Screen Shot 2020-10-21 at 11 59 48

@mmtr mmtr force-pushed the update/donations-fallback branch from 208317e to fcff2c5 Compare October 21, 2020 10:15
@sixhours
Copy link
Contributor

sixhours commented Oct 21, 2020

Donations block not present in the list.

I ran into this problem too @krymson24. I found I had to purchase a more specific Jetpack Complete plan (I think I'd had Jetpack Security initially) for the Donations block to appear. Double check which plan you're on?

@mmtr I got partway through testing this yesterday but couldn't get the Jetpack patch to fully apply on my sandbox. I ran svn up and the pre-patch svn stat looks normal:

Screen Shot 2020-10-21 at 9 27 40 AM

I then ran arc patch D51410 and it says the patch applied successfully (with two warnings):

Screen Shot 2020-10-21 at 9 38 54 AM

But the output still looks broken for email, notifications, and Reader:

Screen Shot 2020-10-21 at 9 40 07 AM

I've confirmed I'm sandboxing the API and the test site(s), so I think it's the patch not applying cleanly. Any ideas?

@mmtr
Copy link
Member Author

mmtr commented Oct 21, 2020

But the output still looks broken for email, notifications, and Reader:

@sixhours did you publish the post before applying the patch? Seems you applied the patch correctly, but maybe you're testing with a post that was already published?

The fallback is only used when saving posts from now on. Contexts where the fallback output is going to be rendered are usually timely streamers, so we don't need to worry about using the fallback in existing posts.

@sixhours
Copy link
Contributor

did you publish the post before applying the patch?

Ahhhh, I bet that's it. I'll give that a try. :D

@sixhours
Copy link
Contributor

Huzzah! I not only had to apply the patch first, I had to switch to a different test site, because the other one appears to be "stuck"; I can't disconnect Stripe, but it doesn't seem to be properly connected to Stripe, either. 🙃

Screen Shot 2020-10-21 at 10 18 15 AM

Screen Shot 2020-10-21 at 10 18 28 AM

Screen Shot 2020-10-21 at 10 19 11 AM

@krymson24
Copy link
Contributor

krymson24 commented Oct 22, 2020

But the output still looks broken for email, notifications, and Reader:

@sixhours did you publish the post before applying the patch? Seems you applied the patch correctly, but maybe you're testing with a post that was already published?

The fallback is only used when saving posts from now on. Contexts where the fallback output is going to be rendered are usually timely streamers, so we don't need to worry about using the fallback in existing posts.

@krymson24 I double checked the instructions, followed them once more and they are working for me. It seems your site is missing a paid plan.

What do you get when you run Jetpack_Editor_Initial_State.available_blocks.donations in the browser JS console while in the editor?

Screen Shot 2020-10-21 at 11 59 48

I tried a Jetpack Security and Complete plan, and available is still false.

Confirming I have Jetpack Complete:

Screen Shot 2020-10-22 at 1 48 41 AM

See below for screenshot that shows no Donations block as an option.

Screen Shot 2020-10-22 at 1 46 32 AM

I thought maybe that I hard coded the availability as false somewhere in my sandbox from a previous change, but I looked through the source code, and I don't think that's it either...

😢

@Automattic Automattic deleted a comment from matsapola Oct 22, 2020
class-jetpack-currencies.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
class-jetpack-currencies.php Outdated Show resolved Hide resolved
extensions/blocks/donations/donations.php Show resolved Hide resolved
extensions/blocks/donations/donations.php Outdated Show resolved Hide resolved
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Oct 22, 2020
@mmtr mmtr force-pushed the update/donations-fallback branch from fcff2c5 to 533ea29 Compare October 26, 2020 11:45
@mmtr mmtr added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Oct 26, 2020
@jeherve jeherve force-pushed the update/donations-fallback branch from 459a9f5 to 4030797 Compare October 26, 2020 17:45
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well for me in Jetpack.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Oct 26, 2020
@jeherve jeherve added this to the 9.1 milestone Oct 26, 2020
@jeherve jeherve added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Oct 26, 2020
/**
* Class for testing the Jetpack_Currencies class.
*/
class WP_Test_Jetpack_Currencies extends WP_UnitTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

@kwight
Copy link
Contributor

kwight commented Oct 26, 2020

I ran into problems testing the WP.com side which looks like it maybe should have been fixed by @jeherve 's last commit (can't cleanly apply the diff related to the currencies bit)? Regardless, the rest looks great and with @sixhours confirmation, I'm approving 👍

@jeherve jeherve merged commit 60f0fa1 into master Oct 27, 2020
@jeherve jeherve deleted the update/donations-fallback branch October 27, 2020 11:33
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Oct 27, 2020
jeherve added a commit that referenced this pull request Oct 27, 2020
@jeherve
Copy link
Member

jeherve commented Oct 28, 2020

Internal reference, part 1: r215962-wpcom

@jeherve
Copy link
Member

jeherve commented Nov 10, 2020

Part 2: r216557-wpcom

anomiex added a commit that referenced this pull request Jul 10, 2024
I don't see anything in #17381 that discusses this behavior. It's
possible it was an accidental bug that wasn't noticed because of the
undefined array key access producing null which produces the empty
string, and that the test was a copy-paste of the previous test that
didn't notice `false` being passed.

I see no other uses of `Jetpack_Currencies` with `$symbol = false` in
the monorepo or opengrok or wpdirectory, so this should be safe to
fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
8 participants