Commit Graph

1039 Commits

Author SHA1 Message Date
Mike Jolley 38775590d5 Allow FormattedMonetaryAmount to deal with string based numbers (https://github.com/woocommerce/woocommerce-blocks/pull/3958) 2021-03-15 15:03:47 +00:00
Darren Ethier afc93035fd Add new config property for payment method registration that allows for additional saved customer token handling. (https://github.com/woocommerce/woocommerce-blocks/pull/3961)
* Add new config for saved token processing by payment methods.

* Implement new saved token handling config from registered payment methods.

* Implement new saved token handling config from registered payment met… … 2b42205 …hods.

* make sure saved token handler component is only loaded when a token payment method is selected
2021-03-15 04:50:49 -04:00
Mike Jolley edcd776a50 Always set value (https://github.com/woocommerce/woocommerce-blocks/pull/3957) 2021-03-12 11:44:34 -05:00
Albert Juhé Lluveras 56092fcdc4 Remove extra padding from payment methods with no description (https://github.com/woocommerce/woocommerce-blocks/pull/3952)
* Remove extra padding from payment methods with no description

* Fix typo in a code snippet in payment method docs

* Remove unnecessary div
2021-03-12 15:40:09 +01:00
Seghir Nadir a422dfd2e4 Fix save payment checkbox not showing (https://github.com/woocommerce/woocommerce-blocks/pull/3950) 2021-03-11 15:40:18 -05:00
Seghir Nadir dff4772d82 Add types to hooks (https://github.com/woocommerce/woocommerce-blocks/pull/3913)
* type hooks

* type useStoreCart

* type the rest

* Remove old typedefs

* Specify that the return value from useDispatch is a Promise< void >

* Change return type of removeItem

* If ref.current is undefined then return value without checking shallowEq

* Revert "Specify that the return value from useDispatch is a Promise< void >"

This reverts commit 97863bd584d38024398913a79ce63fa6b964846a.

* Remove type parameter from removeItem and changeCartItemQuantity

* Change action return type to cater for generator functions

* Remove type parameter from addItemToCart

* Add mapped types file to help with actions that are generator functions

* Include addItemToCart in return types of cart actions

* Use custom DispatchFromMap

* Add todos for why we've redefined functionality that exists in Calypso

* update types

* remove fromEntries and use polyfill

* address review

* ignore ts no shadow

* fix test errors

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2021-03-10 15:03:26 +00:00
Raluca Stan e187b9ef88 Update/typescript checkout shipping (https://github.com/woocommerce/woocommerce-blocks/pull/3925)
* Type shipping related hooks and packages

* Move component interface from shared shipping types file

* Fix Typescript import errors

* Type FormattedMonetaryAmountProps

* Change FormattedMonetaryAmountProps's value prop type

Looks like TotalsItem was the only on sending '-' as a value and it looks like it’s no longer passed through.

* Move `displayType` as a prop on FormattedMonetaryAmount

* Spacing

* Spacing

Co-authored-by: Mike Jolley <mike.jolley@me.com>
2021-03-09 10:55:24 +00:00
Mike Jolley 86328758bb Add billing data to payment method registration, convert cart/checkout context provider to typescript (https://github.com/woocommerce/woocommerce-blocks/pull/3922)
* Add billingData within usePaymentMethodRegistration

* Add typescript config

* Rename to TS

* Typing in context

* FIxed TS warnings

* Typed event emitters

* subscribers > observers

* Renaming some types

* Remove duplicate definition in tsconfig

* removed undefined check
2021-03-09 10:50:51 +00:00
Albert Juhé Lluveras 0e1b1e3579 Add types to packages directory (https://github.com/woocommerce/woocommerce-blocks/pull/3914)
* Add Typescript to Panel and Icon

* Fix Icon component import

* Convert packages/checkout/utils/validation/index to TypeScript

* Convert checkout registry to TypeScript

* Add return type to mustContain

* Add TypeScript to Totals components from @woocommerce/blocks-checkout

* Add TypeScript to @woocommerce/price-format

* Use types from @woocommerce/type-defs when possible

* Allow empty objects when loading

* Fix formatting in payment-method-data-context.js

* Add missing return types

* Fix up price warnings

* Fix more warnings in FormattedMonetaryAmount

Co-authored-by: Raluca Stan <ralucastn@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
2021-03-05 14:03:48 +00:00
Thomas Roberts ba16cf9b74 Inherit line height in Cart item total (https://github.com/woocommerce/woocommerce-blocks/pull/3897) 2021-03-05 14:02:11 +00:00
Albert Juhé Lluveras 0c698b25b2 Add OrderSummary test for woocommerce/woocommerce-blocks#3876 (https://github.com/woocommerce/woocommerce-blocks/pull/3909) 2021-03-04 16:07:57 +01:00
Seghir Nadir 8a89bb0dc0 Sync cart item quantity if its Implicitly changed. (https://github.com/woocommerce/woocommerce-blocks/pull/3907)
* sync quantity when changed outside component

* fix sync hook
2021-03-04 14:56:56 +01:00
Albert Juhé Lluveras 66d0e47427 Show cart item subtotal instead of total in Cart and Checkout blocks (https://github.com/woocommerce/woocommerce-blocks/pull/3905)
* Show cart item subtotal instead of total in Cart and Checkout blocks

* Update test that would have caught this error
2021-03-02 15:47:43 +01:00
Darren Ethier 72d7c46472 Followups and improvements on TS implementation in the Cart data store. (https://github.com/woocommerce/woocommerce-blocks/pull/3893)
* Fix tslint warnings

* Install @automattic/data-stores to get access to some type generics for use with our data stores.

* improve ts typing of cart-data store.

* fix incorrect rebase conflict resolution.
2021-03-01 12:47:22 -05:00
Darren Ethier 253d29b9e1 Move `triggerFetch.setNonce` calls into separate function and add appropriate guards. (https://github.com/woocommerce/woocommerce-blocks/pull/3892) 2021-03-01 06:22:24 -05:00
Thomas Roberts e49a7eaffd Update Label component to TSX (https://github.com/woocommerce/woocommerce-blocks/pull/3889)
* Add tsconfig to components directory and include it as project

* Add @types/classnames package

* Migrate Label component to TSX

* Remove unused imports from Label component

* fix package-lock.json

It was generated with npm 7 and we don’t support that yet (and that update should be done in a separate pull)

* Add interface for LabelProps and implement.

Also:
- import `Fragment` from @wordpress/element.
- import `HTMLAttributes` explicitly as a type from react (@types/wordpress__element doesn’t export this interface).

* fix jest configuration

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-26 11:57:49 +00:00
Darren Ethier af99c16931 Add TypeScript support and convert cart data store to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/3768)
* add typescript support

* Add type declarations for Cart and CartResponse interfaces

* make sure we’re resolving .ts files as well as .js files on imports

* add more types

* type the cart data store

* Apply suggestions from code review (implement .tsx in configs)

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>

* remove global fetchMock declaration and directly import where used.

* rename type

* remove named action types and just infer by returning action creator values as const

* use interface instead of type

* rename

* renames

* create CartAction type as union of action creator returned types and implement in reducer

* remove unused imports

* refresh package-lock after rebase

* Add base TS config that projects will inherit from

* Add tsconfig for assets/js/data project

* Ignore TS error on cart store registration

We will address this in cooldown when we have time to investigate further

* Add tsc to build step to catch TypeScript errors

* add a separate command for tsc and tweak build command to use

* restore checkJs and allowJs values in config and remove ts check from build command

* Add ts:check-all command

* Add TypeScript checking workflows

* Change triggers for TypeScript workflow

* Use npm ci instead of npm install

* Remove ts:check-all from TypeScript workflow

* Remove TS Check GitHub workflow

* Remove type-defs dir from TS include, and remove ts:check-all script

We no longer need the ts:check-all script because ts:check will do this for us, the old ts:check did nothing and did not work.

* fix coupon loading issues

* include .ts files only from type-defs folder

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2021-02-23 20:36:24 -05:00
Thomas Roberts caaedfb386 Show total sale badge in medium carts & make it display below price (https://github.com/woocommerce/woocommerce-blocks/pull/3879)
* Show total sale badge in medium carts

* Add markup to cart line item row to enable it to be displayed as flex

* Add styling to display price and sale badge as flex

* Revert product price being displayed as block

* Rename sale badge and price wrapper

* Hide line-total sale badge on mobile

* Change class name on total price and sale badge wrapper again
2021-02-23 10:12:27 +00:00
Albert Juhé Lluveras 0ddf8587d1 Fix cart line subtotal display when currency has 0 decimals (https://github.com/woocommerce/woocommerce-blocks/pull/3876)
* Fix cart line subtotal display when currency has 0 decimals

* Fix wrong usages of getCurrency instead of getCurrencyFromPriceResponse

* Add tests

* Move comment in tests to relevant line
2021-02-22 13:16:45 +00:00
Mike Jolley 6c963c19e5 Fix button style (https://github.com/woocommerce/woocommerce-blocks/pull/3862) 2021-02-22 11:50:23 +00:00
Raluca Stan c4edcc2740 Move ProductSortSelect and ProductListItem under /product-list (https://github.com/woocommerce/woocommerce-blocks/pull/3870) 2021-02-22 12:04:29 +01:00
Raluca Stan 76295fc972 Move payment-methods folder from base components to cart-checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/3866) 2021-02-19 16:16:39 +01:00
Thomas Roberts b6650ab0bc Replace uppercase Translators with translators & make comment style consistent (https://github.com/woocommerce/woocommerce-blocks/pull/3869)
* Replace uppercase Translators with translators

* Change comment style for all // translators instances
2021-02-19 11:58:44 +00:00
Raluca Stan 7e54af999f Handle out of stock product visibility setting in All Products block. (https://github.com/woocommerce/woocommerce-blocks/pull/3859)
* Take stock status into account for All Products block.

A new `hideOutOfStockItems` setting flag has been added and it is used to hide the out of stock products
from the block. Products that are not out of stock can have 'instock', 'onbackorder' as stock status.

* Update StoreApi docs with new stock_status

* Fix the stock_status query param for collections of products
2021-02-18 10:53:48 +01:00
Mike Jolley 077aaf2be3 Only use SHOP_URL if set (https://github.com/woocommerce/woocommerce-blocks/pull/3845) 2021-02-17 15:17:54 +00:00
Albert Juhé Lluveras b2339bda5d Update Panel component class names to follow guidelines (https://github.com/woocommerce/woocommerce-blocks/pull/3860)
* Rename panel class names to follow correct guidelines

* Remove unused CSS

* Add docs page link
2021-02-17 14:48:53 +01:00
Seghir Nadir 30c2079af4 Enhance checkout filter system. (https://github.com/woocommerce/woocommerce-blocks/pull/3835)
* Add filter to extend product price

* Remove code targeting WC Subscriptions

* Rename filter

* Use extendibility API instead of filters

* Remove __EXPERIMENTAL_CART_ITEM_PRICE_FILTER from docs

* throw errors on validation

* Don't catch filter errors for admins

* Add tests

* wrap filter calls in memo

* pass extensions as top level prop

* abstract errors

* add jsdoc

* update tests

* review

* turn __experimentalApplyCheckoutFilter into a hook and move useMemo inside it

* revert name

* wrap getCheckoutFilters in useMemo

* refactor filter function so memozation is done inside components

* unify true instance

* fix rebase

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2021-02-17 14:01:20 +01:00
Albert Juhé Lluveras eac22ca2f7 Remove shadows from text buttons and gradient background from selects in some themes (https://github.com/woocommerce/woocommerce-blocks/pull/3846)
* Reset select background property instead of only background-color

* Set text-shadow to none in text-button mixin
2021-02-17 13:40:52 +01:00
Thomas Roberts f693fd50ee Fix product price not displaying properly when product is on sale (https://github.com/woocommerce/woocommerce-blocks/pull/3853)
* Use else if in ProductPrice

This is because the priceComponent variable should be set depending on some conditions, but multiple of them could be true, so by using else if we only handle the first true case

* Update snapshots for jest
2021-02-16 11:42:11 +00:00
Albert Juhé Lluveras 5ba68af58b Show cart item total price including taxes when DISPLAY_CART_PRICES_INCLUDING_TAX is true (https://github.com/woocommerce/woocommerce-blocks/pull/3851)
* Show cart item total price including taxes when DISPLAY_CART_PRICES_INCLUDING_TAX is true

* Show cart item total price including taxes in Checkout block too
2021-02-16 09:45:31 +00:00
Mike Jolley 51789e2105 Login via account page (https://github.com/woocommerce/woocommerce-blocks/pull/3844) 2021-02-15 16:46:02 +00:00
Thomas Roberts edf79c699a Catch errors during cart validation (https://github.com/woocommerce/woocommerce-blocks/pull/3703)
* Add new exceptions for out of stock scenarios

These are needed to differentiate between the different stock validation errors, and so we can create the correct error message.

* Catch new out of stock exceptions when checking the cart for errors

This is so we can get the cart sent back to the client, if we don't catch these, then the route will just return a 500 error and crash.

* Add ArrayUtils class

This will contain methods used to operate on arrays that don't fit anywhere else.

* Handle the case in Checkout where the error is already a WP_Error

This will happen when the cart fails validation.

* Handle StockAvailabilityException in AbstractRoute

This will happen when an item or number of items in the cart are out of stock/insufficient stock.

* Throw exceptions for each type of invalid stock in validate_cart_items

This will allow us to create an error message for each type of violation to display to the user.

* Display additional error notices returned by the API

* Fix wording when throwing exceptions relating to stock

* Handle TooManyInCartException in CartController

* Abstract the merging of cart, status, and additional data into new fn

This allows us to simplify the way errors are returned from the API. The reason we have to add all of the data at once is because of how WP_Error works with the additional data, if there is already existing data in a WP_Error object, it gets moved into additional_data. By adding all of the data in one place, we stop this from happening. Also since we're only adding status and/or cart explicitly, it makes sense to just do it in one place.

* Add get_route_error_response_from_object method

This is so we can differentiate between a string and WP_Error object.

* Remove unnecessary slashes from WP_Error instantiation

* Add option to enclose each item in quotes in natural_language_join

* Abstract adding error messages to error object into single function

A lot of code was repeated, so doing this cuts down on that and ensures any changes only need to be made in one place.

* Create new parent exception for each type of out of stock exception

This is so we don't have to repeat code inside each different exception and we can simply inherit StockAvailabilityException.

* Catch the generic StockAvailabilityException in get_cart_item_errors

* No longer recalculate totals in validate function

It is not needed, the totals are recalculated elsewhere. This call was superfluous.

* Reduce nesting, and only throw exception if error object has errors

* Improve comment on get_route_error_response_from_object method

* Fix nesting when throwing the InvalidStockLevelsInCartException

* Catch errors during cart validation

* Add get_error_message_for_stock_exception_type function

This will be used to get an error message depending on the type of extension, and whether the plural form, or singular form is needed. This abstraction is better because the code is used in more than one place in the API.

* Use error message generation function instead of creating errors individually

* Use specific error codes for each type of error & fix PHPDoc

Now the stock_exceptions_to_wp_errors function will return an array of WP_Errors this is better as the client needs a distinct error code to display and replace notices.

* No longer remove items from cart or modify quantity if there is an error

* Return the WP_Error from RouteException or all Stock WP_Errors

* Fix error in PHPDoc

* No longer necessary to add get_cart_item_errors into an array

This is because the method always returns an array now.

* Rename variables in get_cart_item_errors to be more descriptive

* Improve PHPDoc on get_cart_item_errors

* Replace underscores with hyphens in error code

* Only return WP_Errors that have an actual error in them

* Add unit test for ensure the cart errors relating to stock are handled

* Fix typo in comment

* Use optional chaining to add errors to cart
2021-02-15 14:03:04 +00:00
Albert Juhé Lluveras e5f6a1047c Allow extensions to extend cart item price (https://github.com/woocommerce/woocommerce-blocks/pull/3750)
* Add filter to extend product price

* Extend order summary product price too

* Make it so 'format' is applied to all product price types

* Order

* Pass lineItem to the filter

* Remove code targeting WC Subscriptions

* Rename filter

* Remove unnecessary CSS block that made prices be displayed as blocks

* Use line item totals instead of product price multiplied by quantity to show line item price

* Fix wrong currency usage

* Add comment to disable eslint

* Fix JS error when totals is undefined

* Align order summary item price to the right

* Use extendibility API instead of filters

* Remove __EXPERIMENTAL_CART_ITEM_PRICE_FILTER from docs

* fix rebase

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2021-02-12 00:37:05 +01:00
Mike Jolley 7772d41007 Extensibility for Block Checkout Address Fields (https://github.com/woocommerce/woocommerce-blocks/pull/3662)
* Pass get_country_locale via assets

* Create helper to prepare and merge address fields

* Use new helper in address form

* Only pass field overrides now that fields are merged

* Fixc configs and remove lodash usage

* Prevent formatting of empty postcodes to suppress api error

* prevent memo on rerender

* Conitonal enqueue of locale data

* define index in increments of 10

* remove address-form

* circ deps changes

* Workaround for core data issue

* fix test

* remove prepareAddressFields export

* Remove old comment

* object from.entries polyfil

* Revert "object from.entries polyfil"

This reverts commit ba343adcf5fd2f843b225aebe340cce9b664c851.

* replace fromentries

* fix final fromentries
2021-02-11 16:49:27 +00:00
Seghir Nadir 39ab3070c8 fix double imports 2021-02-11 16:36:24 +01:00
Seghir Nadir d107dc89a9 Allow extensions to extend Cart Item Name in Cart and Checkout. (https://github.com/woocommerce/woocommerce-blocks/pull/3807)
* Add validation function

* Prefix validateElementOrString with __experimental

* Update experimental docs

* Typo

* Update JS docs

* Use an object for applyCheckoutFilter args

* Args doesn't need to be an object

* Wrap validation function execution in a try/catch block

* Only accept strings for the totalLabel filter

* Change applyCheckoutFilter signature

* Add validation function

* Add Product name filter

* rebase

* update second filter call

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2021-02-11 13:40:55 +01:00
Thomas Roberts cb09248b07 Add subtotal and sale badge filters - PR to correct branch (https://github.com/woocommerce/woocommerce-blocks/pull/3826)
* Replace filters with an extendibility API to hook into Cart and Checkout blocks

* Update docs

* Add a validate argument

* Add docs comments

* Add tests

* Add validation function

* Prefix validateElementOrString with __experimental

* Update experimental docs

* Typo

* Update comment

* Update JS docs

* Use an object for applyCheckoutFilter args

* Args doesn't need to be an object

* Wrap validation function execution in a try/catch block

* Only accept strings for the totalLabel filter

* Change applyCheckoutFilter signature

* Apply filters for subtotal and sale badge in CartLineItemRow

* Append suffix to prices and SaleBadge if passed in as a prop

* Add subtotal filter to OrderSummaryItem

* Add tests for OrderSummaryItem and ProductPrice

* Rename test for ProductPrice

* Update checkout filter registration plugin name

* Remove obsolete snapshop

* Remove suffix and change to format

This is because we want to make the entire price string editable, not just the part after it.

* Change formatting on SaleBadge to use createInterpolateElement

* Remove tests that are no longer needed.

* Update ProductPrice tests to reflect changes to format prop

* Check that subtotalPriceFormat contains <price/> in OrderSummaryItem

* Fix cart block styling to stop badges overflowing the container

* Add <price/> placeholder in OrderSummaryItem price filter

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2021-02-10 17:12:47 +00:00
Albert Juhé Lluveras 1a97bf80b0 Replace filters with an extendibility API to hook into Cart and Checkout blocks (https://github.com/woocommerce/woocommerce-blocks/pull/3774)
* Replace filters with an extendibility API to hook into Cart and Checkout blocks

* Update docs

* Add a validate argument

* Add docs comments

* Add tests

* Add validation function

* Prefix validateElementOrString with __experimental

* Update experimental docs

* Typo

* Update comment

* Update JS docs

* Use an object for applyCheckoutFilter args

* Args doesn't need to be an object

* Wrap validation function execution in a try/catch block

* Only accept strings for the totalLabel filter

* Change applyCheckoutFilter signature
2021-02-09 17:54:38 +01:00
Albert Juhé Lluveras 77119d9a7e Update Cart and Checkout sidebar design (https://github.com/woocommerce/woocommerce-blocks/pull/3797)
* Fix ShippingRatesControl not honoring renderOption prop

* Update order summary design

* Updates TotalsCoupon design

* Update Cart block sidebar title design

* Make values bold and labels regular in Cart and Checkout sidebar

* Update styles of shipping rates selector and radio control

* Remove unnecessary overflow rule in Panel content

* Fix shipping options in Checkout block

* Add some Twenty Twenty One fixes

* Fix saved payment methods display

* Remove top spacing no longer necessary in order summary quantity badge

* turn Totals title to bold

* Move right padding from product name to item description

* Take left margin off list items in product details

This is because in themes where a left margin is applied to li elements, the product detail/addon gets indented and it does not sit flush with the edge of the product details container. Adding this rule to the main wc-block-components-product-details  rule will stop other themes indenting <li>s

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2021-02-09 09:10:45 +01:00
Albert Juhé Lluveras 2acdbc088b Align Place Order button to the right (https://github.com/woocommerce/woocommerce-blocks/pull/3803)
* Fix Place Order button alignment

* Change order of Place Order and Return to Cart buttons
2021-02-08 14:42:56 +01:00
Bartosz Budzanowski 116ec41c6a Use default "features" values for payment methods. (https://github.com/woocommerce/woocommerce-blocks/pull/3796)
* Use deafault features values for payment methods.

* Fix config check.

* Fix config check.

* Update documentation.
2021-02-05 15:31:34 +00:00
Albert Juhé Lluveras 6ec197007f Decode fees name so special characters are rendered correctly (https://github.com/woocommerce/woocommerce-blocks/pull/3721)
* Decode fees name so special characters are rendered correctly

* Decode fees at hook level

* Fix several tests

* Remove unnecessary check
2021-02-04 18:05:47 +01:00
Seghir Nadir 99b78a1c9a add price package (https://github.com/woocommerce/woocommerce-blocks/pull/3790) 2021-02-04 15:30:28 +00:00
Darren Ethier b991486a84 Fix broken shipping Calculator (https://github.com/woocommerce/woocommerce-blocks/pull/3778)
* move shipping-rates-control and shipping totals back into base/components/cart-checkout

* fix notice styling

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2021-02-03 12:35:17 +01:00
Thomas Roberts 3c516b8dd2 Increase width of Cart's product column on <= medium screens (https://github.com/woocommerce/woocommerce-blocks/pull/3775) 2021-02-02 15:09:57 +00:00
Bartosz Budzanowski 14297add88 Update checkout payment methods design. (https://github.com/woocommerce/woocommerce-blocks/pull/3439)
* Add left vertical bar to payments methods step.

* Remove horizontal borders around order notes.

* Add class to order notes component.

We need it to traget that element with CSS.

* Update padding on order notes checkbox to match desing.

* Remove full stop to match the design.

* Add label for not saved payment methods option.

* Remove use new payment radio.

* Always show new ayment methods selector

* Remove editor context for now.

* Add accordion component skeleton.

* Small component refactor.

* Use accordion for new payment options.

* Fix jsdoc.

* Add styling.

* Add input styling.

* Hide label if we don't have saved methods.

* Cleanup.

* Cleanup and styling.

* Add target class to aid with alignment.

* Update use new payments label styling.

* Update Place Order button location.

* add full stop to payment method copy

* ensure that there is always a (default) selected payment method:
- using `activePaymentMethod` from context
- this ensures there is a default selected on initial render
- and handles any dynamic changes to available payment methods
  - e.g. COD disappearing when change shipping option
- remove unused / redundant selectedMethod prop - context is best

* use tab-based payment UI for 2 or fewer payment methods:
- move saved payment state to payment context; it's shared state needed
  by both PaymentMethodOptions and SavedPaymentMethodOptions
- show previous tabs UI if:
  - customer has no saved payment methods (cards)
  - store has 2 or fewer payment methods available
- when initialising SavedPaymentMethodOptions, only select one if the
  user hasn't selected a real payment method - this ensures radio
  buttons switch correctly between saved card => `Use another`
- remove various props and local state that is no longer required (🤞🏻)

* experimental - styling tweaks for single payment tab (remove "tab" UI)

* Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)"

This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4.

* Add single payment method UI.

* Adjust single method styling.

* Add outline and margin to two methods  version.

* Fix gap for order notes on/off option.

* Update Order button spacing CSS.

* Reuse computed values.

* Remove tabs and single payment option.

* We no longer need this test as the UI was changed.

* Fix payment methods labels height.

* Simplify.

* Remove not needed import.

* Typecheck an option.

* Refactor code.

* Rename.

* Rename.

* Update typdefs.

* Remove border for add order notes.

* Correct spacing for radio-button and label.

* Add simple test. Switch to payment method.

* Update style.

Co-authored-by: Rua Haszard <rua.haszard@automattic.com>
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-02 05:51:47 +01:00
Mike Jolley d9e2f62540 Improve nonce handling by rejecting stale values (https://github.com/woocommerce/woocommerce-blocks/pull/3770)
* Improve nonce handling by rejecting previous nonces from cache

* use timestamp instead of previous nonce

* Switch back to time()

* Seconds not ms

* Add comment about the date code
2021-02-01 17:09:18 +00:00
Bartosz Budzanowski a0eb52d32b Introduce payment gateway feature check for cart content. (https://github.com/woocommerce/woocommerce-blocks/pull/3719)
* Add supports data to payment methods abstractions. Implement in Stripe.

* Add capabilities to the payment gateway.

* Payment requirements in cart schema.

* Supported features format update.

* Formatting.

* Check required payment features.

* Refactor capabilieties check.

* No need for the cart parameter.

* Allow external modifiacation of features capability.

* Use ExtendRestApi to inject payment requirements into cart endpoint.

* Simplify the code.

* Enable more integrations.

* Enable Stripe payment request.

* Move  the filter to a more correc location.

* Add features check.

* Update typedefs and documentation.

* Update tests with new functionality.

* Style fixes.
2021-01-29 07:28:44 +01:00
Mike Jolley 7ae87ca367 Subscriptions Shipping Packages Integration Points (https://github.com/woocommerce/woocommerce-blocks/pull/3687)
* Expose schemas

* Accept strings for select shipping rate

* strings are allowed

* Refactor shipping package to hold it's own state

* Add extension data to cart hook

* Progress but state is broken

* Move state back to hook

* Progress but state is broken

* use shipping hook updates

* Fix re-render issue

* hide x1

* Shipping slot fill

* Working slot fills

* Do not export package

* Update extend usage in unit tests

* update mock test data

* Package per slotfill

* Resolved merge conflicts

* Update assets/js/blocks/cart-checkout/subscriptions-integration.js

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>

* rename slot

* deriveSelectedRates return doc

* useCallback in throwError

* final class ExtendRestApi

* spacing

* Move shipping rate selection to package level

* remove const for counts

* Remove schemas from extend

* unused use

* move to a single fill for packages

* add todos

* move subs code

* fix extra extensions

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2021-01-28 15:24:01 +01:00
Raluca Stan e7af435f08 Fix image link in all products block. (https://github.com/woocommerce/woocommerce-blocks/pull/3722)
* Fix image link in all products block.

- add alt text on product image
- prevent the appearance of both product and placeholder image at the same time
- make anchor with placeholder image accessible

* Add testing for product-elements/image block.
2021-01-28 14:23:20 +01:00