2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-03-26 11:11:46 +00:00
|
|
|
import { ACTION_TYPES } from './constants';
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
/**
|
2020-03-23 20:13:41 +00:00
|
|
|
* @typedef {import('@woocommerce/type-defs/cart').CartBillingData} CartBillingData
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-26 11:11:46 +00:00
|
|
|
const {
|
|
|
|
ERROR,
|
|
|
|
FAILED,
|
|
|
|
SUCCESS,
|
2020-04-14 22:44:31 +00:00
|
|
|
SET_REGISTERED_PAYMENT_METHODS,
|
|
|
|
SET_REGISTERED_EXPRESS_PAYMENT_METHODS,
|
2020-05-12 15:12:28 +00:00
|
|
|
SET_SHOULD_SAVE_PAYMENT_METHOD,
|
2020-03-26 11:11:46 +00:00
|
|
|
} = ACTION_TYPES;
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch a status update only for the given type.
|
|
|
|
*
|
2020-03-13 13:41:59 +00:00
|
|
|
* @param {string} type
|
2020-03-10 13:39:21 +00:00
|
|
|
*
|
|
|
|
* @return {Object} The action object.
|
|
|
|
*/
|
|
|
|
export const statusOnly = ( type ) => ( { type } );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch an error message along with setting current payment status
|
|
|
|
* to ERROR.
|
|
|
|
*
|
|
|
|
* @param {string} errorMessage Whatever error message accompanying the error
|
|
|
|
* condition.
|
|
|
|
*
|
|
|
|
* @return {Object} The action object.
|
|
|
|
*/
|
|
|
|
export const error = ( errorMessage ) => ( {
|
|
|
|
type: ERROR,
|
|
|
|
errorMessage,
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch a payment failed status update.
|
|
|
|
*
|
|
|
|
* @param {Object} action Incoming data for the
|
|
|
|
* action.
|
|
|
|
* @param {string} action.errorMessage Any message accompanying
|
|
|
|
* the failed payment.
|
|
|
|
* @param {Object} action.paymentMethodData Arbitrary extra
|
|
|
|
* information about the
|
|
|
|
* payment method in use
|
|
|
|
* (varies per payment
|
|
|
|
* method).
|
|
|
|
*
|
|
|
|
* @return {Object} An action object.
|
|
|
|
*/
|
2020-03-26 13:31:09 +00:00
|
|
|
export const failed = ( { errorMessage, paymentMethodData } ) => ( {
|
2020-03-10 13:39:21 +00:00
|
|
|
type: FAILED,
|
|
|
|
errorMessage,
|
|
|
|
paymentMethodData,
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch a payment success status update.
|
|
|
|
*
|
|
|
|
* @param {Object} action Incoming data for the
|
|
|
|
* action.
|
|
|
|
* @param {Object} action.paymentMethodData Arbitrary extra
|
|
|
|
* information about the
|
|
|
|
* payment method in use
|
|
|
|
* (varies per payment
|
|
|
|
* method).
|
|
|
|
*
|
|
|
|
* @return {Object} An action object.
|
|
|
|
*/
|
2020-03-26 13:31:09 +00:00
|
|
|
export const success = ( { paymentMethodData } ) => ( {
|
2020-03-10 13:39:21 +00:00
|
|
|
type: SUCCESS,
|
|
|
|
paymentMethodData,
|
|
|
|
} );
|
2020-03-26 11:11:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch an action for updating a registered payment method in the
|
|
|
|
* state.
|
|
|
|
*
|
2020-04-14 22:44:31 +00:00
|
|
|
* @param {Object} paymentMethods Payment methods to register.
|
2020-03-26 11:11:46 +00:00
|
|
|
* @return {Object} An action object.
|
|
|
|
*/
|
2020-04-14 22:44:31 +00:00
|
|
|
export const setRegisteredPaymentMethods = ( paymentMethods ) => ( {
|
|
|
|
type: SET_REGISTERED_PAYMENT_METHODS,
|
|
|
|
paymentMethods,
|
2020-03-26 11:11:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch an action for updating a registered express payment
|
|
|
|
* method in the state.
|
|
|
|
*
|
2020-04-14 22:44:31 +00:00
|
|
|
* @param {Object} paymentMethods Payment methods to register.
|
2020-03-26 11:11:46 +00:00
|
|
|
* @return {Object} An action object.
|
|
|
|
*/
|
2020-04-14 22:44:31 +00:00
|
|
|
export const setRegisteredExpressPaymentMethods = ( paymentMethods ) => ( {
|
|
|
|
type: SET_REGISTERED_EXPRESS_PAYMENT_METHODS,
|
|
|
|
paymentMethods,
|
2020-03-26 11:11:46 +00:00
|
|
|
} );
|
2020-05-12 15:12:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a flag indicating that the payment method info (e.g. a payment card)
|
|
|
|
* should be saved to user account after order completion.
|
|
|
|
*
|
|
|
|
* @param {boolean} shouldSavePaymentMethod
|
|
|
|
* @return {Object} An action object.
|
|
|
|
*/
|
|
|
|
export const setShouldSavePaymentMethod = ( shouldSavePaymentMethod ) => ( {
|
|
|
|
type: SET_SHOULD_SAVE_PAYMENT_METHOD,
|
|
|
|
shouldSavePaymentMethod,
|
|
|
|
} );
|