2020-03-11 10:50:12 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-04-30 09:52:36 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
useCheckoutContext,
|
|
|
|
usePaymentMethodDataContext,
|
|
|
|
} from '@woocommerce/base-context';
|
2021-01-19 15:55:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { usePaymentMethods } from '../payment-methods';
|
2020-03-11 10:50:12 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-30 09:52:36 +00:00
|
|
|
* Returns the submitButtonText, onSubmit interface from the checkout context,
|
|
|
|
* and an indication of submission status.
|
2020-03-11 10:50:12 +00:00
|
|
|
*/
|
|
|
|
export const useCheckoutSubmit = () => {
|
2020-04-30 09:52:36 +00:00
|
|
|
const {
|
|
|
|
onSubmit,
|
|
|
|
isCalculating,
|
|
|
|
isBeforeProcessing,
|
|
|
|
isProcessing,
|
|
|
|
isAfterProcessing,
|
|
|
|
isComplete,
|
|
|
|
hasError,
|
|
|
|
} = useCheckoutContext();
|
2021-01-19 15:55:44 +00:00
|
|
|
const { paymentMethods = {} } = usePaymentMethods();
|
2020-04-30 09:52:36 +00:00
|
|
|
const { activePaymentMethod } = usePaymentMethodDataContext();
|
|
|
|
const paymentMethod = paymentMethods[ activePaymentMethod ] || {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
submitButtonText:
|
|
|
|
paymentMethod?.placeOrderButtonLabel ||
|
|
|
|
__( 'Place Order', 'woo-gutenberg-products-block' ),
|
|
|
|
onSubmit,
|
|
|
|
isCalculating,
|
|
|
|
waitingForProcessing:
|
|
|
|
isProcessing || isAfterProcessing || isBeforeProcessing,
|
|
|
|
waitingForRedirect: isComplete && ! hasError,
|
|
|
|
};
|
2020-03-11 10:50:12 +00:00
|
|
|
};
|