Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Require payment recreate when payment price is wrong #892

Merged
merged 5 commits into from
Sep 10, 2020

Conversation

orzechdev
Copy link
Contributor

@orzechdev orzechdev commented Sep 9, 2020

I want to merge this change because... it

  • redirects the user to shipping step if payment amount is not equal to checkout total price (e.g. item was added to the cart) and thanks to it payment may be recreated with proper payment amount
  • still preserves the possibility for user to go to payment step when shipping was set already
  • fixes the case when user removes all items requiring shipping, leaving only digital product, when active path was /checkout/shipping and user was not redirected to other possible step
  • fixes the case when user removes all items requiring shipping, leaving only digital product and shipping method was still wrongly set, while it shouldn't exist anymore and total price should be updated
  • shipping method is now updated after adding/removing item to cart, and together with updated shipping methods introduced in Fix checkout refreshing #865, it is going to fix shipping method and payment gateway amount not updating when cart changes during checkout #885.

⚠️ Before merge SDK dependency must be updated with changes introduced in saleor/saleor-sdk#33

Screenshots

Pull Request Checklist

  1. All visible strings are translated with proper context.
  2. All data-formatting is locale-aware (dates, numbers, and so on).
  3. The changes are tested.
  4. The code is documented (docstrings, project documentation).
  5. Changes are mentioned in the changelog.

Test Environment Config

API_URI=https://master.staging.saleor.rocks/graphql/

@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 9, 2020 12:12 Inactive
@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 9, 2020 14:10 Inactive
@patrys
Copy link
Member

patrys commented Sep 9, 2020

@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 9, 2020 15:31 Inactive
@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 9, 2020 15:59 Inactive
@orzechdev orzechdev marked this pull request as ready for review September 9, 2020 16:10
export const checkIfShippingRequiredForProducts = (items?: IItems) =>
items?.some(({ variant }) => variant.product?.productType.isShippingRequired);

export const checkIfCheckoutPriceEqualPaymentPrice = (
Copy link
Member

Choose a reason for hiding this comment

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

If you want to test it you have to mock the whole payment object and total price. I see 2 solutions:

  1. Prefereble, easier to implement: Don't we have util for comparing prices?
    If not, I would suggest creating utils/money.ts file with such function (having all utils in one file leads to one, too long file with too broad scope - nightmare to work with).
    Also, unit tests for such function is a must.
  2. Function isCheckoutFullyPaid which takes Checkout as an argument and performs needed checks. Thats more to mock, but could be easier to use in checkout views.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have created isPriceEqual util

Choose a reason for hiding this comment

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

Another way to do it could be to update the available shipping methods when the cart is updated, then check the id of the available shipping methods against the id of the chosen shipping method in the checkout router.

@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 10, 2020 10:01 Inactive
@github-actions github-actions bot temporarily deployed to fix-payment-recreate September 10, 2020 10:47 Inactive
@dominik-zeglen dominik-zeglen merged commit 8670728 into master Sep 10, 2020
@dominik-zeglen dominik-zeglen deleted the fix/payment-recreate branch September 10, 2020 11:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shipping method and payment gateway amount not updating when cart changes during checkout
5 participants