2020-04-15 15:15:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
|
2022-11-17 13:33:58 +00:00
|
|
|
import { StoreNoticesContainer } from '@woocommerce/blocks-checkout';
|
2022-12-19 15:30:13 +00:00
|
|
|
import { noticeContexts } from '@woocommerce/base-context';
|
2020-04-15 15:15:56 +00:00
|
|
|
|
|
|
|
class PaymentMethodErrorBoundary extends Component {
|
|
|
|
state = { errorMessage: '', hasError: false };
|
|
|
|
|
|
|
|
static getDerivedStateFromError( error ) {
|
|
|
|
return {
|
|
|
|
errorMessage: error.message,
|
|
|
|
hasError: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { hasError, errorMessage } = this.state;
|
|
|
|
const { isEditor } = this.props;
|
|
|
|
|
|
|
|
if ( hasError ) {
|
|
|
|
let errorText = __(
|
2022-09-12 08:39:26 +00:00
|
|
|
'We are experiencing difficulties with this payment method. Please contact us for assistance.',
|
2020-04-15 15:15:56 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
);
|
|
|
|
if ( isEditor || CURRENT_USER_IS_ADMIN ) {
|
|
|
|
if ( errorMessage ) {
|
|
|
|
errorText = errorMessage;
|
|
|
|
} else {
|
|
|
|
errorText = __(
|
|
|
|
"There was an error with this payment method. Please verify it's configured correctly.",
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 10:27:54 +00:00
|
|
|
const notices = [
|
|
|
|
{
|
|
|
|
id: '0',
|
|
|
|
content: errorText,
|
|
|
|
isDismissible: false,
|
|
|
|
status: 'error',
|
|
|
|
},
|
|
|
|
];
|
2022-04-08 12:11:50 +00:00
|
|
|
return (
|
|
|
|
<StoreNoticesContainer
|
|
|
|
additionalNotices={ notices }
|
|
|
|
context={ noticeContexts.PAYMENTS }
|
|
|
|
/>
|
|
|
|
);
|
2020-04-15 15:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PaymentMethodErrorBoundary.propTypes = {
|
|
|
|
isEditor: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
PaymentMethodErrorBoundary.defaultProps = {
|
|
|
|
isEditor: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentMethodErrorBoundary;
|