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

Add new hooks related to payment methods and checkout and remove obsolete. #1929

Merged
merged 5 commits into from
Mar 11, 2020

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Mar 10, 2020

This pull continues the extraction process from #1780.

The focus of this pull was primarily around updating existing hooks and adding new hooks related to the new contexts and payment method interface. This also implements the changes and removes obsolete hooks. Broken down, this pull:

  • restructures the base/hooks directory to make things a bit more organized. Primarily moving hooks into their own topical folders (I didn't move existing tests yet, that can be done in subsequent pulls that increase test coverage).
  • Adds useStoreOrder which is a placeholder hook for orderId and order loading. It will be finished in a follow-up pull.
  • Adds useBillingData hook which exposes the billing data interface from the PaymentMethodDataContextProvider.
  • Adds usePaymentMethodInterface hook (and related typedefs) which exposes the interface from contexts that are fed to payment methods as props. Also implements this hook in the payment method components.
  • Add useCheckoutSubmit and useCheckoutRedirectUrl which both expose slices of the checkout context.
  • removes numerous now obsolete hooks that are no longer needed.

To test

This impacts cart and checkout blocks so testing simply involves ensuring that:

  • checkout block loads in frontend and editor without errors in the console.
  • cart block loads in the frontend and existing functionality works as expected without any errors in the console.
  • cart block loads in the editor without any errors in the console.

nerrad added 3 commits March 10, 2020 14:17
- Also restructures hooks directory to make things a bit more organized
- Add useStoreOrder placeholder (followed up in future pull)
- Add useBillingData hook.
- add useCheckoutSubmit which exposes checkout submit button interface
- add useCheckoutRedirectUrl which exposes checkout redirect url interface
@nerrad nerrad requested a review from a team as a code owner March 10, 2020 18:53
@nerrad nerrad requested review from Aljullu and removed request for a team March 10, 2020 18:53
@nerrad nerrad self-assigned this Mar 10, 2020
@nerrad nerrad added focus: blocks Specific work involving or impacting how blocks behave. skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement. labels Mar 10, 2020
@nerrad nerrad added this to the Future Release milestone Mar 10, 2020
@nerrad nerrad requested a review from a team March 10, 2020 18:54
Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Tested this and found no issues. Here's what I tested:

  • Existing cart / checkout blocks render in front end and function correctly.
  • In editor can add new cart / checkout blocks with no errors, publish, they function correctly in front end.
  • Tested various options of the blocks:
    • Cart totals / quantity / removing items, coupons, show/hide shipping calculator
    • Checkout address entry, show/hide privacy policy link

I've added comments here and there - mostly around naming/documentation (none of this is blocking). I'm still getting my head around exactly what things like billing_data, checkoutRedirectUrl, paymentMethodInterface are - it would be great to document how all these pieces fit together at a very high level, using terms that relate directly to the Woo-merchant experience/UI (where possible). (Maybe best to tackle that later, perhaps in a cooldown.)

The only essential follow up from this review is to ensure all the @todos follow the rules of todos, i.e. there is an issue and it's linked in the code.

* callbacks that will fire after
* selecting a shipping rate
* successfully.
* @property {function()} onShippingRateSelectFail Used to subscribe callbacks
Copy link
Member

Choose a reason for hiding this comment

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

Could probably factor out the "used to subscribe callbacks firing when" here into a common doc that applies to all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, not sure I follow what you mean here? Each of these observer registration functions are for something different, so while they all are for subscribing observers to an event (the common bit of the doc), they are for specific events.

The doc blocks are useful for getting IDE tips when hovering over an object given this named type - moving it somewhere else and referencing it would lose that description for a property.

It's entirely possible I'm missing your intent by this comment though and you had in mind something that doesn't affect the above?

/**
* @typedef CheckoutStatusProps
*
* @property {boolean} isCalculating If true then totals are being calculated in
Copy link
Member

Choose a reason for hiding this comment

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

Can some of these status concepts be defined in one place, since they are similar? Examples: complete, calculating, processing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My response is the same as here

*/

/**
* @typedef PaymentStatusProps
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to have a one-liner for each of these types clearly defining the purpose. Sometimes that's more useful than the individual fields. I realise this is not an easy task, we can iterate on this as follow up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can do in a follow-up where more explanation is needed.

isActive: true,
checkoutData,
paymentEvents,
activePaymentMethod: paymentMethod.id,
Copy link
Member

Choose a reason for hiding this comment

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

I've seen that payment methods sometimes have a slug, other times an id (and these is used as key and name in components). If we can standardise on one name for this id / slug (slug?) that might help simplify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call on this. I looked for places where this was inconsistent and addressed (see ff5de1)

// @todo similar logic is done in `blocks/cart-checkout/cart/full-cart/index.js`
// we should extract this to use in both places so it's consistent.
// @todo this will need to account for `DISPLAY_PRICES_INCLUDING_TAXES`.
/**
Copy link
Member

Choose a reason for hiding this comment

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

Agree we need an abstraction for cart totals/arithmetic!

I also think it's a good idea to add an explicit method for converting a money value to float, i.e. parseInt( money_value, 10) is used a lot. Though if we have a cart calculations module then perhaps that's not a big deal.

These @todo comments should have matching issues 📥

Copy link
Contributor Author

@nerrad nerrad Mar 11, 2020

Choose a reason for hiding this comment

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

These @todo comments should have matching issues 📥

See this comment

@nerrad
Copy link
Contributor Author

nerrad commented Mar 11, 2020

The only essential follow up from this review is to ensure all the @todos follow the rules of todos, i.e. there is an issue and it's linked in the code.

Once the reference pull is extracted into individual pulls and they are merged, my plan was to go through the todos and and create issues for them. Nearly all these todos are already noted in this reference pull comment explicitly created for tracking them in the interim.

@nerrad nerrad merged commit 82cc6c6 into master Mar 11, 2020
@nerrad nerrad deleted the add/use-payment-methods-interface-hook branch March 11, 2020 10:50
@nerrad nerrad modified the milestones: Future Release, 2.6.0 Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: blocks Specific work involving or impacting how blocks behave. skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants