From 882b385ab7743357e135b2a8077340d4db236715 Mon Sep 17 00:00:00 2001 From: Miguel Gasca Date: Thu, 2 Nov 2023 16:45:20 +0100 Subject: [PATCH] Avoid returning Stripe error message when capturing more than order amount (#7581) --- ...sage-when-capturing-more-than-order-amount | 4 +++ includes/class-wc-payments.php | 1 + .../class-amount-too-large-exception.php | 26 +++++++++++++++++++ .../class-wc-payments-api-client.php | 15 ++++++++++- 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 changelog/update-7029-avoid-returning-stripe-error-message-when-capturing-more-than-order-amount create mode 100644 includes/exceptions/class-amount-too-large-exception.php diff --git a/changelog/update-7029-avoid-returning-stripe-error-message-when-capturing-more-than-order-amount b/changelog/update-7029-avoid-returning-stripe-error-message-when-capturing-more-than-order-amount new file mode 100644 index 00000000000..115c831ebfe --- /dev/null +++ b/changelog/update-7029-avoid-returning-stripe-error-message-when-capturing-more-than-order-amount @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Redact Stripe support contact prompt from error message when capturing amounts greater than authorized. diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index b0ba6bc201a..a167138b7b2 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -417,6 +417,7 @@ public static function init() { include_once __DIR__ . '/class-wc-payments-woopay-button-handler.php'; include_once __DIR__ . '/class-wc-payments-apple-pay-registration.php'; include_once __DIR__ . '/exceptions/class-add-payment-method-exception.php'; + include_once __DIR__ . '/exceptions/class-amount-too-large-exception.php'; include_once __DIR__ . '/exceptions/class-amount-too-small-exception.php'; include_once __DIR__ . '/exceptions/class-intent-authentication-exception.php'; include_once __DIR__ . '/exceptions/class-invalid-payment-method-exception.php'; diff --git a/includes/exceptions/class-amount-too-large-exception.php b/includes/exceptions/class-amount-too-large-exception.php new file mode 100644 index 00000000000..ae6e9b7df4c --- /dev/null +++ b/includes/exceptions/class-amount-too-large-exception.php @@ -0,0 +1,26 @@ +maybe_act_on_fraud_prevention( $decline_code ); - $error_code = $response_body['error']['code'] ?? $response_body['error']['type'] ?? null; + $error_code = $response_body_error_code ?? $response_body['error']['type'] ?? null; $error_message = $response_body['error']['message'] ?? null; $error_type = $response_body['error']['type'] ?? null; } elseif ( isset( $response_body['code'] ) ) {