Extract error message

This commit is contained in:
Alex P 2022-07-12 21:19:21 +03:00
parent 81c786150d
commit 0ce3af03c3
3 changed files with 30 additions and 3 deletions

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Exception;
use Exception;
use Throwable;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\Messages;
/**
* Class GatewayGenericException
@ -23,7 +24,7 @@ class GatewayGenericException extends Exception {
*/
public function __construct( ?Throwable $inner = null ) {
parent::__construct(
__( 'Failed to process the payment. Please try again or contact the shop admin.', 'woocommerce-paypal-payments' ),
Messages::generic_payment_error_message(),
$inner ? (int) $inner->getCode() : 0,
$inner
);

View file

@ -0,0 +1,27 @@
<?php
/**
* Common messages.
*
* @package WooCommerce\PayPalCommerce\WcGateway\Gateway
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
/**
* Class Messages
*/
class Messages {
/**
* The generic payment failure message.
*
* @return string
*/
public static function generic_payment_error_message(): string {
return apply_filters(
'woocommerce_paypal_payments_generic_payment_error_message',
__( 'Failed to process the payment. Please try again or contact the shop admin.', 'woocommerce-paypal-payments' )
);
}
}

View file

@ -232,8 +232,7 @@ trait ProcessPaymentTrait {
return $this->handle_payment_failure(
$wc_order,
new Exception(
__( 'Failed to process the payment. Please try again or contact the shop admin.', 'woocommerce-paypal-payments' )
. ' ' . $error->getMessage(),
Messages::generic_payment_error_message() . ' ' . $error->getMessage(),
$error->getCode(),
$error
)