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

Pay with PayPal block: Save fallback into post content #17256

Merged
merged 16 commits into from
Sep 29, 2020

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Sep 24, 2020

Fixes #17246
Fixes #17161
Fixes #15591

Changes proposed in this Pull Request:

As @mtias noted in paYKcK-FI-p2#comment-831, the save function of a block is conceptually the proper fallback while render_callback is instead intended for augmenting the content dynamically.

In other words, the save function should return an output that works well enough in any context (email, notifications, feed, as well as unknown clients getting post content from an API, etc). Then, for cases where we want to provide a richer UI (such in the site frontend), the render_callback function should be used for manipulating the block content.

This PR modifies the Pay with PayPal block implementation so it follows the approach above:

  • 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 purchase from the website. This means that the block no longer saves a [simple-payment] shortcode.
  • The block also sets a render callback that augments the UI replacing the link to the post with a PayPal button when the block is rendered in the frontend (determined with a new jetpack_is_frontend function).
  • Changes from Pay with PayPal: Add alternative shortcode output for email notifications #17180 have been reverted so the fallback is only saved 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.

Jetpack product discussion

paYKcK-FI-p2

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 purchase any paid plan.
  • Go to WP Admin > Posts > Add new.
  • Insert a Pay with PayPal block.
  • Fill it with data.
  • Publish the post.
  • Go to WP Admin > Jetpack > Jetpack Beta.
  • Switch to the branch of this PR (update/pay-with-paypal-save-fallback).
  • Visit the frontend of the post you published before.
  • Make sure there are no regressions in the Pay with PayPal block.
  • Go to WP Admin > Posts.
  • Edit the post you published before.
  • Make sure there are no regressions in the Pay with PayPal block.
  • Open the "More" menu and activate the "Code editor" view.
  • Make sure the HTML markup is the fallback output (the one with a "Visit the site to purchase" link).
  • 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 "PayPal" 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 Pay with PayPal block).
  • Make sure the post content uses the fallback.

Screen Shot 2020-09-28 at 17 29 28

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

  • Apply D50134-code to your WP.com sandbox.
  • Sandbox the API and the URL of a WP.com site under a Premium plan.
  • Go to https://wordpress.com/following/manage.
  • Make sure to follow the site under a Premium plan 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/block-editor.
  • Select the site under a Premium plan you sandboxed above.
  • Publish a post that contains a "Pay with PayPal" 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 a "Visit the site to purchase" link.

Screen Shot 2020-09-28 at 16 27 26

  • Open the masterbar notifications.
  • Make sure it includes the "Visit the site to purchase" link.

Screen Shot 2020-09-28 at 16 26 35

  • Go to Reader.
  • Open the post you just published above.
  • Make sure it includes the "Visit the site to purchase" link.

Screen Shot 2020-09-28 at 16 33 29

Proposed changelog entry for your changes:

Pay with PayPal block: Save fallback into post content

@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 D50134-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

@jetpackbot
Copy link

jetpackbot commented Sep 24, 2020

Scheduled Jetpack release: October 6, 2020.
Scheduled code freeze: September 29, 2020

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

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 514d09f

@mmtr mmtr requested a review from a team September 25, 2020 14:47
@mmtr mmtr added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Sep 25, 2020
@mmtr mmtr requested a review from mtias September 25, 2020 16:09
@krymson24
Copy link
Contributor

krymson24 commented Sep 27, 2020

@mmtr

I ran through your test steps --

I'm not sure if I was doing this correctly, but I tried sandboxing the store, but I couldn't purchase a Jetpack plan, so I just gave myself free credits on the store admin, removed the sandbox, and then purchased a Jetpack plan.

Furthermore, I'm not sure what's set up incorrectly locally, but in master as well as your feature branch, I see this error message. So I don't think it's caused by your branch.

2020-09-26 13 10 11 2

No regressions that I found:

Before After
Screen Shot 2020-09-26 at 1 08 11 PM Screen Shot 2020-09-27 at 11 04 05 AM

The fallback link contains what you said it would:

Before After
Screen Shot 2020-09-27 at 10 38 45 AM Screen Shot 2020-09-27 at 11 01 29 AM

@krymson24
Copy link
Contributor

@mmtr I ran through the tests for the email section and it worked as expected!

Screen Shot 2020-09-27 at 11 42 26 AM

Just want to note that in your description, this step:

In a WP.com sandbox run php ./bin/subscriptions/send.php <BLOG_ID> post <POST_ID> <YOUR_EMAIL>.

Should wrap the php at the beginning in code formatting as well php ./bin/subscriptions/send.php <BLOG_ID> post <POST_ID> <YOUR_EMAIL>

I ran it the first time, not noticing the php part and ran into a permissions error, but then read it carefully the second time, and also remembered that I had run this command before 😄

@mmtr
Copy link
Member Author

mmtr commented Sep 28, 2020

Thanks for testing, @krymson24!

I'm not sure if I was doing this correctly, but I tried sandboxing the store, but I couldn't purchase a Jetpack plan, so I just gave myself free credits on the store admin, removed the sandbox, and then purchased a Jetpack plan.

You don't need to sandbox anything for testing this one, so using the production store and not connecting your Jetpack site to your sandbox is fine.

Furthermore, I'm not sure what's set up incorrectly locally, but in master as well as your feature branch, I see this error message. So I don't think it's caused by your branch.

I also saw the SP22 error too, but like you I also get it when testing in master so I was assuming something was wrong on my environment. Not sure if we need to set up something else for testing this block. Will dig into this later.

Should wrap the php at the beginning in code formatting as well php ./bin/subscriptions/send.php <BLOG_ID> post <POST_ID> <YOUR_EMAIL>

Good catch! I actually wanted to include the php as part of the code formatting :) Updated.

functions.global.php Outdated Show resolved Hide resolved
extensions/blocks/simple-payments/simple-payments.php Outdated Show resolved Hide resolved
modules/simple-payments/simple-payments.css Show resolved Hide resolved
extensions/blocks/simple-payments/edit.js Outdated Show resolved Hide resolved
extensions/blocks/simple-payments/save.js Show resolved Hide resolved
extensions/blocks/simple-payments/save.js Outdated Show resolved Hide resolved
modules/simple-payments/simple-payments.php Show resolved Hide resolved
@jeherve jeherve added [Pri] Normal [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Sep 28, 2020
@mmtr
Copy link
Member Author

mmtr commented Sep 28, 2020

I also saw the SP22 error too, but like you I also get it when testing in master so I was assuming something was wrong on my environment. Not sure if we need to set up something else for testing this block. Will dig into this later.

Found it. It's caused by the new Jetpack plans, which have not been added to the list of plans supporting the "Pay with PayPal" functionality. Should be fixed by D50263-code.

@jeherve jeherve added this to the 9.0 milestone Sep 28, 2020
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 tested well for me on Jetpack. I have one comment, but it's not a blocker, it could be addressed in a follow-up PR. It should be good to merge!

}

// Keep content as-is if rendered in other contexts than frontend (i.e. feed, emails, API, etc.).
if ( ! jetpack_is_frontend() ) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should add a Blocks::is_amp_request() check here as well, since this may be another context where we'd want to display a simplified block.

cc @westonruter What are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this makes sense to me. I assume the button just doesn't work in AMP currently, so serving the fallback static content which we know is AMP-compatible seems correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ( ! jetpack_is_frontend() ) {
if ( ! jetpack_is_frontend() || Blocks::is_amp_request() ) {

I'm not set up to test this block, but what does this result in on AMP pages?

Copy link
Member Author

Choose a reason for hiding this comment

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

@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 Crew. Label will be renamed soon. labels Sep 28, 2020
@kwight
Copy link
Contributor

kwight commented Sep 28, 2020

Wonderful! 🎉 I went through all the cases, and only had one glitch: I'm not able to complete the purchase on the front-end view. The PayPal modal pops up, but immediately dies with the following (I don't see this at all on prod, so maybe it's something sandbox-related?):

Console Front-end
Screen Shot 2020-09-28 at 4 02 50 PM Screen Shot 2020-09-28 at 4 04 25 PM

I'm approving, assuming we can determine that the above error isn't a problem related to these changes 👍

}

// Keep content as-is if rendered in other contexts than frontend (i.e. feed, emails, API, etc.).
if ( ! jetpack_is_frontend() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ( ! jetpack_is_frontend() ) {
if ( ! jetpack_is_frontend() || Blocks::is_amp_request() ) {

I'm not set up to test this block, but what does this result in on AMP pages?

@jeherve
Copy link
Member

jeherve commented Sep 29, 2020

I'll merge this for now, so I can get started with the release; @mmtr I'll let you handle the WordPress.com counterpart and the feedback above in a follow-up PR?

@jeherve jeherve dismissed westonruter’s stale review September 29, 2020 08:43

Let's address this in a follow-up PR

@jeherve jeherve merged commit a8b9e2e into master Sep 29, 2020
@jeherve jeherve deleted the update/pay-with-paypal-save-fallback branch September 29, 2020 08:43
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Sep 29, 2020
@mmtr
Copy link
Member Author

mmtr commented Sep 29, 2020

I'm not able to complete the purchase on the front-end view. The PayPal modal pops up, but immediately dies with the following (I don't see this at all on prod, so maybe it's something sandbox-related?)

Yup, seems something caused by our sandboxes, I can see it as long as I'm sandboxed (even when D50134-code is not applied), so definitely unrelated to these changes.

@mmtr
Copy link
Member Author

mmtr commented Sep 29, 2020

Deployed to WP.com in r214381-wpcom.

@mtias
Copy link
Member

mtias commented Oct 1, 2020

@mmtr does it make sense to serialize so much markup as a fallback? I was thinking it would only include the button, which is where this block should be heading.

@mmtr
Copy link
Member Author

mmtr commented Oct 1, 2020

@mtias I think that ideally a block should aim for a markup that works anywhere, so we don't need to augment it. If that is not doable, then the more markup is shared between the fallback and the augmented UI, the easier is going to be the code maintenance.

I agree that it'd be great if this block would be only a button, so users can use other blocks (paragraphs, headings, images) for describing the product they are selling. But in the meantime, I think it's important that the fallback offers enough context to visitors so they can understand the purpose of the block.

Imagine that the fallback of this block would be only a link (it cannot be a button because it does not work on emails) that redirects visitors to the full post in the frontend so they can complete the purchase. These visitors will lack some info such as "what product is the site selling?" or "how much does is cost?".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pay With Paypal aka Simple Payments [Feature] Pay with PayPal aka Simple Payments [Pri] Normal Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
8 participants