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-05-12 15:12:28 +00:00
|
|
|
SET_SHOULD_SAVE_PAYMENT_METHOD: 'set_should_save_payment_method',
|
2020-03-26 11:11:46 +00:00
|
|
|
};
|
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* @todo do typedefs for the payment event state.
|
|
|
|
*/
|
|
|
|
|
2020-05-12 15:12:28 +00:00
|
|
|
// Note - if fields are added/shape is changed, you may want to update
|
|
|
|
// PRISTINE reducer clause to preserve your new field.
|
2020-03-10 13:39:21 +00:00
|
|
|
export const DEFAULT_PAYMENT_DATA = {
|
|
|
|
currentStatus: STATUS.PRISTINE,
|
2020-05-12 15:12:28 +00:00
|
|
|
shouldSavePaymentMethod: false,
|
2020-03-10 13:39:21 +00:00
|
|
|
paymentMethodData: {
|
|
|
|
payment_method: '',
|
|
|
|
// arbitrary data the payment method
|
|
|
|
// wants to pass along for payment
|
|
|
|
// processing server side.
|
|
|
|
},
|
2020-06-07 20:47:16 +00:00
|
|
|
hasSavedToken: false,
|
2020-03-10 13:39:21 +00:00
|
|
|
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
|
|
|
};
|