woocommerce/plugins/woocommerce-blocks/assets/js/base/context/cart-checkout/payment-methods/constants.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

/**
* @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',
};
export const ACTION_TYPES = {
...STATUS,
SET_REGISTERED_PAYMENT_METHODS: 'set_registered_payment_methods',
SET_REGISTERED_EXPRESS_PAYMENT_METHODS:
'set_registered_express_payment_methods',
Allow shopper to save Stripe payment method in user account for subsequent purchases (https://github.com/woocommerce/woocommerce-blocks/pull/2453) * always default "save my card for next time" checkbox to unchecked: This is based on the previous checkout behaviour. I.e. the shopper has to actively opt-in to save their card. * Implement "save payment method for next purchase" in checkout: - send "save card" option using existing post key - wc-stripe-new-payment-method - comment out inappropriate use of "save" when using a saved card (tbc) * don't hard code the payment gateway name in 'save payment method' key * refactor "save payment info" checkbox so payment methods can opt-in: - Add options.allowSavePaymentToken to payment method registration / config. - Opt-in in Stripe CC, it allows saved cards. - Remove render of "save my card" checkbox from Stripe CC UI component. - Render "save my card" checkbox automatically in payment method tab (based on allowSavePaymentToken option). + todo/follow up comments * rejig "save my payment method" behaviour so it's generic: - Any payment method that supports "save" can opt-in: - options.allowSavePaymentToken = true/false - handle `wc-XXX-new-payment-method` key server side to persist - Add support in payment context/state reducer for storing checkbox state, expose value and action via context - Convert state flag to appropriate API key/value in payment processor - Remove previous stripe-specific implementation + bonus add comment to payment context about preserving state in PRISTINE action * rename payment method "allow save" option, more consistent with UI * remove last vestiges of gateway-specific "save card" impl: - No need to pass CheckboxControl to payment methods; checkbox is now handled automatically by checkout. - Remove shouldSavePayment prop passing through various layers of stripe payment processing code. (Now handled in context/processor.) * change new option property name and shape. Also adds validation. * update type-defs * use more reliable `activePaymentMethod` for saved payment method Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2020-05-12 15:12:28 +00:00
SET_SHOULD_SAVE_PAYMENT_METHOD: 'set_should_save_payment_method',
};
/**
* @todo do typedefs for the payment event state.
*/
Allow shopper to save Stripe payment method in user account for subsequent purchases (https://github.com/woocommerce/woocommerce-blocks/pull/2453) * always default "save my card for next time" checkbox to unchecked: This is based on the previous checkout behaviour. I.e. the shopper has to actively opt-in to save their card. * Implement "save payment method for next purchase" in checkout: - send "save card" option using existing post key - wc-stripe-new-payment-method - comment out inappropriate use of "save" when using a saved card (tbc) * don't hard code the payment gateway name in 'save payment method' key * refactor "save payment info" checkbox so payment methods can opt-in: - Add options.allowSavePaymentToken to payment method registration / config. - Opt-in in Stripe CC, it allows saved cards. - Remove render of "save my card" checkbox from Stripe CC UI component. - Render "save my card" checkbox automatically in payment method tab (based on allowSavePaymentToken option). + todo/follow up comments * rejig "save my payment method" behaviour so it's generic: - Any payment method that supports "save" can opt-in: - options.allowSavePaymentToken = true/false - handle `wc-XXX-new-payment-method` key server side to persist - Add support in payment context/state reducer for storing checkbox state, expose value and action via context - Convert state flag to appropriate API key/value in payment processor - Remove previous stripe-specific implementation + bonus add comment to payment context about preserving state in PRISTINE action * rename payment method "allow save" option, more consistent with UI * remove last vestiges of gateway-specific "save card" impl: - No need to pass CheckboxControl to payment methods; checkbox is now handled automatically by checkout. - Remove shouldSavePayment prop passing through various layers of stripe payment processing code. (Now handled in context/processor.) * change new option property name and shape. Also adds validation. * update type-defs * use more reliable `activePaymentMethod` for saved payment method Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
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.
export const DEFAULT_PAYMENT_DATA = {
currentStatus: STATUS.PRISTINE,
Allow shopper to save Stripe payment method in user account for subsequent purchases (https://github.com/woocommerce/woocommerce-blocks/pull/2453) * always default "save my card for next time" checkbox to unchecked: This is based on the previous checkout behaviour. I.e. the shopper has to actively opt-in to save their card. * Implement "save payment method for next purchase" in checkout: - send "save card" option using existing post key - wc-stripe-new-payment-method - comment out inappropriate use of "save" when using a saved card (tbc) * don't hard code the payment gateway name in 'save payment method' key * refactor "save payment info" checkbox so payment methods can opt-in: - Add options.allowSavePaymentToken to payment method registration / config. - Opt-in in Stripe CC, it allows saved cards. - Remove render of "save my card" checkbox from Stripe CC UI component. - Render "save my card" checkbox automatically in payment method tab (based on allowSavePaymentToken option). + todo/follow up comments * rejig "save my payment method" behaviour so it's generic: - Any payment method that supports "save" can opt-in: - options.allowSavePaymentToken = true/false - handle `wc-XXX-new-payment-method` key server side to persist - Add support in payment context/state reducer for storing checkbox state, expose value and action via context - Convert state flag to appropriate API key/value in payment processor - Remove previous stripe-specific implementation + bonus add comment to payment context about preserving state in PRISTINE action * rename payment method "allow save" option, more consistent with UI * remove last vestiges of gateway-specific "save card" impl: - No need to pass CheckboxControl to payment methods; checkbox is now handled automatically by checkout. - Remove shouldSavePayment prop passing through various layers of stripe payment processing code. (Now handled in context/processor.) * change new option property name and shape. Also adds validation. * update type-defs * use more reliable `activePaymentMethod` for saved payment method Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2020-05-12 15:12:28 +00:00
shouldSavePaymentMethod: false,
paymentMethodData: {
payment_method: '',
// arbitrary data the payment method
// wants to pass along for payment
// processing server side.
},
hasSavedToken: false,
errorMessage: '',
paymentMethods: {},
expressPaymentMethods: {},
};
/**
* @type {PaymentMethodDataContext}
*/
export const DEFAULT_PAYMENT_METHOD_DATA = {
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 ],
} ),
currentStatus: {
isPristine: true,
isStarted: false,
isProcessing: false,
isFinished: false,
hasError: false,
hasFailed: false,
isSuccessful: false,
},
paymentStatuses: STATUS,
paymentMethodData: {},
errorMessage: '',
activePaymentMethod: '',
setActivePaymentMethod: () => void null,
customerPaymentMethods: {},
paymentMethods: {},
expressPaymentMethods: {},
paymentMethodsInitialized: false,
expressPaymentMethodsInitialized: false,
onPaymentProcessing: () => void null,
onPaymentSuccess: () => void null,
onPaymentFail: () => void null,
};