This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { default as useCheckoutEvents } from './use-checkout-events'; | ||
export { default as useCheckoutNotices } from './use-checkout-notices'; | ||
export { default as useCheckoutRedirectUrls } from './use-checkout-redirect-urls'; | ||
export { default as useCheckoutData } from './use-checkout-data'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @todo this should be a value object. Provided via wc-settings? | ||
const currencyObject = { | ||
code: 'USD', | ||
precision: 2, | ||
symbol: '$', | ||
symbolPosition: 'left', | ||
decimalSeparator: '.', | ||
priceFormat: '%1$s%2$s', | ||
thousandSeparator: ',', | ||
}; | ||
|
||
const useCheckoutData = () => { | ||
// @todo this will likely be a global wp.data store state so that things | ||
// like shipping selection, quantity changes, etc that affect totals etc | ||
// will automatically update the payment data. For POC this is hardcoded | ||
const checkoutData = { | ||
// this likely should be a float. | ||
total: 10.123, | ||
currency: currencyObject, | ||
// @todo, should this be a standard format of items in the checkout/cart | ||
// provided to ALL payment methods? Line items includes taxes/shipping | ||
// costs? Coupons? | ||
lineItems: [], | ||
}; | ||
const updateCheckoutData = () => {}; | ||
return [ checkoutData, updateCheckoutData ]; | ||
}; | ||
|
||
export default useCheckoutData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import useCheckoutContext from '@woocommerce/base-context/checkout-context'; | ||
|
||
export const useCheckoutEvents = () => { | ||
const { | ||
checkoutComplete, | ||
setCheckoutComplete, | ||
checkoutHasError, | ||
setCheckoutHasError, | ||
isCalculating, | ||
setIsCalculating, | ||
} = useCheckoutContext(); | ||
const setHasError = () => { | ||
setCheckoutHasError( true ); | ||
}; | ||
const cancelCheckoutError = () => { | ||
setCheckoutHasError( false ); | ||
}; | ||
const setComplete = () => { | ||
cancelCheckoutError(); | ||
setCheckoutComplete( true ); | ||
}; | ||
const setCalculating = () => { | ||
setIsCalculating( true ); | ||
}; | ||
const cancelCalculating = () => { | ||
setIsCalculating( false ); | ||
}; | ||
return { | ||
setCheckoutComplete: setComplete, | ||
setCheckoutHasError: setHasError, | ||
cancelCheckoutError, | ||
setIsCalculating: setCalculating, | ||
cancelCalculating, | ||
isCalculating, | ||
checkoutComplete, | ||
checkoutHasError, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import useCheckoutContext from '@woocommerce/base-context/checkout-context'; | ||
|
||
const useCheckoutNotices = () => { | ||
const { notices, updateNotices } = useCheckoutContext(); | ||
const addNotice = ( notice ) => { | ||
updateNotices( ( originalNotices ) => [ ...originalNotices, notice ] ); | ||
}; | ||
const removeNotice = ( notice ) => { | ||
// @todo...figure out how notices are saved - might need unique ids? | ||
// Do we have a special notice creator that takes care of that? | ||
// Use wp notice api? | ||
return notice; | ||
}; | ||
return { | ||
notices, | ||
addNotice, | ||
removeNotice, | ||
}; | ||
}; | ||
|
||
export default useCheckoutNotices; |
22 changes: 22 additions & 0 deletions
22
assets/js/base/hooks/checkout/use-checkout-redirect-urls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import useCheckoutContext from '@woocommerce/base-context/checkout-context'; | ||
|
||
const useCheckoutRedirectUrls = () => { | ||
const { | ||
successRedirectUrl, | ||
setSuccessRedirectUrl, | ||
failureRedirectUrl, | ||
setFailureRedirectUrl, | ||
} = useCheckoutContext(); | ||
|
||
return { | ||
successRedirectUrl, | ||
setSuccessRedirectUrl, | ||
failureRedirectUrl, | ||
setFailureRedirectUrl, | ||
}; | ||
}; | ||
|
||
export default useCheckoutRedirectUrls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters