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 Payment Request button support for Woo blocks #1529

Merged
merged 52 commits into from
May 6, 2021

Conversation

ricardo
Copy link
Member

@ricardo ricardo commented Apr 7, 2021

Fixes #1416
Fixes #1544
Fixes #1677

Changes proposed in this Pull Request

  • Add Payment Request blocks integration. The code is adapted from the Stripe Payment Gateway (1467-gh-woocommerce/woocommerce-gateway-stripe).
  • Use same normalization functions and API in blocks and shortcode.
  • Remove some leftover code from shortcode integration (e.g. clearCart, unnecessary i18n and nonce variables) and make shortcode integration more similar to the classic checkout by using the WCPayAPI.
  • Fix 3D Secure / SCA confirmation with payment request buttons.

There are a few improvements left to do:

  • Perhaps change folder structure, moving everything related to blocks into client/blocks/. - This requires changing the current credit card checkout as well.
  • Add loading indicator to PRB when 3DS modal is open or intent is being validated. - Not really related to this PR, as it applies to the shortcode implementation too.

Testing instructions

  • Run npm run build:client.
  • Install Gutenberg and WooCommerce Blocks.
  • Create a second cart page and add the cart block to it.
  • Create a second checkout page and add the checkout block to it.
  • Test using the payment request button in the product, cart and checkout pages, both shortcode and blocks.
  • Verify that the button shows up as expected.
  • Verify that the order is created as expected when the payment succeeds.

  • Added changelog entry (or does not apply)
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

@ricardo ricardo force-pushed the add/1416-payment-request-support-for-woo-blocks branch 3 times, most recently from 9aec227 to c8a8123 Compare April 22, 2021 21:29
@ricardo ricardo force-pushed the add/1416-payment-request-support-for-woo-blocks branch from c8a8123 to a079411 Compare April 26, 2021 09:16
@ricardo ricardo force-pushed the add/1416-payment-request-support-for-woo-blocks branch from 4104b3b to 6d7755f Compare April 26, 2021 23:45
@ricardo ricardo requested a review from dechov April 27, 2021 00:14
@asumaran
Copy link
Contributor

@ricardo I've tested my PR #1642 on top of your branch and didn't see any issue. My PR affects the Product page only.

@ricardo
Copy link
Member Author

ricardo commented Apr 27, 2021

@asumaran Thanks for testing it. I was concerned the changes I made to the payment request button class could break your PR.

@ricardo ricardo requested a review from reykjalin April 28, 2021 13:55
Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

Just noticed that Google Pay does not have a light-outline theme; only dark and light:

PRB Network request
image image

I think the fix for this is basically just to map light-outline to light?

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

When you fail the 3DS authentication while paying with a PRB the error message isn't properly formatted:

image

image

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

This is all coming along nicely! I think there's just some minor comments on the code, and the issues I pointed out ^ above.

I'm going to do some more testing, especially to make sure the shortcode flow is still working as expected following the changes to the API, but I think this is all generally looking pretty good ☺️

I really like how you've been able to adapt the Stripe implementation to fit better into the WCPay codebase. Excellent work! 👏

client/payment-request/event-handlers.js Show resolved Hide resolved
client/payment-request/utils/normalize.js Outdated Show resolved Hide resolved
client/payment-request/utils/normalize.js Outdated Show resolved Hide resolved
client/payment-request/utils/utils.js Show resolved Hide resolved
Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

This is sort-of unrelated to this PR, but I'm reporting it here anyway; @ricardo please let me know if I should move this to a different issue/PR

When I tried to pay through the credit card form with a card that will be declined (4000 0000 0000 0002) I don't get the expected Card declined error, and instead get this generic message at the top of the checkout page:

Error Message Credit Card Form
image image

The PRB shows the expected error message in the correct place.

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

It seems the aforementioned issue with failing 3DS verification through a PRB might be an issue that existed before this PR, since the product page shows the exact same result:

image

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

Related to the light-outline button not showing up correctly it works on the Product page, so that's definitely new with this PR.

image

@ricardo
Copy link
Member Author

ricardo commented Apr 29, 2021

This is sort-of unrelated to this PR, but I'm reporting it here anyway; @ricardo please let me know if I should move this to a different issue/PR

Please move to a new issue 👍

I have seen this error before, but didn't connect the dots. Well observed though.

It's probably because the block credit card method is still using the generic Gutenberg checkout endpoint to create the order, and that's not throwing any specific response from Stripe.

@ricardo
Copy link
Member Author

ricardo commented Apr 29, 2021

Just noticed that Google Pay does not have a light-outline theme; only dark and light:

Great catch! I changed the behavior a little bit, after looking at how Stripe renders the actual Google Pay button. The light version does not have a box-shadow.

I had to add a small vertical margin so that the outline shadow doesn't get cut by overflow: hidden in the blocks layout.

Fixed in ffb0de4

It seems the aforementioned issue with failing 3DS verification through a PRB might be an issue that existed before this PR, since the product page shows the exact same result:

The issue was actually generated from this PR 😬

Fixed it in eb615a7.

@reykjalin
Copy link
Contributor

This is sort-of unrelated to this PR, but I'm reporting it here anyway; @ricardo please let me know if I should move this to a different issue/PR

Please move to a new issue 👍

Issue opened in #1706

Copy link
Contributor

@reykjalin reykjalin left a comment

Choose a reason for hiding this comment

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

Just 2 minor comments on the updated PRB styling, but otherwise this looks good!

All the issues I encountered during my previous review have been fixed! Awesome work! 👏

Let's get that CSS fixed (possibly with the help of @LevinMedia) and then get this shipped 🎉

&:active {
background-color: #fff;
}
&:hover {
background-color: #f8f8f8;
}
&:focus {
box-shadow: #e8e8e8 0 1px 1px 0, #e8e8e8 0 1px 3px;
outline: 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to include the box-shadow here to indicate whether the element is focused when (for example) navigating via the tab key.

Personally, I think we should allow the purple outline set by WC Core, since that's really universal throughout WC pages; I don't see why we would remove that. Maybe @LevinMedia has some thoughts on that, design-wise?
The box-shadow on its own is very difficult to notice.

We should also make sure this is the same across both Stripe and WCPay, so what we decide to do here, I will also do in Stripe. For now I just added the box-shadow back in Stripe.

Copy link
Member Author

@ricardo ricardo May 1, 2021

Choose a reason for hiding this comment

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

Good point about the accessibility issue.

I removed the box-shadow because the Google Pay button that Stripe renders (when you have the wallet available) doesn't have a box-shadow.

Apparently, it uses the same styling as :hover, so perhaps the right thing to do is to use:

&:hover, &:focus {
	background-color: #f8f8f8;
}

image

Copy link
Member Author

Choose a reason for hiding this comment

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

We can remove the box-shadow styling from :focus in the light-outline theme too. Stripe adds the same styling as in :hover.

image

Copy link
Contributor

@reykjalin reykjalin May 3, 2021

Choose a reason for hiding this comment

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

The Stripe plugin version of this is not the best version of this either IMO, so I'd really like to get @LevinMedia's 👀 on this 🙂

I'll ping him in Slack 👍

EDIT: Nevermind, he's AFK until tomorrow so I'm not going to ping him now. Let's not leave this as a blocker, but if we haven't merged before he's back (tomorrow) I think it's worth it to have him take a look at this ☺️ .

@@ -46,13 +60,13 @@
background-color: #3c4043;
}
&:focus {
box-shadow: #5f6368 0 1px 1px 0, #5f6368 0 1px 3px;
outline: 0;
}
Copy link
Contributor

@reykjalin reykjalin May 1, 2021

Choose a reason for hiding this comment

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

Same as above ^, we need to include the box-shadow at the very least, and maybe allow the outline too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Stripe also removes the outline property. I guess the best here is to be compliant with Stripe's standards. Using the same background-color as in :hover fixes this.

image

@ricardo ricardo force-pushed the add/1416-payment-request-support-for-woo-blocks branch from bef480e to 5b2980c Compare May 6, 2021 01:26
@LevinMedia
Copy link
Contributor

@reykjalin @ricardo - let's just use the styling that stripe provides for now - I'm hesitant to use a specific color outline for focus since it may not always work with a theme's styles 👍

@ricardo ricardo merged commit 09092e3 into develop May 6, 2021
@ricardo ricardo deleted the add/1416-payment-request-support-for-woo-blocks branch May 6, 2021 16:35
};

export const shippingOptionChangeHandler = async ( api, event ) => {
const response = await api.paymentRequestUpdateShippingDetails( event );
Copy link
Contributor

Choose a reason for hiding this comment

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

@ricardo it should've been event.shippingOption. I'm submitting a PR fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants