Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Improve Stripe (chrome pay) express payment method availability #3424

Merged
merged 4 commits into from
Nov 20, 2020

Conversation

mikejolley
Copy link
Member

This PR will hide/show Stripe in the cart/checkout Express Payment area based on the value of the cart. Transactions lower than 0.30 cents are blocked.

This required a fix to the SET_REGISTERED_EXPRESS_PAYMENT_METHODS reducer becaused it merged, rather than replaced, available payment methods.

Fixes #3402

How to test the changes in this Pull Request:

  1. Enable Stripe + Chrome Pay
  2. Add an item to the cart costing 0.10
  3. No express payment method is visible
  4. Increase quantity in cart to 3. Express payment method should then be shown.
  5. Reduce the quantity again. The payment method will dissapear.

Changelog

Improve Stripe (chrome pay) express payment method availability so it's hidden when the transaction would be too low in value.

@mikejolley mikejolley added this to the 3.9.0 milestone Nov 18, 2020
@mikejolley mikejolley requested a review from a team as a code owner November 18, 2020 10:33
@mikejolley mikejolley self-assigned this Nov 18, 2020
@mikejolley mikejolley requested review from budzanowski and removed request for a team November 18, 2020 10:33
@github-actions
Copy link
Contributor

github-actions bot commented Nov 18, 2020

Size Change: +11.9 kB (1%)

Total Size: 1.12 MB

Filename Size Change
build/all-products.js 36.2 kB +27 B (0%)
build/all-reviews.js 9.78 kB +4 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.2 kB +4 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 8.96 kB -4 B (0%)
build/atomic-block-components/add-to-cart.js 7.53 kB +9 B (0%)
build/atomic-block-components/button-frontend.js 2.04 kB -2 B (0%)
build/atomic-block-components/button.js 838 B -1 B
build/atomic-block-components/category-list-frontend.js 468 B -1 B
build/atomic-block-components/price.js 2.32 kB -2 B (0%)
build/atomic-block-components/rating.js 527 B +1 B
build/atomic-block-components/sku-frontend.js 389 B +3 B (0%)
build/atomic-block-components/sku.js 394 B -1 B
build/atomic-block-components/summary.js 925 B -2 B (0%)
build/atomic-block-components/tag-list.js 473 B -1 B
build/atomic-block-components/title-frontend.js 1.23 kB -1 B
build/atomic-block-components/title.js 1.06 kB +1 B
build/attribute-filter.js 12.5 kB +7 B (0%)
build/blocks.js 3.54 kB +1 B
build/cart-frontend.js 71.3 kB -4 B (0%)
build/cart.js 39.8 kB -38 B (0%)
build/checkout-frontend.js 86.4 kB +524 B (0%)
build/checkout.js 42.2 kB -34 B (0%)
build/featured-category.js 7.73 kB +3 B (0%)
build/featured-product.js 9.98 kB +8 B (0%)
build/handpicked-products.js 7.37 kB +7 B (0%)
build/price-filter.js 10.4 kB -6 B (0%)
build/product-best-sellers.js 7.44 kB +3 B (0%)
build/product-categories.js 3.23 kB +4 B (0%)
build/product-category.js 8.38 kB +5 B (0%)
build/product-new.js 7.61 kB +4 B (0%)
build/product-on-sale.js 8 kB +7 B (0%)
build/product-tag.js 6.53 kB +1 B
build/product-top-rated.js 7.58 kB +7 B (0%)
build/products-by-attribute.js 8.35 kB +9 B (0%)
build/reviews-by-category.js 11.8 kB +11 B (0%)
build/reviews-by-product.js 13.4 kB +13 B (0%)
build/single-product.js 10.1 kB -5 B (0%)
build/vendors.js 418 kB +11.3 kB (2%)
build/wc-blocks-data.js 7.1 kB +2 B (0%)
build/wc-blocks-middleware.js 932 B +1 B
build/wc-blocks-registry.js 2.39 kB +65 B (2%)
build/wc-payment-method-bacs.js 775 B -15 B (1%)
build/wc-payment-method-cheque.js 771 B -16 B (2%)
build/wc-payment-method-cod.js 866 B -13 B (1%)
build/wc-payment-method-paypal.js 813 B -18 B (2%)
build/wc-payment-method-stripe.js 12 kB +49 B (0%)
build/wc-settings.js 2.35 kB +1 B
build/wc-shared-hocs.js 1.66 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.89 kB 0 B
build/active-filters.js 8.94 kB 0 B
build/all-products-frontend.js 31.2 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/category-list.js 478 B 0 B
build/atomic-block-components/image-frontend.js 1.7 kB 0 B
build/atomic-block-components/image.js 1.15 kB 0 B
build/atomic-block-components/price-frontend.js 2.29 kB 0 B
build/atomic-block-components/rating-frontend.js 523 B 0 B
build/atomic-block-components/sale-badge-frontend.js 858 B 0 B
build/atomic-block-components/sale-badge.js 863 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary-frontend.js 917 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/attribute-filter-frontend.js 18.2 kB 0 B
build/editor-rtl.css 13.8 kB 0 B
build/editor.css 13.9 kB 0 B
build/price-filter-frontend.js 14.9 kB 0 B
build/product-search.js 3.56 kB 0 B
build/reviews-frontend.js 9.37 kB 0 B
build/single-product-frontend.js 33.8 kB 0 B
build/style-rtl.css 17.9 kB 0 B
build/style.css 17.9 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 5.65 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B

compressed-size-action

),
paymentRequestAvailable( {
currencyCode: cartData?.cartTotals?.currency_code?.toLowerCase(),
totalPrice: parseInt( cartData?.cartTotals?.total_price, 10 ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we get total_price using the optional chaining operator we assume that we can get undefined as a result. Undefined passed to parseInt will get us NaN. When we plug the NaN to the test used on line 26 if ( totalPrice < 30 ) we get False and continue but we should stop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I committed a fallback to || 0.

@mikejolley mikejolley merged commit 005fbe4 into trunk Nov 20, 2020
@mikejolley mikejolley deleted the fix/3402-express-availability branch November 20, 2020 10:10
@nerrad nerrad added category: extensibility Work involving adding or updating extensibility. Useful to combine with other scopes impacted. type: bug The issue/PR concerns a confirmed bug. block: checkout Issues related to the checkout block. labels Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: checkout Issues related to the checkout block. category: extensibility Work involving adding or updating extensibility. Useful to combine with other scopes impacted. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Express Payment Request API (Stripe) Errors not surfaced
3 participants