2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { STATUS } from './constants';
|
|
|
|
|
|
|
|
/**
|
2020-03-23 20:13:41 +00:00
|
|
|
* @typedef {import('@woocommerce/type-defs/cart').CartBillingData} CartBillingData
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const { ERROR, FAILED, SUCCESS } = STATUS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2020-03-23 20:13:41 +00:00
|
|
|
* @param {CartBillingData} action.billingData Billing data used for
|
2020-03-10 13:39:21 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
export const failed = ( {
|
|
|
|
errorMessage,
|
|
|
|
billingData,
|
|
|
|
paymentMethodData,
|
|
|
|
} ) => ( {
|
|
|
|
type: FAILED,
|
|
|
|
errorMessage,
|
|
|
|
billingData,
|
|
|
|
paymentMethodData,
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch a payment success status update.
|
|
|
|
*
|
|
|
|
* @param {Object} action Incoming data for the
|
|
|
|
* action.
|
2020-03-23 20:13:41 +00:00
|
|
|
* @param {CartBillingData} action.billingData Billing data used for
|
2020-03-10 13:39:21 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
export const success = ( { billingData, paymentMethodData } ) => ( {
|
|
|
|
type: SUCCESS,
|
|
|
|
billingData,
|
|
|
|
paymentMethodData,
|
|
|
|
} );
|