admin-views
1 week ago
bootstrap.php
1 week ago
error.php
1 week ago
extensions.php
1 week ago
modules.php
1 week ago
services.php
1 week ago
error.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | // phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType |
| 4 | declare (strict_types=1); |
| 5 | namespace Syde\Vendor\Worldline; |
| 6 | |
| 7 | use Syde\Vendor\Worldline\Dhii\Validation\Exception\ValidationFailedExceptionInterface; |
| 8 | return (static function () : callable { |
| 9 | /** |
| 10 | * @psalm-suppress MissingClosureParamType |
| 11 | */ |
| 12 | $formatValidationError = static function ($error) : string { |
| 13 | if ($error instanceof \Throwable) { |
| 14 | return $error->getMessage(); |
| 15 | } |
| 16 | return (string) $error; |
| 17 | }; |
| 18 | return static function (\Throwable $exception) use($formatValidationError) : void { |
| 19 | $message = $exception->getMessage(); |
| 20 | if ($exception instanceof ValidationFailedExceptionInterface) { |
| 21 | $errors = []; |
| 22 | foreach ($exception->getValidationErrors() as $validationError) { |
| 23 | $errors[] = $formatValidationError($validationError); |
| 24 | } |
| 25 | $message .= '</br>' . \implode('</br>', $errors); |
| 26 | } |
| 27 | \add_action('all_admin_notices', static function () use($message) { |
| 28 | $class = 'notice notice-error'; |
| 29 | \printf('<div class="%1$s"><h4>%2$s</h4><p>%3$s</p></div>', \esc_attr($class), \esc_html__('Worldline payments failed to initialize', 'worldline-for-woocommerce'), \wp_kses_post($message)); |
| 30 | }); |
| 31 | }; |
| 32 | })(); |
| 33 |