2022-06-10 16:33:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-06-21 14:09:22 +00:00
|
|
|
import { PaymentResult } from '@woocommerce/types';
|
2022-06-10 16:33:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ACTION_TYPES as types } from './action-types';
|
2022-06-21 14:09:22 +00:00
|
|
|
import { ReturnOrGeneratorYieldUnion } from '../mapped-types';
|
|
|
|
|
|
|
|
// `Thunks are functions that can be dispatched, similar to actions creators
|
|
|
|
export * from './thunks';
|
2022-06-10 16:33:15 +00:00
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the checkout status to `idle`
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setIdle = () => ( {
|
|
|
|
type: types.SET_IDLE,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the checkout status to `before_processing`
|
|
|
|
*/
|
|
|
|
export const setBeforeProcessing = () => ( {
|
|
|
|
type: types.SET_BEFORE_PROCESSING,
|
2022-06-10 16:33:15 +00:00
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the checkout status to `processing`
|
|
|
|
*/
|
|
|
|
export const setProcessing = () => ( {
|
|
|
|
type: types.SET_PROCESSING,
|
2022-06-10 16:33:15 +00:00
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the checkout status to `after_processing`
|
|
|
|
*/
|
|
|
|
export const setAfterProcessing = () => ( {
|
|
|
|
type: types.SET_AFTER_PROCESSING,
|
2022-06-10 16:33:15 +00:00
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the checkout status to `complete`
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setComplete = ( data: Record< string, unknown > = {} ) => ( {
|
|
|
|
type: types.SET_COMPLETE,
|
|
|
|
data,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the url to redirect to after checkout completes`
|
|
|
|
*
|
|
|
|
* @param redirectUrl the url to redirect to
|
|
|
|
*/
|
|
|
|
export const setRedirectUrl = ( redirectUrl: string ) => ( {
|
|
|
|
type: types.SET_REDIRECT_URL,
|
|
|
|
redirectUrl,
|
2022-06-10 16:33:15 +00:00
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Store the result of the payment attempt from the /checkout StoreApi call
|
|
|
|
*
|
|
|
|
* @param data The result of the payment attempt through the StoreApi /checkout endpoints
|
|
|
|
*/
|
|
|
|
export const setPaymentResult = ( data: PaymentResult ) => ( {
|
|
|
|
type: types.SET_PAYMENT_RESULT,
|
|
|
|
data,
|
2022-06-10 16:33:15 +00:00
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set whether the checkout has an error or not
|
|
|
|
*
|
|
|
|
* @param hasError Wether the checkout has an error or not
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setHasError = ( hasError = true ) => ( {
|
|
|
|
type: types.SET_HAS_ERROR,
|
|
|
|
hasError,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Used when any of the totals, taxes, shipping, etc need to be calculated, the `calculatingCount` will be increased
|
|
|
|
* A `calculatingCount` of 0 means nothing is being updated.
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const incrementCalculating = () => ( {
|
|
|
|
type: types.INCREMENT_CALCULATING,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* When any of the totals, taxes, shipping, etc are done beign calculated, the `calculatingCount` will be decreased
|
|
|
|
* A `calculatingCount` of 0 means nothing is being updated.
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const decrementCalculating = () => ( {
|
|
|
|
type: types.DECREMENT_CALCULATING,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the customer id
|
|
|
|
*
|
|
|
|
* @param customerId ID of the customer who is checking out.
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setCustomerId = ( customerId: number ) => ( {
|
|
|
|
type: types.SET_CUSTOMER_ID,
|
|
|
|
customerId,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Whether to use the shipping address as the billing address
|
|
|
|
*
|
|
|
|
* @param useShippingAsBilling True if shipping address should be the same as billing, false otherwise
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setUseShippingAsBilling = ( useShippingAsBilling: boolean ) => ( {
|
|
|
|
type: types.SET_SHIPPING_ADDRESS_AS_BILLING_ADDRESS,
|
|
|
|
useShippingAsBilling,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Whether an account should be created for the user while checking out
|
|
|
|
*
|
|
|
|
* @param shouldCreateAccount True if an account should be created, false otherwise
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setShouldCreateAccount = ( shouldCreateAccount: boolean ) => ( {
|
|
|
|
type: types.SET_SHOULD_CREATE_ACCOUNT,
|
|
|
|
shouldCreateAccount,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Set the notes for the order
|
|
|
|
*
|
|
|
|
* @param orderNotes String that represents a note for the order
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setOrderNotes = ( orderNotes: string ) => ( {
|
|
|
|
type: types.SET_ORDER_NOTES,
|
|
|
|
orderNotes,
|
|
|
|
} );
|
|
|
|
|
2022-09-30 14:34:14 +00:00
|
|
|
/**
|
|
|
|
* Register some extra data for an extension.
|
|
|
|
*
|
|
|
|
* @param extensionData An object containing the data to register for an extension
|
|
|
|
*/
|
2022-06-10 16:33:15 +00:00
|
|
|
export const setExtensionData = (
|
|
|
|
extensionData: Record< string, Record< string, unknown > >
|
|
|
|
) => ( {
|
|
|
|
type: types.SET_EXTENSION_DATA,
|
|
|
|
extensionData,
|
|
|
|
} );
|
|
|
|
|
2022-09-22 15:43:48 +00:00
|
|
|
export type CheckoutAction =
|
|
|
|
| ReturnOrGeneratorYieldUnion<
|
|
|
|
| typeof setIdle
|
|
|
|
| typeof setComplete
|
|
|
|
| typeof setProcessing
|
2022-09-30 14:34:14 +00:00
|
|
|
| typeof setPaymentResult
|
2022-09-22 15:43:48 +00:00
|
|
|
| typeof setBeforeProcessing
|
|
|
|
| typeof setAfterProcessing
|
|
|
|
| typeof setRedirectUrl
|
|
|
|
| typeof setHasError
|
|
|
|
| typeof incrementCalculating
|
|
|
|
| typeof decrementCalculating
|
|
|
|
| typeof setCustomerId
|
|
|
|
| typeof setUseShippingAsBilling
|
|
|
|
| typeof setShouldCreateAccount
|
|
|
|
| typeof setOrderNotes
|
|
|
|
| typeof setExtensionData
|
|
|
|
>
|
|
|
|
| Record< string, never >;
|