2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* @typedef {import('@woocommerce/type-defs/contexts').PaymentMethodDataContext} PaymentMethodDataContext
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const STATUS = {
|
|
|
|
PRISTINE: 'pristine',
|
|
|
|
STARTED: 'started',
|
|
|
|
PROCESSING: 'processing',
|
|
|
|
ERROR: 'has_error',
|
|
|
|
FAILED: 'failed',
|
|
|
|
SUCCESS: 'success',
|
|
|
|
COMPLETE: 'complete',
|
|
|
|
};
|
|
|
|
|
2020-03-26 11:11:46 +00:00
|
|
|
export const ACTION_TYPES = {
|
|
|
|
...STATUS,
|
2020-04-14 22:44:31 +00:00
|
|
|
SET_REGISTERED_PAYMENT_METHODS: 'set_registered_payment_methods',
|
|
|
|
SET_REGISTERED_EXPRESS_PAYMENT_METHODS:
|
|
|
|
'set_registered_express_payment_methods',
|
2020-03-26 11:11:46 +00:00
|
|
|
};
|
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* @todo do typedefs for the payment event state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const DEFAULT_PAYMENT_DATA = {
|
|
|
|
currentStatus: STATUS.PRISTINE,
|
|
|
|
paymentMethodData: {
|
|
|
|
payment_method: '',
|
|
|
|
// arbitrary data the payment method
|
|
|
|
// wants to pass along for payment
|
|
|
|
// processing server side.
|
|
|
|
},
|
|
|
|
errorMessage: '',
|
2020-03-26 11:11:46 +00:00
|
|
|
paymentMethods: {},
|
|
|
|
expressPaymentMethods: {},
|
2020-03-10 13:39:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {PaymentMethodDataContext}
|
|
|
|
*/
|
|
|
|
export const DEFAULT_PAYMENT_METHOD_DATA = {
|
2020-04-03 11:50:54 +00:00
|
|
|
setPaymentStatus: () => ( {
|
|
|
|
started: () => void null,
|
|
|
|
processing: () => void null,
|
|
|
|
completed: () => void null,
|
|
|
|
error: ( errorMessage ) => void errorMessage,
|
|
|
|
failed: ( errorMessage, paymentMethodData ) =>
|
|
|
|
void [ errorMessage, paymentMethodData ],
|
|
|
|
success: ( paymentMethodData, billingData ) =>
|
|
|
|
void [ paymentMethodData, billingData ],
|
|
|
|
} ),
|
2020-03-10 13:39:21 +00:00
|
|
|
currentStatus: {
|
|
|
|
isPristine: true,
|
|
|
|
isStarted: false,
|
|
|
|
isProcessing: false,
|
|
|
|
isFinished: false,
|
|
|
|
hasError: false,
|
|
|
|
hasFailed: false,
|
|
|
|
isSuccessful: false,
|
|
|
|
},
|
|
|
|
paymentStatuses: STATUS,
|
|
|
|
paymentMethodData: {},
|
|
|
|
errorMessage: '',
|
|
|
|
activePaymentMethod: '',
|
|
|
|
setActivePaymentMethod: () => void null,
|
2020-03-26 11:11:46 +00:00
|
|
|
customerPaymentMethods: {},
|
|
|
|
paymentMethods: {},
|
|
|
|
expressPaymentMethods: {},
|
|
|
|
paymentMethodsInitialized: false,
|
|
|
|
expressPaymentMethodsInitialized: false,
|
2020-04-03 11:50:54 +00:00
|
|
|
onPaymentProcessing: () => void null,
|
|
|
|
onPaymentSuccess: () => void null,
|
|
|
|
onPaymentFail: () => void null,
|
2020-03-10 13:39:21 +00:00
|
|
|
};
|